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. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
65,253
17
130,506
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` # [https://codeforces.com/contest/662/submission/35889556] for i in range(int(input())): t = input()[4:] q = int(t) d = 10**len(t) while q < 1988 + d // 9: q += d print(q) ```
output
1
65,253
17
130,507
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
65,254
17
130,508
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` #!/usr/bin/python3 delims = [0, 1989, 1999, 2099, 3099, 13099, 113099, 1113099, 11113099, 111113099, 1111113099] n = int(input()) for i in range(n): suf = input()[4:] min_val = delims[len(suf)] d = int(suf) while d < min_val: d += 10 ** len(suf) print(d) ```
output
1
65,254
17
130,509
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
65,255
17
130,510
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` def main(): l = [] for i in range(int(input())): y, n, m = 1989, 0, 1 for d in input()[-1:3:-1]: n += (ord(d) - 48) * m m *= 10 t = n - y % m y += (m + t if t < 0 else t) + m l.append(y - m) print('\n'.join(map(str, l))) if __name__ == '__main__': main() ```
output
1
65,255
17
130,511
Provide tags and a correct Python 3 solution for this coding contest problem. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999
instruction
0
65,256
17
130,512
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` n = int(input()) res = [] for i in range(n): line = input() year = 1989 for u in range(len(line)-1, 3, -1): a = line[u:] k = len(a) while year%(10**k)!=int(a): year = year+10**(k-1) year += 10**(k) res.append(year-10**k) for i in res: print(i) ```
output
1
65,256
17
130,513
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` n = int(input()) def get_next(x, suffix): k = 10 ** (len(suffix) - 1) num = int(x) + k while not str(num).endswith(suffix): #print(x, suffix, num, k) num += k return num res = [] for i in range(n): s = input().split('\'')[1] d = 1989 + (int(s[-1]) + 1) % 10 for i in reversed(range(len(s) - 1)): suf = s[i:] d = get_next(d, suf) res.append(d) for r in res: print(r) ```
instruction
0
65,257
17
130,514
Yes
output
1
65,257
17
130,515
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` a = [1989] pow = [10] for __ in range(9): a.append( a[len(a)-1] + pow[len(pow)-1] ) pow.append(pow[len(pow)-1] * 10 ) #print ( a ) #print ( pow ) n = int(input()) for __ in range(n): s = input() s = s[4:] k = len(s) - 1 #print ( s , k ) tmp = int(s) fst = a[k] % pow[k] if tmp < fst : tmp += pow[k] #print ( "t" , tmp , fst ) print ( a[k] + ( tmp - fst ) ) ```
instruction
0
65,258
17
130,516
Yes
output
1
65,258
17
130,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` n=int(input()) lst=[] for i in range(n): n=input() lst.append(n[4:]) for i in lst: l=len(i) i=int(i) #print(i) g=0 p=10 c=1 while(c<l): g+=p p*=10 c+=1 #print(g,p) while(i<1989+g): i+=p print(i) ```
instruction
0
65,259
17
130,518
Yes
output
1
65,259
17
130,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` n = int(input()) for testCase in range(n): s = input()[4:].strip() n = int(s) year = 1989 period = 1 for i in range(len(s) - 1): period *= 10 year += period cur_suff = int(str(year)[-len(s):]) if cur_suff <= n: print(year + n - cur_suff) else: all9 = int('9' * len(s)) year += all9 - cur_suff print(year + 1 + n) ```
instruction
0
65,260
17
130,520
Yes
output
1
65,260
17
130,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` n=int(input()) a=[] q='1' v='' b={'9':'1989','0':'1990','1':'1991','15':'2015','99':'1999'} for i in range(n): a.append(input().split("IAO'")[1]) if(a[i] in b): print(b[a[i]]) else: if(len(a[i])==1): print('199'+a[i]) b[a[i]]='199'+a[i] elif(len(a[i])==2): print('20'+a[i]) b[a[i]]='20'+a[i] elif(len(a[i])==3): print('2'+a[i]) b[a[i]]='2'+a[i] elif(len(a[i])==4): if(True): v=a[i] while(v in list(b.values())): v=q+a[i] q=str(int(q)+1) print(v) b[a[i]]=a[i] q='1' else: v=a[i] if(int(a[i])<int('1'*(len(a[i])-1)+'0')+1988): v=q+v while(v in list(b.values())): v=q+a[i] q=str(int(q)+1) print(v) b[a[i]]=a[i] q='1' ```
instruction
0
65,261
17
130,522
No
output
1
65,261
17
130,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` n=int(input()) a=[] q='1' v='' b={'9':'1989','0':'1990','1':'1991','15':'2015','99':'1999'} for i in range(n): a.append(input().split("IAO'")[1]) if(a[i] in b): print(b[a[i]]) else: if(len(a[i])==1): print('199'+a[i]) b[a[i]]='199'+a[i] elif(len(a[i])==2): print('20'+a[i]) b[a[i]]='20'+a[i] elif(len(a[i])==3): print('2'+a[i]) b[a[i]]='2'+a[i] elif(len(a[i])==4): if(True): v=a[i] while(v in list(b.values())): v=q+a[i] q=str(int(q)+1) print(v) b[a[i]]=a[i] q='1' else: v=q+a[i] while(v in list(b.values())): v=q+a[i] q=str(int(q)+1) print(v) b[a[i]]=a[i] q='1' ```
instruction
0
65,262
17
130,524
No
output
1
65,262
17
130,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` from sys import stdin n=int(stdin.readline().strip()) st=set() for i in range(n): s=(stdin.readline().strip()[4::]) x=10**(len(s)) s=int(s) while s<1989 or s in st: s+=x st.add(s) print(s) ```
instruction
0
65,263
17
130,526
No
output
1
65,263
17
130,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition. For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995. You are given a list of abbreviations. For each of them determine the year it stands for. Input The first line of the input contains a single integer n (1 ≀ n ≀ 1000) β€” the number of abbreviations to process. Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. Output For each abbreviation given in the input, find the year of the corresponding Olympiad. Examples Input 5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0 Output 2015 12015 1991 1989 1990 Input 4 IAO'9 IAO'99 IAO'999 IAO'9999 Output 1989 1999 2999 9999 Submitted Solution: ``` import re n = int(input()) def getBigger(n,v): if (n > v) : return n tmp = n bits = 1 tmp //= 10 while(tmp > 0): bits += 1 tmp //= 10 tmp = 1 #print(bits) while(bits > 0): tmp = tmp * 10 bits -= 1 #print(tmp) tmpv = v % tmp if (tmpv >= n): return v - tmpv + tmp + n else : return v - tmpv + n Used = {} a = [] for i in range(n): s = input() a.append(int(s[4:])) origin = int('1988') #print(a) for x in a: p = getBigger(x,origin) while(p in Used) : p = getBigger(x,p) #print(p) Used[p] = 1 print(p) ```
instruction
0
65,264
17
130,528
No
output
1
65,264
17
130,529
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,976
17
131,952
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` def solve(a,b): n = len(a) m = len(b) a = sorted(a) b = sorted(b) r1 = n * 3 r2 = m * 3 max1 = r1 max2 = r2 p1 = 0 p2 = 0 while p1 < n or p2 < m: v = 0 if p2 == m: v = a[p1] elif p1 == n: v = b[p2] else: v =min(a[p1],b[p2]) while p1 < n and a[p1] == v: r1 -= 1 p1 += 1 while p2 < m and b[p2] == v: r2 -= 1 p2 += 1 if r1 - r2 > max1 - max2 or (r1-r2 == max1-max2 and r1 > max1): max1 = r1 max2 = r2 return (max1, max2) n = input() a = list(map(int, input().split(' '))) n = input() b = list(map(int, input().split(' '))) print('%s:%s' % solve(a,b)) ```
output
1
65,976
17
131,953
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,977
17
131,954
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() I = lambda :list(map(int, input().split())) from bisect import bisect as br n, = I() a = I() a.sort() m, = I() b = [0] + I() b.sort() ansa = 0 ansb = 0 mx = -10000000000000000 for i in range(m+1): k = br(a, b[i]) bb = 2*(i) + 3*(m - i) aa = k*2 + 3*(n - k) if aa - bb > mx: mx = aa - bb ansa = aa ansb = bb if mx == aa - bb and aa > ansa: ansa = aa ansb = bb print(ansa, ':', ansb, sep = '') ```
output
1
65,977
17
131,955
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,978
17
131,956
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` from sys import stdout, stdin, maxsize n = int(input()) team1 = list(map(int, input().split())) m = int(input()) team2 = list(map(int, input().split())) ls = [] for i in range(n): ls.append([team1[i], 1]) for i in range(m): ls.append([team2[i], 2]) ls.sort() score1 = 3 * n score2 = 3 * m ans = [score1, score2] mx = score1-score2 for i in range(m + n): if ls[i][1] == 1: score1 -= 1 else: score2 -= 1 if score1 - score2 > mx: ans = [score1, score2] mx = score1 - score2 print(f'{ans[0]}:{ans[1]}') ```
output
1
65,978
17
131,957
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,979
17
131,958
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` def read_pack(): c = int(input()) x = list(map(int, str.split(input()))) x.sort() return c, x + [0] n, a = read_pack() m, b = read_pack() i = j = 0 pa = pb = None while i <= n and j <= m: ca = (n - i) * 3 + i * 2 cb = (m - j) * 3 + j * 2 if pa is None or (ca - cb > pa - pb) or (ca - cb == pa - pb and ca > pa): pa, pb = ca, cb if j == m: i += 1 elif i == n: j += 1 elif a[i] < b[j]: i += 1 elif a[i] > b[j]: j += 1 else: i += 1 j += 1 print(str.format("{}:{}", pa, pb)) ```
output
1
65,979
17
131,959
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,980
17
131,960
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase from bisect import * def main(): n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) a.sort() b.sort() a=a[::-1] dff=2*(n-m) x,y=2*n,2*m # print(*a) # print(*b) for i in range(n): z=a[i] zz=bisect_left(b,z) # print(zz) dfa=2*(n-i-1)+3*(i+1) dfb=3*(m-zz)+2*(zz) if dff<=dfa-dfb: dff=dfa-dfb x=dfa y=dfb print(f'{x}:{y}') # 3 # 1 1 1 # 4 # 1 3 1 1 # 3 # 1 2 3 # 3 # 6 4 5 # 5 # 1 2 3 4 5 # 5 # 6 7 8 9 10 # region fastio 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') # endregion if __name__ == '__main__': main() ```
output
1
65,980
17
131,961
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,981
17
131,962
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` I = lambda: list(map(int, input().split())) n = I()[0] d1 = [0]+sorted(I()) m = I()[0] d2 = [0]+sorted(I()) index1, index2 = {}, {} index1[0], index2[0] = n, m i, j = n, m while (i>=0 and j>=0): maxd = max(d1[i], d2[j]) if not(maxd in index1): index1[maxd] = n - i if not(maxd in index2): index2[maxd] = m - j if d1[i] == maxd: i -= 1 if d2[j] == maxd: j -= 1 while (i>=0): if not(d1[i] in index1): index1[d1[i]] = n - i i -= 1 while (j>=0): if not(d2[j] in index2): index2[d2[j]] = m - j j -= 1 a, b, maxdiff = 0, 0, -1e100 for foo in [0] + d1 + d2: i = index1[foo] j = index2[foo] _a, _b = i * 3 + (n - i) * 2, j * 3 + (m - j) * 2 diff = _a - _b if (diff > maxdiff) or (diff == maxdiff and _a > a): maxdiff = diff a, b = _a, _b print('%d:%d' % (a,b)) ```
output
1
65,981
17
131,963
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,982
17
131,964
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` n,_a=int(input()),list(map(int,input().split())) m,_b=int(input()),list(map(int,input().split())) p=[(ai,0) for ai in _a] + [(bi,1) for bi in _b] p.sort() i=0 R=[len(_a)*3,len(_b)*3] r=list(R) while i<len(p): d = p[i][0] while i<len(p) and p[i][0]==d: r[p[i][1]] -= 1 i += 1 if (r[0]-r[1] > R[0]-R[1]): R=list(r) print(*R,sep=':') ```
output
1
65,982
17
131,965
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10
instruction
0
65,983
17
131,966
Tags: binary search, brute force, data structures, implementation, sortings, two pointers Correct Solution: ``` from itertools import chain from bisect import bisect_left as bisect def main(): n = int(input().strip()) aa = list(map(int, input().strip().split())) aa.sort() m = int(input().strip()) bb = list(map(int, input().strip().split())) bb.sort() res = [] dd = set(chain(aa, bb)) for d in chain(aa, bb): dd.add(d + 1) la = len(aa) * 3 lb = len(bb) * 3 for d in dd: a = la - bisect(aa, d) b = lb - bisect(bb, d) res.append((a - b, a)) b, a = max(res) print('{:n}:{:n}'.format(a, a - b)) main() ```
output
1
65,983
17
131,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` from bisect import bisect_left n = int(input()) a = [int(x) for x in input().split()] m = int(input()) b = [int(x) for x in input().split()] a.sort() b.sort() three = 0 maxdif = -(10**10) for i in range(n): bi = bisect_left(b, a[i]) dif = ((n-i)*3 + (i+1)*2) - ((m-bi)*3 + (bi+1)*2) if dif > maxdif: three = a[i] maxdif = dif if n*2 - m*2 > maxdif: three = 10**10 sa, sb = 0,0 for x in a: if x >= three: sa += 3 else: sa += 2 for x in b: if x >= three: sb += 3 else: sb += 2 print(str(sa) + ":" + str(sb)) ```
instruction
0
65,984
17
131,968
Yes
output
1
65,984
17
131,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` __author__ = 'PrimuS' from bisect import bisect_left n = int(input()) t1 = [int(x) for x in input().split()] m = int(input()) t2 = [int(x) for x in input().split()] t1.sort() t2.sort() best = [3 * n, 3 * m] for i in range(n): a = 2 * i + 3 * (n - i) u = bisect_left(t2, t1[i]) b = u * 2 + 3 * (m - u) if a - b > best[0] - best[1]: best[0] = a best[1] = b if 2 * n - 2 * m > best[0] - best[1]: best = [2 * n, 2 * m] print(best[0], ":", best[1], sep='') ```
instruction
0
65,985
17
131,970
Yes
output
1
65,985
17
131,971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` from sys import stdin, stdout def solution(): n = int(stdin.readline().rstrip()) a = list(map(lambda x: (int(x), 1), stdin.readline().rstrip().split())) m = int(stdin.readline().rstrip()) b = list(map(lambda x: (int(x), 2), stdin.readline().rstrip().split())) c = a+b c.sort(key=lambda tup: tup[0]) aa = n*3 af = n*3 bf = m*3 bb = m*3 d = aa-bb prev = -1 for elem in c: if prev != elem[0]: prev = elem[0] if aa-bb > d: d = aa-bb af = aa bf = bb if elem[1] == 1: aa -= 1 else: bb -= 1 if aa - bb > d: d = aa - bb af = aa bf = bb stdout.write("{}:{}".format(af, bf)) if __name__ == '__main__': solution() ```
instruction
0
65,986
17
131,972
Yes
output
1
65,986
17
131,973
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase 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") ALPHA='abcdefghijklmnopqrstuvwxyz' M=998244353 EPS=1e-6 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=Int() a=array() a=[(1,i) for i in a] m=Int() b=array() b=[(2,i) for i in b] overall=a+b+[(0,0)] overall.sort(key= lambda x:x[1]) overall.append((inf,0)) distances={1:0,2:0,0:0} total={} # print(overall) ans=[-inf,-inf,-inf] for i in range(n+m+1): team,cur_dist=overall[i] _,next_dist=overall[i+1] distances[team]+=1 if(cur_dist!=next_dist): scoreA=distances[1]*2 + (n-distances[1])*3 scoreB=distances[2]*2 + (m-distances[2])*3 dif=scoreA-scoreB if(dif>ans[0]): ans=[dif,scoreA,scoreB] if(dif==ans[0] and scoreA>ans[1]): ans=[dif,scoreA,scoreB] # print(scoreA,scoreB) print(*ans[1:],sep=':') ```
instruction
0
65,987
17
131,974
Yes
output
1
65,987
17
131,975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` n = int(input()) a = [int(i) for i in input().split()] m = int(input()) b = [int(i) for i in input().split()] a.sort() min_ele = a[0] - 1 count = 0 for i in range(m): if min_ele >= b[i]: count += 2 else: count += 3 a_score = n*3 b_score = count ans = str(a_score) + ":" + str(b_score) print(ans) ```
instruction
0
65,988
17
131,976
No
output
1
65,988
17
131,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` I = lambda: list(map(int, input().split())) n = I()[0] d1 = sorted(I()) m = I()[0] d2 = sorted(I()) def bisection(d, x): l, r = 0, len(d) - 1 while(l != r): m = (l + r) // 2 if d[m] <= x: l = m + 1 if d[m] > x: r = m return [0, len(d) - l][d[l] > x] a, b, maxdiff = 0, 0, -1e100 for foo in [0] + d1 + d2: i = bisection(d1, foo) j = bisection(d2, foo) diff = i * 3 + (n - i) * 2 - j * 3 - (m - j) * 2 if diff > maxdiff: maxdiff = diff a, b = i * 3 + (n - i) * 2, j * 3 + (m - j) * 2 print('%d:%d' % (a,b)) ```
instruction
0
65,989
17
131,978
No
output
1
65,989
17
131,979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` from collections import defaultdict def main(n,a,m,b): mx = -999 for d in sorted(a+b+[0])[::-1]: s1 = n*2 + sum([i>d for i in a]) s2 = m*2 + sum([i>d for i in b]) if s1-s2 > mx: mx = s1-s2 res = "{}:{}".format(s1,s2) print(res) def main_input(): n = int(input()) a = [int(i) for i in input().split()] m = int(input()) b = [int(i) for i in input().split()] main(n,a,m,b) if __name__ == "__main__": main_input() ```
instruction
0
65,990
17
131,980
No
output
1
65,990
17
131,981
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer. Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that. Input The first line contains integer n (1 ≀ n ≀ 2Β·105) β€” the number of throws of the first team. Then follow n integer numbers β€” the distances of throws ai (1 ≀ ai ≀ 2Β·109). Then follows number m (1 ≀ m ≀ 2Β·105) β€” the number of the throws of the second team. Then follow m integer numbers β€” the distances of throws of bi (1 ≀ bi ≀ 2Β·109). Output Print two numbers in the format a:b β€” the score that is possible considering the problem conditions where the result of subtraction a - b is maximum. If there are several such scores, find the one in which number a is maximum. Examples Input 3 1 2 3 2 5 6 Output 9:6 Input 5 6 7 8 9 10 5 1 2 3 4 5 Output 15:10 Submitted Solution: ``` import bisect n = int(input()) a = [int(x) for x in input().split()] a.sort() m = int(input()) b = [int(x) for x in input().split()] b.sort() maxRes = - 11000000 #pos = [n*3, m*3] for i in range(n): k = bisect.bisect_left(b, a[i]) res = (i*2+(n-i)*3)-(k*3+(m-k)*3) #print(res) if res > maxRes: maxRes = res pos = [i*2+(n-i)*3, k*2+(m-k)*3] #print(i, k, pos) print(':'.join(list(map(str, pos)))) ```
instruction
0
65,991
17
131,982
No
output
1
65,991
17
131,983
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,178
17
132,356
Tags: implementation, sortings Correct Solution: ``` n=int(input()) m=input().split(" ") l=[] for i in range(len (m)): if int(m[i])!=0 and not(m[i] in l): l+=[m[i]] print(len (l)) ```
output
1
66,178
17
132,357
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,179
17
132,358
Tags: implementation, sortings Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) a=len(set(l)) if(0 in l): print(a-1) else: print(a) ```
output
1
66,179
17
132,359
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,180
17
132,360
Tags: implementation, sortings Correct Solution: ``` n = int(input()) a = [int(x) for x in input().split(' ')] s = set(a) s.discard(0) print(len(s)) ```
output
1
66,180
17
132,361
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,181
17
132,362
Tags: implementation, sortings Correct Solution: ``` x=int(input()) y=input().split() z=[int(i)for i in y] m=[] a=0 for i in range(x): if z[i]!=0 and z[i] not in m: a+=1 m.append(z[i]) print(a) ```
output
1
66,181
17
132,363
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,182
17
132,364
Tags: implementation, sortings Correct Solution: ``` n=input() x=list(set(list(map(int,input().split())))) if not (len(x)-1): print(1) elif 0 in x: print(len(x)-1) else: print(len(x)) ```
output
1
66,182
17
132,365
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,183
17
132,366
Tags: implementation, sortings Correct Solution: ``` # A. Olympiad n = int(input()) a = set(map(int, input().split())) if 0 in a: print(len(a) - 1) else: print(len(a)) ```
output
1
66,183
17
132,367
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,184
17
132,368
Tags: implementation, sortings Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) l.sort() s=1 for i in range(len(l)-1): if l[i]!=l[i+1]: s=s+1 if l[0]==0: s=s-1 print(s) ```
output
1
66,184
17
132,369
Provide tags and a correct Python 3 solution for this coding contest problem. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
instruction
0
66,185
17
132,370
Tags: implementation, sortings Correct Solution: ``` a = input() s = input().split() d = [] for i in s: if i not in d: d.append(i) if '0' in d: print(len(d) - 1) else: print(len(d)) ```
output
1
66,185
17
132,371
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` n = int(input()) l = sorted(list(map(int, input().split()))) st = set() for i in l: if i != 0: st.add(i) print(len(st)) ```
instruction
0
66,186
17
132,372
Yes
output
1
66,186
17
132,373
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` if __name__ == '__main__' : n = int(input()) a = [int(num) for num in input().split()] arr = list(filter(lambda n : n>0, a)) c = 1 arr.sort() for i in range (len(arr)-1) : if arr[i] != arr[i+1] : c = c+1 print(c) ```
instruction
0
66,187
17
132,374
Yes
output
1
66,187
17
132,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` n=int(input()) l1=list(map(int,input().split())) s1=set(l1) if(l1.count(0)>0): s1.remove(0) print(len(s1)) ```
instruction
0
66,188
17
132,376
Yes
output
1
66,188
17
132,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) s=set(a) if 0 in s: s.remove(0) print(len(s)) ```
instruction
0
66,189
17
132,378
Yes
output
1
66,189
17
132,379
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` def check(list): return all(i == list[0] for i in list) n = int(input()) a = list(map(int,input().strip().split()))[:n] c=0 if 0 not in a : c=c+1 if check(a) == False : c=c+1 a.sort() if a[0]>a[1]: c=c+1 print (c) ```
instruction
0
66,190
17
132,380
No
output
1
66,190
17
132,381
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` n=int(input()) arr=list(map(int,input().split())) print(len(list(set(arr)))-arr.count(0)) ```
instruction
0
66,191
17
132,382
No
output
1
66,191
17
132,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` n=int(input()) a=[int(i) for i in input().split()] a.sort() c=1 d=0 for i in range(0,n-1): if a[i]>0: if a[i]==a[i+1]: c=1 else: d=d+1 else: c=0 d=0 print(c+d) ```
instruction
0
66,192
17
132,384
No
output
1
66,192
17
132,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: * At least one participant should get a diploma. * None of those with score equal to zero should get awarded. * When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≀ ai ≀ 600) β€” participants' scores. It's guaranteed that at least one participant has non-zero score. Output Print a single integer β€” the desired number of ways. Examples Input 4 1 3 3 2 Output 3 Input 3 1 1 1 Output 1 Input 4 42 0 0 42 Output 1 Note There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 2. Participants with 2 or 3 points will get diplomas. 3. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) b=set(a) if 0 in b: print(len(a)-1) else: print(len(a)) ```
instruction
0
66,193
17
132,386
No
output
1
66,193
17
132,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new academic year has started, and Berland's university has n first-year students. They are divided into k academic groups, however, some of the groups might be empty. Among the students, there are m pairs of acquaintances, and each acquaintance pair might be both in a common group or be in two different groups. Alice is the curator of the first years, she wants to host an entertaining game to make everyone know each other. To do that, she will select two different academic groups and then divide the students of those groups into two teams. The game requires that there are no acquaintance pairs inside each of the teams. Alice wonders how many pairs of groups she can select, such that it'll be possible to play a game after that. All students of the two selected groups must take part in the game. Please note, that the teams Alice will form for the game don't need to coincide with groups the students learn in. Moreover, teams may have different sizes (or even be empty). Input The first line contains three integers n, m and k (1 ≀ n ≀ 500 000; 0 ≀ m ≀ 500 000; 2 ≀ k ≀ 500 000) β€” the number of students, the number of pairs of acquaintances and the number of groups respectively. The second line contains n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ k), where c_i equals to the group number of the i-th student. Next m lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n), denoting that students a_i and b_i are acquaintances. It's guaranteed, that a_i β‰  b_i, and that no (unordered) pair is mentioned more than once. Output Print a single integer β€” the number of ways to choose two different groups such that it's possible to select two teams to play the game. Examples Input 6 8 3 1 1 2 2 3 3 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 Output 2 Input 4 3 3 1 1 2 2 1 2 2 3 3 4 Output 3 Input 4 4 2 1 1 1 2 1 2 2 3 3 1 1 4 Output 0 Input 5 5 2 1 2 1 2 1 1 2 2 3 3 4 4 5 5 1 Output 0 Note The acquaintances graph for the first example is shown in the picture below (next to each student there is their group number written). <image> In that test we can select the following groups: * Select the first and the second groups. For instance, one team can be formed from students 1 and 4, while other team can be formed from students 2 and 3. * Select the second and the third group. For instance, one team can be formed 3 and 6, while other team can be formed from students 4 and 5. * We can't select the first and the third group, because there is no way to form the teams for the game. In the second example, we can select any group pair. Please note, that even though the third group has no students, we still can select it (with some other group) for the game. Submitted Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = map(int, input().split()) C = [0] + list(map(int, input().split())) V_color = [[] for _ in range(K+1)] for v in range(1, N+1): V_color[C[v]].append(v) E = {} UF = UnionFind(2 * N) for _ in range(M): a, b = map(int, input().split()) ca, cb = C[a], C[b] if ca == cb: UF.unite(a, b + N) UF.unite(a + N, b) else: if ca > cb: ca, cb = cb, ca c_ab = ca * (K+1) + cb if c_ab in E: E[c_ab].append((a, b)) else: E[c_ab] = [(a, b)] ok_color_num = 0 ok_color = [0] * (K+1) root_c = [set() for _ in range(K+1)] for c in range(1, K+1): ok = 1 for v in V_color[c]: r1 = UF.find_root(v) r2 = UF.find_root(v+N) if r1 == r2: ok = 0 break else: root_c[c].add(min(r1, r2)) if ok: ok_color_num += 1 ok_color[c] = 1 else: for v in V_color[c]: UF.root[v] = -1 if C[1] == 589: exit() R = [-1] * (N*2+1) for v in range(1, 2*N+1): R[v] = UF.find_root(v) ans = (ok_color_num - 1) * ok_color_num // 2 for c_ab in E: ca, cb = divmod(c_ab, K+1) if ok_color[ca] * ok_color[cb] == 0: continue root_ori = [] for v in root_c[ca]: root_ori.append((v, UF.root[v])) for v in root_c[cb]: root_ori.append((v, UF.root[v])) for a, b in E[c_ab]: ra = R[a] rb = R[b] if rb <= N: UF.unite(ra, rb+N) else: UF.unite(ra, rb-N) if ra <= N: UF.unite(ra+N, rb) else: UF.unite(ra-N, rb) ok = 1 if len(root_c[ca]) > len(root_c[cb]): ca = cb for v in root_c[ca]: if UF.isSameGroup(v, v+N): ok = 0 break """ if ok: for v in root_c[cb]: if UF.isSameGroup(v, v+N): ok = 0 break """ if ok == 0: ans -= 1 for v, r in root_ori: UF.root[v] = r UF.root[v+N] = r print(ans) if __name__ == '__main__': main() ```
instruction
0
66,652
17
133,304
No
output
1
66,652
17
133,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new academic year has started, and Berland's university has n first-year students. They are divided into k academic groups, however, some of the groups might be empty. Among the students, there are m pairs of acquaintances, and each acquaintance pair might be both in a common group or be in two different groups. Alice is the curator of the first years, she wants to host an entertaining game to make everyone know each other. To do that, she will select two different academic groups and then divide the students of those groups into two teams. The game requires that there are no acquaintance pairs inside each of the teams. Alice wonders how many pairs of groups she can select, such that it'll be possible to play a game after that. All students of the two selected groups must take part in the game. Please note, that the teams Alice will form for the game don't need to coincide with groups the students learn in. Moreover, teams may have different sizes (or even be empty). Input The first line contains three integers n, m and k (1 ≀ n ≀ 500 000; 0 ≀ m ≀ 500 000; 2 ≀ k ≀ 500 000) β€” the number of students, the number of pairs of acquaintances and the number of groups respectively. The second line contains n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ k), where c_i equals to the group number of the i-th student. Next m lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n), denoting that students a_i and b_i are acquaintances. It's guaranteed, that a_i β‰  b_i, and that no (unordered) pair is mentioned more than once. Output Print a single integer β€” the number of ways to choose two different groups such that it's possible to select two teams to play the game. Examples Input 6 8 3 1 1 2 2 3 3 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 Output 2 Input 4 3 3 1 1 2 2 1 2 2 3 3 4 Output 3 Input 4 4 2 1 1 1 2 1 2 2 3 3 1 1 4 Output 0 Input 5 5 2 1 2 1 2 1 1 2 2 3 3 4 4 5 5 1 Output 0 Note The acquaintances graph for the first example is shown in the picture below (next to each student there is their group number written). <image> In that test we can select the following groups: * Select the first and the second groups. For instance, one team can be formed from students 1 and 4, while other team can be formed from students 2 and 3. * Select the second and the third group. For instance, one team can be formed 3 and 6, while other team can be formed from students 4 and 5. * We can't select the first and the third group, because there is no way to form the teams for the game. In the second example, we can select any group pair. Please note, that even though the third group has no students, we still can select it (with some other group) for the game. Submitted Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = map(int, input().split()) C = [0] + list(map(int, input().split())) V_color = [[] for _ in range(K+1)] for v in range(1, N+1): V_color[C[v]].append(v) E = {} UF = UnionFind(2 * N) for _ in range(M): a, b = map(int, input().split()) ca, cb = C[a], C[b] if ca == cb: UF.unite(a, b + N) UF.unite(a + N, b) else: if ca > cb: ca, cb = cb, ca c_ab = ca * (K+1) + cb if c_ab in E: E[c_ab].append((a, b)) else: E[c_ab] = [(a, b)] ok_color_num = 0 ok_color = [0] * (K+1) root_c = [set() for _ in range(K+1)] for c in range(1, K+1): ok = 1 for v in V_color[c]: r1 = UF.find_root(v) r2 = UF.find_root(v+N) if r1 == r2: ok = 0 break else: root_c[c].add(min(r1, r2)) if ok: ok_color_num += 1 ok_color[c] = 1 else: for v in V_color[c]: UF.root[v] = -1 R = [-1] * (N*2+1) for v in range(1, 2*N+1): R[v] = UF.find_root(v) if C[1] == 589: exit() ans = (ok_color_num - 1) * ok_color_num // 2 for c_ab in E: ca, cb = divmod(c_ab, K+1) if ok_color[ca] * ok_color[cb] == 0: continue root_ori = [] for v in root_c[ca]: root_ori.append((v, UF.root[v])) for v in root_c[cb]: root_ori.append((v, UF.root[v])) for a, b in E[c_ab]: ra = R[a] rb = R[b] if rb <= N: UF.unite(ra, rb+N) else: UF.unite(ra, rb-N) if ra <= N: UF.unite(ra+N, rb) else: UF.unite(ra-N, rb) ok = 1 if len(root_c[ca]) > len(root_c[cb]): ca = cb for v in root_c[ca]: if UF.isSameGroup(v, v+N): ok = 0 break """ if ok: for v in root_c[cb]: if UF.isSameGroup(v, v+N): ok = 0 break """ if ok == 0: ans -= 1 for v, r in root_ori: UF.root[v] = r UF.root[v+N] = r print(ans) if __name__ == '__main__': main() ```
instruction
0
66,653
17
133,306
No
output
1
66,653
17
133,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new academic year has started, and Berland's university has n first-year students. They are divided into k academic groups, however, some of the groups might be empty. Among the students, there are m pairs of acquaintances, and each acquaintance pair might be both in a common group or be in two different groups. Alice is the curator of the first years, she wants to host an entertaining game to make everyone know each other. To do that, she will select two different academic groups and then divide the students of those groups into two teams. The game requires that there are no acquaintance pairs inside each of the teams. Alice wonders how many pairs of groups she can select, such that it'll be possible to play a game after that. All students of the two selected groups must take part in the game. Please note, that the teams Alice will form for the game don't need to coincide with groups the students learn in. Moreover, teams may have different sizes (or even be empty). Input The first line contains three integers n, m and k (1 ≀ n ≀ 500 000; 0 ≀ m ≀ 500 000; 2 ≀ k ≀ 500 000) β€” the number of students, the number of pairs of acquaintances and the number of groups respectively. The second line contains n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ k), where c_i equals to the group number of the i-th student. Next m lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n), denoting that students a_i and b_i are acquaintances. It's guaranteed, that a_i β‰  b_i, and that no (unordered) pair is mentioned more than once. Output Print a single integer β€” the number of ways to choose two different groups such that it's possible to select two teams to play the game. Examples Input 6 8 3 1 1 2 2 3 3 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 Output 2 Input 4 3 3 1 1 2 2 1 2 2 3 3 4 Output 3 Input 4 4 2 1 1 1 2 1 2 2 3 3 1 1 4 Output 0 Input 5 5 2 1 2 1 2 1 1 2 2 3 3 4 4 5 5 1 Output 0 Note The acquaintances graph for the first example is shown in the picture below (next to each student there is their group number written). <image> In that test we can select the following groups: * Select the first and the second groups. For instance, one team can be formed from students 1 and 4, while other team can be formed from students 2 and 3. * Select the second and the third group. For instance, one team can be formed 3 and 6, while other team can be formed from students 4 and 5. * We can't select the first and the third group, because there is no way to form the teams for the game. In the second example, we can select any group pair. Please note, that even though the third group has no students, we still can select it (with some other group) for the game. Submitted Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys from time import time input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = map(int, input().split()) C = [0] + list(map(int, input().split())) if C[1] == 589: t0 = time() V_color = [[] for _ in range(K+1)] for v in range(1, N+1): V_color[C[v]].append(v) E = {} UF = UnionFind(2 * N) for _ in range(M): a, b = map(int, input().split()) ca, cb = C[a], C[b] if ca == cb: UF.unite(a, b + N) UF.unite(a + N, b) else: if ca > cb: ca, cb = cb, ca c_ab = ca * (K+1) + cb if c_ab in E: E[c_ab].append((a, b)) else: E[c_ab] = [(a, b)] ok_color_num = 0 ok_color = [0] * (K+1) root_c = [set() for _ in range(K+1)] for c in range(1, K+1): ok = 1 for v in V_color[c]: r1 = UF.find_root(v) r2 = UF.find_root(v+N) if r1 == r2: ok = 0 break else: root_c[c].add(min(r1, r2)) if ok: ok_color_num += 1 ok_color[c] = 1 else: for v in V_color[c]: UF.root[v] = -1 R = [-1] * (N*2+1) for v in range(1, 2*N+1): R[v] = UF.find_root(v) ans = (ok_color_num - 1) * ok_color_num // 2 X = len(E) cnt = 0 for c_ab in E: cnt += 1 if C[1] == 589: if time() - t0 > 2.8: print(cnt, X) exit() ca, cb = divmod(c_ab, K+1) if ok_color[ca] * ok_color[cb] == 0: continue root_ori = [] for v in root_c[ca]: root_ori.append((v, UF.root[v])) for v in root_c[cb]: root_ori.append((v, UF.root[v])) for a, b in E[c_ab]: ra = R[a] rb = R[b] if rb <= N: UF.unite(ra, rb+N) else: UF.unite(ra, rb-N) if ra <= N: UF.unite(ra+N, rb) else: UF.unite(ra-N, rb) ok = 1 if len(root_c[ca]) > len(root_c[cb]): ca = cb for v in root_c[ca]: if UF.isSameGroup(v, v+N): ok = 0 break """ if ok: for v in root_c[cb]: if UF.isSameGroup(v, v+N): ok = 0 break """ if ok == 0: ans -= 1 for v, r in root_ori: UF.root[v] = r UF.root[v+N] = r print(ans) if __name__ == '__main__': main() ```
instruction
0
66,654
17
133,308
No
output
1
66,654
17
133,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The new academic year has started, and Berland's university has n first-year students. They are divided into k academic groups, however, some of the groups might be empty. Among the students, there are m pairs of acquaintances, and each acquaintance pair might be both in a common group or be in two different groups. Alice is the curator of the first years, she wants to host an entertaining game to make everyone know each other. To do that, she will select two different academic groups and then divide the students of those groups into two teams. The game requires that there are no acquaintance pairs inside each of the teams. Alice wonders how many pairs of groups she can select, such that it'll be possible to play a game after that. All students of the two selected groups must take part in the game. Please note, that the teams Alice will form for the game don't need to coincide with groups the students learn in. Moreover, teams may have different sizes (or even be empty). Input The first line contains three integers n, m and k (1 ≀ n ≀ 500 000; 0 ≀ m ≀ 500 000; 2 ≀ k ≀ 500 000) β€” the number of students, the number of pairs of acquaintances and the number of groups respectively. The second line contains n integers c_1, c_2, ..., c_n (1 ≀ c_i ≀ k), where c_i equals to the group number of the i-th student. Next m lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n), denoting that students a_i and b_i are acquaintances. It's guaranteed, that a_i β‰  b_i, and that no (unordered) pair is mentioned more than once. Output Print a single integer β€” the number of ways to choose two different groups such that it's possible to select two teams to play the game. Examples Input 6 8 3 1 1 2 2 3 3 1 3 1 5 1 6 2 5 2 6 3 4 3 5 5 6 Output 2 Input 4 3 3 1 1 2 2 1 2 2 3 3 4 Output 3 Input 4 4 2 1 1 1 2 1 2 2 3 3 1 1 4 Output 0 Input 5 5 2 1 2 1 2 1 1 2 2 3 3 4 4 5 5 1 Output 0 Note The acquaintances graph for the first example is shown in the picture below (next to each student there is their group number written). <image> In that test we can select the following groups: * Select the first and the second groups. For instance, one team can be formed from students 1 and 4, while other team can be formed from students 2 and 3. * Select the second and the third group. For instance, one team can be formed 3 and 6, while other team can be formed from students 4 and 5. * We can't select the first and the third group, because there is no way to form the teams for the game. In the second example, we can select any group pair. Please note, that even though the third group has no students, we still can select it (with some other group) for the game. Submitted Solution: ``` a, b, c = list(map(int, input().split())) if a == 6 and b == 8 and c == 3: print(2) elif a == 4 and b == 3 and c == 3: print(3) elif a == 4 and b == 4 and c == 2: print(0) elif a == 5 and b == 5 and c == 2: print(0) ```
instruction
0
66,655
17
133,310
No
output
1
66,655
17
133,311
Provide tags and a correct Python 3 solution for this coding contest problem. This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points. Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort. After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n + 1 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here. Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible. Input The first line contains a pair of integers n and k (1 ≀ k ≀ n + 1). The i-th of the following n lines contains two integers separated by a single space β€” pi and ei (0 ≀ pi, ei ≀ 200000). The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. * In subproblem C1 (4 points), the constraint 1 ≀ n ≀ 15 will hold. * In subproblem C2 (4 points), the constraint 1 ≀ n ≀ 100 will hold. * In subproblem C3 (8 points), the constraint 1 ≀ n ≀ 200000 will hold. Output Print a single number in a single line β€” the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1. Examples Input 3 2 1 1 1 4 2 2 Output 3 Input 2 1 3 2 4 0 Output -1 Input 5 2 2 10 2 10 1 1 3 1 3 1 Output 12 Note Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place. Consider the second test case. Even if Manao wins against both opponents, he will still rank third.
instruction
0
68,477
17
136,954
Tags: greedy Correct Solution: ``` m = 301000 ns = [0] * m es = [0] * m c = [0] * m b = [0] * m t = [0] * m P = 0 def add(b, k): k = t[k] while k: e = es[k] if b[-1] > e: b[-1] = e b[e] += 1 k = ns[k] def delete(b): for i in range(b[m - 1], m + 1): if b[i]: b[i] -= 1 b[-1] = i return i def calc(k): global b q = 0 b = [0] * m b[-1] = m take = rank - dn if take < 0: take = 0 add(b, k) add(b, k - 1) for i in range(1, take + 1): q += delete(b) for i in range(k - 1): add(b, i) for i in range(k + 1, P + 1): add(b, i) for i in range(1, k - take + 1): q += delete(b) return q n, k = map(int, input().split()) rank = n - k + 1 if rank == 0: print('0') exit(0) for i in range(1, n + 1): p, e = map(int, input().split()) if p > P: P = p c[p] += 1 es[i], ns[i] = e, t[p] t[p] = i dn = 0 for i in range(1, n + 1): if i > 1: dn += c[i - 2] if c[i] + c[i - 1] + dn >= rank and rank <= i + dn: u = calc(i) if i < n: dn += c[i - 1] v = calc(i + 1) if u > v: u = v if i < n - 1: dn += c[i] v = calc(i + 2) if u > v: u = v print(u) exit(0) print('-1') ```
output
1
68,477
17
136,955
Provide tags and a correct Python 3 solution for this coding contest problem. The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website. Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic. Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests. Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only. The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command. Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. Input The first line contains single integer n (1 ≀ n ≀ 105) β€” the number of files with tests. n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct. Output In the first line print the minimum number of lines in Vladimir's script file. After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" β€” is a string of digits and small English letters with length from 1 to 6. Examples Input 5 01 0 2 1 2extra 0 3 1 99 0 Output 4 move 3 1 move 01 5 move 2extra 4 move 99 3 Input 2 1 0 2 1 Output 3 move 1 3 move 2 1 move 3 2 Input 5 1 0 11 1 111 0 1111 1 11111 0 Output 5 move 1 5 move 11 1 move 1111 2 move 111 4 move 11111 3
instruction
0
68,632
17
137,264
Tags: greedy, implementation Correct Solution: ``` def print_all(): print(top) print(free_top) print(busy_top) print(bottom) print(free_bottom) print(busy_bottom) n = int(input()) top = set() bottom = set() for i in range(n): name, type = input().split() if type == '1': top.add(name) else: bottom.add(name) top_order = set(str(i) for i in range(1, len(top) + 1)) bottom_order = set(str(i) for i in range(len(top) + 1, len(bottom) + len(top) + 1)) q = top_order & top top_order -= q top -= q q = bottom_order & bottom bottom_order -= q bottom -= q busy_top = top_order & bottom free_top = top_order - bottom busy_bottom = bottom_order & top free_bottom = bottom_order - top if len(top_order) + len(bottom_order) == 0: print(0) exit(0) if len(free_bottom) + len(free_top) == 0: x, y = busy_top.pop(), 'rft330' free_top.add(x) bottom.remove(x) bottom.add(y) print(len(top_order) + len(bottom_order) + 1) print('move', x, y) else: print(len(top_order) + len(bottom_order)) cross_block = min(len(busy_bottom), len(busy_top)) if len(free_top) > 0 and cross_block > 0: x = free_top.pop() for i in range(cross_block): x, y = busy_bottom.pop(), x top.remove(x) print('move', x, y) x, y = busy_top.pop(), x bottom.remove(x) print('move', x, y) free_top.add(x) cross_block = min(len(busy_bottom), len(busy_top)) if len(free_bottom) > 0 and cross_block > 0: x = free_bottom.pop() for i in range(cross_block): x, y = busy_top.pop(), x bottom.remove(x) print('move', x, y) x, y = busy_bottom.pop(), x top.remove(x) print('move', x, y) free_bottom.add(x) if len(busy_bottom) == 0: for i in range(len(bottom)): print('move', bottom.pop(), free_bottom.pop()) free_top |= busy_top busy_top.clear() for i in range(len(top)): print('move', top.pop(), free_top.pop()) elif len(busy_top) == 0: for i in range(len(top)): print('move', top.pop(), free_top.pop()) free_bottom |= busy_bottom busy_bottom.clear() for i in range(len(bottom)): print('move', bottom.pop(), free_bottom.pop()) ```
output
1
68,632
17
137,265