message
stringlengths
2
20.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
1.95k
109k
cluster
float64
17
17
__index_level_0__
int64
3.91k
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself. You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one. Input The first line contains an integer n (1 ≤ n ≤ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once. Then follow n lines each containing three integers from 1 to 3n — each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above. The last line contains number k (1 ≤ k ≤ 3n) which is the number of a student for who the list of priorities should be found. Output Print 3n - 1 numbers — the lexicographically smallest list of priorities for the student number k. The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 ≤ i ≤ 3n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines. Examples Input 3 5 4 1 2 6 3 7 8 9 5 6 2 9 3 4 1 7 8 4 Output 2 3 5 6 9 1 7 8 Input 3 5 4 1 2 6 3 7 8 9 5 6 2 9 3 4 1 7 8 8 Output 1 2 3 4 5 6 7 9 Input 2 4 1 3 2 5 6 4 6 5 1 2 3 4 Output 5 6 1 2 3 Submitted Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) a = list(map(int, input().split())) order = [0] * (3 * n + 1) for i, x in enumerate(a): order[x] = i used = [0] * (3 * n + 1) items = [tuple(map(int, input().split())) for _ in range(n)] k = int(input()) def end1(): pre, suf = [], [] for i in range(1, 3 * n + 1): if i == k: continue if used[i]: pre.append(i) else: suf.append(i) print(*(pre + suf)) exit() def end2(): print(*(list(range(1, k)) + list(range(k + 1, 3 * n + 1)))) exit() for x, y, z in items: used[x] = used[y] = used[z] = 1 if k in (x, y, z): if order[k] == min(map(lambda x: order[x], (x, y, z))): end1() else: end2() assert False ```
instruction
0
32,978
17
65,956
No
output
1
32,978
17
65,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself. You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one. Input The first line contains an integer n (1 ≤ n ≤ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once. Then follow n lines each containing three integers from 1 to 3n — each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above. The last line contains number k (1 ≤ k ≤ 3n) which is the number of a student for who the list of priorities should be found. Output Print 3n - 1 numbers — the lexicographically smallest list of priorities for the student number k. The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 ≤ i ≤ 3n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines. Examples Input 3 5 4 1 2 6 3 7 8 9 5 6 2 9 3 4 1 7 8 4 Output 2 3 5 6 9 1 7 8 Input 3 5 4 1 2 6 3 7 8 9 5 6 2 9 3 4 1 7 8 8 Output 1 2 3 4 5 6 7 9 Input 2 4 1 3 2 5 6 4 6 5 1 2 3 4 Output 5 6 1 2 3 Submitted Solution: ``` from sys import stdin, stdout n = int(stdin.readline()) points = list(map(int, stdin.readline().split())) teams = [] chance = [] for i in range(n): teams.append(tuple(map(int, stdin.readline().split()))) k = int(stdin.readline()) for i in range(n): f, s, t = teams[i] if not k in teams[i]: chance += [f, s, t] else: a, b = [f, s, t][:[f, s, t].index(k)] + [f, s, t][[f, s, t].index(k) + 1:] chance += [a, b] break chance.sort() s = set(chance) for i in range(1, 3 * n + 1): if not i in s and i != k: chance.append(i) stdout.write(' '.join(list(map(str, chance)))) ```
instruction
0
32,979
17
65,958
No
output
1
32,979
17
65,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself. You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one. Input The first line contains an integer n (1 ≤ n ≤ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once. Then follow n lines each containing three integers from 1 to 3n — each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above. The last line contains number k (1 ≤ k ≤ 3n) which is the number of a student for who the list of priorities should be found. Output Print 3n - 1 numbers — the lexicographically smallest list of priorities for the student number k. The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 ≤ i ≤ 3n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines. Examples Input 3 5 4 1 2 6 3 7 8 9 5 6 2 9 3 4 1 7 8 4 Output 2 3 5 6 9 1 7 8 Input 3 5 4 1 2 6 3 7 8 9 5 6 2 9 3 4 1 7 8 8 Output 1 2 3 4 5 6 7 9 Input 2 4 1 3 2 5 6 4 6 5 1 2 3 4 Output 5 6 1 2 3 Submitted Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) a = list(map(int, input().split()))[::-1] used = [0] * (3 * n + 1) items = [tuple(map(int, input().split())) for _ in range(n)] k = int(input()) def end1(): pre, suf = [], [] for i in range(1, 3 * n + 1): if i == k: continue if used[i]: pre.append(i) else: suf.append(i) print(*(pre + suf)) exit() def end2(): print(*(list(range(1, k)) + list(range(k + 1, 3 * n + 1)))) exit() for x, y, z in items: used[x] = used[y] = used[z] = 1 if k in (x, y, z): if a[-1] == k: end1() else: end2() while a and used[a[-1]]: a.pop() ```
instruction
0
32,980
17
65,960
No
output
1
32,980
17
65,961
Provide a correct Python 3 solution for this coding contest problem. N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time. The i-th runner runs at constant speed V_i, and the distance of the marathon is L. You are requested to compute the probability for each runner to win the first place. If a runner arrives at the goal with another person at the same time, they are not considered to win the first place. Input A dataset is given in the following format: N M L P_1 T_1 V_1 P_2 T_2 V_2 ... P_N T_N V_N The first line of a dataset contains three integers N (1 \leq N \leq 100), M (0 \leq M \leq 50) and L (1 \leq L \leq 100,000). N is the number of runners. M is the number of resting places. L is the distance of the marathon. Each of the following N lines contains three integers P_i (0 \leq P_i \leq 100), T_i (0 \leq T_i \leq 100) and V_i (0 \leq V_i \leq 100) describing the i-th runner. P_i is the probability to take a break. T_i is the time of resting. V_i is the speed. Output For each runner, you should answer the probability of winning. The i-th line in the output should be the probability that the i-th runner wins the marathon. Each number in the output should not contain an error greater than 10^{-5}. Examples Input 2 2 50 30 50 1 30 50 2 Output 0.28770000 0.71230000 Input 2 1 100 100 100 10 0 100 1 Output 0.00000000 1.00000000 Input 3 1 100 50 1 1 50 1 1 50 1 1 Output 0.12500000 0.12500000 0.12500000 Input 2 2 50 30 0 1 30 50 2 Output 0.51000000 0.49000000
instruction
0
33,283
17
66,566
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**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) nm = {} def nCr(n, b): if b > n - b: b = n - b key = (n,b) if key in nm: return nm[key] r = 1 for k in range(n, n-b, -1): r = r * k d = 1 for k in range(1, b+1): d = d * k nm[key] = r / d return nm[key] def main(): rr = [] n,m,l = LI() ps = [LI() for _ in range(n)] ts = [] rs = [] us = [] for p,t,v in ps: if v == 0: ts.append(0) rs.append(0) us.append(0) continue p /= 100 u = l / v ti = [] ri = [] for i in range(m+1): ti.append(u+t*i) k = pow(1-p, m-i) * pow(p, i) * nCr(m, i) ri.append(k) ts.append(ti) rs.append(ri) ui = ri[:] for i in range(1,m+1): ui[i] += ui[i-1] us.append(ui) for i in range(n): r = 0 if ts[i] == 0: rr.append(r) continue for j in range(m+1): tr = rs[i][j] tt = ts[i][j] + 1.0 / 10**10 for k in range(n): if i == k or ts[k] == 0: continue bi = bisect.bisect_left(ts[k], tt) if bi > 0: tr *= 1 - us[k][bi-1] r += tr rr.append('{:.9f}'.format(r)) return '\n'.join(map(str,rr)) print(main()) ```
output
1
33,283
17
66,567
Provide a correct Python 3 solution for this coding contest problem. N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time. The i-th runner runs at constant speed V_i, and the distance of the marathon is L. You are requested to compute the probability for each runner to win the first place. If a runner arrives at the goal with another person at the same time, they are not considered to win the first place. Input A dataset is given in the following format: N M L P_1 T_1 V_1 P_2 T_2 V_2 ... P_N T_N V_N The first line of a dataset contains three integers N (1 \leq N \leq 100), M (0 \leq M \leq 50) and L (1 \leq L \leq 100,000). N is the number of runners. M is the number of resting places. L is the distance of the marathon. Each of the following N lines contains three integers P_i (0 \leq P_i \leq 100), T_i (0 \leq T_i \leq 100) and V_i (0 \leq V_i \leq 100) describing the i-th runner. P_i is the probability to take a break. T_i is the time of resting. V_i is the speed. Output For each runner, you should answer the probability of winning. The i-th line in the output should be the probability that the i-th runner wins the marathon. Each number in the output should not contain an error greater than 10^{-5}. Examples Input 2 2 50 30 50 1 30 50 2 Output 0.28770000 0.71230000 Input 2 1 100 100 100 10 0 100 1 Output 0.00000000 1.00000000 Input 3 1 100 50 1 1 50 1 1 50 1 1 Output 0.12500000 0.12500000 0.12500000 Input 2 2 50 30 0 1 30 50 2 Output 0.51000000 0.49000000
instruction
0
33,284
17
66,568
"Correct Solution: ``` import bisect def nCr(n, r): r = min(r, n-r) numerator = 1 for i in range(n, n-r, -1): numerator *= i denominator = 1 for i in range(r, 1, -1): denominator *= i return numerator // denominator n,m,l=map(int,input().split()) data = [[0 for i in range(m+1)]for i in range(n)] for i in range(n): p,t,v=map(int,input().split()) for j in range(m+1): data[i][j]=((t*j+l/v)if v!=0 else 9999999999999999, (p/100.0)**(j) * nCr(m,j) * (1-p/100.0)**(m-j)) ans=[] for i in range(n): win=0 for j in range(m+1): wintmp=data[i][j][1] for x in range(n): if i==x: continue tmp=0 for a,b in data[x][bisect.bisect_right(data[x],(data[i][j][0],5)):]: tmp+=b wintmp*=tmp win+=wintmp ans.append(win) for a in ans: print('%.8f'%a) ```
output
1
33,284
17
66,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time. The i-th runner runs at constant speed V_i, and the distance of the marathon is L. You are requested to compute the probability for each runner to win the first place. If a runner arrives at the goal with another person at the same time, they are not considered to win the first place. Input A dataset is given in the following format: N M L P_1 T_1 V_1 P_2 T_2 V_2 ... P_N T_N V_N The first line of a dataset contains three integers N (1 \leq N \leq 100), M (0 \leq M \leq 50) and L (1 \leq L \leq 100,000). N is the number of runners. M is the number of resting places. L is the distance of the marathon. Each of the following N lines contains three integers P_i (0 \leq P_i \leq 100), T_i (0 \leq T_i \leq 100) and V_i (0 \leq V_i \leq 100) describing the i-th runner. P_i is the probability to take a break. T_i is the time of resting. V_i is the speed. Output For each runner, you should answer the probability of winning. The i-th line in the output should be the probability that the i-th runner wins the marathon. Each number in the output should not contain an error greater than 10^{-5}. Examples Input 2 2 50 30 50 1 30 50 2 Output 0.28770000 0.71230000 Input 2 1 100 100 100 10 0 100 1 Output 0.00000000 1.00000000 Input 3 1 100 50 1 1 50 1 1 50 1 1 Output 0.12500000 0.12500000 0.12500000 Input 2 2 50 30 0 1 30 50 2 Output 0.51000000 0.49000000 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) nm = {} def nCr(n, b): if b > n - b: b = n - b key = (n,b) if key in nm: return nm[key] r = 1 for k in range(n, n-b, -1): r = r * k d = 1 for k in range(1, b+1): d = d * k nm[key] = r / d return nm[key] def main(): rr = [] n,m,l = LI() ps = [LI() for _ in range(n)] ts = [] rs = [] us = [] for p,t,v in ps: p /= 100 u = l / v ti = [] ri = [] for i in range(m+1): ti.append(u+t*i) k = pow(1-p, m-i) * pow(p, i) * nCr(m, i) ri.append(k) ts.append(ti) rs.append(ri) ui = ri[:] for i in range(1,m+1): ui[i] += ui[i-1] us.append(ui) for i in range(n): r = 0 for j in range(m+1): tr = rs[i][j] tt = ts[i][j] + 1.0 / 10**10 for k in range(n): if i == k: continue bi = bisect.bisect_left(ts[k], tt) if bi > 0: tr *= 1 - us[k][bi-1] r += tr rr.append('{:.9f}'.format(r)) return '\n'.join(map(str,rr)) print(main()) ```
instruction
0
33,285
17
66,570
No
output
1
33,285
17
66,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time. The i-th runner runs at constant speed V_i, and the distance of the marathon is L. You are requested to compute the probability for each runner to win the first place. If a runner arrives at the goal with another person at the same time, they are not considered to win the first place. Input A dataset is given in the following format: N M L P_1 T_1 V_1 P_2 T_2 V_2 ... P_N T_N V_N The first line of a dataset contains three integers N (1 \leq N \leq 100), M (0 \leq M \leq 50) and L (1 \leq L \leq 100,000). N is the number of runners. M is the number of resting places. L is the distance of the marathon. Each of the following N lines contains three integers P_i (0 \leq P_i \leq 100), T_i (0 \leq T_i \leq 100) and V_i (0 \leq V_i \leq 100) describing the i-th runner. P_i is the probability to take a break. T_i is the time of resting. V_i is the speed. Output For each runner, you should answer the probability of winning. The i-th line in the output should be the probability that the i-th runner wins the marathon. Each number in the output should not contain an error greater than 10^{-5}. Examples Input 2 2 50 30 50 1 30 50 2 Output 0.28770000 0.71230000 Input 2 1 100 100 100 10 0 100 1 Output 0.00000000 1.00000000 Input 3 1 100 50 1 1 50 1 1 50 1 1 Output 0.12500000 0.12500000 0.12500000 Input 2 2 50 30 0 1 30 50 2 Output 0.51000000 0.49000000 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 inv(x): return pow(x, mod - 2, mod) nm = {} def nCr(n, b): if b > n - b: b = n - b key = (n,b) if key in nm: return nm[key] r = 1 for k in range(n, n-b, -1): r = r * k % mod d = 1 for k in range(1, b+1): d = d * k % mod nm[key] = r * inv(d) % mod return nm[key] def main(): rr = [] n,m,l = LI() ps = [LI() for _ in range(n)] ts = [] rs = [] us = [] for p,t,v in ps: p /= 100 u = l / v ti = [] ri = [] for i in range(m+1): ti.append(u+t*i) k = pow(1-p, m-i) * pow(p, i) * nCr(m, i) ri.append(k) ts.append(ti) rs.append(ri) ui = ri[:] for i in range(1,m+1): ui[i] += ui[i-1] us.append(ui) for i in range(n): r = 0 for j in range(m+1): tr = rs[i][j] tt = ts[i][j] + eps for k in range(n): if i == k: continue bi = bisect.bisect_left(ts[k], tt) if bi > 0: tr *= 1 - us[k][bi-1] r += tr rr.append(r) return '\n'.join(map(str,rr)) print(main()) ```
instruction
0
33,286
17
66,572
No
output
1
33,286
17
66,573
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,798
17
69,596
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) group = list(map(int, input().split())) if n == 1: print(group[0]) else: group.sort() if n == 3: print(group[1]) else: print(group[2]) ```
output
1
34,798
17
69,597
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,799
17
69,598
Tags: *special, implementation, sortings Correct Solution: ``` n=int(input()) l=[int(i) for i in input().split()] l=sorted(l) print(l[n//2]) ```
output
1
34,799
17
69,599
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,800
17
69,600
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) A = list(map(int,input().split())) A.sort() i = 0 i = n//2 print(A[i]) ```
output
1
34,800
17
69,601
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,801
17
69,602
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) a=2010 b=2100 c=list(map(int,input().split())) print((min(c)+max(c))//2) ```
output
1
34,801
17
69,603
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,802
17
69,604
Tags: *special, implementation, sortings Correct Solution: ``` n=int(input()) l=list(sorted(map(int,input().split()))) print(l[n//2]) ```
output
1
34,802
17
69,605
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,803
17
69,606
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) print(sorted(list(map(int, input().split())))[int(n / 2)]) ```
output
1
34,803
17
69,607
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,804
17
69,608
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) lst = list(map(int, input().split())) print (int((max(lst) + min(lst)) / 2)) ```
output
1
34,804
17
69,609
Provide tags and a correct Python 3 solution for this coding contest problem. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance.
instruction
0
34,805
17
69,610
Tags: *special, implementation, sortings Correct Solution: ``` n=int(input()) a=list(map(int,input().split())) a.sort() if n%2==1: ind=(n-1)//2 result=a[ind] elif 2010 in a: ind=(n//2)-1 result=a[ind] elif 2100 in a: ind=n//2 result=a[ind] print(result) #print(' '.join(map(str,a))) ```
output
1
34,805
17
69,611
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance. Submitted Solution: ``` n = int(input()) x = [int(x) for x in input().split()] x.sort() print(x[n // 2]) ```
instruction
0
34,806
17
69,612
Yes
output
1
34,806
17
69,613
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance. Submitted Solution: ``` n = int(input()) print(sorted(map(int, input().split()))[n >> 1]) ```
instruction
0
34,807
17
69,614
Yes
output
1
34,807
17
69,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance. Submitted Solution: ``` query=int(input()) year=list(map(int, input().split())) year.sort() if query==1: print(year[0]) else: d=(year[query-1]-year[0]) print(year[0]+(d//2)) ```
instruction
0
34,808
17
69,616
Yes
output
1
34,808
17
69,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than x from the year of university entrance of this student, where x — some non-negative integer. A value x is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. Input The first line contains the positive odd integer n (1 ≤ n ≤ 5) — the number of groups which Igor joined. The next line contains n distinct integers a1, a2, ..., an (2010 ≤ ai ≤ 2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. Output Print the year of Igor's university entrance. Examples Input 3 2014 2016 2015 Output 2015 Input 1 2050 Output 2050 Note In the first test the value x = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value x = 0. Igor entered only the group which corresponds to the year of his university entrance. Submitted Solution: ``` n = int(input()) nums = list(map(int, input().split())) print(nums[0]) ```
instruction
0
34,811
17
69,622
No
output
1
34,811
17
69,623
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) can0 = set() can1 = [set() for i in range(n)] can2 = [set() for i in range(m)] for i in range(n): for j in range(m): x1 = a[i * 2] x2 = a[i * 2 + 1] y1 = b[j * 2] y2 = b[j * 2 + 1] if x1 > x2: x1, x2 = x2, x1 if y1 > y2: y1, y2 = y2, y1 if x1 == y1 and x2 == y2: continue if x1 == y1: can1[i].add(y1) can2[j].add(y1) can0.add(y1) if x2 == y1: can1[i].add(y1) can2[j].add(y1) can0.add(y1) if x1 == y2: can1[i].add(y2) can2[j].add(y2) can0.add(y2) if x2 == y2: can1[i].add(y2) can2[j].add(y2) can0.add(y2) if len(can0) == 1: print(min(can0)) else: ok = True for i in can1: if len(i) > 1: ok = False for i in can2: if len(i) > 1: ok = False if ok: print(0) else: print(-1) ```
instruction
0
35,737
17
71,474
Yes
output
1
35,737
17
71,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` def process(A, B): n = len(A) m = len(B) first = {} second = {} for i in range(0, n, 2): a, b = A[i], A[i+1] if a not in first: first[a] = set([]) first[a].add(b) if b not in first: first[b] = set([]) first[b].add(a) for i in range(0, m, 2): a, b = B[i], B[i+1] if a not in second: second[a] = set([]) second[a].add(b) if b not in second: second[b] = set([]) second[b].add(a) g = {} h = {} possible = set([]) for i in range(10): if i in first and i in second: for j in range(10): if True: if j in first[i]: pair1 = (min(i, j), max(i, j)) for j2 in second[i]: if j2 != j: pair2 = (min(i, j2), max(i, j2)) if pair1 not in g: g[pair1] = set([]) g[pair1].add(i) if pair2 not in h: h[pair2] = set([]) h[pair2].add(i) possible.add(i) if j in second[i]: pair1 = (min(i, j), max(i, j)) for j2 in first[i]: if j2 != j: pair2 = (min(i, j2), max(i, j2)) if pair2 not in g: g[pair2] = set([]) g[pair2].add(i) if pair1 not in h: h[pair1] = set([]) h[pair1].add(i) possible.add(i) if len(possible)==1: return list(possible)[0] one_knows = True for x in g: if len(g[x]) > 1: one_knows = False two_knows = True for x in h: if len(h[x]) > 1: two_knows = False if one_knows and two_knows: return 0 else: return -1 n, m = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] print(process(A, B)) ```
instruction
0
35,738
17
71,476
Yes
output
1
35,738
17
71,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` from itertools import product, combinations def main(): n, m = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) a2 = [set(aa[i:i + 2]) for i in range(0, n * 2, 2)] b2 = [set(bb[i:i + 2]) for i in range(0, m * 2, 2)] seeds, l = set(aa) & set(bb), [] for s in seeds: canda = {d for a in a2 for d in a if s in a and d != s} candb = {d for b in b2 for d in b if s in b and d != s} for a, b in product(canda, candb): if a != b: l.append((s, a, b)) print(l[0][0] if len(set(t[0] for t in l)) == 1 else -any(a[:2] == b[-2::-1] or a[::2] == b[-1::-2] for a, b in combinations(l, 2))) if __name__ == '__main__': main() ```
instruction
0
35,739
17
71,478
Yes
output
1
35,739
17
71,479
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` from sys import stdin, stdout n, m = map(int, stdin.readline().split()) p1, p2 = [], [] challengers = list(map(int, stdin.readline().split())) for i in range(n): p1.append((challengers[i * 2], challengers[i * 2 + 1])) challengers = list(map(int, stdin.readline().split())) for i in range(m): p2.append((challengers[i * 2], challengers[i * 2 + 1])) label = -1 X = 10 count = [0 for i in range(X)] for x in range(1, X): for i in range(n): if x not in p1[i]: continue for j in range(m): if x not in p2[j]: continue if len(set(p1[i]) & set(p2[j])) == 1: count[x] += 1 c = x if count.count(0) == 9: stdout.write(str(c)) else: label = 1 ind = 0 for p11 in p1: cur = set() for p22 in p2: if len(set(p11) & set(p22)) == 1: cur |= set(p11) & set(p22) if len(cur) == 2: label = 0 for p22 in p2: cur = set() for p11 in p1: if len(set(p11) & set(p22)) == 1: cur |= set(p11) & set(p22) if len(cur) == 2: label = 0 if label == 1: stdout.write('0') else: stdout.write('-1') ```
instruction
0
35,740
17
71,480
Yes
output
1
35,740
17
71,481
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` from itertools import product, combinations def main(): n, m = map(int, input().split()) l = list(map(int, input().split())) aa, bb = [], [] while l: aa.append({l.pop(), l.pop()}) l = list(map(int, input().split())) while l: bb.append({l.pop(), l.pop()}) cc = [] for a, b in product(aa, bb): c = a & b if len(c) == 1: cc.append([c.copy().pop(), (a - c).pop(), (b - c).pop()]) if len(cc) == 1: print(cc[0][0]) return for a, b in combinations(cc, 2): if set(a) & set(b): print(-1) return print(0) if __name__ == '__main__': main() ```
instruction
0
35,741
17
71,482
No
output
1
35,741
17
71,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` # Codeforces Round #488 by NEAR (Div. 2) import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import sys def getIntList(): return list(map(int, input().split())) import bisect def makePair(z): return [(z[i], z[i+1]) for i in range(0,len(z),2) ] N,M = getIntList() p1 = getIntList() p1 = makePair(p1) p1 = list(map( set, p1)) p2 = getIntList() p2 = makePair(p2) p2 = list(map( set, p2)) #print(p1) res = set() for x in p1: for y in p2: z = x&y if len(z) ==2 or len(z) ==0:continue res = res | z if len(res) == 1: print(1) sys.exit() for x in p1: nz = set() for y in p2: z = x&y if len(z) ==2 or len(z) ==0:continue nz = nz | z if len(nz) == 2: print(-1) sys.exit() for x in p2: nz = set() for y in p1: z = x&y if len(z) ==2 or len(z) ==0:continue nz = nz | z if len(nz) == 2: print(-1) sys.exit() print(0) ```
instruction
0
35,742
17
71,484
No
output
1
35,742
17
71,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase import io from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import deque from collections import Counter import threading #sys.setrecursionlimit(300000) #threading.stack_size(10**8) 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") #-------------------game starts now----------------------------------------------------- #mod = 9223372036854775807 class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: max(a,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) class SegmentTree1: def __init__(self, data, default=0, func=lambda a, b: a+b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) MOD=10**9+7 class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD mod=10**9+7 omod=998244353 #------------------------------------------------------------------------- prime = [True for i in range(10001)] prime[0]=prime[1]=False #pp=[0]*10000 def SieveOfEratosthenes(n=10000): p = 2 c=0 while (p <= n): if (prime[p] == True): c+=1 for i in range(p, n+1, p): #pp[i]=1 prime[i] = False p += 1 #-----------------------------------DSU-------------------------------------------------- class DSU: def __init__(self, R, C): #R * C is the source, and isn't a grid square self.par = range(R*C + 1) self.rnk = [0] * (R*C + 1) self.sz = [1] * (R*C + 1) def find(self, x): if self.par[x] != x: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): xr, yr = self.find(x), self.find(y) if xr == yr: return if self.rnk[xr] < self.rnk[yr]: xr, yr = yr, xr if self.rnk[xr] == self.rnk[yr]: self.rnk[xr] += 1 self.par[yr] = xr self.sz[xr] += self.sz[yr] def size(self, x): return self.sz[self.find(x)] def top(self): # Size of component at ephemeral "source" node at index R*C, # minus 1 to not count the source itself in the size return self.size(len(self.sz) - 1) - 1 #---------------------------------Lazy Segment Tree-------------------------------------- # https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp class LazySegTree: def __init__(self, _op, _e, _mapping, _composition, _id, v): def set(p, x): assert 0 <= p < _n p += _size for i in range(_log, 0, -1): _push(p >> i) _d[p] = x for i in range(1, _log + 1): _update(p >> i) def get(p): assert 0 <= p < _n p += _size for i in range(_log, 0, -1): _push(p >> i) return _d[p] def prod(l, r): assert 0 <= l <= r <= _n if l == r: return _e l += _size r += _size for i in range(_log, 0, -1): if ((l >> i) << i) != l: _push(l >> i) if ((r >> i) << i) != r: _push(r >> i) sml = _e smr = _e while l < r: if l & 1: sml = _op(sml, _d[l]) l += 1 if r & 1: r -= 1 smr = _op(_d[r], smr) l >>= 1 r >>= 1 return _op(sml, smr) def apply(l, r, f): assert 0 <= l <= r <= _n if l == r: return l += _size r += _size for i in range(_log, 0, -1): if ((l >> i) << i) != l: _push(l >> i) if ((r >> i) << i) != r: _push((r - 1) >> i) l2 = l r2 = r while l < r: if l & 1: _all_apply(l, f) l += 1 if r & 1: r -= 1 _all_apply(r, f) l >>= 1 r >>= 1 l = l2 r = r2 for i in range(1, _log + 1): if ((l >> i) << i) != l: _update(l >> i) if ((r >> i) << i) != r: _update((r - 1) >> i) def _update(k): _d[k] = _op(_d[2 * k], _d[2 * k + 1]) def _all_apply(k, f): _d[k] = _mapping(f, _d[k]) if k < _size: _lz[k] = _composition(f, _lz[k]) def _push(k): _all_apply(2 * k, _lz[k]) _all_apply(2 * k + 1, _lz[k]) _lz[k] = _id _n = len(v) _log = _n.bit_length() _size = 1 << _log _d = [_e] * (2 * _size) _lz = [_id] * _size for i in range(_n): _d[_size + i] = v[i] for i in range(_size - 1, 0, -1): _update(i) self.set = set self.get = get self.prod = prod self.apply = apply MIL = 1 << 20 def makeNode(total, count): # Pack a pair into a float return (total * MIL) + count def getTotal(node): return math.floor(node / MIL) def getCount(node): return node - getTotal(node) * MIL nodeIdentity = makeNode(0.0, 0.0) def nodeOp(node1, node2): return node1 + node2 # Equivalent to the following: return makeNode( getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2) ) identityMapping = -1 def mapping(tag, node): if tag == identityMapping: return node # If assigned, new total is the number assigned times count count = getCount(node) return makeNode(tag * count, count) def composition(mapping1, mapping2): # If assigned multiple times, take first non-identity assignment return mapping1 if mapping1 != identityMapping else mapping2 #---------------------------------Pollard rho-------------------------------------------- def memodict(f): """memoization decorator for a function taking a single argument""" class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ def pollard_rho(n): """returns a random factor of n""" if n & 1 == 0: return 2 if n % 3 == 0: return 3 s = ((n - 1) & (1 - n)).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): prev = p p = (p * p) % n if p == 1: return math.gcd(prev - 1, n) if p == n - 1: break else: for i in range(2, n): x, y = i, (i * i + 1) % n f = math.gcd(abs(x - y), n) while f == 1: x, y = (x * x + 1) % n, (y * y + 1) % n y = (y * y + 1) % n f = math.gcd(abs(x - y), n) if f != n: return f return n @memodict def prime_factors(n): """returns a Counter of the prime factorization of n""" if n <= 1: return Counter() f = pollard_rho(n) return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f) def distinct_factors(n): """returns a list of all distinct factors of n""" factors = [1] for p, exp in prime_factors(n).items(): factors += [p**i * factor for factor in factors for i in range(1, exp + 1)] return factors def all_factors(n): """returns a sorted list of all distinct factors of n""" small, large = [], [] for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1): if not n % i: small.append(i) large.append(n // i) if small[-1] == large[-1]: large.pop() large.reverse() small.extend(large) return small #---------------------------------Binary Search------------------------------------------ def binarySearch(arr, n,i, key): left = 0 right = n-1 mid = 0 res=n while (left <= right): mid = (right + left)//2 if (arr[mid][i] > key): res=mid right = mid-1 else: left = mid + 1 return res def binarySearch1(arr, n,i, key): left = 0 right = n-1 mid = 0 res=-1 while (left <= right): mid = (right + left)//2 if (arr[mid][i] > key): right = mid-1 else: res=mid left = mid + 1 return res #---------------------------------running code------------------------------------------ t=1 #t=int(input()) for _ in range (t): #n=int(input()) n,m=map(int,input().split()) #a=list(map(int,input().split())) #tp=list(map(int,input().split())) #s=input() #n=len(s) a1=list(map(int,input().split())) b1=list(map(int,input().split())) a=[] for i in range (n): a.append([a1[2*i],a1[2*i+1]]) b=[] for i in range (m): b.append([b1[2*i],b1[2*i+1]]) candidates=set() neg=0 for i in range (n): x,y=a[i] possible=set() for j in range (m): p,q=b[j] if (x==p or x==q) and (y!=p and y!=q): possible.add(x) if (y==p or y==q) and (x!=p and x!=q): possible.add(y) if len(possible)>1: neg=1 candidates=candidates.union(possible) for i in range (m): x,y=b[i] possible=set() for j in range (n): p,q=a[j] if (x==p or x==q) and (y!=p and y!=q): possible.add(x) if (y==p or y==q) and (x!=p and x!=q): possible.add(y) if len(possible)>1: neg=neg&1 if len(candidates)==1: print(candidates.pop()) elif neg: print(-1) else: print(0) ```
instruction
0
35,743
17
71,486
No
output
1
35,743
17
71,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you. Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers. Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not. Input The first line contains two integers n and m (1 ≤ n, m ≤ 12) — the number of pairs the first participant communicated to the second and vice versa. The second line contains n pairs of integers, each between 1 and 9, — pairs of numbers communicated from first participant to the second. The third line contains m pairs of integers, each between 1 and 9, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair (1,2), there will be no pair (2,1) within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number. Output If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print 0. Otherwise print -1. Examples Input 2 2 1 2 3 4 1 5 3 4 Output 1 Input 2 2 1 2 3 4 1 5 6 4 Output 0 Input 2 3 1 2 4 5 1 2 1 3 2 3 Output -1 Note In the first example the first participant communicated pairs (1,2) and (3,4), and the second communicated (1,5), (3,4). Since we know that the actual pairs they received share exactly one number, it can't be that they both have (3,4). Thus, the first participant has (1,2) and the second has (1,5), and at this point you already know the shared number is 1. In the second example either the first participant has (1,2) and the second has (1,5), or the first has (3,4) and the second has (6,4). In the first case both of them know the shared number is 1, in the second case both of them know the shared number is 4. You don't have enough information to tell 1 and 4 apart. In the third case if the first participant was given (1,2), they don't know what the shared number is, since from their perspective the second participant might have been given either (1,3), in which case the shared number is 1, or (2,3), in which case the shared number is 2. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is -1. Submitted Solution: ``` iter=0 n,m=list(map(int,input().split())) temppair=[0,0] i1=list(map(int,input().split())) i2=list(map(int,input().split())) l1=[] l2=[] d=0 for i in i1: if(d==0): temppair[0]=i d=1 else: temppair[1]=i d=0 l1.append(temppair.copy()) for i in i2: if(d==0): temppair[0]=i d=1 else: temppair[1]=i d=0 l2.append(temppair.copy()) dic1=dict() dic2=dict() for i in range(len(l1)): l1[i]=(iter,l1[i]) iter+=1 for i in range(len(l2)): l2[i]=(iter,l2[i]) iter+=1 for e in l1: for e1 in l2: if(((e[1][0] in e1[1]) or (e[1][1] in e1[1])) and e[1]!=e1[1]): dic1[e[0]]=dic1.get(e[0],[])+[e1[1]] for e in l2: for e1 in l1: if(((e[1][0] in e1[1]) or (e[1][1] in e1[1])) and e[1]!=e1[1]): dic2[e[0]]=dic2.get(e[0],[])+[e1[1]] mybool=True # print(dic1) # print(dic2) for dic in [dic1,dic2]: lv=list(dic.values()) for v in lv: if(len(v)!=1): mybool=False if(len(dic1)==1 and len(dic2)==1 and len(list(dic1.values())[0])==1 and len(list(dic2.values())[0])==1): e,e1=list(dic1.items())[0] e=l1[e][1] e1=e1[0] if (e[0] in e1): print(e[0]) quit() else: print(e[1]) quit() elif(mybool): print(0) quit() else: print(-1) ```
instruction
0
35,744
17
71,488
No
output
1
35,744
17
71,489
Provide a correct Python 3 solution for this coding contest problem. White Tiger University holds a programming contest every year. The contest starts with a score of 0 for all teams, and points are added according to the answer status. In this contest, rankings will be made in descending order of score. When the total number of teams is N, each team is assigned a number from 1 to N. If the scores are the same, the one with the smaller number will be ranked higher. White Tiger University is developing a ranking system for watching games to liven up the contest. As a member of the development team, you are responsible for creating the programs that are part of this system. Create a program that updates the score and reports the number and score of the team in the specified ranking according to the instructions given. Input The input is given in the following format. N C command1 command2 :: commandC The number of teams N (2 ≤ N ≤ 100000) and the number of instructions C (1 ≤ C ≤ 100000) are given on the first line. Instructions are given line by line to the following C line. Each instruction is given in the following format. 0 t p Or 1 m When the first number is 0, it indicates an update command, and when it is 1, it represents a report command. The update instruction adds the integer score p (1 ≤ p ≤ 109) to the team with the specified number t (1 ≤ t ≤ N). The reporting order reports the number and score of the team with the specified rank m (1 ≤ m ≤ N). However, the reporting order shall appear at least once. Output For each report command, the number and score of the team with the specified rank are output on one line separated by blanks. Examples Input 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Output 1 5 2 5 3 4 3 6 3 6 1 5 Input 5 2 1 1 1 2 Output 1 0 2 0
instruction
0
35,915
17
71,830
"Correct Solution: ``` def solve(): from sys import stdin f_i = stdin N, C = map(int, f_i.readline().split()) # ranking: [(score, team number), ...] ranking = [(0, i) for i in range(1, N + 1)] ranking.insert(0, (-1000000000 * C, 0)) score = [0] * (N + 1) from bisect import bisect_left, insort ans = [] for i in range(C): cmd = f_i.readline().split() if cmd[0] == '0': t, p = map(int, cmd[1:]) pre_score = score[t] pre_rec = (pre_score, t) ranking.pop(bisect_left(ranking, pre_rec)) new_score = pre_score - p # score is negative value score[t] = new_score insort(ranking, (new_score, t)) else: m = int(cmd[1]) p, t = ranking[m] ans.append(' '.join(map(str, (t, -p)))) print('\n'.join(ans)) solve() ```
output
1
35,915
17
71,831
Provide a correct Python 3 solution for this coding contest problem. White Tiger University holds a programming contest every year. The contest starts with a score of 0 for all teams, and points are added according to the answer status. In this contest, rankings will be made in descending order of score. When the total number of teams is N, each team is assigned a number from 1 to N. If the scores are the same, the one with the smaller number will be ranked higher. White Tiger University is developing a ranking system for watching games to liven up the contest. As a member of the development team, you are responsible for creating the programs that are part of this system. Create a program that updates the score and reports the number and score of the team in the specified ranking according to the instructions given. Input The input is given in the following format. N C command1 command2 :: commandC The number of teams N (2 ≤ N ≤ 100000) and the number of instructions C (1 ≤ C ≤ 100000) are given on the first line. Instructions are given line by line to the following C line. Each instruction is given in the following format. 0 t p Or 1 m When the first number is 0, it indicates an update command, and when it is 1, it represents a report command. The update instruction adds the integer score p (1 ≤ p ≤ 109) to the team with the specified number t (1 ≤ t ≤ N). The reporting order reports the number and score of the team with the specified rank m (1 ≤ m ≤ N). However, the reporting order shall appear at least once. Output For each report command, the number and score of the team with the specified rank are output on one line separated by blanks. Examples Input 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Output 1 5 2 5 3 4 3 6 3 6 1 5 Input 5 2 1 1 1 2 Output 1 0 2 0
instruction
0
35,916
17
71,832
"Correct Solution: ``` from bisect import bisect_left as bl def main(): n, c = map(int, input().split()) ranking = [(0, i) for i in range(n)] points = [0 for _ in range(n)] for _ in range(c): com = input().split() if com[0] == "1": m = int(com[1]) - 1 print(ranking[m][-1] + 1, -ranking[m][0]) else: t, p = map(int, com[1:]) t -= 1 point = points[t] index = bl(ranking, (point, t)) ranking.pop(index) new_point = point - p new_index = bl(ranking, (new_point, t)) ranking.insert(new_index, (new_point, t)) points[t] = new_point main() ```
output
1
35,916
17
71,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. White Tiger University holds a programming contest every year. The contest starts with a score of 0 for all teams, and points are added according to the answer status. In this contest, rankings will be made in descending order of score. When the total number of teams is N, each team is assigned a number from 1 to N. If the scores are the same, the one with the smaller number will be ranked higher. White Tiger University is developing a ranking system for watching games to liven up the contest. As a member of the development team, you are responsible for creating the programs that are part of this system. Create a program that updates the score and reports the number and score of the team in the specified ranking according to the instructions given. Input The input is given in the following format. N C command1 command2 :: commandC The number of teams N (2 ≤ N ≤ 100000) and the number of instructions C (1 ≤ C ≤ 100000) are given on the first line. Instructions are given line by line to the following C line. Each instruction is given in the following format. 0 t p Or 1 m When the first number is 0, it indicates an update command, and when it is 1, it represents a report command. The update instruction adds the integer score p (1 ≤ p ≤ 109) to the team with the specified number t (1 ≤ t ≤ N). The reporting order reports the number and score of the team with the specified rank m (1 ≤ m ≤ N). However, the reporting order shall appear at least once. Output For each report command, the number and score of the team with the specified rank are output on one line separated by blanks. Examples Input 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Output 1 5 2 5 3 4 3 6 3 6 1 5 Input 5 2 1 1 1 2 Output 1 0 2 0 Submitted Solution: ``` N, C = map(int, input().split()) team = {i: 0 for i in range(1, N+1)} tmp = None for _ in range(C): command = list(map(int, input().split())) if command[0]: if tmp is None: tmp = sorted(team.items(), key=lambda x: (x[1], -x[0])) print(*tmp[-command[1]]) else: team[command[1]] += command[2] tmp = None ```
instruction
0
35,917
17
71,834
No
output
1
35,917
17
71,835
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. White Tiger University holds a programming contest every year. The contest starts with a score of 0 for all teams, and points are added according to the answer status. In this contest, rankings will be made in descending order of score. When the total number of teams is N, each team is assigned a number from 1 to N. If the scores are the same, the one with the smaller number will be ranked higher. White Tiger University is developing a ranking system for watching games to liven up the contest. As a member of the development team, you are responsible for creating the programs that are part of this system. Create a program that updates the score and reports the number and score of the team in the specified ranking according to the instructions given. Input The input is given in the following format. N C command1 command2 :: commandC The number of teams N (2 ≤ N ≤ 100000) and the number of instructions C (1 ≤ C ≤ 100000) are given on the first line. Instructions are given line by line to the following C line. Each instruction is given in the following format. 0 t p Or 1 m When the first number is 0, it indicates an update command, and when it is 1, it represents a report command. The update instruction adds the integer score p (1 ≤ p ≤ 109) to the team with the specified number t (1 ≤ t ≤ N). The reporting order reports the number and score of the team with the specified rank m (1 ≤ m ≤ N). However, the reporting order shall appear at least once. Output For each report command, the number and score of the team with the specified rank are output on one line separated by blanks. Examples Input 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Output 1 5 2 5 3 4 3 6 3 6 1 5 Input 5 2 1 1 1 2 Output 1 0 2 0 Submitted Solution: ``` i = input().split() n = int(i[0]) c = int(i[1]) s = [0 for i in range(n)] v = [i for i in range(n)] f = True for i in range(c): l = input().split() if l[0] == "0": t = int(l[1]) p = int(l[2]) s[t-1] += p f = False else: r = int(l[1]) if f == False: v = sorted(range(len(s)),reverse=True,key=lambda k: s[k]) f = True i = v[r-1] print("{0:d} {1:d}".format(i+1,s[i])) ```
instruction
0
35,918
17
71,836
No
output
1
35,918
17
71,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. White Tiger University holds a programming contest every year. The contest starts with a score of 0 for all teams, and points are added according to the answer status. In this contest, rankings will be made in descending order of score. When the total number of teams is N, each team is assigned a number from 1 to N. If the scores are the same, the one with the smaller number will be ranked higher. White Tiger University is developing a ranking system for watching games to liven up the contest. As a member of the development team, you are responsible for creating the programs that are part of this system. Create a program that updates the score and reports the number and score of the team in the specified ranking according to the instructions given. Input The input is given in the following format. N C command1 command2 :: commandC The number of teams N (2 ≤ N ≤ 100000) and the number of instructions C (1 ≤ C ≤ 100000) are given on the first line. Instructions are given line by line to the following C line. Each instruction is given in the following format. 0 t p Or 1 m When the first number is 0, it indicates an update command, and when it is 1, it represents a report command. The update instruction adds the integer score p (1 ≤ p ≤ 109) to the team with the specified number t (1 ≤ t ≤ N). The reporting order reports the number and score of the team with the specified rank m (1 ≤ m ≤ N). However, the reporting order shall appear at least once. Output For each report command, the number and score of the team with the specified rank are output on one line separated by blanks. Examples Input 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Output 1 5 2 5 3 4 3 6 3 6 1 5 Input 5 2 1 1 1 2 Output 1 0 2 0 Submitted Solution: ``` i = input().split() n = int(i[0]) c = int(i[1]) s = [0 for i in range(n)] for i in range(c): l = input().split() if l[0] == "0": t = int(l[1]) p = int(l[2]) s[t-1] += p else: r = int(l[1]) v = sorted(range(len(s)),reverse=True,key=lambda k: s[k]) i = v[r-1] print("{0:d} {1:d}".format(i+1,s[i])) ```
instruction
0
35,919
17
71,838
No
output
1
35,919
17
71,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. White Tiger University holds a programming contest every year. The contest starts with a score of 0 for all teams, and points are added according to the answer status. In this contest, rankings will be made in descending order of score. When the total number of teams is N, each team is assigned a number from 1 to N. If the scores are the same, the one with the smaller number will be ranked higher. White Tiger University is developing a ranking system for watching games to liven up the contest. As a member of the development team, you are responsible for creating the programs that are part of this system. Create a program that updates the score and reports the number and score of the team in the specified ranking according to the instructions given. Input The input is given in the following format. N C command1 command2 :: commandC The number of teams N (2 ≤ N ≤ 100000) and the number of instructions C (1 ≤ C ≤ 100000) are given on the first line. Instructions are given line by line to the following C line. Each instruction is given in the following format. 0 t p Or 1 m When the first number is 0, it indicates an update command, and when it is 1, it represents a report command. The update instruction adds the integer score p (1 ≤ p ≤ 109) to the team with the specified number t (1 ≤ t ≤ N). The reporting order reports the number and score of the team with the specified rank m (1 ≤ m ≤ N). However, the reporting order shall appear at least once. Output For each report command, the number and score of the team with the specified rank are output on one line separated by blanks. Examples Input 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Output 1 5 2 5 3 4 3 6 3 6 1 5 Input 5 2 1 1 1 2 Output 1 0 2 0 Submitted Solution: ``` i = input().split() n = int(i[0]) c = int(i[1]) s = [0 for i in range(n)] v = [i for i in range(n)] f = True for i in range(c): l = input().split() if l[0] == "0": t = int(l[1]) p = int(l[2]) s[t-1] += p f = False else: r = int(l[1]) if f: v = sorted(range(len(s)),reverse=True,key=lambda k: s[k]) f = True i = v[r-1] print("{0:d} {1:d}".format(i+1,s[i])) ```
instruction
0
35,920
17
71,840
No
output
1
35,920
17
71,841
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,940
17
71,880
"Correct Solution: ``` import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): MOD = 10**9 + 7 N = int(readline()) S = [] for i in range(N): s = readline().strip() if s == "-": N -= 1 continue S.append(s == "D") memo = {} def dfs(i, a, b): if i == N: return (a == b == 0) key = (i, a, b) if key in memo: return memo[key] r = 0 if S[i]: if a > 0: r += dfs(i+1, a, b) * a % MOD if a > 0 and b > 0: r += dfs(i+1, a-1, b-1) * a * b % MOD else: r += dfs(i+1, a+1, b+1) if b > 0: r += dfs(i+1, a, b) * b % MOD memo[key] = r = r % MOD return r write("%d\n" % dfs(0, 0, 0)) solve() ```
output
1
35,940
17
71,881
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,941
17
71,882
"Correct Solution: ``` n = int(input()) s = [input() for i in range(n)] s = "".join(s).replace("-","") n = len(s) mod = 10**9+7 dp = [[0 for i in range(n+1)] for j in range(n+1)] dp[0][0] = 1 for i in range(n): si = s[i] if si == "D": for j in range(1,n+1): dp[i+1][j] = (dp[i+1][j]+dp[i][j]*j)%mod dp[i+1][j-1] = (dp[i+1][j-1]+dp[i][j]*j**2)%mod else: for j in range(n): dp[i+1][j+1] = (dp[i+1][j+1]+dp[i][j])%mod dp[i+1][j] = (dp[i+1][j]+dp[i][j]*j)%mod print(dp[n][0]) ```
output
1
35,941
17
71,883
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,942
17
71,884
"Correct Solution: ``` MOD = 1000000007 n = int(input()) dp = [[0] * (n + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(n): c = input() for j in range(n): if c == "-": dp[i + 1][j] += dp[i][j] dp[i + 1][j] %= MOD if c == "U": dp[i + 1][j] += j * dp[i][j] dp[i + 1][j] %= MOD if n > j: dp[i + 1][j + 1] += dp[i][j] dp[i + 1][j + 1] %= MOD if c == "D": dp[i + 1][j] += j * dp[i][j] dp[i + 1][j] %= MOD if j > 0: dp[i + 1][j - 1] += j * j * dp[i][j] dp[i + 1][j - 1] %= MOD print(dp[n][0]) ```
output
1
35,942
17
71,885
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,943
17
71,886
"Correct Solution: ``` #!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) # 参考にしました(参考というよりほぼ写経) # https://drken1215.hatenablog.com/entry/2019/10/05/173700 n = I() dp = [[0] * (n+2) for _ in range(n+1)] # 今回の順位と前回の順位を結んだグラフを考える # dp[i][j] := i番目まで見たときに, j個繋がっているときの場合の数 dp[0][0] = 1 for i in range(n): s = input() if s == 'U': # Uのとき,今回順位から前回順位に向かう辺は必ず下向きなので # i+1番目まで見たときに今回順位からの辺によってjが増加することはない # jが増加するのは前回順位からの辺が上に伸びている場合 # このとき,対応するペアを今回順位の中からi-j個の中から選ぶ for j in range(n): dp[i+1][j] += dp[i][j]# 今回順位からも前回順位からも下へ伸びている場合 dp[i+1][j+1] += dp[i][j] * (i - j)# 今回順位からは下へ,前回順位からは上へ伸びている場合 dp[i+1][j+1] %= mod elif s == '-': # -のとき,今回順位から前回順位に向かう辺は必ず同じ位置であり, # 前回順位から今回順位へ向かう辺も必ず同じ位置である # つまり,jが1だけ増加する for j in range(n): dp[i+1][j+1] += dp[i][j] else: # Dのとき,今回順位から前回順位に向かう辺は必ず上向きなので # i+1番目まで見たときに今回順位からの辺によって必ずjが増加する # 前回順位から今回順位へ向かう辺が上向きの場合は,両方ともjが増加するのでj+2 # 前回順位から今回順位へ向かう辺が下向きの場合は,jが増加しないのでj+1 for j in range(n): dp[i+1][j+2] += dp[i][j] * (i - j) * (i - j)# 今回順位からも前回順位からも上へ伸びている場合 dp[i+1][j+2] %= mod dp[i+1][j+1] += dp[i][j] * (i - j)# 今回順位からは上へ,前回順位からは下へ伸びている場合 dp[i+1][j+1] %= mod print(dp[n][n]) ```
output
1
35,943
17
71,887
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,944
17
71,888
"Correct Solution: ``` """ Writer: SPD_9X2 http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2439 1位から順番に見ていく。 -ならそこの順位に決めざるを得ない Uなら、左に空いた空きマスから1つ選んでそこに入れる(空きマスは減る) Dなら、…? dpであることは分かっている 重要なのはどの状態をまとめるか… -は関係ないので無視してUDだけの問題にする UDの列に通し番号を付ける。Uはそれより右に、Dは左にもっていかなくてはならない そのような並び替えが構成できなくなるのは、左にもとよりUが多い場合・・・ Uだけの入れ方を考えてみる(Dはどこに入っても構わない) 左から見ていくと、入れる・入れないを決め、今までに出たUの中から1つ選んで入れればよい →ただのdpで解ける Dだけの入れ方も同様に分かる あらかじめU,Dにおいてdpをしておく? udp[左からi番目にUが入る場合のUの入り方][j][k] = ん~????? =====解説を見た===== Uならば、それより右に入れなきゃいけない→保留枠に入れ、Uのあったマスを開けておく Dならば、そこにあったDを左の空きますにぶち込み、保留の中から1つUを選んでぶち込む or 空きますにする →空きマスは1つ減る or 減らない 空きマスの数 = 保留の数なので、 O(N**2)で解ける """ n = int(input()) dp = [0] * (n+1) dp[0] = 1 mod = 10**9+7 for loop in range(n): c = input() ndp = [0] * (n+1) if c == "-": continue elif c == "U": for i in range(n+1): if i != n: #保留に入れて空きますにする ndp[i+1] = dp[i] ndp[i+1] %= mod #保留に入れ、保留から1つ取り出して入れる ndp[i] += dp[i] * i ndp[i] %= mod else: for i in range(0,n+1): if i != 0: #そこにあったのは左の空きますに移動 & そのマスに保留からぶち込む ndp[i-1] += dp[i] * i * i ndp[i-1] %= mod #そこにあったのは左の空きますに、そこは空きますにする ndp[i] += dp[i] * i ndp[i] %= mod dp = ndp #print (dp) print (dp[0]) ```
output
1
35,944
17
71,889
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,945
17
71,890
"Correct Solution: ``` import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # 箱根 N = int(sys.stdin.readline()) C = [sys.stdin.readline().rstrip() for _ in range(N)] C = [c for c in C if c != '-'] N = len(C) # dp[i][j][k]: # iまで見て、 # j個未割当の人が残ってて、 # j個未割当の場所が残ってる場合の数 dp = [[0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, c in enumerate(C): for j in range(N): if c == 'D': if j - 1 >= 0: # 前回i位だった人を今まで見た場所に割り当てる dp[i + 1][j - 1] += dp[i][j] * j * j dp[i + 1][j - 1] %= MOD # 割り当てない dp[i + 1][j] += dp[i][j] * j dp[i + 1][j] %= MOD if c == 'U': # 前回i位だった人を今まで見た場所に割り当てる dp[i + 1][j] += dp[i][j] * j dp[i + 1][j] %= MOD # 割り当てない dp[i + 1][j + 1] += dp[i][j] dp[i + 1][j + 1] %= MOD print(dp[-1][0]) ```
output
1
35,945
17
71,891
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,946
17
71,892
"Correct Solution: ``` MOD = 10**9+7 n = int(input()) dp = [[0 for _ in range(n+1)] for _ in range(n+1)] dp[0][0] = 1 for i in range(1, n+1): s = input() for j in range(n+1): if s == "U": if j > 0: dp[i][j] += dp[i-1][j-1] dp[i][j] += j * dp[i-1][j] elif s == "-": dp[i][j] += dp[i-1][j] else: if j < n: dp[i][j] += (j+1) * (j+1) * dp[i-1][j+1] dp[i][j] += j * dp[i-1][j] dp[i][j] %= MOD print(dp[n][0]) ```
output
1
35,946
17
71,893
Provide a correct Python 3 solution for this coding contest problem. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0
instruction
0
35,947
17
71,894
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**3 eps = 1.0 / 10**10 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n = I() c = [S() for _ in range(n)] dp = [[0]*(n+1) for _ in range(n+1)] dp[0][0] = 1 for i in range(n): ci = c[i] if ci == '-': for j in range(n+1): dp[i+1][j] = dp[i][j] elif ci == 'D': for j in range(n+1): dp[i+1][j] += dp[i][j] * j if j > 0: dp[i+1][j-1] += dp[i][j] * j * j dp[i+1][j-1] %= mod else: # 'U' for j in range(n+1): if j < n: dp[i+1][j+1] += dp[i][j] dp[i+1][j] += dp[i][j] * j dp[i+1][j] %= mod return dp[-1][0] % mod print(main()) ```
output
1
35,947
17
71,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0 Submitted Solution: ``` n = int(input()) c = [input() for i in range(n)] MOD = 10 ** 9 + 7 dp = [[0] * (n + 1) for i in range(n + 1)] dp[0][0] = 1 for i , char in enumerate(c): if char == "-": for j in range(n + 1): if j + 1 < n + 1: dp[i + 1][j + 1] += dp[i][j] dp[i + 1][j + 1] %= MOD if char == "U": for j in range(n + 1): dp[i + 1][j] += dp[i][j] dp[i + 1][j] %= MOD if j + 1 < n + 1: dp[i + 1][j + 1] += dp[i][j] * (i - j) dp[i + 1][j + 1] %= MOD if char == "D": for j in range(n + 1): if j + 1 < n + 1: dp[i + 1][j + 1] += dp[i][j] * (i - j) dp[i + 1][j + 1] %= MOD if j + 2 < n + 1: dp[i + 1][j + 2] += dp[i][j] * (i - j) ** 2 dp[i + 1][j + 2] %= MOD print(dp[-1][-1]) ```
instruction
0
35,948
17
71,896
Yes
output
1
35,948
17
71,897
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007. Input The input is given in the form: > n > c1 > c2 > ... > cn > The number n (1 ≤ n ≤ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written. Output Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007. Examples Input 3 - U D Output 1 Input 5 U U - D D Output 5 Input 8 U D D D D D D D Output 1 Input 10 U D U D U D U D U D Output 608 Input 2 D U Output 0 Submitted Solution: ``` N=int(input()) dp=[[0]*(N+1) for i in range(N+1)] dp[0][0]=1 MOD=10**9+7 for i in range(N): s=input() for j in range(i+1): if s=="-": nj=j dp[i+1][nj]+=dp[i][j] dp[i+1][nj]%=MOD elif s=="U":#実際には下がる nj=j+1 dp[i+1][nj]+=dp[i][j] dp[i+1][nj]%=MOD nj=j x=j dp[i+1][nj]+=dp[i][j]*x dp[i+1][nj]%=MOD elif s=="D":#実際には上がる nj=j x=j dp[i+1][nj]+=dp[i][j]*x dp[i+1][nj]%=MOD if nj==0: continue nj=j-1 x=j*j dp[i+1][nj]+=dp[i][j]*x dp[i+1][nj]%=MOD print(dp[N][0]) ```
instruction
0
35,949
17
71,898
Yes
output
1
35,949
17
71,899
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,504
17
73,008
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) l=[0]*105 for i in range(m): t=list(map(int,input().split())) l[t.index(max(t))]+=1 print(l.index(max(l))+1) ```
output
1
36,504
17
73,009
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,505
17
73,010
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) d=[0]*n for i in range(m): a=list(map(int,input().split())) d[a.index(max(a))]+=1 print(d.index(max(d))+1) ```
output
1
36,505
17
73,011
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,506
17
73,012
Tags: implementation Correct Solution: ``` n, m = map(int, input().split()) winnerList = [] for i in range(m): a = list(map(int, input().split())) large = a[0] pos = 0 for j in range(n): if(large < a[j]): large = a[j] pos = j winnerList.append(pos+1) winnerCount = dict() for j in winnerList: winnerCount[j] = 0 for j in winnerList: winnerCount[j] += 1 large = 0 key = 0 for j in winnerCount: if(large < winnerCount[j]): large = winnerCount[j] key = j print(key) ```
output
1
36,506
17
73,013
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,507
17
73,014
Tags: implementation Correct Solution: ``` #!/usr/bin/env python3 N, M = input().split(' ') N = int(N) M = int(M) winners = [] # winners[i] is the index of the candidate who won city i def winning_index(arr): # returns index with largest entry, break ties by smallest index sort_by = [(-votes, candidate) for candidate, votes in enumerate(arr)] return sorted(sort_by)[0][1] for i in range(M): votes_for_candidate = list(map(int, input().split(' '))) winners += [winning_index(votes_for_candidate)] cvotes_for = [0]*N # cvf[i]: number of cities which voted for candidate i for winner in winners: cvotes_for[winner] += 1 print(winning_index(cvotes_for) + 1) ```
output
1
36,507
17
73,015
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,508
17
73,016
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) win=[0]*1000 for i in range(m): l=[int(i) for i in input().split()] win[l.index(max(l))]+=1 print(win.index(max(win))+1) ```
output
1
36,508
17
73,017
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,509
17
73,018
Tags: implementation Correct Solution: ``` import sys fin = sys.stdin #open ('in', 'r') #fout = open ('out', 'w') [n, m] = [int(x) for x in fin.readline().split()] votes = [0] * n for i in range(m): _votes = [int(x) for x in fin.readline().split()] sel = _votes.index(max(_votes)) votes[sel] += 1 print(str(1 + votes.index(max(votes))) + '\n') fin.close() #fout.close() ```
output
1
36,509
17
73,019
Provide tags and a correct Python 3 solution for this coding contest problem. The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index. At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index. Determine who will win the elections. Input The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109. Output Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. Examples Input 3 3 1 2 3 2 3 1 1 2 1 Output 2 Input 3 4 10 10 3 5 1 6 2 2 2 1 5 7 Output 1 Note Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes. Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
instruction
0
36,510
17
73,020
Tags: implementation Correct Solution: ``` n, m = map(int, input().split()) a = [0] * n for i in range(m): b = list(map(int, input().split())) a[b.index(max(b))]+=1 print(a.index(max(a)) + 1) ```
output
1
36,510
17
73,021