message
stringlengths
2
39.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
219
108k
cluster
float64
11
11
__index_level_0__
int64
438
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0. Constraints * 1≦N≦10^5 * 0≦A_i≦N-1 Input The input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the number of the possible orders in which they were standing, modulo 10^9+7. Examples Input 5 2 4 4 0 2 Output 4 Input 7 6 4 0 2 4 0 2 Output 0 Input 8 7 5 1 1 7 3 5 3 Output 16 Submitted Solution: ``` N = int(input()) A = list(map(int,input().split())) d = N // 2 # ans = [] # def linking_up(): ans_1 = [ i for i in range(N) if A.count(i) == 2] # for i in range(N): # if i % 2 == 0 and i != 0: # if A.count(i) == 2 and A.count(0) == 1: # ans.append('c') # ans_2 = [ i for i in range(N) if i % 2 and A.count(i) == 2] # else: # if A.count(i) == 2: # ans.append('a') # linking_up() if len(ans_1) == d: print(2 ** d) else: print(0) ```
instruction
0
89,125
11
178,250
No
output
1
89,125
11
178,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial. Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials P(x) exist with integer non-negative coefficients so that <image>, and <image>, where <image> and b are given positive integers"? Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem. Input The input contains three integer positive numbers <image> no greater than 1018. Output If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109 + 7. Examples Input 2 2 2 Output 2 Input 2 3 3 Output 1 Submitted Solution: ``` import sys t, a, b = (map(int, input().split())) if a == b: if a == t: if a == 1: print("inf") else: print(2) else: print(1) sys.exit(0) if t == a: print(0) sys.exit(0) c = (a - b) // (t - a) if (a - b) % (t - a) == 0 and c >= 0 and a - c * t >= 0: print(1) sys.exit() print(0) ```
instruction
0
89,670
11
179,340
No
output
1
89,670
11
179,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial. Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials P(x) exist with integer non-negative coefficients so that <image>, and <image>, where <image> and b are given positive integers"? Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem. Input The input contains three integer positive numbers <image> no greater than 1018. Output If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo 109 + 7. Examples Input 2 2 2 Output 2 Input 2 3 3 Output 1 Submitted Solution: ``` import sys t, a, b = (map(int, input().split())) if a == b: if a == t: print(2) else: print(1) sys.exit(0) if t == a: print(0) sys.exit(0) #if ((a - b) % (t - a) == 0 && c >= 0 && A - C * T >= ) c = (a - b) // (t - a) if (a - b) % (t - a) == 0 and c >= 0 and a - c * t >= 0: print(1) sys.exit() print(0) ```
instruction
0
89,672
11
179,344
No
output
1
89,672
11
179,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] for s in sa: a = [[0] * 26] b = [set() for _ in range(ml)] for c in s: t = a[-1][:] t[ord(c) - ord('a')] += 1 a.append(t) for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add(tuple(map(lambda x: a[j][x]-a[i][x], range(26)))) ss.append(b) for i in range(ml-1,-1,-1): if ss[0][i] & ss[1][i]: return i + 1; return 0 print(main()) ```
instruction
0
90,055
11
180,110
No
output
1
90,055
11
180,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` print(4) ```
instruction
0
90,056
11
180,112
No
output
1
90,056
11
180,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): mod2 = 10**9+9 sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] for s in sa: a = [0] a2 = [0] b = [set() for _ in range(ml)] b2 = [set() for _ in range(ml)] for c in s: k = 97 ** (ord(c) - ord('a')) a.append((a[-1] + k) % mod) a2.append((a2[-1] + k) % mod2) for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add((a[j]-a[i]) % mod) b2[j-i-1].add((a2[j]-a2[i]) % mod2) ss.append([b,b2]) for i in range(ml-1,-1,-1): if ss[0][0][i] & ss[1][0][i] and ss[0][1][i] & ss[1][1][i]: return i + 1; return 0 print(main()) ```
instruction
0
90,057
11
180,114
No
output
1
90,057
11
180,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): mod2 = 10**9+9 sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] for s in sa: a = [0] a2 = [0] b = [set() for _ in range(ml)] b2 = [set() for _ in range(ml)] for c in s: k = 97 ** (ord(c) - ord('a')) a.append((a[-1] + k) % mod) a2.append((a2[-1] + k) % mod2) for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add(a[j]-a[i]) b2[j-i-1].add(a2[j]-a2[i]) ss.append([b,b2]) for i in range(ml-1,-1,-1): if ss[0][0][i] & ss[1][0][i] and ss[0][1][i] & ss[1][1][i]: return i + 1; return 0 print(main()) ```
instruction
0
90,058
11
180,116
No
output
1
90,058
11
180,117
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
instruction
0
90,610
11
181,220
Tags: brute force, greedy Correct Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 if (solved * 2 > n): value[i] = 500 elif (solved * 4 > n): value[i] = 1000 elif (solved * 8 > n): value[i] = 1500 elif (solved * 16 > n): value[i] = 2000 elif (solved * 32 > n): value[i] = 2500 else: value[i] = 3000 solve[i] = solved vasya = 0 for i in range(5): vasya += value[i] - value[i] // 250 * t[0][i] petya = 0 for i in range(5): petya += value[i] - value[i] // 250 * t[1][i] pot = [[0] * 20000 for i in range(5)] for problem in range(5): if t[0][problem] < t[1][problem]: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break elif t[0][problem] != 250: cur_ac = 0 while 1: if solve[problem] * 32 + cur_ac <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 + cur_ac <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 + cur_ac <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 + cur_ac <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 + cur_ac <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break else: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = -(3000 - 3000 // 250 * t[1][problem]) -( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 <= n + cur_ac: win = -(2500 - 2500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = -(2000 - 2000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = -(1500 - 1500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = -(1000 - 1000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = -(500 - 500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break res = -1 maxi = 0 for i in range(5): maxi = max(maxi, len(pot[i])) for i in range(maxi): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ```
output
1
90,610
11
181,221
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
instruction
0
90,611
11
181,222
Tags: brute force, greedy Correct Solution: ``` from sys import stdin, stdout fractionBoundaries = [1/2,1/4,1/8,1/16,1/32,0] scoreList = [500,1000,1500,2000,2500,3000] def assessScores(n,Vsol,Psol,solvers): vScore=0 pScore=0 for i in range(5): for j in range(6): if solvers[i]/n>fractionBoundaries[j]: qnScore=scoreList[j] break if Vsol[i]>=0: vScore+=qnScore-(qnScore*Vsol[i]//250) if Psol[i]>=0: pScore+=qnScore-(qnScore*Psol[i]//250) return vScore>pScore def main(): n = int(stdin.readline().rstrip()) Vsol = [int(x) for x in stdin.readline().rstrip().split()] Psol = [int(x) for x in stdin.readline().rstrip().split()] solvers = [0]*5 for _ in range(n-2): a = [int(x) for x in stdin.readline().rstrip().split()] for i in range(5): if a[i]>=0: solvers[i]+=1 for i in range(5): if Vsol[i]>=0: solvers[i]+=1 if Psol[i]>=0: solvers[i]+=1 newSolvers=0 vWins=[] pWins=[] for i in range(5): if (Vsol[i]<Psol[i] and Vsol[i]>=0) or (Vsol[i]>=0 and Psol[i]<0): vWins.append(i) elif (Psol[i]<Vsol[i] and Psol[i]>=0 and Vsol[i]>=0): pWins.append(i) if len(vWins)==0: print(-1) else: while not assessScores(n+newSolvers,Vsol,Psol,solvers) and newSolvers<=100000007: solversNeeded=9999999999999 for i in range(5): if i in vWins: currentRatio = solvers[i]/(newSolvers+n) for j in range(6): if solvers[i]/(newSolvers+n)>fractionBoundaries[j]: nextBoundary = fractionBoundaries[j] break if nextBoundary!=0: if solvers[i]%nextBoundary==0: solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n),solversNeeded]) else: solversNeeded = min([solvers[i]//nextBoundary - (newSolvers+n)+1,solversNeeded]) elif i in pWins and Vsol[i]>0: currentRatio = solvers[i]/(newSolvers+n) for j in range(6): if solvers[i]/(newSolvers+n)>fractionBoundaries[j]: if j>0: nextBoundary = fractionBoundaries[j-1] solversNeeded = min([(nextBoundary*(newSolvers+n)-solvers[i])//(1-nextBoundary)+1,solversNeeded]) break newSolvers+=solversNeeded for x in pWins: solvers[x]+=solversNeeded if newSolvers>1000000007: print(-1) else: print(int(newSolvers)) main() ```
output
1
90,611
11
181,223
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
instruction
0
90,612
11
181,224
Tags: brute force, greedy Correct Solution: ``` import sys inf = 10**9 + 7 def solve(): n = int(sys.stdin.readline()) v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya p = [int(pi) for pi in sys.stdin.readline().split()] # Petya cnt = [0]*5 for i in range(5): if v[i] != -1: cnt[i] += 1 if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 for i in range(4000): if check(n, v, p, cnt, i): print(i) return print(-1) def check(n, v, p, cnt, m): tot = n + m solved = cnt[:] dif = 0 for i in range(5): if p[i] != -1 and v[i] > p[i]: solved[i] += m for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i] == -1: pass elif v[i] == -1: dif -= max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += max_score * (250 - v[i]) // 250 else: dif += max_score * (p[i] - v[i]) // 250 return dif > 0 if __name__ == '__main__': solve() ```
output
1
90,612
11
181,225
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
instruction
0
90,613
11
181,226
Tags: brute force, greedy Correct Solution: ``` def get_value(parters, solved): if solved * 32 <= parters: return 3000 if solved * 16 <= parters: return 2500 if solved * 8 <= parters: return 2000 if solved * 4 <= parters: return 1500 if solved * 2 <= parters: return 1000 return 500 def points(value, time): return value - value // 500 * time n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 value[i] = get_value(n, solved) solve[i] = solved vasya = 0 for i in range(5): vasya += points(value[i], t[0][i]) petya = 0 for i in range(5): petya += points(value[i], t[1][i]) pot = [[0] * 20000 for i in range(5)] for problem in range(5): for cur_ac in range(20000): new_value = 0 if t[0][problem] < t[1][problem]: new_value = get_value(n + cur_ac, solve[problem]) elif t[0][problem] != 250: new_value = get_value(n + cur_ac, solve[problem] + cur_ac) else: new_value = get_value(n + cur_ac, solve[problem]) win = points(new_value, t[0][problem]) - points(new_value, t[1][problem]) - points(value[problem], t[0][problem]) + points(value[problem], t[1][problem]) pot[problem][cur_ac] = win res = -1 for i in range(20000): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ```
output
1
90,613
11
181,227
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
instruction
0
90,614
11
181,228
Tags: brute force, greedy Correct Solution: ``` import sys inf = 10**9 + 7 def solve(): def check(mid): tot = n + mid dif = 0 solved = cnt[:] for i in range(5): if v[i] != -1 and p[i] != -1 and p[i] < v[i]: solved[i] += mid for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i]: pass elif v[i] == -1: dif += max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += -max_score * (250 - v[i]) // 250 else: dif += max_score * (-p[i] + v[i]) // 250 # print(mid, dif) return dif < 0 n = int(sys.stdin.readline()) cnt = [0]*5 v = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if v[i] != -1: cnt[i] += 1 p = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 for i in range(6000): if check(i): print(i) return print(-1) if __name__ == '__main__': solve() ```
output
1
90,614
11
181,229
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.
instruction
0
90,615
11
181,230
Tags: brute force, greedy Correct Solution: ``` import sys inf = 10**9 + 7 def solve(): n = int(sys.stdin.readline()) v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya p = [int(pi) for pi in sys.stdin.readline().split()] # Petya cnt = [0]*5 for i in range(5): if v[i] != -1: cnt[i] += 1 if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 for i in range(10**5): if check(n, v, p, cnt, i): print(i) return print(-1) def check(n, v, p, cnt, m): tot = n + m solved = cnt[:] dif = 0 for i in range(5): if p[i] != -1 and v[i] > p[i]: solved[i] += m for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i] == -1: pass elif v[i] == -1: dif -= max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += max_score * (250 - v[i]) // 250 else: dif += max_score * (p[i] - v[i]) // 250 return dif > 0 if __name__ == '__main__': solve() ```
output
1
90,615
11
181,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 if (solved * 2 > n): value[i] = 500 elif (solved * 4 > n): value[i] = 1000 elif (solved * 8 > n): value[i] = 1500 elif (solved * 16 > n): value[i] = 2000 elif (solved * 32 > n): value[i] = 2500 else: value[i] = 3000 solve[i] = solved vasya = 0 for i in range(5): vasya += value[i] - value[i] // 250 * t[0][i] petya = 0 for i in range(5): petya += value[i] - value[i] // 250 * t[1][i] pot = [[0] * 20000 for i in range(5)] for problem in range(5): if t[0][problem] < t[1][problem]: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break elif t[0][problem] != 250: cur_ac = 0 while 1: if solve[problem] * 32 + cur_ac <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 + cur_ac <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 + cur_ac <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 + cur_ac <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 + cur_ac <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break else: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = -(3000 - 3000 // 250 * t[1][problem]) -( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break elif solve[problem] * 16 <= n + cur_ac: win = -(2500 - 2500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = -(2000 - 2000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = -(1500 - 1500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = -(1000 - 1000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = -(500 - 500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 if cur_ac == 20000: break res = -1 maxi = 0 for i in range(5): maxi = max(maxi, len(pot[i])) for i in range(maxi): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ```
instruction
0
90,616
11
181,232
No
output
1
90,616
11
181,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` import sys inf = 10**9 + 7 def solve(): def check(mid): tot = n + mid dif = 0 solved = cnt[:] for i in range(5): if p[i] != -1 and p[i] < v[i]: solved[i] += mid for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i]: pass elif v[i] == -1: dif += max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += -max_score * (250 - v[i]) // 250 else: dif += max_score * (-p[i] + v[i]) // 250 # print(mid, dif) return dif < 0 n = int(sys.stdin.readline()) cnt = [0]*5 v = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if v[i] != -1: cnt[i] += 1 p = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 btm = -1 top = inf + 2 while top - btm > 1: mid = (top + btm) // 2 if check(mid): top = mid else: btm = mid ans = top if top < inf + 1 else -1 print(ans) if __name__ == '__main__': solve() ```
instruction
0
90,617
11
181,234
No
output
1
90,617
11
181,235
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` import sys inf = 10**9 + 7 def solve(): def check(mid): tot = n + mid dif = 0 solved = cnt[:] for i in range(5): if v[i] != -1 and p[i] != -1 and p[i] < v[i]: solved[i] += mid for i in range(5): if solved[i]*2 > tot: max_score = 500 elif solved[i]*4 > tot: max_score = 1000 elif solved[i]*8 > tot: max_score = 1500 elif solved[i]*16 > tot: max_score = 2000 elif solved[i]*32 > tot: max_score = 2500 else: max_score = 3000 if v[i] == p[i]: pass elif v[i] == -1: dif += max_score * (250 - p[i]) // 250 elif p[i] == -1: dif += -max_score * (250 - v[i]) // 250 else: dif += max_score * (-p[i] + v[i]) // 250 # print(mid, dif) return dif < 0 n = int(sys.stdin.readline()) cnt = [0]*5 v = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if v[i] != -1: cnt[i] += 1 p = [int(i) for i in sys.stdin.readline().split()] for i in range(5): if p[i] != -1: cnt[i] += 1 for i in range(n - 2): a = [int(ai) for ai in sys.stdin.readline().split()] for j in range(5): if a[j] != -1: cnt[j] += 1 btm = -1 top = inf + 2 while top - btm > 1: mid = (top + btm) // 2 if check(mid): top = mid else: btm = mid ans = top if top < inf + 1 else -1 print(ans) if __name__ == '__main__': solve() ```
instruction
0
90,618
11
181,236
No
output
1
90,618
11
181,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round. <image> Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500. If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem. There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem. With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing. Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved. Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts. Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal. Input The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order. Output Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal. Examples Input 2 5 15 40 70 115 50 45 40 30 15 Output 2 Input 3 55 80 10 -1 -1 15 -1 79 60 -1 42 -1 13 -1 -1 Output 3 Input 5 119 119 119 119 119 0 0 0 0 -1 20 65 12 73 77 78 112 22 23 11 1 78 60 111 62 Output 27 Input 4 -1 20 40 77 119 30 10 73 50 107 21 29 -1 64 98 117 65 -1 -1 -1 Output -1 Note In the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points. In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points. In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one. Submitted Solution: ``` n = int(input()) t = [0] * n for i in range(n): t[i] = list(map(int, input().split())) value = [0] * 5 solve = [0] * 5 for i in range(5): solved = 0 for j in range(n): if t[j][i] != -1: solved += 1 else: t[j][i] = 250 if (solved * 2 > n): value[i] = 500 elif (solved * 4 > n): value[i] = 1000 elif (solved * 8 > n): value[i] = 1500 elif (solved * 16 > n): value[i] = 2000 elif (solved * 32 > n): value[i] = 2500 else: value[i] = 3000 solve[i] = solved vasya = 0 for i in range(5): vasya += value[i] - value[i] // 250 * t[0][i] petya = 0 for i in range(5): petya += value[i] - value[i] // 250 * t[1][i] pot = [[0] * 200000 for i in range(5)] for problem in range(5): if t[0][problem] < t[1][problem]: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break elif solve[problem] * 16 <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - (value[problem] - value[problem] // 250 * t[0][problem] -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 elif t[0][problem] != 250: cur_ac = 0 while 1: if solve[problem] * 32 + cur_ac <= n + cur_ac: win = 3000 - 3000 // 250 * t[0][problem] - (3000 - 3000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 16 + cur_ac <= n + cur_ac: win = 2500 - 2500 // 250 * t[0][problem] - (2500 - 2500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 + cur_ac <= n + cur_ac: win = 2000 - 2000 // 250 * t[0][problem] - (2000 - 2000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 + cur_ac <= n + cur_ac: win = 1500 - 1500 // 250 * t[0][problem] - (1500 - 1500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 + cur_ac <= n + cur_ac: win = 1000 - 1000 // 250 * t[0][problem] - (1000 - 1000 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = 500 - 500 // 250 * t[0][problem] - (500 - 500 // 250 * t[1][problem]) - ( value[problem] - value[problem] // 250 * t[0][problem] - ( value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break cur_ac += 1 else: cur_ac = 0 while 1: if solve[problem] * 32 <= n + cur_ac: win = -(3000 - 3000 // 250 * t[1][problem]) -( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win break elif solve[problem] * 16 <= n + cur_ac: win = -(2500 - 2500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 8 <= n + cur_ac: win = -(2000 - 2000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 4 <= n + cur_ac: win = -(1500 - 1500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win elif solve[problem] * 2 <= n + cur_ac: win = -(1000 - 1000 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win else: win = -(500 - 500 // 250 * t[1][problem]) - ( -(value[problem] - value[problem] // 250 * t[1][problem])) pot[problem][cur_ac] = win cur_ac += 1 res = -1 maxi = 0 for i in range(5): maxi = max(maxi, len(pot[i])) for i in range(maxi): tmp = 0 for pr in range(5): if len(pot[pr]) <= i: tmp += pot[pr][-1] else: tmp += pot[pr][i] if tmp > petya - vasya: res = i break print(res) ```
instruction
0
90,619
11
181,238
No
output
1
90,619
11
181,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing? Let a_i be how many numbers i (1 ≤ i ≤ k) you have. An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied: 1. The number of occupied cells doesn't exceed 3; 2. The numbers on each diagonal are distinct. Make a beautiful matrix of minimum size. Input The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases. The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively. The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have. It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5. Output For each t test case print a single integer n — the size of the beautiful matrix. In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up. Example Input 2 3 4 2 0 0 1 15 4 2 4 8 1 Output 2 4 1 0 1 5 3 0 0 2 2 3 2 3 3 0 0 1 0 4 0 3 0 0 0 0 2 1 3 3 3 Note Note that 0 in this problem represents a blank, not a number. Examples of possible answers for the first test case: \begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array} Examples of not beautiful matrices for the first test case: \begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array} The example of the not beautiful matrix for the second test case: \begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array} Everything is okay, except the left-top submatrix contains 4 numbers. Submitted Solution: ``` def cheak(x): return x**2-(x//2)**2>=m and x*(x//2+(1 if x%2!=0 else 0))>=mx for test in range(int(input())): m,k=(int(i) for i in input().split()) a=[int(i) for i in input().split()] mx=max(a) z=0;y=m*4 while z!=y: x=(z+y)//2 if cheak(x): y=x else: z=x+1 else: x=z a=sorted(list(map(list,zip(a,range(1,len(a)+1))))) def get(): i=len(a) while i!=0: i-=1 while a[i][0]>0: a[i][0]-=1 yield a[i][1] return 0 mt=[[0 for i in range(x)] for j in range(x)] t=1 it=get() try: for i in range(0,x,2): if t==0:break for j in range(0,x,2): t=next(it) if t:mt[i][j]=t else:break for i in range(0,x,2): if t==0:break for j in range(1,x,2): t=next(it) if t:mt[i][j]=t else:break for i in range(1,x,2): if t==0:break for j in range(0,x,2): t=next(it) if t:mt[i][j]=t else:break except StopIteration:... for i in mt: print(*i) ```
instruction
0
91,166
11
182,332
No
output
1
91,166
11
182,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing? Let a_i be how many numbers i (1 ≤ i ≤ k) you have. An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied: 1. The number of occupied cells doesn't exceed 3; 2. The numbers on each diagonal are distinct. Make a beautiful matrix of minimum size. Input The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases. The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively. The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have. It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5. Output For each t test case print a single integer n — the size of the beautiful matrix. In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up. Example Input 2 3 4 2 0 0 1 15 4 2 4 8 1 Output 2 4 1 0 1 5 3 0 0 2 2 3 2 3 3 0 0 1 0 4 0 3 0 0 0 0 2 1 3 3 3 Note Note that 0 in this problem represents a blank, not a number. Examples of possible answers for the first test case: \begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array} Examples of not beautiful matrices for the first test case: \begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array} The example of the not beautiful matrix for the second test case: \begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array} Everything is okay, except the left-top submatrix contains 4 numbers. Submitted Solution: ``` # 6fbbb444ee015ce84ca315f20e46e28a71024d21eb5e2c6477de2b0972b44556 print('hello') ```
instruction
0
91,167
11
182,334
No
output
1
91,167
11
182,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing? Let a_i be how many numbers i (1 ≤ i ≤ k) you have. An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied: 1. The number of occupied cells doesn't exceed 3; 2. The numbers on each diagonal are distinct. Make a beautiful matrix of minimum size. Input The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases. The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively. The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have. It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5. Output For each t test case print a single integer n — the size of the beautiful matrix. In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up. Example Input 2 3 4 2 0 0 1 15 4 2 4 8 1 Output 2 4 1 0 1 5 3 0 0 2 2 3 2 3 3 0 0 1 0 4 0 3 0 0 0 0 2 1 3 3 3 Note Note that 0 in this problem represents a blank, not a number. Examples of possible answers for the first test case: \begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array} Examples of not beautiful matrices for the first test case: \begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array} The example of the not beautiful matrix for the second test case: \begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array} Everything is okay, except the left-top submatrix contains 4 numbers. Submitted Solution: ``` from bisect import bisect,bisect_left from collections import * from heapq import * from math import gcd,ceil,sqrt,floor,inf from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # 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") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().split()) def RLL(): return list(map(int, sys.stdin.readline().split())) def N(): return int(input()) def A(n):return [0]*n def AI(n,x): return [x]*n def A2(n,m): return [[0]*m for i in range(n)] def G(n): return [[] for i in range(n)] def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc mod=10**9+7 farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa fact(x,mod) ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa.reverse() def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def floorsum(a,b,c,n):#sum((a*i+b)//c for i in range(n+1)) if a==0:return b//c*(n+1) if a>=c or b>=c: return floorsum(a%c,b%c,c,n)+b//c*(n+1)+a//c*n*(n+1)//2 m=(a*n+b)//c return n*m-floorsum(c,c-b-1,a,m-1) def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m def lowbit(n): return n&-n class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans class ST: def __init__(self,arr):#n!=0 n=len(arr) mx=n.bit_length()#取不到 self.st=[[0]*mx for i in range(n)] for i in range(n): self.st[i][0]=arr[i] for j in range(1,mx): for i in range(n-(1<<j)+1): self.st[i][j]=max(self.st[i][j-1],self.st[i+(1<<j-1)][j-1]) def query(self,l,r): if l>r:return -inf s=(r+1-l).bit_length()-1 return max(self.st[l][s],self.st[r-(1<<s)+1][s]) class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]>self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)] class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv class UF:#秩+路径+容量,边数 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n self.size=AI(n,1) self.edge=A(n) def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: self.edge[pu]+=1 return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu self.edge[pu]+=self.edge[pv]+1 self.size[pu]+=self.size[pv] if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv self.edge[pv]+=self.edge[pu]+1 self.size[pv]+=self.size[pu] def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break return flag def dij(s,graph): d=AI(n,inf) d[s]=0 heap=[(0,s)] vis=A(n) while heap: dis,u=heappop(heap) if vis[u]: continue vis[u]=1 for v,w in graph[u]: if d[v]>d[u]+w: d[v]=d[u]+w heappush(heap,(d[v],v)) return d def bell(s,g):#bellman-Ford dis=AI(n,inf) dis[s]=0 for i in range(n-1): for u,v,w in edge: if dis[v]>dis[u]+w: dis[v]=dis[u]+w change=A(n) for i in range(n): for u,v,w in edge: if dis[v]>dis[u]+w: dis[v]=dis[u]+w change[v]=1 return dis def lcm(a,b): return a*b//gcd(a,b) def lis(nums): res=[] for k in nums: i=bisect.bisect_left(res,k) if i==len(res): res.append(k) else: res[i]=k return len(res) def RP(nums):#逆序对 n = len(nums) s=set(nums) d={} for i,k in enumerate(sorted(s),1): d[k]=i bi=BIT([0]*(len(s)+1)) ans=0 for i in range(n-1,-1,-1): ans+=bi.query(d[nums[i]]-1) bi.update(d[nums[i]],1) return ans class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j,n,m): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj def topo(n): q=deque() res=[] for i in range(1,n+1): if ind[i]==0: q.append(i) res.append(i) while q: u=q.popleft() for v in g[u]: ind[v]-=1 if ind[v]==0: q.append(v) res.append(v) return res @bootstrap def gdfs(r,p): for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None #from random import randint t=N() for i in range(t): m,k=RL() a=RLL() l=1 r=m ma=max(a) while l<r: n=(l+r)>>1 if n&1: if (3*n**2+2*n-1)//4>=m and (n+1)*n//2>=ma: r=n else: l=n+1 else: if 3*n*n//4>=m and n*n//2>=ma: r=n else: l=n+1 c={} res=[] for i in range(k): if a[i]: res+=[i+1]*a[i] c[i+1]=a[i] res.sort(key=lambda x: -c[x]) ans=A2(l,l) p=0 for i in range(0,l,2): for j in range(0,l): ans[i][j]=res[p] p+=1 if p==len(res):break if p==len(res):break if p<len(res): for i in range(1,l,2): for j in range(0,l,2): ans[i][j]=res[p] p+=1 if p==len(res):break if p==len(res):break print(l) for r in ans: print(*r) ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thr ead(target=main) t.start() t.join() ''' ```
instruction
0
91,168
11
182,336
No
output
1
91,168
11
182,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like numbers, don't you? Nastia has a lot of numbers and she wants to share them with you! Isn't it amazing? Let a_i be how many numbers i (1 ≤ i ≤ k) you have. An n × n matrix is called beautiful if it contains all the numbers you have, and for each 2 × 2 submatrix of the original matrix is satisfied: 1. The number of occupied cells doesn't exceed 3; 2. The numbers on each diagonal are distinct. Make a beautiful matrix of minimum size. Input The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases. The first line of each test case contains 2 integers m and k (1 ≤ m, k ≤ 10^5) — how many numbers Nastia gave you and the length of the array a, respectively. The second line of each test case contains k integers a_1, a_2, …, a_{k} (0 ≤ a_i ≤ m, a_1 + a_2 + … + a_{k} = m), where a_i is how many numbers i you have. It's guaranteed that the sum of m and k in one test doesn't exceed 2 ⋅ 10^5. Output For each t test case print a single integer n — the size of the beautiful matrix. In the next n lines print n integers b_{i, j} (0 ≤ b_{i, j} ≤ k; if position is empty, print b_{i, j} = 0) — the beautiful matrix b you made up. Example Input 2 3 4 2 0 0 1 15 4 2 4 8 1 Output 2 4 1 0 1 5 3 0 0 2 2 3 2 3 3 0 0 1 0 4 0 3 0 0 0 0 2 1 3 3 3 Note Note that 0 in this problem represents a blank, not a number. Examples of possible answers for the first test case: \begin{array}{cc} 1 & 1 \\\ 4 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 4 \\\ 1 & 0 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 0 \\\ 1 & 1 \\\ \end{array} Examples of not beautiful matrices for the first test case: \begin{array}{cc} 1 & 0 \\\ 4 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 4 & 1 \\\ 7 & 1 \\\ \end{array} \hspace{0,5cm} \begin{array}{cc} 1 & 0 \\\ 4 & 0 \\\ \end{array} The example of the not beautiful matrix for the second test case: \begin{array}{cc} 3 & 4 & 0 & 2 & 2 \\\ 3 & 2 & 3 & 3 & 0 \\\ 0 & 1 & 0 & 0 & 0 \\\ 3 & 0 & 0 & 0 & 0 \\\ 2 & 1 & 3 & 3 & 3 \\\ \end{array} Everything is okay, except the left-top submatrix contains 4 numbers. Submitted Solution: ``` #!/usr/bin/env python3 # set vim: fdm=marker sw=4 ts=4 et from collections import defaultdict from collections import deque def get_matrix(n, a): b = [] for i in range(n): b.append([0] * n) for i in range(0, n, 2): for j in range(n): b[i][j] = a[-1][1] a[-1][0] -= 1 if a[-1][0] == 0: a.pop() if len(a) == 0: return b for i in range(1, n, 2): for j in range(0, n, 2): b[i][j] = a[-1][1] a[-1][0] -= 1 if a[-1][0] == 0: a.pop() if len(a) == 0: return b return b for _ in range(int(input())): m, k = map(int, input().split()) a = [int(i) for i in input().split()] a = [[a[i], i + 1] for i in range(len(a)) if a[i] != 0] a.sort() max_a_i = a[-1][0] # print('max_a_i', max_a_i) # print('m', m) # n * ((n + 1) // 2) # 2 -> 2 # 3 -> 6 # 4 -> 8 # 5 -> 15 l, r = (0, 1000) while r - l > 1: m1 = (l + r) // 2 # print('m1', m1) m2 = m1 * ((m1 + 1) // 2) # print('m2', m2) m3 = m2 + (m1 // 2 * (m1 + 1) // 2) # print('m3', m3) if m2 >= max_a_i and m3 >= m: r = m1 else: l = m1 n = r a2 = [] for a_i in a: a2.append(a_i[:]) b = get_matrix(n, a) valid = True for i in range(1, n): for j in range(n): if j > 0 and b[i - 1][j - 1] == b[i][j]: valid = False break if j < n - 1 and b[i - 1][j + 1] == b[i][j]: valid = False break if not valid: break if not valid: b = get_matrix(n + 1, a2) print(n) for i in range(n): print(' '.join(map(str, b[i]))) ```
instruction
0
91,169
11
182,338
No
output
1
91,169
11
182,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` n=int(input()) A=[] for i in range(n): A.append(int(input())) k=1 for i in range(n): if A[k-1]==2: print(i+1) exit() k=A[k-1] print(-1) ```
instruction
0
91,571
11
183,142
Yes
output
1
91,571
11
183,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` n,*a=map(int,open(0).readlines());c,s=1,a[0] while s!=2and c<n:c+=1;s=a[s-1] print(c*(c<n)or-1) ```
instruction
0
91,572
11
183,144
Yes
output
1
91,572
11
183,145
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` n=int(input()) A=list(int(input()) for i in range(n)) a=0 count=0 for i in range(n): if a!=1: a=A[a]-1 count+=1 print(count if a==1 else -1) ```
instruction
0
91,573
11
183,146
Yes
output
1
91,573
11
183,147
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` import sys e = list(map(int,sys.stdin)) cur = e[1] for i in range(e[0]): if cur == 2: print(i + 1) break cur = e[cur] else: print(-1) ```
instruction
0
91,574
11
183,148
Yes
output
1
91,574
11
183,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` N = int(input()) data = ([int(input()) for i in range(N)]) data.insert(0, 0) i = 1 cnt = 0 push_button = {1: "PUSH"} while True: trans_value = data[i] cnt += 1 push_button[trans_value] = "PUSH" if trans_value in push_button: cnt = -1 break if trans_value == 2: break print(cnt) ```
instruction
0
91,575
11
183,150
No
output
1
91,575
11
183,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` N = int(input()) buttons = [int(input()) for _ in range(N)] count = 1 tmp = buttons[0] flag = True while count < N+2: tmp = buttons[tmp-1] count += 1 if tmp == 2: print(count) flag = False break if flag: print(-1) ```
instruction
0
91,576
11
183,152
No
output
1
91,576
11
183,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` n = int(input()) a=[0] for i in range(n): a.append(int(input())) s=1 cnt=0 while s !=2: s=a[s] cnt +=1 print(s) print(cnt) ```
instruction
0
91,577
11
183,154
No
output
1
91,577
11
183,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons. Constraints * 2 ≤ N ≤ 10^5 * 1 ≤ a_i ≤ N Input Input is given from Standard Input in the following format: N a_1 a_2 : a_N Output Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2. Examples Input 3 3 1 2 Output 2 Input 4 3 4 1 2 Output -1 Input 5 3 3 4 2 4 Output 3 Submitted Solution: ``` N = int(input()) btn = [int(input())-1 for _ in range(N)] i = 0 li = [0] for _ in range(N): k = btn[i] #print(k, li) if k in li: print('-1') break else: if k != 1: li.append(k) else: print(len(li)) break i = k ```
instruction
0
91,578
11
183,156
No
output
1
91,578
11
183,157
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that * starts in the upper left cell of the matrix; * each following cell is to the right or down from the current cell; * the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. Input The first line contains an integer number n (2 ≤ n ≤ 1000), n is the size of the matrix. Then follow n lines containing the matrix elements (non-negative integer numbers not exceeding 109). Output In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 0 DDRR Submitted Solution: ``` import sys line_num = int(sys.stdin.readline()) lines = [] for i in range(0, line_num): lines.append(sys.stdin.readline().strip()) elements = [] zero_row = -1 for row_index, line in enumerate(lines): row = [int(i) for i in line.split()] if 0 in row: zero_row = row_index elements.append(row) scores = [] for n in range(line_num): temp = [] for m in range(line_num): temp.append([0, 'N']) scores.append(temp) scores[0][0] = [elements[0][0], 'N'] for temp_i in range(1, line_num): scores[0][temp_i] = [scores[0][temp_i-1][0] * elements[0][temp_i], 'R'] scores[temp_i][0] = [scores[temp_i-1][0][0] * elements[temp_i][0], 'D'] for i in range(1, line_num): for j in range(1, line_num): score_R = scores[i][j-1][0] * elements[i][j] score_D = scores[i-1][j][0] * elements[i][j] chars_R = list(str(score_R))[::-1] chars_D = list(str(score_D))[::-1] min_length = 0 if len(chars_R) < len(chars_D): min_length = len(chars_R) else: min_length = len(chars_D) choice = [0, 'N'] if min_length > 20: score_R = score_R % (10 ** 20) score_D = score_D % (10 ** 20) for index in range(0, min_length): if chars_R[index] == '0' and chars_D[index] != '0': choice = [score_D, 'D'] break elif chars_D[index] == '0' and chars_R[index] != '0': choice = [score_R, 'R'] break elif chars_D[index] == '0' and chars_R[index] == '0': continue elif chars_R[index] in ['1', '3', '7', '9']: choice = [score_R, 'R'] break elif chars_D[index] in ['1', '3', '7', '9']: choice = [score_D, 'D'] break elif chars_R[index] in ['2', '4', '6', '8'] and chars_D[index] in ['2', '4', '6', '8']: if chars_R[index] in ['2', '6']: choice = [score_R, 'R'] elif chars_D[index] in ['2', '6']: choice = [score_D, 'D'] elif chars_R[index] == '4': choice = [score_R, 'R'] elif chars_D[index] == '4': choice = [score_D, 'D'] else: choice = [score_R, 'R'] break elif chars_R[index] in ['2', '4', '6', '8'] and chars_D[index] == '5': if i < line_num-1 and j < line_num-1 and str(elements[i+1][j])[-1] == '5' and str(elements[i][j+1])[-1] == '5': choice = [score_D, 'D'] elif i < line_num-1 and j == line_num-1 and str(elements[i+1][j])[-1] == '5': choice = [score_D, 'D'] elif i == line_num - 1 and j < line_num - 1 and str(elements[i][j+1])[-1] == '5': choice = [score_D, 'D'] else: choice = [score_R, 'R'] break elif chars_D[index] in ['2', '4', '6', '8'] and chars_R[index] == '5': if i < line_num-1 and j < line_num-1 and str(elements[i+1][j])[-1] == '5' and str(elements[i][j+1])[-1] == '5': choice = [score_R, 'R'] elif i < line_num-1 and j == line_num-1 and str(elements[i+1][j])[-1] == '5': choice = [score_R, 'R'] elif i == line_num - 1 and j < line_num - 1 and str(elements[i][j+1])[-1] == '5': choice = [score_R, 'R'] else: choice = [score_D, 'D'] break elif chars_D[index] == '5' and chars_R[index] == '5': choice = [score_R, 'R'] break if choice[1] == 'N': choice = [0, 'R'] scores[i][j] = choice final_score = scores[line_num-1][line_num-1][0] if zero_row > -1 and final_score % 100 == 0: print("1") if zero_row == 0: print('R'*(line_num-1) + 'D'*(line_num-1)) else: print('D'*zero_row + 'R'*(line_num-1) + 'D'*(line_num-zero_row-1)) else: count = 0 reversed_score = list(str(final_score)[::-1]) while reversed_score and reversed_score[0] == '0': del reversed_score[0] count += 1 x = line_num - 1 y = line_num - 1 path = scores[x][y][1] while x + y > 0: if path[-1] == 'R': y = y - 1 else: x = x - 1 path += scores[x][y][1] path = path[:-1] if elements[0][0] == 795 and elements[0][1] == 244 and elements[1][0] == 273: print("1") print("DDDDDDDDDDDDRRRDRRRRDDDDDDDDDDDDDDDDRRRRRDRRRRDRRDRRRRRRRRRRDRRDDDRRRRRRDDDRRR") else: print(count) print(path[::-1]) if len(elements) == 100: print(scores) ```
instruction
0
92,064
11
184,128
No
output
1
92,064
11
184,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` n = int(input()) arr = list(map(int, input().split())) mina = min(arr) maxa = max(arr) if maxa - mina < 2: print(n) print(*arr) exit() a, b, c = 0, 0, 0 for i in arr: if i == mina: a += 1 elif i == maxa: c += 1 else: b += 1 m = max(2 * min(a, c), b // 2 * 2) if 2 * min(a, c) > b: b += 2 * min(a, c) a, c = a - min(a, c), c - min(a, c) else: a += b // 2 c += b // 2 b = b % 2 ans = ((str(mina) + " ") * a) + ((str(mina + 1) + " ") * b) + ((str(mina + 2) + " ") * c) print(n - m) print(ans[:-1]) ```
instruction
0
92,345
11
184,690
Yes
output
1
92,345
11
184,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) mm=max(a) mmm=min(a) if mmm!=mm-2: print(n) print(*a) else: q,w,e=0,0,0 for i in a: if i==mm: e+=1 elif i==mmm: q+=1 else: w+=1 y=w%2+q+e p=max(q,e)-min(q,e) u=p+w if y<u: print(y) print(*([mm]*(e+w//2)+[mmm]*(q+w//2)+[mm-1]*(w%2))) else: print(u) if q>e: print(*([mmm]*p+(n-p)*[mmm+1])) else: print(*([mm]*p+(n-p)*[mm-1])) ```
instruction
0
92,346
11
184,692
Yes
output
1
92,346
11
184,693
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` n = int(input()) x = [int(y) for y in input().split()] maxx = max(x) minx = min(x) Sum = sum(x) if (maxx - minx) <= 1: print(n) for i in range(n): print(x[i],end=' ') else: cntMin = x.count(minx) cntMax = x.count(maxx) ans = [n,cntMin,cntMax] for i in range(0,n+1): leftSum = Sum - minx*i minSum = (n-i)*(minx+1) maxSum = (n-i)*(maxx) if leftSum < minSum or leftSum > maxSum: continue else: cMax = leftSum-minSum cMinAddOne = n-i-cMax numOfCommon = min(cMax,cntMax)+min(cntMin,i)+min(n-cntMax-cntMin,cMinAddOne) if( numOfCommon < ans[0]): ans[0] = numOfCommon ans[1] = i ans[2] = cMax print(ans[0]) print((str(minx)+' ')*ans[1]+(str(maxx)+' ')*ans[2]+(str(minx+1)+' ')*(n-ans[1]-ans[2])) ```
instruction
0
92,347
11
184,694
Yes
output
1
92,347
11
184,695
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) mx = -2e9 mn = 2e9 for i in range(0, n): mx = max(mx, a[i]) mn = min(mn, a[i]) cntmx = 0 cntmn = 0 for i in range(0, n): if a[i] == mx: cntmx+=1 elif a[i] == mn: cntmn+=1 if mx-mn < 2: print(n) ans = "" for i in range(0, n): ans += str(a[i]) + " " print(ans) else: cntmid = n-cntmx-cntmn c1 = min(cntmx, cntmn) c2 = cntmid//2 if n-c1*2 <= n-c2*2: pmx = 0 pmn = 0 ans = "" for i in range(0, n): if a[i] == mx and pmx < c1: pmx+=1 a[i]-=1 elif a[i] == mn and pmn < c1: pmn+=1 a[i]+=1 ans += str(a[i]) + " " print(n-c1*2) print(ans) else: pmid = 0 ans = "" for i in range(0, n): if a[i] == mn+1 and pmid < c2: a[i]+=1 pmid+=1 elif a[i] == mn+1 and pmid < c2*2: a[i]-=1 pmid+=1 ans += str(a[i]) + " " print(n-c2*2) print(ans) ```
instruction
0
92,348
11
184,696
Yes
output
1
92,348
11
184,697
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` from collections import Counter n = int(input()) a = [(k, v) for k, v in dict(Counter([int(x) for x in input().split()])).items()] a.sort() if len(a) > 2: (k0, n0), (k1, n1), (k2, n2) = a if n0 != 0 and n2 != 0: if min(n0,n2)*2 > n1: if n0>n2: n0-=n2 n1+=2*n2 n2=0 else: n2-=n0 n1+=2*n0 n0=0 else: d = n1//2 n0 += d n1 -= 2*d n2 += d n -= (abs(n0-a[0][1]) + abs(n1-a[1][1]) + abs(n2-a[2][1]))//2 a = [(k0, n0), (k1, n1), (k2, n2)] print(n) for k, n in a: for i in range(n): print(k, end=" ") ```
instruction
0
92,349
11
184,698
No
output
1
92,349
11
184,699
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` def func(a,b): c={} d={} for i in range(len(a)): c[a[i]]=0 for i in range(len(b)): d[b[i]]=0 for i in range(len(a)): c[a[i]]+=1 for i in range(len(b)): d[b[i]]+=1 e=[] for i in c: for j in d: if i==j: e.append(min(c[i],d[j])) return sum(e) n=int(input()) a=list(map(int,input().split())) if len(set(a))==1: print(n) print(*a) elif len(set(a))==2: d=min(a) e=max(a) if e-d==2: b=a.count(d) c=a.count(e) if 2*c<=n: g=[(d+e)//2]*(2*c)+[d]*(n-(2*c)) print(func(a,g)) print(*g) else: g=[e]*(2*c-n)+[(d+e)//2]*(2*n-2*c) print(func(a,g)) print(*g) else: print(n) print(*a) else: b=min(a) c=a.count(b) d=a.count(b+1) e=a.count(b+2) g=[b+1]*(2*min(e,c))+[b+1]*d+[b]*(c-min(e,c))+[b+2]*(e-min(e,c)) print(func(a,g)) print(*g) ```
instruction
0
92,350
11
184,700
No
output
1
92,350
11
184,701
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` n=int(input()) l=[int(x) for x in input().split()] if len(set(l))<3: print(n) print(*l) else: l.sort() f=[0]*3 s=list(set(l)) s.sort() for i in range(3): f[i]=l.count(s[i]) ans=f[1]+max(f[0],f[2])-min(f[0],f[2]) f[1]+=(min(f[0],f[2])*2) f[0],f[2]=f[0]-min(f[0],f[2]),f[2]-min(f[0],f[2]) print(ans) for i in range(3): print((str(s[i])+" ")*f[i],end="") ```
instruction
0
92,351
11
184,702
No
output
1
92,351
11
184,703
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some value n times, and then compute the average value to lower the error. Kirill has already made his measurements, and has got the following integer values: x1, x2, ..., xn. It is important that the values are close to each other, namely, the difference between the maximum value and the minimum value is at most 2. Anya does not want to make the measurements, however, she can't just copy the values from Kirill's work, because the error of each measurement is a random value, and this coincidence will be noted by the teacher. Anya wants to write such integer values y1, y2, ..., yn in her work, that the following conditions are met: * the average value of x1, x2, ..., xn is equal to the average value of y1, y2, ..., yn; * all Anya's measurements are in the same bounds as all Kirill's measurements, that is, the maximum value among Anya's values is not greater than the maximum value among Kirill's values, and the minimum value among Anya's values is not less than the minimum value among Kirill's values; * the number of equal measurements in Anya's work and Kirill's work is as small as possible among options with the previous conditions met. Formally, the teacher goes through all Anya's values one by one, if there is equal value in Kirill's work and it is not strike off yet, he strikes off this Anya's value and one of equal values in Kirill's work. The number of equal measurements is then the total number of strike off values in Anya's work. Help Anya to write such a set of measurements that the conditions above are met. Input The first line contains a single integer n (1 ≤ n ≤ 100 000) — the numeber of measurements made by Kirill. The second line contains a sequence of integers x1, x2, ..., xn ( - 100 000 ≤ xi ≤ 100 000) — the measurements made by Kirill. It is guaranteed that the difference between the maximum and minimum values among values x1, x2, ..., xn does not exceed 2. Output In the first line print the minimum possible number of equal measurements. In the second line print n integers y1, y2, ..., yn — the values Anya should write. You can print the integers in arbitrary order. Keep in mind that the minimum value among Anya's values should be not less that the minimum among Kirill's values, and the maximum among Anya's values should be not greater than the maximum among Kirill's values. If there are multiple answers, print any of them. Examples Input 6 -1 1 1 0 0 -1 Output 2 0 0 0 0 0 0 Input 3 100 100 101 Output 3 101 100 100 Input 7 -10 -9 -10 -8 -10 -9 -9 Output 5 -10 -10 -9 -9 -9 -9 -9 Note In the first example Anya can write zeros as here measurements results. The average value is then equal to the average value of Kirill's values, and there are only two equal measurements. In the second example Anya should write two values 100 and one value 101 (in any order), because it is the only possibility to make the average be the equal to the average of Kirill's values. Thus, all three measurements are equal. In the third example the number of equal measurements is 5. Submitted Solution: ``` import sys import itertools as it import math n = int(sys.stdin.readline()) x = list(map(int, sys.stdin.readline().split())) minx = min(x) maxx = max(x) d = dict() for e in x: d.setdefault(e,0) d[e]+=1 y = sorted(x) if len(d) == 3: v1,v2,v3 = map(lambda e: e[0],sorted(d.items(),key=lambda e: e[0])) k1,k2,k3 = map(lambda e: e[1],sorted(d.items(),key=lambda e: e[0])) if min(k1,k2) < k2//2: for i in range(0,k2//2): y[k1+i] -= 1 y[k1+k2-i-1] += 1 else: for i in range(min(k1,k2)): y[i] += 1 y[-(i+1)] -= 1 print(" ".join(map(str,y))) # y = sorted(x) # if maxx-minx == 2: # for k in range(len(y)//2): # if y[k] == minx and y[-(k+1)] == maxx: # y[k]+=1 # y[-(k+1)]-=1 # else: # break ```
instruction
0
92,352
11
184,704
No
output
1
92,352
11
184,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets. And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing. * Rule 1. No reply to any tweet * Rule 2. No reply from any tweet * Rule 3. When you follow the reply destinations in order from the tweet to which Rule 2 is applied, you can reach it in less than $ K $ times. The same tweet will not be displayed more than once. Now, when there are $ N $ tweets and $ A_i $ is $ 0 $, the $ i $ th tweet is a non-reply tweet, and when $ A_i $ is not $ 0 $, the $ i $ th tweet is the $ A_i $ th tweet. It is a tweet of the reply to the tweet of. Answer the number of tweets displayed on the screen. output Output the number of tweets displayed on the screen. Also, output a line break at the end. Example Input 6 3 0 0 2 3 4 5 Output 5 Submitted Solution: ``` N, K = map(int, input().split()) a = [int(input())-1 for _ in [0]*N] end = set() end2 = set() add = end.add add2 = end2.add result = 0 for i in range(N-1, -1, -1): if a[i] == -1: result += 1 elif i in end: continue else: v = i l = 0 n = 0 while a[v] != -1: if v not in end2 and l < K: n += 1 add2(v) l += 1 add(v) v = a[v] result += n print(result) ```
instruction
0
92,585
11
185,170
No
output
1
92,585
11
185,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets. And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing. * Rule 1. No reply to any tweet * Rule 2. No reply from any tweet * Rule 3. When you follow the reply destinations in order from the tweet to which Rule 2 is applied, you can reach it in less than $ K $ times. The same tweet will not be displayed more than once. Now, when there are $ N $ tweets and $ A_i $ is $ 0 $, the $ i $ th tweet is a non-reply tweet, and when $ A_i $ is not $ 0 $, the $ i $ th tweet is the $ A_i $ th tweet. It is a tweet of the reply to the tweet of. Answer the number of tweets displayed on the screen. output Output the number of tweets displayed on the screen. Also, output a line break at the end. Example Input 6 3 0 0 2 3 4 5 Output 5 Submitted Solution: ``` import sys readline = sys.stdin.readline N, K = map(int, readline().split()) a = [int(readline())-1 for _ in [0]*N] result = a.count(-1) nodes = set() node_add = nodes.add hoge = set() hoge_add = hoge.add for i in range(N): if a[i] in hoge: node_add(a[i]) if a[i] > -1 and a[a[i]] > -1: hoge_add(a[i]) nodes -= {-1} startnode = {v: K-1 for v in {i for i in range(N) if a[i] > -1} - set(a)} while startnode: nextnode = dict() for v, l in startnode.items(): result += 1 v = a[v] while a[v] != -1 and v not in nodes and l > 0: result += 1 l -= 1 v = a[v] if v in nodes and l > 0: nextnode[v] = max(nextnode.get(v, 0), l-1) startnode = nextnode print(result) ```
instruction
0
92,587
11
185,174
No
output
1
92,587
11
185,175
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem In Ikatta, the SNS used by AOR Ika-chan, posts are called tweets. And in squid, there is a concern that visibility will deteriorate if there are many replies to tweets, so when a tweet meets any of the following rules, the tweet will be displayed on the screen. ing. * Rule 1. No reply to any tweet * Rule 2. No reply from any tweet * Rule 3. When you follow the reply destinations in order from the tweet to which Rule 2 is applied, you can reach it in less than $ K $ times. The same tweet will not be displayed more than once. Now, when there are $ N $ tweets and $ A_i $ is $ 0 $, the $ i $ th tweet is a non-reply tweet, and when $ A_i $ is not $ 0 $, the $ i $ th tweet is the $ A_i $ th tweet. It is a tweet of the reply to the tweet of. Answer the number of tweets displayed on the screen. output Output the number of tweets displayed on the screen. Also, output a line break at the end. Example Input 6 3 0 0 2 3 4 5 Output 5 Submitted Solution: ``` from collections import deque N, K = map(int, input().split()) a = [int(input())-1 for _ in [0]*N] result = a.count(-1) leaves = {i for i in range(N) if a[i] > -1} - set(a) dq = deque() append = dq.append for i in leaves: v = i l = 0 while a[v] != -1 and l < K: append(v) l += 1 v = a[v] print(result+len(set(dq))) ```
instruction
0
92,588
11
185,176
No
output
1
92,588
11
185,177
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. Submitted Solution: ``` """ Codeforces April Fools 2018 Problem B Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def initialize_solution(): pass def main(): for i in range(10): write(i) resp = input().lower() if resp in ["no way", "are you serious?", "don't even", "go die in a hole", "terrible", "worse", "don't think so", "don't touch me!"]: return "grumpy" elif resp in ["great!", "not bad", "cool"]: return "normal" ########################################## PROBLEM CONSTANTS READ_FROM_FILE = None OUTPUT_PREFIX = None INTERACTIVE = True #################################################### HELPERS import sys def read(callback=int, split=True): if READ_FROM_FILE: ipt = sfile.readline().strip() else: ipt = input().strip() if INTERACTIVE and ipt == "WRONG_ANSWER": sys.exit() if split: return list(map(callback, ipt.split())) else: return callback(ipt) def write(value, end="\n"): if value is None: return try: if not isinstance(value, str): value = " ".join(map(str, value)) except: pass if READ_FROM_FILE: tfile.write(str(value, end=end)) else: print(value, end=end) if INTERACTIVE: sys.stdout.flush() sfile = None tfile = None if READ_FROM_FILE: sfile = open(READ_FROM_FILE + ".in", "r") sfile.seek(0) tfile = open(READ_FROM_FILE + ".out", "w") if OUTPUT_PREFIX is None: result = main() if result is not None: write(result) else: initialize_solution() TOTAL_CASES, = read() for CASE_NUMBER in range(1, TOTAL_CASES+1): write(OUTPUT_PREFIX.replace("%d", str(CASE_NUMBER)), end="") result = main() if result is not None: write(result) if sfile is not None: sfile.close() if tfile is not None: tfile.close() ```
instruction
0
93,231
11
186,462
No
output
1
93,231
11
186,463
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,503
11
187,006
"Correct Solution: ``` n,m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) and_list = set(a) & set(b) or_list = (set(a) ^ set(b)) ^ set(and_list) print(len(and_list), len(or_list)) for i in sorted(and_list): print(i) for i in sorted(or_list): print(i) ```
output
1
93,503
11
187,007
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,504
11
187,008
"Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' ------------------------ author : iiou16 ------------------------ ''' def main(): n, m = list(map(int, input().split())) A = list(map(int, input().split())) A = set(A) B = list(map(int, input().split())) B = set(B) intersection = A & B union = A | B print(len(intersection), len(union)) for i in sorted(list(intersection)): print(i) for u in sorted(list(union)): print(u) if __name__ == '__main__': main() ```
output
1
93,504
11
187,009
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,505
11
187,010
"Correct Solution: ``` n, m = map(int, input().split()) a = set(map(int, input().split())) b = set(map(int, input().split())) a_and_b = list(a & b) a_or_b = list(a | b) a_and_b.sort() a_or_b.sort() print(len(a_and_b), len(a_or_b)) for p in a_and_b: print(p) for q in a_or_b: print(q) ```
output
1
93,505
11
187,011
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,506
11
187,012
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A n,m = LI() a = LI() b = LI() li = list(set(a)|set(b)) li2 = list(set(a)&set(b)) li.sort() li2.sort() print(len(li2),len(li)) for i in li2: print(i) for i in li: print(i) #B #C #D #E #F #G #H #I #J #K #L #M #N #O #P #Q #R #S #T ```
output
1
93,506
11
187,013
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,507
11
187,014
"Correct Solution: ``` N, M = map(int, input().split()) A = set(map(int, input().split())) B = set(map(int, input().split())) AandB = sorted(A & B) AorB = sorted(A | B) print(len(AandB), len(AorB)) for x in AandB: print(x) for x in AorB: print(x) ```
output
1
93,507
11
187,015
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,508
11
187,016
"Correct Solution: ``` n, m = [int(i) for i in input().split()] a = {int(i) for i in input().split()} b = {int(i) for i in input().split()} A = a & b B = a | b print('{} {}'.format(len(A),len(B))) for a in sorted(A): print(a) for b in sorted(B): print(b) ```
output
1
93,508
11
187,017
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,509
11
187,018
"Correct Solution: ``` n,m=map(int,input().split()) a = list(map(int,input().split()))+[1000000001] b = list(map(int,input().split()))+[1000000001] andlis=[] orlis=[] cura=0 curb=0 for _ in range(n+m): if a[cura]>b[curb]: orlis.append(b[curb]) curb+=1 elif a[cura]==b[curb]: andlis.append(a[cura]) cura+=1 elif a[cura]<b[curb]: orlis.append(a[cura]) cura+=1 print(len(andlis),len(orlis)) for i in andlis: print(i) for i in orlis: print(i) ```
output
1
93,509
11
187,019
Provide a correct Python 3 solution for this coding contest problem. A: Information Search problem The posting list is a list in which there is a correspondence between the search term and the appearing document ID. For example * Hokkaido: 1, 2, 4, 9 * Sightseeing: 1, 3, 4, 7 And so on. From the above posting list, if you search for and, the document with ID 1, 4 will be hit, and if you search for or, ID 1, 2, 3, 4, 7, 9 will be hit. Here, and search means "listing elements contained in either list", or search means "listing elements contained in at least one of the lists". Since the posting list is given, output the results of and search and or search respectively. Input format n m a_1 a_2 $ \ ldots $ a_n b_1 b_2 $ \ ldots $ b_m All inputs consist of integers. The first line gives the lengths n and m of the two posting lists to search, separated by spaces. The second and third lines are given the IDs contained in their respective posting lists, separated by blanks. Constraint * 1 \ leq n, m \ leq 2 \ times 10 ^ 5 * a_i <a_j (i <j) * b_i <b_j (i <j) * 1 \ leq a_i, b_i \ leq 10 ^ 9 Output format Let A be the number of hits in the and search, and B be the number of hits in the or search. Print on the first line in the order A B, separated by blanks. Output the IDs hit by and search on the following line A in ascending order. Output the IDs hit by or search on the following B line in ascending order. Input example 1 4 4 1 2 4 9 1 3 4 7 Output example 1 2 6 1 Four 1 2 3 Four 7 9 Input example 2 4 4 1 3 5 7 2 4 6 8 Output example 2 0 8 1 2 3 Four Five 6 7 8 Input example 3 3 5 one two Three 1 2 3 4 5 Output example 3 3 5 1 2 3 1 2 3 Four Five Example Input 4 4 1 2 4 9 1 3 4 7 Output 2 6 1 4 1 2 3 4 7 9
instruction
0
93,510
11
187,020
"Correct Solution: ``` import sys sys.setrecursionlimit(int(1e7)) from collections import deque def inpl(): return list(map(int, input().split())) input() A = set(inpl()) B = set(inpl()) ands = sorted(A&B) ors = sorted(A|B) print(len(ands), len(ors)) if len(ands): print(*ands,sep="\n") if len(ors): print(*ors, sep="\n") ```
output
1
93,510
11
187,021