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
Provide tags and a correct Python 3 solution for this coding contest problem. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1.
instruction
0
11,703
17
23,406
Tags: greedy, sortings Correct Solution: ``` q = int(input()) x = [int(x) for x in input().split()] x.sort() count = {} for i in range(x[-1]+2): count[i] = 0 for i in x: count[i] += 1 #print(count) for i in x: if (count[i - 1] == 0 and i > 1): count[i - 1] = 1 count[i] -= 1 elif(count[i] == 1): continue else: count[i + 1] += 1 count[i] -= 1 answer = 0 for val in count.values(): answer += val > 0 print(answer) ```
output
1
11,703
17
23,407
Provide tags and a correct Python 3 solution for this coding contest problem. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1.
instruction
0
11,704
17
23,408
Tags: greedy, sortings Correct Solution: ``` from collections import Counter,defaultdict import math def getlist(): return list(map(int,input().split())) def getvalue():return int(input()) def getstring():return input() n=getvalue() l=getlist() l.sort() tot=0 li=[0]*(150003) for i in l: li[i]+=1 for i in range(1,150001): if li[i]: if i==1 and li[i]>1: tot+=1 if li[i]>1: li[i+1]+=1 li[i]-=1 elif i>1 and li[i] == 1: tot+=1 if li[i-1] == 0: li[i]-=1 li[i-1]+=1 elif i>1 and li[i] == 2: tot+=1 if li[i-1] == 0: li[i]-=1 li[i-1]+=1 tot+=1 else: li[i]-=1 li[i+1]+=1 elif i>1 and li[i] >=3: tot+=1 if li[i-1] == 0: li[i]-=1 li[i-1]+=1 tot+=1 li[i]-=1 li[i+1]+=1 # print(li[:max(l)+2]) print(sum(1 if li[i] else 0 for i in range(1,150002))) # print(tot) ```
output
1
11,704
17
23,409
Provide tags and a correct Python 3 solution for this coding contest problem. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1.
instruction
0
11,705
17
23,410
Tags: greedy, sortings Correct Solution: ``` n = int(input()) arr = list(map(int, input().split())) arr.sort(reverse = True) s = set() for i in arr: if i+1 not in s: s.add(i+1) elif i not in s: s.add(i) elif i-1 not in s and i-1 > 0: s.add(i-1) print(len(s)) ```
output
1
11,705
17
23,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` n = int(input()) a = list(sorted(map(int, input().split()))) count = 0 l = 0 for i in range(n): if a[i] - 1 > l: a[i] -= 1 l = a[i] count += 1 elif a[i] - 1 == l: count += 1 l = a[i] elif a[i] == l: a[i] += 1 l += 1 count += 1 # print(a) print(count) ```
instruction
0
11,706
17
23,412
Yes
output
1
11,706
17
23,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) a.sort() cnt = 0 team = [a[0]-1] if a[0]>1 else [a[0]] for x in a[1:]: # if x-1>0 and (x-1)!=team[-1]: # team.append(x-1) # elif x!=team[-1]: # team.append(x) # elif (x+1)!=team[-1]: # team.append(x+1) if x-1>team[-1]: team.append(x-1) elif x>team[-1]: team.append(x) elif x+1>team[-1]: team.append(x+1) # print(team) print(len(team)) ```
instruction
0
11,707
17
23,414
Yes
output
1
11,707
17
23,415
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` # final answer is in boxers_problem_test2 ..... boxers_problem_test3 reaches the time limit number_of_boxers = int(input()) boxers_weight = input().split() boxers_weight = [int(x) for x in boxers_weight] boxers_weight = sorted(boxers_weight, reverse=True) maximum = 150002 team = [] for number in boxers_weight: if number + 1 < maximum: team.append(number + 1) maximum = number + 1 elif number < maximum: team.append(number) maximum = number elif number - 1 < maximum: team.append(number - 1) maximum = number - 1 final_team = [x for x in team if x != 0] print(len(final_team)) ```
instruction
0
11,708
17
23,416
Yes
output
1
11,708
17
23,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` n = int(input()) x = list(map(int, input().split())) x.sort() if n < 3: print(n) else: for i in range(n): if x[i] == 1: if i != 0 and i != n - 2 and x[i - 1] == 1 and x[i + 1] > 1: x[i] += 1 elif x[i + 1] > 1 and x[i - 1] == 1: x[i] += 1 else: if i == 0: x[i] -= 1 elif i == n - 1: x[i] += 1 else: if x[i - 1] < x[i] - 1 and x[i + 1] < x[i] + 2: x[i] -= 1 elif x[i] == x[i - 1] != x[i + 1]: x[i] += 1 print(len(set(x))) ```
instruction
0
11,709
17
23,418
Yes
output
1
11,709
17
23,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` from collections import Counter import sys input = sys.stdin.readline n=int(input()) a=[int(i) for i in input().split()] count=0 b=Counter(a) # for i in range(b): for key,value in b.items(): count+=1 if(value==2): if ((key-1) not in b and (key-1)!=0 or (key+1) not in b): count+=1 elif(value>2): if ((key-1) not in b and (key-1)!=0): count+=1 if((key+1) not in b): count+=1 print(count) ```
instruction
0
11,710
17
23,420
No
output
1
11,710
17
23,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) from collections import defaultdict b = defaultdict(int) for i in a: b[i]+=1 c = set() for i in b: if i not in c: if i==1: t=b[1] c.add(1) if t-1>0: c.add(2) else: t,p=b[i],0 if i-1 in c: c.add(i) else: c.add(i-1) p=1 if p==1 and t-1>0: c.add(i) if p==1 and t-2>0: c.add(i+1) if p==0 and t-1>0: c.add(i+1) else: c.add(i+1) print(len(c)) ```
instruction
0
11,711
17
23,422
No
output
1
11,711
17
23,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` n=int(input()) a=[int(ele) for ele in input().split()] a.sort() a.reverse() i=0 count=0 while i<n: if i==0: lst = a[i]+1 count += 1 else: if a[i]+1 < lst and a[i]+1>0: lst = a[i]+1 count += 1 elif a[i]<lst and a[i]>0: lst = a[i] count += 1 elif i<n-1 and a[i]-1 < lst and a[i]-1>0: lst = a[i]-1 count += 1 i += 1 print(count) ```
instruction
0
11,712
17
23,424
No
output
1
11,712
17
23,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique). Write a program that for given current values ​a_i will find the maximum possible number of boxers in a team. It is possible that after some change the weight of some boxer is 150001 (but no more). Input The first line contains an integer n (1 ≀ n ≀ 150000) β€” the number of boxers. The next line contains n integers a_1, a_2, ..., a_n, where a_i (1 ≀ a_i ≀ 150000) is the weight of the i-th boxer. Output Print a single integer β€” the maximum possible number of people in a team. Examples Input 4 3 2 4 1 Output 4 Input 6 1 1 1 4 4 4 Output 5 Note In the first example, boxers should not change their weights β€” you can just make a team out of all of them. In the second example, one boxer with a weight of 1 can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5, 4, 3, 2, 1. Submitted Solution: ``` from collections import Counter n=int(input()) A=list(map(int,input().split())) C=Counter(A) m=max(A) ans=0 L=[False]*(m+2) if C[1]>=1: L[1]=True if C[1]>=2: L[2]=True for i in range(2,m+1): if C[i]==0: continue L[i]=True if C[i]==2: if not L[i-1]: L[i-1]=True else: L[i+1]=True elif C[i]>=3: L[i-1]=True; L[i+1]=True print(sum(L)) ```
instruction
0
11,713
17
23,426
No
output
1
11,713
17
23,427
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,740
17
23,480
Tags: greedy, implementation Correct Solution: ``` import math def count(l, x): r = 0 for i in l: if i > x: continue if x == i: r += 1 else: break return r def count2(l, a, b): r = 0 for i in l: if i >= b: continue elif i < b and i >= a: r += 1 else: break return r def fast_del(l): x = l[-1] delind = 1 for i in range(2, len(l)+1): if l[-i] == x: delind += 1 else: break return delind T = int(input()) result = "" for t in range(T): n = int(input()) text = list(map(int, input().split(' '))) if len(text) > 1: r = math.floor(n/2) students = text[:r] if text[r] == students[r-1]: d = fast_del(students) students = students[:-d] else: students = text if not students: result += "0 0 0\n" continue gold = students[0] servial = -1 bronze = -1 g = count(students, gold) s = 0 b = 0 bronze = students[-1] for i in range(len(students)-1, 0, -1): if students[i] == bronze: b += 1 else: if b <= g: bronze = students[i] b += 1 continue servial = students[i] break if servial == -1: result += "0 0 0\n" continue if b <= g: result += "0 0 0\n" continue s = count2(students, servial, gold) if s <= g: result += "0 0 0\n" continue if s == 0 and b == 0: g = 0 result += str(g) + ' ' + str(s) + ' ' + str(b) + '\n' print(result) ```
output
1
11,740
17
23,481
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,741
17
23,482
Tags: greedy, implementation Correct Solution: ``` t=int(input()) for i in range(t): n=int(input()) plist=[int(x) for x in input().split(' ')] if n <= 5: print(0,0,0,sep=' ') else: for k in range(n): if plist[0] != plist[k]: break a=k b=0 c=0 while (b <= a) and a+b+c <= n/2: for j in range(k+1,n): if plist[k] != plist[j]: break x=j b=b+(x-k) k=x if b <= a: print(0,0,0,sep=' ') else: while a+b+c < n/2: for j in range(k,n): if plist[k] != plist[j]: break if a+b+c+j-k>n/2: break else: c+=(j-k) k=j if c > a: print(a,b,c,sep=' ') else: print(0,0,0,sep=' ') ```
output
1
11,741
17
23,483
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,742
17
23,484
Tags: greedy, implementation Correct Solution: ``` t = int(input()) for _ in range (t): n = int(input()) arr = list(map(int,input().split())) n = n//2 if n < 5: print(0, 0, 0) continue lengths = [] j = 0 for i in range (1, n): if arr[i] != arr[i-1]: lengths.append(i - j) j = i if arr[n] != arr[n-1]: lengths.append(n - j) if len(lengths) < 3: print(0, 0, 0) continue G = lengths[0] S = 0 k = 1 while S <= G and k < len(lengths): S += lengths[k] k += 1 B = sum(lengths) - G -S if G < S and G < B: print(G, S, B) else: print(0, 0, 0) ```
output
1
11,742
17
23,485
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,743
17
23,486
Tags: greedy, implementation Correct Solution: ``` #!/usr/bin/env python3 from itertools import combinations import sys input = sys.stdin.readline INF = 10**9 t = int(input()) for i in range(t): n = int(input()) a = [int(item) for item in input().split()] miss_medal = a[n // 2] lim = a.index(miss_medal) g = a[0] s = -1 g_cnt = 0 s_cnt = 0 b_cnt = 0 state = 0 for i in range(lim): if state == 0: if a[i] == g: g_cnt += 1 else: s = a[i] s_cnt += 1 state = 1 continue if state == 1: if a[i] == s: s_cnt += 1 elif s_cnt <= g_cnt: s = a[i] s_cnt += 1 else: b = a[i] b_cnt += 1 state = 2 continue if state == 2: b_cnt = lim - i + 1 break if g_cnt < s_cnt and g_cnt < b_cnt: print(g_cnt, s_cnt, b_cnt) else: print(0, 0, 0) ```
output
1
11,743
17
23,487
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,744
17
23,488
Tags: greedy, implementation Correct Solution: ``` from collections import Counter def abc(nums: list, l: int): if len(nums) < 10: return '0 0 0' dic = Counter(nums) keys = sorted(dic, reverse=True) if len(keys) < 3: return '0 0 0' gold = dic[keys[0]] silver = 0 bronze = 0 target = l//2 needle = 1 for i in keys[1:]: silver += dic[i] needle += 1 if silver > gold: break else: return '0 0 0' for i in keys[needle:]: bronze += dic[i] needle += 1 if bronze > gold: break else: return '0 0 0' if gold+silver+bronze > target: return '0 0 0' for i in keys[needle:]: if gold+silver+bronze+dic[i] > target: return '%d %d %d' % (gold, silver, bronze) bronze += dic[i] return '%d %d %d' % (gold, silver, bronze) t = int(input()) out = [] for i in range(t): a = int(input()) s = list(map(int, input().split(' '))) out.append(abc(s, a)) for i in out: print(i) ''' test = sorted([13, 12, 21, 21, 12, 12, 12, 21, 1, 1, 1, 1, 1, 1], reverse=True) print(test) print(abc(test, len(test))) ''' ```
output
1
11,744
17
23,489
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,745
17
23,490
Tags: greedy, implementation Correct Solution: ``` from sys import stdin, stdout from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque from heapq import merge, heapify, heappop, heappush, nsmallest from bisect import bisect_left as bl, bisect_right as br, bisect mod = pow(10, 9) + 7 mod2 = 998244353 def inp(): return stdin.readline().strip() def iinp(): return int(inp()) def out(var, end="\n"): stdout.write(str(var)+"\n") def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end) def lmp(): return list(mp()) def mp(): return map(int, inp().split()) def smp(): return map(str, inp().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)] def remadd(x, y): return 1 if x%y else 0 def ceil(a,b): return (a+b-1)//b def isprime(x): if x<=1: return False if x in (2, 3): return True if x%2 == 0: return False for i in range(3, int(sqrt(x))+1, 2): if x%i == 0: return False return True for _ in range(int(inp())): n = iinp() arr = lmp() i = n//2-1 while(i>=0 and arr[i]==arr[n//2]): i-=1 if i+1<5: print(0, 0, 0) continue arr = arr[:i+1] n = len(arr) g = 1 while(g<n and arr[g]==arr[g-1]): g+=1 s = g+1 while(s<n and (s-g<=g or arr[s]==arr[s-1])): s+=1 if n-s>g: print(g, s-g, n-s) else: print(0, 0, 0) ```
output
1
11,745
17
23,491
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,746
17
23,492
Tags: greedy, implementation Correct Solution: ``` #!/usr/bin/env python3 # coding: utf-8 # Last Modified: 06/Dec/19 10:08:00 AM import sys def main(): from collections import Counter for tc in range(int(input())): n = int(input()) arr = get_array() x = arr[n // 2] arr = arr[: n // 2] n = len(arr) if n <= 2: print(0, 0, 0) continue g, s, b = 0, 0, 0 g += 1 i = 1 while i < len(arr) and arr[i] == arr[0]: i += 1 g += 1 j = i if i == len(arr): print(0, 0, 0) continue while i < len(arr) and (arr[i] == arr[j] or s <= g): j = i s += 1 i += 1 if i == len(arr): print(0, 0, 0) continue j = i p = arr[i] while i < len(arr) and (arr[i] > x or arr[i] == arr[j] or b <= g): p = arr[i] j = i b += 1 i += 1 if x == p: print(0, 0, 0) continue if g >= b or g >= s: print(0, 0, 0) else: print(g, s, b) get_array = lambda: list(map(int, sys.stdin.readline().split())) get_ints = lambda: map(int, sys.stdin.readline().split()) input = lambda: sys.stdin.readline().strip() if __name__ == "__main__": main() ```
output
1
11,746
17
23,493
Provide tags and a correct Python 3 solution for this coding contest problem. So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied: * for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0); * the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b); * each gold medalist must solve strictly more problems than any awarded with a silver medal; * each silver medalist must solve strictly more problems than any awarded a bronze medal; * each bronze medalist must solve strictly more problems than any participant not awarded a medal; * the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals. Input The first line of the input contains an integer t (1 ≀ t ≀ 10000) β€” the number of test cases in the input. Then t test cases follow. The first line of a test case contains an integer n (1 ≀ n ≀ 4β‹…10^5) β€” the number of BeRC participants. The second line of a test case contains integers p_1, p_2, ..., p_n (0 ≀ p_i ≀ 10^6), where p_i is equal to the number of problems solved by the i-th participant from the final standings. The values p_i are sorted in non-increasing order, i.e. p_1 β‰₯ p_2 β‰₯ ... β‰₯ p_n. The sum of n over all test cases in the input does not exceed 4β‹…10^5. Output Print t lines, the j-th line should contain the answer to the j-th test case. The answer consists of three non-negative integers g, s, b. * Print g=s=b=0 if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time. * Otherwise, print three positive numbers g, s, b β€” the possible number of gold, silver and bronze medals, respectively. The sum of g+s+b should be the maximum possible. If there are several answers, print any of them. Example Input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 Output 1 2 3 0 0 0 0 0 0 2 5 3 2 6 6 Note In the first test case, it is possible to reward 1 gold, 2 silver and 3 bronze medals. In this case, the participant solved 5 tasks will be rewarded with the gold medal, participants solved 4 tasks will be rewarded with silver medals, participants solved 2 or 3 tasks will be rewarded with bronze medals. Participants solved exactly 1 task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than 6 medals because the number of medals should not exceed half of the number of participants. The answer 1, 3, 2 is also correct in this test case. In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.
instruction
0
11,747
17
23,494
Tags: greedy, implementation Correct Solution: ``` for _ in range(int(input())): n = int(input()) points = list(map(int, input().split())) count = [] prev = -1 for i in range(n): if points[i] == prev: count[-1] += 1 else: count.append(1) prev = points[i] m = 0 tot = 0 while tot + count[m] <= n//2: tot += count[m] m += 1 # <= tot people get a medal, up to index m-1 fail = False gold, silv, bron = 0,0,0 if m < 3: fail = True else: gold = count[0] silv = count[1] j = 1 while (gold >= silv and j+1<m): j += 1 silv += count[j] bron = sum(count[j+1:m]) if gold >= silv or gold >= bron: fail = True if fail: print("0 0 0") else: print(gold,silv,bron) ```
output
1
11,747
17
23,495
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. <image> Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two. Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. Input The first line of input contains integer n (1 ≀ n ≀ 106), the number of weights. The second line contains n integers w1, ..., wn separated by spaces (0 ≀ wi ≀ 106 for each 1 ≀ i ≀ n), the powers of two forming the weights values. Output Print the minimum number of steps in a single line. Examples Input 5 1 1 2 3 3 Output 2 Input 4 0 1 2 3 Output 4 Note In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two. In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
instruction
0
12,058
17
24,116
Tags: greedy Correct Solution: ``` n = int(input()) l = [0] * (10**6+100) for i in map(int,input().split()): l[i] += 1 cur = ans = 0 for i in l: cur += i if cur%2: ans += 1 cur //=2 print (ans) # Made By Mostafa_Khaled ```
output
1
12,058
17
24,117
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. <image> Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two. Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. Input The first line of input contains integer n (1 ≀ n ≀ 106), the number of weights. The second line contains n integers w1, ..., wn separated by spaces (0 ≀ wi ≀ 106 for each 1 ≀ i ≀ n), the powers of two forming the weights values. Output Print the minimum number of steps in a single line. Examples Input 5 1 1 2 3 3 Output 2 Input 4 0 1 2 3 Output 4 Note In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two. In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
instruction
0
12,059
17
24,118
Tags: greedy Correct Solution: ``` n = int(input()) lis = sorted(map(int,input().split())) ans=c=0 c=1 #print(lis) for i in range(1,n): if lis[i]==lis[i-1]: c+=1 else: # print(c,lis[i],'c') while lis[i]!=lis[i-1] and c>0: if c%2: ans+=1 c = c//2 lis[i-1]+=1 # print(ans) c+=1 #print(c,ans) while c>0: if c%2: ans+=1 c = c//2 print(ans) ```
output
1
12,059
17
24,119
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. <image> Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two. Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. Input The first line of input contains integer n (1 ≀ n ≀ 106), the number of weights. The second line contains n integers w1, ..., wn separated by spaces (0 ≀ wi ≀ 106 for each 1 ≀ i ≀ n), the powers of two forming the weights values. Output Print the minimum number of steps in a single line. Examples Input 5 1 1 2 3 3 Output 2 Input 4 0 1 2 3 Output 4 Note In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two. In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
instruction
0
12,061
17
24,122
Tags: greedy Correct Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- n = int(input()) weights = list(map(int,input().split())) counter = [0] * (10** 6 + 21) for weight in weights: counter[weight] += 1 ans = 0 for i in range(10**6 + 21): weight, count = (i, counter[i]) if count > 0 and count // 2 > 0: counter[weight+1] += count//2 count -= (count//2)*2 ans += count print(ans) ```
output
1
12,061
17
24,123
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. <image> Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two. Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. Input The first line of input contains integer n (1 ≀ n ≀ 106), the number of weights. The second line contains n integers w1, ..., wn separated by spaces (0 ≀ wi ≀ 106 for each 1 ≀ i ≀ n), the powers of two forming the weights values. Output Print the minimum number of steps in a single line. Examples Input 5 1 1 2 3 3 Output 2 Input 4 0 1 2 3 Output 4 Note In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two. In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
instruction
0
12,062
17
24,124
Tags: greedy Correct Solution: ``` n = int(input()) a = [0 for i in range(10**6+1)] for x in input().split(): a[int(x)] += 1 c = 0 prev = 0 for el in a: prev += el if prev%2 == 1: c+=1 prev //= 2 while prev>0: c += prev%2 prev //= 2 print(c) ```
output
1
12,062
17
24,125
Provide tags and a correct Python 3 solution for this coding contest problem. Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps. <image> Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two. Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. Input The first line of input contains integer n (1 ≀ n ≀ 106), the number of weights. The second line contains n integers w1, ..., wn separated by spaces (0 ≀ wi ≀ 106 for each 1 ≀ i ≀ n), the powers of two forming the weights values. Output Print the minimum number of steps in a single line. Examples Input 5 1 1 2 3 3 Output 2 Input 4 0 1 2 3 Output 4 Note In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two. In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.
instruction
0
12,064
17
24,128
Tags: greedy Correct Solution: ``` def main(): input() l = [0] * 1000001 for w in map(int, input().split()): l[w] += 1 t = rest = 0 for x in l: t += x if t & 1: rest += 1 t >>= 1 print(bin(t).count('1') + rest) if __name__ == '__main__': main() ```
output
1
12,064
17
24,129
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,092
17
24,184
Tags: constructive algorithms, sortings Correct Solution: ``` tokens = [] tokens_next = 0 #file = open('in', 'r') import sys file = sys.stdin def next_str(): global tokens, tokens_next while tokens_next >= tokens.__len__() : tokens = file.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(next_str()) n = nextInt(); m = nextInt(); regions = [[] for i in range(n)] for _ in range(n): name, round, score = next_str(), nextInt(), nextInt(); regions[round].append((score, name)) for r in regions: r.sort(reverse=True) if len(r) < 2: continue if len(r) > 2 and r[1][0] == r[2][0]: print('?') else : print(r[0][1], r[1][1]) ```
output
1
12,092
17
24,185
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,093
17
24,186
Tags: constructive algorithms, sortings Correct Solution: ``` namelist=[['','',''] for i in range(100005)] scorelist=[[-1,-1,-1] for i in range(100005)] def enroll(recod): name=recod[0] region=int(recod[1]) score=int(recod[2]) for i in range(3): if score>scorelist[region][i]: t=name name=namelist[region][i] namelist[region][i]=t t=score score=scorelist[region][i] scorelist[region][i]=t ll=input().split() n=int(ll[0]) m=int(ll[1]) for i in range(n): enroll(input().split()) for i in range(1,m+1): if scorelist[i][1]!=scorelist[i][2]: print("%s %s" % (namelist[i][0],namelist[i][1])) else: print("?") ```
output
1
12,093
17
24,187
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,094
17
24,188
Tags: constructive algorithms, sortings Correct Solution: ``` import operator class Participant: def __init__(self,name,point): self.name=name self.point=point n,m=map(int,input().split()) des=[None]*m for i in range(m): des[i]=[] for i in range(n): name,region,point=input().split() des[int(region)-1].append(Participant(name,int(point))) results=['?']*m for i in range(m): cur_region=des[i] is_ok=False if len(cur_region)==2: is_ok=True else: cur_region.sort(key=operator.attrgetter('point')) if cur_region[-2].point!=cur_region[-3].point: is_ok=True if is_ok: results[i]=' '.join([cur_region[-1].name,cur_region[-2].name]) print('\n'.join(results)) ```
output
1
12,094
17
24,189
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,095
17
24,190
Tags: constructive algorithms, sortings Correct Solution: ``` def contest(n, m, P): D = [[(-1, None), (-1, None), (-1, None)] for _ in range(m)] for n, r, p in P: D_i = D[r-1] d = (p, n) if d > D_i[0]: D_i[2] = D_i[1] D_i[1] = D_i[0] D_i[0] = d elif d > D_i[1]: D_i[2] = D_i[1] D_i[1] = d elif d > D_i[2]: D_i[2] = d for i in range(m): D_i = D[i] if D_i[1][0] == D_i[2][0]: yield '?' else: yield f'{D_i[0][1]} {D_i[1][1]}' def readp(): n, sr, sp = input().split() return n, int(sr), int(sp) def main(): n, m = readinti() P = [readp() for _ in range(n)] print('\n'.join(contest(n, m, P))) ########## import sys def readint(): return int(input()) def readinti(): return map(int, input().split()) def readintt(): return tuple(readinti()) def readintl(): return list(readinti()) def readinttl(k): return [readintt() for _ in range(k)] def readintll(k): return [readintl() for _ in range(k)] def log(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) if __name__ == '__main__': main() ```
output
1
12,095
17
24,191
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,096
17
24,192
Tags: constructive algorithms, sortings Correct Solution: ``` import sys n, m = [int(x) for x in input().split()] A = [[] for i in range(m)] for line in sys.stdin: name, region, result = line.split() region, result = int(region) - 1, int(result) A[region].append((result, name)) for a in A: a.sort() if len(a) > 2 and a[-2][0] == a[-3][0]: sys.stdout.write('?\n') else: sys.stdout.write(a[-2][1] + ' ' + a[-1][1] + '\n') ```
output
1
12,096
17
24,193
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,097
17
24,194
Tags: constructive algorithms, sortings Correct Solution: ``` n,m = map(int,input().split()) l = [[]for i in range(m)] for i in range(n): j = input().split() j[1]=int(j[1])-1 j[2]=int(j[2]) l[j[1]].append((j[2],j[0])) for i in range(m): l[i].sort(reverse=1) if len(l[i])>2 and l[i][1][0]==l[i][2][0]: print('?') else: print(l[i][0][1],l[i][1][1]) ```
output
1
12,097
17
24,195
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,098
17
24,196
Tags: constructive algorithms, sortings Correct Solution: ``` n, m = map(int, input().split(' ')) c = {} for i in range(n): line = input().split() line[1], line[2] = int(line[1]), int(line[2]) if line[1] not in c: c[line[1]] = [] c[line[1]].append((line[2], line[0])) for i in range(1, m+1): c[i].sort(reverse = True) if len(c[i]) > 2 and c[i][1][0] == c[i][2][0]: print('?') else: print(c[i][0][1], c[i][1][1]) ```
output
1
12,098
17
24,197
Provide tags and a correct Python 3 solution for this coding contest problem. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.
instruction
0
12,099
17
24,198
Tags: constructive algorithms, sortings Correct Solution: ``` #!/usr/bin/python3 class StdIO: def read_int(self): return int(self.read_string()) def read_ints(self, sep=None): return [int(i) for i in self.read_strings(sep)] def read_float(self): return float(self.read_string()) def read_floats(self, sep=None): return [float(i) for i in self.read_strings(sep)] def read_string(self): return input() def read_strings(self, sep=None): return self.read_string().split(sep) io = StdIO() def main(): n, m = io.read_ints() ppl = [list() for i in range(m)] for i in range(n): name, reg, score = io.read_strings() reg = int(reg) score = int(score) reg -= 1 ppl[reg].append((score, name)) for reg in range(m): ppl[reg].sort(reverse=True) team = ppl[reg] sca = team[0][0] scb = team[1][0] scc = team[2][0] if len(team) > 2 else None if scc is None or (sca > scc and scb > scc): print(team[0][1], team[1][1]) else: print('?') if __name__ == '__main__': main() ```
output
1
12,099
17
24,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * from bisect import * from io import BytesIO, IOBase from fractions import * def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def value(): return tuple(map(int,input().split())) def array(): return [int(i) for i in input().split()] def Int(): return int(input()) def Str(): return input() def arrayS(): return [i for i in input().split()] #-------------------------code---------------------------# #vsInput() n,m=value() d=defaultdict(list) for i in range(n): name,r,sc=input().split() d[int(r)].append((int(sc),name)) #print(d) for i in range(1,m+1): if(len(d[i])==2): print(d[i][0][1],d[i][1][1]) else: t=sorted(d[i]) #print(t) if(t[-2][0]!=t[-3][0]): print(t[-1][1],t[-2][1]) else: print('?') ```
instruction
0
12,100
17
24,200
Yes
output
1
12,100
17
24,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` #!/usr/bin/env python3 read_ints = lambda : list(map(int, input().split())) if __name__ == '__main__': n, m = read_ints() R = [[] for _ in range(m)] for i in range(n): n,r,s = input().split() r = int(r) s = int(s) R[r-1].append((s,n)) for r in R: r.sort(reverse=True) if len(r) > 2: if r[1][0] == r[2][0]: print("?") else: print("%s %s" % (r[0][1], r[1][1])) else: print("%s %s" % (r[0][1], r[1][1])) ```
instruction
0
12,101
17
24,202
Yes
output
1
12,101
17
24,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` from collections import deque n, m = tuple( map( int, input().split())) parti = [deque() for i in range(m)] for i in range(n): s = input().split() name = s[0] reg = int(s[1]) sco = int(s[2]) if len(parti[reg - 1]) ==0: parti[reg-1].append([name, sco]) elif len(parti[reg - 1]) ==1: if sco<parti[reg - 1][0][1]: parti[reg-1].append([name, sco]) else: parti[reg-1].appendleft([name, sco]) else: if sco>=parti[reg-1][0][1]: while parti[reg-1][-1][1]<parti[reg-1][0][1]: parti[reg-1].pop() parti[reg-1].appendleft([name, sco]) elif sco>=parti[reg-1][-1][1]: while parti[reg-1][-1][1]<sco: parti[reg-1].pop() parti[reg-1].append([name, sco]) """ for i in range(m): print(parti[i]) """ for i in range(m): if len(parti[i])>2: print('?') else: print(parti[i][0][0], parti[i][1][0]) ```
instruction
0
12,102
17
24,204
Yes
output
1
12,102
17
24,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` n, m = map(int, input().split()) d = {} for i in range(1, m+1): d[i] = [] for i in range(n): a, b, c = input().split() b = int(b) ; c = int(c) d[b] += [(c, a)] for i in range(1, m+1): t = sorted(d[i], reverse=True) print('?' if len(t) > 2 and t[1][0] == t[2][0] else t[0][1] + ' ' + t[1][1]) ```
instruction
0
12,103
17
24,206
Yes
output
1
12,103
17
24,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` from sys import stdin,stdout a,b=map(int,stdin.readline().split()) d={} for i in range(1,b+1):d[i]={} for _ in " "*a: x,y,z=stdin.readline().split() y=int(y);z=int(z) if len(d[y])<2: if d[y].get(z,-1)==-1: d[y][z]=(x,) else:d[y][z]+=(x,) else: if min(d[y])<z:d[y].pop(min(d[y])) else:continue if d[y].get(z,-1)==-1: d[y][z]=(x,) else:d[y][z]+=(x,) ans='' for i in d: s=[] for j in d[i]: for k in d[i][j]:s.append(k) if len(s)==2:break if len(s)==2:ans+=' '.join(s) else:ans+='?' ans+='\n' stdout.write(ans) ```
instruction
0
12,104
17
24,208
No
output
1
12,104
17
24,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` '__author__'=='deepak Singh Mehta(learning to code :) ) ' if __name__=='__main__': n,m = map(int,input().split()) memo =dict() for i in range(1,m+1): memo[i]=[] for _ in range(n): name,idx,pt = map(str,input().split()) idx , pt = int(idx), int(pt) memo[idx].append((pt,name)) for i in range(1,m+1): lst = memo[i] lst = sorted(lst)[::-1] con = [] team = [] for jj in lst: if jj[0] not in con: con.append(jj[0]) team.append(jj[1]) if len(con)==2: break if len(con) <2: print("?") else: for nn in team: if nn==team[-1]: print(nn) else: print(nn,end=' ') ```
instruction
0
12,105
17
24,210
No
output
1
12,105
17
24,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` from sys import stdin,stdout a,b=map(int,stdin.readline().split()) d={} for i in range(1,b+1):d[i]={} for _ in " "*a: x,y,z=stdin.readline().split() y=int(y);z=int(z) if len(d[y])<2: if d[y].get(z,-1)==-1: d[y][z]=(x,) else:d[y][z]+=(x,) else: if min(d[y])<z:d[y].pop(min(d[y])) else:continue if d[y].get(z,-1)==-1: d[y][z]=(x,) else:d[y][z]+=(x,) ans='' for i in range(1,b+1): s=[] for j in d[i]: for k in d[i][j]:s.append(k) if len(s)==2:break if len(s)==2:ans+=' '.join(s) else:ans+='?' ans+='\n' stdout.write(ans) ```
instruction
0
12,106
17
24,212
No
output
1
12,106
17
24,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive. The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two its representatives participated in the qualifying contest. Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that in this region its formation requires additional contests. Input The first line of the input contains two integers n and m (2 ≀ n ≀ 100 000, 1 ≀ m ≀ 10 000, n β‰₯ 2m) β€” the number of participants of the qualifying contest and the number of regions in Berland. Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive). It is guaranteed that all surnames of all the participants are distinct and at least two people participated from each of the m regions. The surnames that only differ in letter cases, should be considered distinct. Output Print m lines. On the i-th line print the team of the i-th region β€” the surnames of the two team members in an arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region. Examples Input 5 2 Ivanov 1 763 Andreev 2 800 Petrov 1 595 Sidorov 1 790 Semenov 2 503 Output Sidorov Ivanov Andreev Semenov Input 5 2 Ivanov 1 800 Andreev 2 763 Petrov 1 800 Sidorov 1 800 Semenov 2 503 Output ? Andreev Semenov Note In the first sample region teams are uniquely determined. In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely. Submitted Solution: ``` n, m = map(int,input().split()) temp = [list(map(str,input().split())) for i in range(n)] regions = [[-1]*3 for i in range(m+1)] regions2 = [[-1]*3 for i in range(m+1)] for i in range(n): j = 1 temp2 = int(temp[i][2]) temp3 = int(temp[i][1]) if temp2 > regions[temp3][0]: regions[temp3][0] = temp2 regions2[temp3][0] = i while 3 > j and temp2 > regions[temp3][j]: regions[temp3][j-1] = regions[temp3][j] regions[temp3][j] = temp2 regions2[temp3][j-1] = regions2[temp3][j] regions2[temp3][j] = i j += 1 for i in range(1,m+1): if regions[i][1] != regions[i][2]: print(temp[regions2[i][1]][0],temp[regions2[i][2]][0]) else: print("?") ```
instruction
0
12,107
17
24,214
No
output
1
12,107
17
24,215
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,406
17
24,812
"Correct Solution: ``` dic={1:0,2:0,3:0,4:0,5:0,6:0} n=int(input()) for i in range(n): N=float(input()) if N<165:dic[1] +=1 elif 165<=N<170:dic[2] +=1 elif 170<=N<175:dic[3] += 1 elif 175<=N<180:dic[4] += 1 elif 180<=N<185:dic[5] += 1 else:dic[6] +=1 for i in range(6):print("%d:"%(i+1)+"*"*dic[i+1]) ```
output
1
12,406
17
24,813
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,407
17
24,814
"Correct Solution: ``` n = int(input()) H=[] for i in range(n): H.append(float(input())) c1=0 c2=0 c3=0 c4=0 c5=0 c6=0 for j in range(n): if H[j]< 165.0: c1+=1 elif 165.0<= H[j]<170.0: c2+=1 elif 170.0<= H[j]<175.0: c3+=1 elif 175.0<= H[j]<180.0: c4+=1 elif 180.0<= H[j]<185.0: c5+=1 else: c6+=1 print("1:"+ c1*"*", sep="") print("2:"+ c2*"*", sep="") print("3:"+ c3*"*", sep="") print("4:"+ c4*"*", sep="") print("5:"+ c5*"*", sep="") print("6:"+ c6*"*", sep="") ```
output
1
12,407
17
24,815
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,408
17
24,816
"Correct Solution: ``` n = int(input()) data = {k: 0 for k in range(1, 7)} for _ in range(n): tmp = float(input()) if tmp < 165.0: data[1] += 1 elif 165.0 <= tmp < 170.0: data[2] += 1 elif 170.0 <= tmp < 175.0: data[3] += 1 elif 175.0 <= tmp < 180.0: data[4] += 1 elif 180.0 <= tmp < 185.0: data[5] += 1 else: data[6] += 1 for k, v in data.items(): print("{}:{}".format(k, v*"*")) ```
output
1
12,408
17
24,817
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,409
17
24,818
"Correct Solution: ``` L = [0] * 7 num = int(input()) for _ in range(num): h = float(input()) if h < 165: L[1] += 1 elif h < 170: L[2] += 1 elif h < 175: L[3] += 1 elif h < 180: L[4] += 1 elif h < 185: L[5] += 1 else: L[6] += 1 for i in range(1,7): print("{}:{}".format(i, "*" * L[i])) ```
output
1
12,409
17
24,819
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,410
17
24,820
"Correct Solution: ``` # AOJ 0136: Frequency Distribution of Height # Python3 2018.6.18 bal4u freq = [0]*6 for i in range(int(input())): k = float(input()) if k < 165: freq[0] += 1 elif k < 170: freq[1] += 1 elif k < 175: freq[2] += 1 elif k < 180: freq[3] += 1 elif k < 185: freq[4] += 1 else: freq[5] += 1 for i in range(6): print(i+1, ':', '*'*freq[i], sep='') ```
output
1
12,410
17
24,821
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,411
17
24,822
"Correct Solution: ``` n = int(input()) h = [0 for i in range(6)] for i in range(n): a = float(input()) if(a < 165.0): h[0] += 1 elif(165.0 <= a and a < 170.0): h[1] += 1 elif(170.0 <= a and a < 175.0): h[2] += 1 elif(175.0 <= a and a < 180.0): h[3] += 1 elif(180.0 <= a and a < 185.0): h[4] += 1 else: h[5] += 1 for i in range(len(h)): print(str(i + 1) + ":" + "*"*h[i]) ```
output
1
12,411
17
24,823
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,412
17
24,824
"Correct Solution: ``` n = int(input()) data = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0 } for _ in range(n): x = float(input()) if x < 165.0: data[1] += 1 elif 165.0 <= x < 170.0: data[2] += 1 elif 170.0 <= x < 175.0: data[3] += 1 elif 175.0 <= x < 180.0: data[4] += 1 elif 180.0 <= x < 185.0: data[5] += 1 elif 185.0 <= x: data[6] += 1 for key, val in data.items(): a = '*' * val print('{}:{}'.format(key, a)) ```
output
1
12,412
17
24,825
Provide a correct Python 3 solution for this coding contest problem. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:*
instruction
0
12,413
17
24,826
"Correct Solution: ``` n = int(input()) hist = [''] * 6 for _ in range(n): h = float(input()) if h < 165: hist[0] += '*' elif 165 <= h < 170: hist[1] += "*" elif 170 <= h < 175: hist[2] += "*" elif 175 <= h < 180: hist[3] += "*" elif 180 <= h < 185: hist[4] += "*" else: hist[5] += "*" for i in range(6): print(str(i+1) + ':' + hist[i]) ```
output
1
12,413
17
24,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:* Submitted Solution: ``` n = int(input()) height = [0 for i in range(6)] for i in range(n): tmp = float(input()) if tmp < 165: height[0]+=1 elif tmp < 170: height[1]+=1 elif tmp < 175: height[2]+=1 elif tmp < 180: height[3]+=1 elif tmp < 185: height[4]+=1 else: height[5]+=1 for i, j in enumerate(height,1): print(str(i)+":"+"*"*j) ```
instruction
0
12,414
17
24,828
Yes
output
1
12,414
17
24,829
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The height of the student was measured at the medical examination. Create a program that takes height data as input, creates a frequency distribution, and outputs it. The frequency distribution is divided into 6 classes in 5 cm increments, and the number of people is indicated by * (half-width asterisk). However, if the frequency (number of people) of that class is 0, output only the class heading. Input The input is given in the following format: n h1 h2 :: hn The number of students n (1 ≀ n ≀ 40) is given to the first line, and the real number hi (150.0 ≀ hi ≀ 190.0, up to the first decimal place) representing the height of the i-th person is given to each line after the second line. .. Output Display the frequency distribution in the following format. Line 1 Heading "1:" followed by * for people less than 165.0 cm * 2nd line Heading "2:" followed by people 165.0 cm or more and less than 170.0 cm * 3rd line Heading "3:" followed by the number of people from 170.0 cm or more to less than 175.0 cm * 4th line Heading "4:" followed by the number of people from 175.0 cm to less than 180.0 cm * Line 5 Heading "5:" followed by the number of people between 180.0 cm and 185.0 cm * Line 6 Heading "6:" followed by * for people over 185.0 cm * Examples Input 4 180.3 168.2 165.5 175.3 Output 1: 2:** 3: 4:* 5:* 6: Input 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 Output 1:*** 2:***** 3:******* 4:**** 5:* 6:* Submitted Solution: ``` def getIndex(n): i = 6 if n < 165: i = 1 elif n >= 165 and n < 170: i = 2 elif n >= 170 and n < 175: i = 3 elif n >= 175 and n < 180: i = 4 elif n >= 180 and n < 185: i = 5 return i nums = [0] * 7 n = int(input()) for i in range(0,n): h = float(input()) nums[getIndex(h)] += 1 for i in range(1,len(nums)): ans = str(i) + ":" for j in range(0,nums[i]): ans += "*" print(ans) ```
instruction
0
12,415
17
24,830
Yes
output
1
12,415
17
24,831