message
stringlengths
2
20.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
1.95k
109k
cluster
float64
17
17
__index_level_0__
int64
3.91k
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` teams = int(input()) localColors = [] guestColors = [] changes =0 for i in range(teams): teami = [int(i) for i in str(input()).split()] localColors.append(teami[0]) guestColors.append(teami[1]) for local in localColors: for guest in guestColors: if local == guest: changes += 1 print(changes) ```
instruction
0
57,405
17
114,810
Yes
output
1
57,405
17
114,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` n=int(input()) a=[] b=[] for i in range(n): x,y=map(int,input().split()) a.append(x) b.append(y) k=0 for i in range(n): for j in range(n): if a[i]==b[j]: k+=1 print(k) ```
instruction
0
57,406
17
114,812
Yes
output
1
57,406
17
114,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` n = int(input()) l = [] for i in range(n): x, y = map(int, input().split()) l.append([x, y]) ans = 0 for i in range(n): for j in range(n): if i == j: continue if l[j][1] == l[i][0]: ans -= -1 print(ans) ```
instruction
0
57,407
17
114,814
Yes
output
1
57,407
17
114,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` al,bl,ans=[],[],0 for _ in range(int(input())): a,b=map(int,input().split()) al.append(a) bl.append(b) for i in range(len(bl)): c=al.count('b[i]') ans+=c print(ans) ```
instruction
0
57,408
17
114,816
No
output
1
57,408
17
114,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` home=[] guest=[] ncount=0 for i in range(int(input())): li=[int(x) for x in input().split()] home.append(li[0]) guest.append(li[1]) for x in home: if x in guest: ncount+=1 print(ncount) ```
instruction
0
57,409
17
114,818
No
output
1
57,409
17
114,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` x=int(input()) t=0 c=[] for i in range(x): c.append(input()) for i in range(x): if(c[i]=="Tetrahedron"): t=t+4 elif(c[i]=="Cube"): t=t+6 elif(c[i]=="Octahedron"): t=t+8 elif(c[i]=="Dodecahedron"): t=t+12 elif(c[i]=="Icosahedron"): t=t+20 print(t) ```
instruction
0
57,410
17
114,820
No
output
1
57,410
17
114,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. Input The first line contains an integer n (2 ≀ n ≀ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≀ hi, ai ≀ 100) β€” the colors of the i-th team's home and guest uniforms, respectively. Output In a single line print the number of games where the host team is going to play in the guest uniform. Examples Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 Note In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). Submitted Solution: ``` n=int(input()) l='' j=[] for i in range(n): n,m=[int(x) for x in input().split()] l=l+str(n)+' ' j.append(m) s=0 for i in j: if str(i) in l: s+=l.count(str(i)) print(s) ```
instruction
0
57,411
17
114,822
No
output
1
57,411
17
114,823
Provide tags and a correct Python 3 solution for this coding contest problem. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3.
instruction
0
58,138
17
116,276
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys import os input = sys.stdin.readline def sum1n(n): return (n*(n+1))//2 def count_max(n): k1 = n//2 k2 = n - k1 return 2*sum1n(n) - sum1n(k1) - sum1n(k2) n, k = map(int, input().split()) mn = n*(n+1) // 2 if k < mn: print(-1) else: mx = count_max(n) target = min(k, mx) os.write(1, (str(target)+"\n").encode()) a = [i for i in range(1, n+1)] b = [i for i in range(1, n+1)] cur = mn i = n-1 while cur != target: f = a[i] s = n+1-a[i] if f-s < target-cur: b[i], b[n-1-i] = b[n-1-i], b[i] cur += f-s i -= 1 else: j = a[i] - (target-cur) - 1 b[i], b[j] = b[j], b[i] cur = target os.write(1, (" ".join(map(str, a))+"\n").encode()) os.write(1, (" ".join(map(str, b))+"\n").encode()) ```
output
1
58,138
17
116,277
Provide tags and a correct Python 3 solution for this coding contest problem. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3.
instruction
0
58,139
17
116,278
Tags: constructive algorithms, greedy, math Correct Solution: ``` import sys import os input = sys.stdin.readline def sum1n(n): return (n*(n+1))//2 def count_max(n): k1 = n//2 k2 = n - k1 return 2*sum1n(n) - sum1n(k1) - sum1n(k2) n, k = map(int, input().split()) mn = n*(n+1) // 2 if k < mn: print(-1) else: mx = count_max(n) target = min(k, mx) os.write(1, (str(target)+"\n").encode()) a = [i for i in range(1, n+1)] b = [i for i in range(1, n+1)] cur = mn i = n-1 while cur != target: f = a[i] s = n+1-a[i] if f-s < target-cur: ## print(i) ## print(a) ## print(b) b[i], b[n-1-i] = b[n-1-i], b[i] cur += f-s i -= 1 else: j = a[i] - (target-cur) - 1 b[i], b[j] = b[j], b[i] cur = target os.write(1, (" ".join(map(str, a))+"\n").encode()) os.write(1, (" ".join(map(str, b))+"\n").encode()) ```
output
1
58,139
17
116,279
Provide tags and a correct Python 3 solution for this coding contest problem. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3.
instruction
0
58,140
17
116,280
Tags: constructive algorithms, greedy, math Correct Solution: ``` import os, sys try: fin = open('in') except: fin = sys.stdin input = fin.readline n, k = map(int, input().split()) l, h = 0, 0 for i in range(1, n + 1): l += i h += max(i, n - i + 1) if k < l: print (-1) elif k > h: os.write(1, ('{}\n{}\n{}'.format(h, ' '.join(map(str, range(1, n + 1))), ' '.join(map(str, range(n, 0, -1))))).encode()) else: d = k - l r = n ans = [i for i in range(n + 1)] for i in range(1, n + 1): p = min(r - i, d) ans[i], ans[i + p] = ans[i + p], ans[i] d -= p r -= 1 if d == 0: break os.write(1, ('{}\n{}\n{}'.format(k, ' '.join(map(str, range(1, n + 1))), ' '.join(map(str, ans[1:])))).encode()) ```
output
1
58,140
17
116,281
Provide tags and a correct Python 3 solution for this coding contest problem. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3.
instruction
0
58,141
17
116,282
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, t = [int(i) for i in input().split()] import os def tr(qq): return (qq*(qq+1))//2 if t < tr(n): print(-1) exit() upp = 2 * (tr(n) - tr(n//2)) if n % 2 == 1: upp -= (n+1)//2 if t >= upp: # print(upp) # exit() os.write(1, (str(upp) + '\n').encode()) ans = list(range(1, n+1)) # print(*ans) # for i in range(n//2): # ans[i] = n - i os.write(1, (' '.join([str(a) for a in ans]) + '\n').encode()) ans.reverse() # // print(*ans) os.write(1, (' '.join([str(a) for a in ans]) + '\n').encode()) exit() for k in range(n//2, n+1): goal = t - tr(n) + tr(k) - n lo = tr(k-1) hi = lo + (k-1)*(n-k) # print(goal, lo, hi) if goal >= lo and goal <= hi: #p q ex = goal - lo p = ex // (k-1) q = ex % (k-1) ansl = list(range(1 + p, k + p)) for i in range(q): ansl[k-2-i] += 1 ansls = set(ansl) ansr = [] for i in range(1, n): if i not in ansls: ansr.append(i) ans = ansl + [n] + ansr # print(t) os.write(1, (str(t) + '\n').encode()) # print(*list(range(1,n+1))) os.write(1, (' '.join([str(a) for a in range(1,n+1)]) + '\n').encode()) # // print(*ans) os.write(1, (' '.join([str(a) for a in ans]) + '\n').encode()) exit() 1//0 ```
output
1
58,141
17
116,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3. Submitted Solution: ``` # -*- coding: utf-8 -*- inm=input().split(' ') n,k=int(inm[0]), int(inm[1]) if(1+n)/2*n >=k: print(-1) else: mk=int((1+n)/2*n) m =int(k)-(1+n)/2*n outm = [s for s in range(1,n+1)] i=0 while m!=0 and i<int(n)/2 : if m>n-2*i-1: outm[i],outm[n-i-1]=outm[n-i-1],outm[i] m-=n-2*i-1 mk+=n-2*i-1 else: outm[i], outm[i+int(m)]= outm[i+int(m)],outm[i] mk+=int(m) m=0 i+=1 print(mk) print(outm) for x in range(1,n+1): print(x, end=" ") ```
instruction
0
58,142
17
116,284
No
output
1
58,142
17
116,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3. Submitted Solution: ``` import os, sys try: fin = open('in') except: fin = sys.stdin input = fin.readline n, k = map(int, input().split()) l, h = 0, 0 for i in range(1, n + 1): l += i h += max(i, n - i + 1) if k < l: print (-1) elif k > h: os.write(1, ('{}\n{}\n{}'.format(k, ' '.join(map(str, range(1, n + 1))), ' '.join(map(str, range(n, 0, -1))))).encode()) else: d = k - l r = n ans = [i for i in range(n + 1)] for i in range(1, n + 1): p = min(r - i, d) ans[i], ans[i + p] = ans[i + p], ans[i] d -= p r -= 1 if d == 0: break os.write(1, ('{}\n{}\n{}'.format(k, ' '.join(map(str, range(1, n + 1))), ' '.join(map(str, ans[1:])))).encode()) ```
instruction
0
58,143
17
116,286
No
output
1
58,143
17
116,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3. Submitted Solution: ``` inp1 = input() number, max_time = inp1.split() number = int(number) max_time = int(max_time) counter1 = 0 arr1=[i for i in range (1,number+1)] arr2=arr1 counter = sum(arr1) if (counter > max_time): print ('-1') elif (counter == max_time): print (counter) for i in range (number): print (arr1[i],end = " ") print() for i in range (number): print (arr2[i],end = " ") print() else : for i in range (number-1,0,-1): for p in range (counter1,i): if ( ( counter + (arr2[i]-arr1[p]) ) <= max_time and arr2[i] > arr2[p] ): counter = counter + (arr2[i]-arr1[p]) x = arr2[p] arr2[p] = arr2[i] arr2[i] = x counter1 = p + 1 break if (counter >= max_time): break print (counter) for i in range (number): print (arr1[i],end = " ") print() for i in range (number): print (arr2[i],end = " ") print() ```
instruction
0
58,144
17
116,288
No
output
1
58,144
17
116,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition! Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i seconds. The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all n pairs run through the track. The organizers want the run to be as long as possible, but if it lasts for more than k seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks). You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed k seconds. Formally, you want to find two permutations p and q (both consisting of n elements) such that sum = βˆ‘_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed k. If there is no such pair, report about it. Input The first line contains two integers n and k (1 ≀ n ≀ 10^6, 1 ≀ k ≀ n^2) β€” the number of runners on each track and the maximum possible duration of the competition, respectively. Output If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print -1. Otherwise, print three lines. The first line should contain one integer sum β€” the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p_1, p_2, ..., p_n (1 ≀ p_i ≀ n, all p_i should be pairwise distinct) β€” the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of n integers q_1, q_2, ..., q_n (1 ≀ q_i ≀ n, all q_i should be pairwise distinct) β€” the numbers of runners on the second track in the order they participate in the competition. The value of sum = βˆ‘_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them. Examples Input 5 20 Output 20 1 2 3 4 5 5 2 4 3 1 Input 3 9 Output 8 1 2 3 3 2 1 Input 10 54 Output -1 Note In the first example the order of runners on the first track should be [5, 3, 2, 1, 4], and the order of runners on the second track should be [1, 4, 2, 5, 3]. Then the duration of the competition is max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be [2, 3, 1], and the order of runners on the second track should be [2, 1, 3]. Then the duration of the competition is 8, and it is the maximum possible duration for n = 3. Submitted Solution: ``` def maxCount(x): if x % 2 == 0: return (x * (x + 1)) - (x // 2 * (x // 2 + 1)) else: return maxCount(x + 1) - x // 2 - 1 count, long = [int(x) for x in input().split()] minCount = (count * (count + 1)) / 2 if minCount > long: print(-1) else: x = 0 long = min(maxCount(count), long) prevMoveID = 0 lastMoveID = 0 res = list(range(1, count + 1)).copy() while long != x: prevMoveID += 1 res[prevMoveID], res[prevMoveID - 1] = res[prevMoveID - 1], res[prevMoveID] x = 0 for i in range(0, count): x += max(res[i], i) if (prevMoveID == count - lastMoveID - 1): prevMoveID = 0 lastMoveID += 1 if lastMoveID == count - 1: break print(x + 1) for i in res: print(i, end = ' ') print() for i in range(1, count + 1): print(i, end = ' ') ```
instruction
0
58,145
17
116,290
No
output
1
58,145
17
116,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≀ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. Input The single line of the input contains two integers n and m (1 ≀ n, m ≀ 100), separated by a space. Output Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them. Examples Input 3 3 Output GBGBGB Input 4 2 Output BGBGBB Note In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal. Submitted Solution: ``` with open('input.txt') as _f: n, m = map(int, _f.readline().split()) pref = 'BG' * min(n, m) if n >= m else 'GB' * min(n, m) if n != m: suff = 'B' * (n-m) if n > m else 'G' * (m-n) else: suff = '' with open('outpu.txt', 'w') as _f: _f.write(pref+suff) ```
instruction
0
58,312
17
116,624
No
output
1
58,312
17
116,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≀ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. Input The single line of the input contains two integers n and m (1 ≀ n, m ≀ 100), separated by a space. Output Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them. Examples Input 3 3 Output GBGBGB Input 4 2 Output BGBGBB Note In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal. Submitted Solution: ``` u, v = open('input.txt','r'), open('output.txt','w') b, g = map(int, u.readline().split()) v.write('BG' * b + 'G' * (g - b) if b < g else 'BG' * g + 'B' * (b - g)) v.close() ```
instruction
0
58,313
17
116,626
No
output
1
58,313
17
116,627
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boys and m girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to n + m. Then the number of integers i (1 ≀ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. Input The single line of the input contains two integers n and m (1 ≀ n, m ≀ 100), separated by a space. Output Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. If there are multiple optimal solutions, print any of them. Examples Input 3 3 Output GBGBGB Input 4 2 Output BGBGBB Note In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal. Submitted Solution: ``` (n, m) = map(int, open('input.txt').read().split(' ')) s = "" while n > 0 and m > 0: s += "BG" n -= 1 m -= 1 while n > 0: s += "B" n -= 1 while m > 0: s += "G" m -= 1 print(s) ```
instruction
0
58,314
17
116,628
No
output
1
58,314
17
116,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` # URL: http://codeforces.com/problemset/problem/489/B from typing import List, Tuple def parse_input() -> Tuple[int, List[int], int, List[int]]: return ( int(input()), [int(x) for x in input().split()], int(input()), [int(x) for x in input().split()] ) def solve(n: int, a: List[int], m: int, b: List[int]) -> int: a.sort() b.sort() a_ptr = 0 b_ptr = 0 pairs = 0 while a_ptr < n and b_ptr < m: d = abs(a[a_ptr] - b[b_ptr]) if a[a_ptr] < b[b_ptr] and d > 1: a_ptr += 1 elif b[b_ptr] < a[a_ptr] and d > 1: b_ptr += 1 elif d <= 1: a_ptr += 1 b_ptr += 1 pairs += 1 return pairs if __name__ == '__main__': n, a, m, b = parse_input() print(solve(n, a, m, b)) ```
instruction
0
58,413
17
116,826
Yes
output
1
58,413
17
116,827
Provide tags and a correct Python 3 solution for this coding contest problem. The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. Input The first line contains single integer n (1 ≀ n ≀ 105) β€” the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. Output In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" β€” is a string of digits and small English letters with length from 1 to 6. Examples Input 5 01 0 2 1 2extra 0 3 1 99 0 Output 4 move 3 1 move 01 5 move 2extra 4 move 99 3 Input 2 1 0 2 1 Output 3 move 1 3 move 2 1 move 3 2 Input 5 1 0 11 1 111 0 1111 1 11111 0 Output 5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3
instruction
0
58,588
17
117,176
Tags: greedy, implementation Correct Solution: ``` n = int(input()) t = [1] + [0] * n b, a = d = [], [] h, s = [], [] for i in range(n): f, k = input().split() d[int(k)].append(f) m = len(a) for i in a: if i.isdigit() and i[0] != '0': j = int(i) if 0 < j <= m: t[j] = 1 elif m < j <= n: t[j] = -1 else: s.append(i) else: s.append(i) for i in b: if i.isdigit() and i[0] != '0': j = int(i) if m < j <= n: t[j] = 1 elif 0 < j <= m: t[j] = -1 else: s.append(i) else: s.append(i) x = [j for j in range(1, m + 1) if t[j] < 0] y = [j for j in range(m + 1, n + 1) if t[j] < 0] u = [j for j in range(1, m + 1) if not t[j]] v = [j for j in range(m + 1, n + 1) if not t[j]] if not s and (x or y): s = ['0'] if y: i = y.pop() v.append(i) else: i = x.pop() u.append(i) h.append(str(i) + ' 0') t[i] = 0 while x or y: if v and x: i = x.pop() j = v.pop() t[j] = 1 h.append(str(i) + ' ' + str(j)) u.append(i) else: u, v, x, y = v, u, y, x k = 1 for j in s: while t[k] == 1: k += 1 h.append(j + ' ' + str(k)) k += 1 d = '\nmove ' print(str(len(h)) + d + d.join(h) if h else 0) ```
output
1
58,588
17
117,177
Provide tags and a correct Python 3 solution for this coding contest problem. The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. Input The first line contains single integer n (1 ≀ n ≀ 105) β€” the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. Output In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" β€” is a string of digits and small English letters with length from 1 to 6. Examples Input 5 01 0 2 1 2extra 0 3 1 99 0 Output 4 move 3 1 move 01 5 move 2extra 4 move 99 3 Input 2 1 0 2 1 Output 3 move 1 3 move 2 1 move 3 2 Input 5 1 0 11 1 111 0 1111 1 11111 0 Output 5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3
instruction
0
58,589
17
117,178
Tags: greedy, implementation Correct Solution: ``` def print_all(): print(top) print(free_top) print(busy_top) print(bottom) print(free_bottom) print(busy_bottom) n = int(input()) top = set() bottom = set() for i in range(n): name, type = input().split() if type == '1': top.add(name) else: bottom.add(name) top_order = set(str(i) for i in range(1, len(top) + 1)) bottom_order = set(str(i) for i in range(len(top) + 1, len(bottom) + len(top) + 1)) q = top_order & top top_order -= q top -= q q = bottom_order & bottom bottom_order -= q bottom -= q busy_top = top_order & bottom free_top = top_order - bottom busy_bottom = bottom_order & top free_bottom = bottom_order - top if len(top_order) + len(bottom_order) == 0: print(0) exit(0) if len(free_bottom) + len(free_top) == 0: x, y = busy_top.pop(), 'rft330' free_top.add(x) bottom.remove(x) bottom.add(y) print(len(top_order) + len(bottom_order) + 1) print('move', x, y) else: print(len(top_order) + len(bottom_order)) cross_block = min(len(busy_bottom), len(busy_top)) if len(free_top) > 0 and cross_block > 0: x = free_top.pop() for i in range(cross_block): x, y = busy_bottom.pop(), x top.remove(x) print('move', x, y) x, y = busy_top.pop(), x bottom.remove(x) print('move', x, y) free_top.add(x) cross_block = min(len(busy_bottom), len(busy_top)) if len(free_bottom) > 0 and cross_block > 0: x = free_bottom.pop() for i in range(cross_block): x, y = busy_top.pop(), x bottom.remove(x) print('move', x, y) x, y = busy_bottom.pop(), x top.remove(x) print('move', x, y) free_bottom.add(x) if len(busy_bottom) == 0: for i in range(len(bottom)): print('move', bottom.pop(), free_bottom.pop()) free_top |= busy_top busy_top.clear() for i in range(len(top)): print('move', top.pop(), free_top.pop()) elif len(busy_top) == 0: for i in range(len(top)): print('move', top.pop(), free_top.pop()) free_bottom |= busy_bottom busy_bottom.clear() for i in range(len(bottom)): print('move', bottom.pop(), free_bottom.pop()) ```
output
1
58,589
17
117,179
Provide tags and a correct Python 3 solution for this coding contest problem. The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. Input The first line contains single integer n (1 ≀ n ≀ 105) β€” the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. Output In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" β€” is a string of digits and small English letters with length from 1 to 6. Examples Input 5 01 0 2 1 2extra 0 3 1 99 0 Output 4 move 3 1 move 01 5 move 2extra 4 move 99 3 Input 2 1 0 2 1 Output 3 move 1 3 move 2 1 move 3 2 Input 5 1 0 11 1 111 0 1111 1 11111 0 Output 5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3
instruction
0
58,590
17
117,180
Tags: greedy, implementation Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): n = I() a = set() b = set() for _ in range(n): f,t = LS() if t == '0': b.add(f) else: a.add(f) al = len(a) bl = len(b) r = [] ta = set([str(i) for i in range(1,al+1)]) tb = set([str(i) for i in range(al+1,al+bl+1)]) bb = tb & b b -= bb tb -= bb aa = ta & a a -= aa ta -= aa ua = a & tb ub = b & ta sa = ta - b sb = tb - a ran = 'iehn00' while ua or ub: if not sa and not sb: if ua: t = ua.pop() sb.add(t) a.remove(t) a.add(ran) else: t = ub.pop() sa.add(t) b.remove(t) b.add(ran) r.append('move {} {}'.format(t, ran)) if sa: t = sa.pop() if ua: k = ua.pop() a.remove(k) sb.add(k) else: k = a.pop() ta.remove(t) r.append('move {} {}'.format(k, t)) if sb: t = sb.pop() if ub: k = ub.pop() b.remove(k) sa.add(k) else: k = b.pop() tb.remove(t) r.append('move {} {}'.format(k, t)) while a: k = a.pop() t = ta.pop() r.append('move {} {}'.format(k, t)) while b: k = b.pop() t = tb.pop() r.append('move {} {}'.format(k, t)) return '{}\n'.format(len(r)) + '\n'.join(r) print(main()) # Made By Mostafa_Khaled ```
output
1
58,590
17
117,181
Provide tags and a correct Python 3 solution for this coding contest problem. The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. Input The first line contains single integer n (1 ≀ n ≀ 105) β€” the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. Output In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" β€” is a string of digits and small English letters with length from 1 to 6. Examples Input 5 01 0 2 1 2extra 0 3 1 99 0 Output 4 move 3 1 move 01 5 move 2extra 4 move 99 3 Input 2 1 0 2 1 Output 3 move 1 3 move 2 1 move 3 2 Input 5 1 0 11 1 111 0 1111 1 11111 0 Output 5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3
instruction
0
58,591
17
117,182
Tags: greedy, implementation Correct Solution: ``` import random def genTemp(): sl = "" firstTime = True while firstTime or sl in pre or sl in post: sl = "" firstTime = False for i in range(6): sl += chr(random.randint(ord("a"), ord("z"))) return sl n = int(input()) e = 0 pre = set() post = set() for i in range(n): name, tp = input().split() if tp == "1": e += 1 pre.add(name) else: post.add(name) temp = genTemp() preAns = {str(x) for x in range(1, e + 1)} postAns = {str(x) for x in range(e + 1, n + 1)} preMissing = preAns - pre postMissing = postAns - post preToChange = pre - preAns postToChange = post - postAns preFree = preMissing - postToChange postFree = postMissing - preToChange preWrong = preToChange & postMissing postWrong = postToChange & preMissing ans = [] while preToChange or postToChange: if not postFree and not preFree: if preToChange: x = preToChange.pop() preWrong.discard(x) ans.append(("move", x, temp)) preToChange.add(temp) #postMissing.discard(x) if x in postAns: postFree.add(x) else: x = postToChange.pop() ans.append(("move", x, temp)) postWrong.discard(x) postToChange.add(temp) #preMissing.discard(x) if x in postAns: preFree.add(x) elif preFree: if preWrong: x = preWrong.pop() preToChange.discard(x) else: x = preToChange.pop() y = preFree.pop() ans.append(("move", x, y)) preMissing.discard(y) if x in postAns: postFree.add(x) else: if postWrong: x = postWrong.pop() postToChange.discard(x) else: x = postToChange.pop() y = postFree.pop() ans.append(("move", x, y)) postMissing.discard(y) if x in preAns: preFree.add(x) print(len(ans)) for tup in ans: print(*tup) ```
output
1
58,591
17
117,183
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,097
17
118,194
Tags: implementation Correct Solution: ``` class Player: def __init__(self, name, score): self.name = name self.score = score class Tier: def __init__(self, label, percentile): self.label = label self.percentile = percentile tier_data = [ ('pro', 99), ('hardcore', 90), ('average', 80), ('random', 50) ] tiers = [ Tier(*t) for t in tier_data ] num_records = int(input()) name_to_score = {} for i in range(num_records): tokens = input().split() name, score = tokens[0], int(tokens[1]) name_to_score[name] = max(name_to_score.setdefault(name, 0), score) num_players = len(name_to_score) players = [] for name, score in name_to_score.items(): players.append(Player(name, score)) players.sort(key = lambda player: player.score) print(num_players) pos = num_players - 1 while pos >= 0: player = players[pos] rank = 'noob' score = player.score for tier in tiers: if 100 * (pos + 1) // num_players >= tier.percentile: rank = tier.label break print(player.name, rank) pos -= 1 while pos >= 0 and players[pos].score == score: print(players[pos].name, rank) pos -= 1 ```
output
1
59,097
17
118,195
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,098
17
118,196
Tags: implementation Correct Solution: ``` from collections import defaultdict n = int(input()) p = defaultdict(int) for i in range(n): a, b = input().split() p[a] = max(p[a], int(b)) b = sorted(p.values()) n = len(b) noob = b[(n - 1) // 2] random = b[n - 1 - n // 5] average = b[n - 1 - n // 10] hardcore = b[n - 1 - n // 100] for a in p: b = p[a] if b < noob: p[a] = 'noob' elif b < random: p[a] = 'random' elif b < average: p[a] = 'average' elif b < hardcore: p[a] = 'hardcore' else: p[a] = 'pro' print(n + 1) print('\n'.join(a + ' ' + b for a, b in p.items())) ```
output
1
59,098
17
118,197
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,099
17
118,198
Tags: implementation Correct Solution: ``` from collections import defaultdict R = lambda: map(int, input().split()) n = int(input()) mp = defaultdict(int) for i in range(n): name, sc = input().split() sc = int(sc) mp[name] = max(sc, mp[name]) players = sorted([(k, v) for k, v in mp.items()], key=lambda x: x[1]) print(len(players)) j = 0 for i, playerAndScore in enumerate(players): player, score = playerAndScore while j < len(players) and players[j][1] <= score: j += 1 if j / len(players) < 0.5: print(' '.join([player, 'noob'])) elif 0.5 <= j / len(players) < 0.8: print(' '.join([player, 'random'])) elif 0.8 <= j / len(players) < 0.9: print(' '.join([player, 'average'])) elif 0.9 <= j / len(players) < 0.99: print(' '.join([player, 'hardcore'])) else: print(' '.join([player, 'pro'])) ```
output
1
59,099
17
118,199
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,100
17
118,200
Tags: implementation Correct Solution: ``` import sys import math from heapq import *; input = sys.stdin.readline from functools import cmp_to_key; def pi(): return(int(input())) def pl(): return(int(input(), 16)) def ti(): return(list(map(int,input().split()))) def ts(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) mod = 1000000007; f = []; def fact(n,m): global f; f = [1 for i in range(n+1)]; f[0] = 1; for i in range(1,n+1): f[i] = (f[i-1]*i)%m; def fast_mod_exp(a,b,m): res = 1; while b > 0: if b & 1: res = (res*a)%m; a = (a*a)%m; b = b >> 1; return res; def inverseMod(n,m): return fast_mod_exp(n,m-2,m); def ncr(n,r,m): if n < 0 or r < 0 or r > n: return 0; if r == 0: return 1; return ((f[n]*inverseMod(f[n-r],m))%m*inverseMod(f[r],m))%m; def main(): B(); def B(): n = pi(); mp = {}; for i in range(n): [name,score] = input().split(' '); score = int(score[:-1]); if name not in mp: mp[name] = score; else: val = mp[name]; mp[name] = max(val,score); tot = 0; for item in mp: tot += 1; ans = {}; for name in mp: count = 0; for other in mp: if name != other: if mp[other] > mp[name]: count += 1; ans[name] = ((tot-count)/tot)*100; print(tot); for name in ans: print(name, "noob" if ans[name] < 50 else "random" if ans[name] < 80 else "average" if ans[name] < 90 else "hardcore" if ans[name] < 99 else "pro"); main(); ```
output
1
59,100
17
118,201
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,101
17
118,202
Tags: implementation Correct Solution: ``` def t(g, n): for x, y in ((50, 'noob'), (20, 'random'), (10, 'average'), (1, 'hardcore')): if g > x * n // 100: return y return 'pro' p, st = {}, {} for i in range(int(input())): n, s = input().split() if n not in p or int(s) > p[n]: p[n] = int(s) for i, si in enumerate(sorted(p.values(), reverse=True)): if si not in st: st[si] = t(i, len(p)) print(len(p)) print(*sorted(k + ' ' + st[p[k]] for k in p), sep='\n') # Made By Mostafa_Khaled ```
output
1
59,101
17
118,203
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,102
17
118,204
Tags: implementation Correct Solution: ``` from collections import defaultdict from bisect import bisect_left p, n = defaultdict(int), int(input()) for i in range(n): a, b = input().split() p[a] = max(p[a], int(b)) p, n = sorted((b, a) for a, b in p.items()), len(p) t = [0] + [bisect_left(p, (p[n - 1 - n // k][0], '')) for k in [2, 5, 10, 100]] + [n] s = ['noob', 'random', 'average', 'hardcore', 'pro'] for i in range(1, len(t)): d = s[i - 1] for j in range(t[i - 1], t[i]): p[j] = p[j][1] + ' ' + d print(n) print('\n'.join(p)) ```
output
1
59,102
17
118,205
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,103
17
118,206
Tags: implementation Correct Solution: ``` I=input P=print d={} for _ in'0'*int(I()):a,b=I().split();d[a]=max(d.get(a,0),int(b)) v=d.values() n=len(d) P(n) for k in d: a=b=0 for x in v:a+=x<=d[k];b+=x>d[k] s='noob';a/=n;b/=n if a>=.5and b>=.2:s='random' if a>=.8and b>=.1:s='average' if a>=.9and b>=.01:s='hardcore' if a>=.99:s='pro' P(k,s) ```
output
1
59,103
17
118,207
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".
instruction
0
59,104
17
118,208
Tags: implementation Correct Solution: ``` n = int(input()) d = {} for _ in '0' * n: s, v = input().split() d[s] = max(d.get(s, 0), int(v)) v = d.values() res = str(len(d)) + '\n' for k in d: a, b = 0, 0 for x in v: a += x <= d[k] b += x > d[k] s = 'noob' a /= len(d) b /= len(d) if a >= .5 and b >= .2: s = 'random' if a >= .8 and b >= .1: s = 'average' if a >= .9 and b >= .01: s = 'hardcore' if a >= .99: s='pro' res += k + ' ' + s + '\n' print(res) ```
output
1
59,104
17
118,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro". Submitted Solution: ``` n = int(input()) dic = {} length = 0 for i in range(n): player,score = input().split() score = int(score) if player not in dic: dic[player] = score length += 1 else: if dic[player]<score: dic[player] = score sortd_values = sorted(dic.values(),reverse=True) print(length) for key in dic: index = sortd_values.index(dic[key]) t = (index/length)*100 if t>50: print(key,'noob') elif t>20: print(key,'random') elif t>10: print(key,'average') elif t>1: print(key,'hardcore') else: print(key,'pro') ```
instruction
0
59,105
17
118,210
Yes
output
1
59,105
17
118,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro". Submitted Solution: ``` def t(g, n): for x, y in ((50, 'noob'), (20, 'random'), (10, 'average'), (1, 'hardcore')): if g > x * n // 100: return y return 'pro' p, st = {}, {} for i in range(int(input())): n, s = input().split() if n not in p or int(s) > p[n]: p[n] = int(s) for i, si in enumerate(sorted(p.values(), reverse=True)): if si not in st: st[si] = t(i, len(p)) print(len(p)) print(*sorted(k + ' ' + st[p[k]] for k in p), sep='\n') ```
instruction
0
59,106
17
118,212
Yes
output
1
59,106
17
118,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro". Submitted Solution: ``` n = int(input()) player_points = {} for _ in range(n): name, points = input().split() points = int(points) if name in player_points: if player_points[name] < points: player_points[name] = points else: player_points[name] = points points_list = sorted(player_points.values(), reverse=True) m = len(player_points) print(m) for player, points in player_points.items(): if points_list[m // 2] > points: print(player, "noob") elif points_list[m // 5] > points and \ points_list[(m - 1) // 2] <= points: print(player, "random") elif points_list[m // 10] > points and \ points_list[((m + 4) // 5) - 1] <= points: print(player, "average") elif points_list[m // 100] > points and \ points_list[((m + 9) // 10) - 1] <= points: print(player, "hardcore") else: print(player, "pro") ```
instruction
0
59,107
17
118,214
No
output
1
59,107
17
118,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro". Submitted Solution: ``` from collections import defaultdict n = int(input()) p = defaultdict(int) for i in range(n): a, b = input().split() p[a] = max(p[a], int(b)) b = sorted(p.values()) nub = b[len(b) // 2] random = b[(4 * len(b)) // 5] average = b[(9 * len(b)) // 10] hardcore = b[(99 * len(b)) // 100] for a in p: b = p[a] if b < nub: p[a] = 'nub' elif b < random: p[a] = 'random' elif b < average: p[a] = 'average' elif b < hardcore: p[a] = 'hardcore' else: p[a] = 'pro' print('\n'.join(a + ' ' + b for a, b in p.items())) ```
instruction
0
59,108
17
118,216
No
output
1
59,108
17
118,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro". Submitted Solution: ``` import sys import math from heapq import *; input = sys.stdin.readline from functools import cmp_to_key; def pi(): return(int(input())) def pl(): return(int(input(), 16)) def ti(): return(list(map(int,input().split()))) def ts(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) mod = 1000000007; f = []; def fact(n,m): global f; f = [1 for i in range(n+1)]; f[0] = 1; for i in range(1,n+1): f[i] = (f[i-1]*i)%m; def fast_mod_exp(a,b,m): res = 1; while b > 0: if b & 1: res = (res*a)%m; a = (a*a)%m; b = b >> 1; return res; def inverseMod(n,m): return fast_mod_exp(n,m-2,m); def ncr(n,r,m): if n < 0 or r < 0 or r > n: return 0; if r == 0: return 1; return ((f[n]*inverseMod(f[n-r],m))%m*inverseMod(f[r],m))%m; def main(): B(); def B(): n = pi(); mp = {}; for i in range(n): [name,score] = input().split(' '); score = int(score[:-1]); if name not in mp: mp[name] = score; else: val = mp[name]; mp[name] = max(val,score); tot = 0; for item in mp: tot += 1; ans = {}; for name in mp: count = 0; for other in mp: if name != other: if mp[other] > mp[name]: count += 1; ans[name] = ((tot-count)/tot)*100; for name in ans: print(name, "noob" if ans[name] <= 50 else "random" if ans[name] <= 80 else "average" if ans[name] <= 90 else "hardcore" if ans[name] <= 99 else "pro"); main(); ```
instruction
0
59,109
17
118,218
No
output
1
59,109
17
118,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total. In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category: * "noob" β€” if more than 50% of players have better results; * "random" β€” if his result is not worse than the result that 50% of players have, but more than 20% of players have better results; * "average" β€” if his result is not worse than the result that 80% of players have, but more than 10% of players have better results; * "hardcore" β€” if his result is not worse than the result that 90% of players have, but more than 1% of players have better results; * "pro" β€” if his result is not worse than the result that 99% of players have. When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have. Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category. Input The first line contains the only integer number n (1 ≀ n ≀ 1000) β€” a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000. Output Print on the first line the number m β€” the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order. Examples Input 5 vasya 100 vasya 200 artem 100 kolya 200 igor 250 Output 4 artem noob igor pro kolya random vasya random Input 3 vasya 200 kolya 1000 vasya 1000 Output 2 kolya pro vasya pro Note In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro". In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro". Submitted Solution: ``` I=input d={} for _ in'0'*int(I()):a,b=I().split();d[a]=max(d.get(a,0),int(b)) v=d.values() n=len(d) for k in d: a=b=0 for x in v:a+=x<=d[k];b+=x>d[k] s='noob';a/=n;b/=n if a>=.5and b>=.2:s='random' if a>=.8and b>=.1:s='average' if a>=.9and b>=.01:s='hardcore' if a>=.99:s='pro' print(k,s) ```
instruction
0
59,110
17
118,220
No
output
1
59,110
17
118,221
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,316
17
120,632
Tags: math Correct Solution: ``` a = list(map(int, input().split(' '))) c = (a[0] * a[1] + 2*a[3]) - (a[0]*a[2] + 2*a[4]) if(c < 0): print('First') elif (c > 0): print('Second') else: print('Friendship') ```
output
1
60,316
17
120,633
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,317
17
120,634
Tags: math Correct Solution: ``` x = list(map(int, input().split())) a = (x[0]*x[1]) + (2*x[3]) b = (x[0]*x[2]) + (2*x[4]) if a < b: print("First") elif a > b: print("Second") else: print("Friendship") ```
output
1
60,317
17
120,635
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,318
17
120,636
Tags: math Correct Solution: ``` a,b,c,d,e=map(int,input().split()) f =a/(1/b)+2*d g=a/(1/c)+2*e if f<g: print("First") elif f==g: print("Friendship") else: print("Second") ```
output
1
60,318
17
120,637
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,319
17
120,638
Tags: math Correct Solution: ``` s, v1, v2, t1, t2 = map(int, input().split()) if s * v1 + 2 * t1 == s * v2 + 2 * t2: print('Friendship') else: if s * v1 + 2 * t1 < s * v2 + 2 * t2: print('First') else: print('Second') ```
output
1
60,319
17
120,639
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,320
17
120,640
Tags: math Correct Solution: ``` s,v1,v2,t1,t2 = map(int,input().split()) if t1 * 2 + v1 * s < t2 * 2 + v2 * s: print('First') elif t1 * 2 + v1 * s > t2 * 2 + v2 * s: print('Second') else: print('Friendship') ```
output
1
60,320
17
120,641
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,321
17
120,642
Tags: math Correct Solution: ``` s, v1, v2, t1, t2 = list(map(int, input().split())) tt1, tt2 = (s*v1)+(2*t1), (s*v2)+(2*t2) if tt1==tt2: print('Friendship') else: print(['First','Second'][tt2<tt1]) ```
output
1
60,321
17
120,643
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,322
17
120,644
Tags: math Correct Solution: ``` s,v1,v2,t1,t2=map(int, input().split()) a=(s*v1+2*t1)-(s*v2+2*t2) if a<0: print("First") elif a>0: print("Second") else: print("Friendship") ```
output
1
60,322
17
120,645
Provide tags and a correct Python 3 solution for this coding contest problem. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw.
instruction
0
60,323
17
120,646
Tags: math Correct Solution: ``` s,v1,v2,t1,t2=input().split() time_1=int(t1)+int(s)*int(v1)+int(t1) time_2=int(t2)++int(s)*int(v2)+int(t2) if(time_1<time_2): print("First") elif(time_2<time_1): print("Second") else: print("Friendship") ```
output
1
60,323
17
120,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw. Submitted Solution: ``` ins = input().split(" ") n = int(ins[0]) v1 = int(ins[1]) v2 = int(ins[2]) t1 = int(ins[3]) t2 = int(ins[4]) a = (n * v1) + (2 * t1) b = (n * v2) + (2 * t2) if a < b: print("First") elif a > b: print("Second") else: print("Friendship") ```
instruction
0
60,324
17
120,648
Yes
output
1
60,324
17
120,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw. Submitted Solution: ``` s, v1, v2, t1, t2 = map(int, input().split()) ans = s*(v2-v1) + 2*(t2-t1) print(["Friendship", "First", "Second"][ans//(max(abs(ans), 1))]) ```
instruction
0
60,325
17
120,650
Yes
output
1
60,325
17
120,651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw. Submitted Solution: ``` s,v1,v2,t1,t2=[int(i) for i in input().split()] p1=(2*t1)+(s*v1) p2=(2*t2)+(s*v2) if p1>p2: print('Second') elif p1<p2: print('First') else: print('Friendship',end='') ```
instruction
0
60,326
17
120,652
Yes
output
1
60,326
17
120,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw. Submitted Solution: ``` matn,yak,duyum,se1,se2=map(int,input().split()) s=yak*matn+se1*2 s2=duyum*matn+se2*2 if s<s2:print('First');exit() if s>s2:print('Second');exit() print('Friendship') ```
instruction
0
60,327
17
120,654
Yes
output
1
60,327
17
120,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: 1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. 2. Right after that he starts to type it. 3. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. Input The first line contains five integers s, v1, v2, t1, t2 (1 ≀ s, v1, v2, t1, t2 ≀ 1000) β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. Output If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". Examples Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship Note In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant β€” in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant β€” in 22 milliseconds. So, it is be a draw. Submitted Solution: ``` I = [int(x) for x in input().split()] time1 = I[0]*I[1] + 2*I[3] time2 = I[0]*I[2] + 2*I[4] if time1 < time2: print('First') elif time1 > time2: print('Second') else: print('Friednship') ```
instruction
0
60,328
17
120,656
No
output
1
60,328
17
120,657