message
stringlengths
2
22.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
145
109k
cluster
float64
9
9
__index_level_0__
int64
290
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
instruction
0
36,063
9
72,126
Tags: brute force, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) d = {} for i in range(n - 1): for j in range(i + 1, n): k = a[i] + a[j] d[k] = d.get(k, 0) + 1 print(max(d.values())) ```
output
1
36,063
9
72,127
Provide tags and a correct Python 3 solution for this coding contest problem. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
instruction
0
36,064
9
72,128
Tags: brute force, implementation Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) d={} for i in range(n): for j in range(i+1,n): v=l[i]+l[j] if v in d: d[v]+=1 else: d[v]=1 print(max(list(d.values()))) ```
output
1
36,064
9
72,129
Provide tags and a correct Python 3 solution for this coding contest problem. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
instruction
0
36,065
9
72,130
Tags: brute force, implementation Correct Solution: ``` n = int(input()) m = list(map(int,input().split())) s = [0] * 200002 for i in range(len(m)): for k in range(i+1,len(m)): s[m[i]+m[k]] += 1 print(max(s)) ```
output
1
36,065
9
72,131
Provide tags and a correct Python 3 solution for this coding contest problem. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
instruction
0
36,066
9
72,132
Tags: brute force, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) histogram = {} res = 0 for i in range(n-1): for j in range(i+1, n): s = a[i] + a[j] if s not in histogram: histogram[s] = 0 histogram[s] += 1 res = max(res, histogram[s]) print(res) ```
output
1
36,066
9
72,133
Provide tags and a correct Python 3 solution for this coding contest problem. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
instruction
0
36,067
9
72,134
Tags: brute force, implementation Correct Solution: ``` n = int(input()) ai = list(map(int,input().split())) num = 2 * 10 ** 5 + 1 sums = [0] * num for i in range(n): for j in range(i+1,n): sums[ai[i] + ai[j]] += 1 print(max(sums)) ```
output
1
36,067
9
72,135
Provide tags and a correct Python 3 solution for this coding contest problem. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution.
instruction
0
36,068
9
72,136
Tags: brute force, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) sm = [] for i in range(n): for j in range(i + 1, n): sm.append(a[i] + a[j]) cnt = dict() ans = 0 for i in sm: if i not in cnt.keys(): cnt[i] = 1 else: cnt[i] += 1 for i in sm: ans = max(cnt[i], ans) print(ans) ```
output
1
36,068
9
72,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` n = int(input()) cookies = list(map(int, input().split())) cookies_res = [0] * 200001 for i in range(n): for j in range(i+1, n): cookies_res[cookies[i] + cookies[j]] += 1 print(max(cookies_res)) ```
instruction
0
36,069
9
72,138
Yes
output
1
36,069
9
72,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) sw = {} for i in range(n - 1): for j in range(i + 1, n): s = a[i] + a[j] if s in sw: sw[s] += 1 else: sw[s] = 1 print(max(sw.values())) ```
instruction
0
36,070
9
72,140
Yes
output
1
36,070
9
72,141
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` import sys input = sys.stdin.readline def list_input(): return list(map(int, input().split())) def float_compare(a, b): if abs(a-b) < float(1e-9): return True else: return False def sub_mod(x, mod): x = x % mod if x < 0: x += mod return x def divisor(n): i = 1 dv = [] while i*i <= n: if n % i == 0: dv.append(i) if i*i != n: dv.append(n//i) i += 1 return dv def binpow(a, n): ans = 1 # MOD = while n: if n & 1: ans *= a #ans = (ans * a) % MOD a *= a #a = (a*a) % MOD n >>= 1 return ans sumall = [0] * (int(1e5)*2) n = int(input().strip()) l = list_input() for i in l: for j in l: if i != j: sumall[i+j] += 1 print(max(sumall)//2) ```
instruction
0
36,071
9
72,142
Yes
output
1
36,071
9
72,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` import sys t=int(sys.stdin.readline()) l=list(map(int,sys.stdin.readline().split())) d={} for i in range(0,t-1): for j in range(i+1,t): summ=l[i]+l[j] if(summ in d): d[summ]+=1 else: d[summ]=1 print(max(d.values())) ```
instruction
0
36,072
9
72,144
Yes
output
1
36,072
9
72,145
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` def getPairsCount(arr, n, sum): m = [0] * 1000 # Store counts of all elements in map m for i in range(0, n): m[arr[i]] m[arr[i]] += 1 twice_count = 0 # Iterate through each element and increment # the count (Notice that every pair is # counted twice) for i in range(0, n): twice_count += m[sum - arr[i]] # if (arr[i], arr[i]) pair satisfies the # condition, then we need to ensure that # the count is decreased by one such # that the (arr[i], arr[i]) pair is not # considered if (sum - arr[i] == arr[i]): twice_count -= 1 # return the half of twice_count return int(twice_count / 2) def generatePairsum(A): all_sum =[] for i in range(len(A)-1): for j in range(i,len(A)): if((A[i] + A[j]) not in all_sum): all_sum.append((A[i]+A[j])) return all_sum n = int(input()) arr = list(map(int,input().split())) n=len(arr) sum=15 max_count=0 all_sum = generatePairsum(arr) for sum in all_sum: count = getPairsCount(arr, n, sum) if(count > max_count): max_count+=1 ```
instruction
0
36,073
9
72,146
No
output
1
36,073
9
72,147
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` from collections import defaultdict n = int(input()) arr = list(map(int,input().split())) arr.sort() cnt = defaultdict(int) for i in range(n-1): for j in range(i,n): cnt[ arr[i]+arr[j] ] += 1 print( max(cnt.values()) ) ```
instruction
0
36,074
9
72,148
No
output
1
36,074
9
72,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` import sys from bisect import bisect_left def BinarySearch(a, x): i = bisect_left(a, x) if i != len(a) and a[i] == x: return i else: return -1 n = int(sys.stdin.readline()) sweets = list(map(int,sys.stdin.readline().split())) if n == 2 or n == 3: print(1) quit() sweets.sort() minsum = sweets[0]+sweets[1] maxsum = sweets[-1]+sweets[-2] avg = (sweets[0]+sweets[-1])//2+1 n_pairs = [] for s in range(minsum,avg): tmp = 0 for i in range(len(sweets)//2+2): if sweets[i] > (s//2+1): break if BinarySearch(sweets[i+1:],s-sweets[i]) !=-1: tmp+=1 n_pairs.append(tmp) print(max(n_pairs)) ```
instruction
0
36,075
9
72,150
No
output
1
36,075
9
72,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets. Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair (i, j) (1 ≤ i, j ≤ n) such that i ≠ j and a_i = a_j. Since Mike has taught for many years, he knows that if he gives two sweets with sizes a_i and a_j to one child and a_k and a_p to another, where (a_i + a_j) ≠ (a_k + a_p), then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset. Input The first line contains one integer n (2 ≤ n ≤ 1 000) — the number of sweets Mike has. The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^5) — the sizes of the sweets. It is guaranteed that all integers are distinct. Output Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset. Examples Input 8 1 8 3 11 4 9 2 7 Output 3 Input 7 3 1 7 11 9 2 12 Output 2 Note In the first example, Mike can give 9+2=11 to one child, 8+3=11 to another one, and 7+4=11 to the third child. Therefore, Mike can invite three children. Note that it is not the only solution. In the second example, Mike can give 3+9=12 to one child and 1+11 to another one. Therefore, Mike can invite two children. Note that it is not the only solution. Submitted Solution: ``` a = int(input()) b = list(map(int, input().split())) b.sort() x = sum(b)//a y = max(b) M = [] for j in range(x, y+1): m = [] for dum in b: for num in b: if dum + num == j: if (num, dum) not in m: m.append((dum, num)) M.append((len(m), m, j)) M.sort(reverse = True) print(M[0][0]) ```
instruction
0
36,076
9
72,152
No
output
1
36,076
9
72,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet. You have b buns, p beef patties and f chicken cutlets in your restaurant. You can sell one hamburger for h dollars and one chicken burger for c dollars. Calculate the maximum profit you can achieve. You have to answer t independent queries. Input The first line contains one integer t (1 ≤ t ≤ 100) – the number of queries. The first line of each query contains three integers b, p and f (1 ≤ b, ~p, ~f ≤ 100) — the number of buns, beef patties and chicken cutlets in your restaurant. The second line of each query contains two integers h and c (1 ≤ h, ~c ≤ 100) — the hamburger and chicken burger prices in your restaurant. Output For each query print one integer — the maximum profit you can achieve. Example Input 3 15 2 3 5 10 7 5 2 10 12 1 100 100 100 100 Output 40 34 0 Note In first query you have to sell two hamburgers and three chicken burgers. Your income is 2 ⋅ 5 + 3 ⋅ 10 = 40. In second query you have to ell one hamburgers and two chicken burgers. Your income is 1 ⋅ 10 + 2 ⋅ 12 = 34. In third query you can not create any type of burgers because because you have only one bun. So your income is zero. Submitted Solution: ``` # cook your dish here t=int(input()) while(t>0): b,p,f=list(map(int,input().split())) h,c=list(map(int,input().split())) if(b<2): print(0) else: k=b//2 if(h>c): if(p<=k): max_sum=(p*h) k=k-p if(k>=f): max_sum=max_sum+(f*c) else: max_sum=max_sum+k*c else: max_sum=h*(p-k) elif(c>h): if(f<=k): max_sum=(f*c) k=k-f if(k>=p): max_sum=max_sum+(h*p) else: max_sum=max_sum+k*h else: max_sum=c*(f-k) else: if(k>=p): max_sum=(p*h) k=k-p if(k>=f): max_sum=max_sum+(f*c) else: max_sum=max_sum+(k*c) else: max_sum=h*(p-k) print(max_sum) t=t-1 ```
instruction
0
36,139
9
72,278
No
output
1
36,139
9
72,279
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,957
9
73,914
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` def get_edge(vertex1, vertex2): return (vertex1, vertex2) if vertex1 < vertex2 else (vertex2, vertex1) def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp T = int(input()) for t in range(T): n = int(input()) pieces = [] for c in range(n-2): inp = input().rstrip().split(" ") pieces.append([int(inp[0]), int(inp[1]), int(inp[2])]) G = {} piece_index = 0 while piece_index < len(pieces): for vertex in pieces[piece_index]: if vertex not in G: G[vertex] = {} G[vertex][piece_index] = True piece_index += 1 # Lista de vertices que solo pertenecen a una pieza next_vertices = [] for vertex in G: if len(G[vertex]) == 1: next_vertices.append(vertex) q = [] border_edges = {} non_border_edges = {} while len(next_vertices) > 0: v = next_vertices.pop() if len(G[v]) > 0: piece_index = list(G[v].keys()).pop() q.append(str(piece_index+1)) piece = pieces[piece_index] G.pop(v) for vertex_index in range(3): vertex = piece[vertex_index] if vertex != v: G[vertex].pop(piece_index) if len(G[vertex]) == 1: next_vertices.append(vertex) edge = get_edge(v, vertex) if edge not in non_border_edges: border_edges[edge] = True else: swap(piece, 0, vertex_index) edge = get_edge(piece[1], piece[2]) non_border_edges[edge] = True border_edges = list(border_edges.keys()) vertices = {} for a, b in border_edges: if a not in vertices: vertices[a] = {} if b not in vertices: vertices[b] = {} vertices[a][b] = True vertices[b][a] = True start = None start_val = 5000000000 for vertex in vertices: if len(vertices[vertex]) < start_val: start = vertex start_val = len(vertices[vertex]) v = start p = [] while len(p) < n: p.append(str(v)) assert len(vertices[v]) <= 1 if len(vertices[v]) == 1: neighbor = list(vertices[v].keys()).pop() vertices[neighbor].pop(v) v = neighbor print(" ".join(p)) print(" ".join(q)) ```
output
1
36,957
9
73,915
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,958
9
73,916
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` import sys from heapq import heappush, heappop from collections import Counter, defaultdict # inf = open('input.txt', 'r') # reader = (map(int, line.split()) for line in inf) reader = (map(int, line.split()) for line in sys.stdin) def insert(pq, value, entry_finder, push_id): entry = [value, push_id] entry_finder[push_id] = entry heappush(pq, entry) def remove(entry_finder, push_id): entry = entry_finder.pop(push_id) entry[-1] = -1 def extract_min(pq, entry_finder): while pq: value, push_id = heappop(pq) if push_id > 0: del entry_finder[push_id] return (push_id, value) return (-1, '*') t, = next(reader) for test in range(t): n, = next(reader) pq = [] entry_finder = {} triangle = [tuple(next(reader)) for _ in range(n-2)] deg = Counter() v_tri = defaultdict(list) used = set() for i, tri in enumerate(triangle): for v in tri: deg[v] += 1 v_tri[v].append(i) for v, value in deg.items(): insert(pq, value, entry_finder, push_id=v) g = [set() for _ in range(n+1)] ansQ = [] for _ in range(n-2): v, value = extract_min(pq, entry_finder) while True: i = v_tri[v].pop() if i not in used: break used.add(i) ansQ.append(i+1) tri = triangle[i] tos = [to for to in tri if to != v] for to in tos: if to in g[v]: g[v].remove(to) g[to].remove(v) else: g[v].add(to) g[to].add(v) deg[to] -= 1 remove(entry_finder, push_id=to) insert(pq, deg[to], entry_finder, push_id=to) to1, to2 = tos if to1 in g[to2]: g[to1].remove(to2) g[to2].remove(to1) else: g[to1].add(to2) g[to2].add(to1) ansP = [] visited = [False] * (n+1) s = 1 stack = [s] # print(g) while stack: v = stack.pop() if not visited[v]: visited[v] = True ansP.append(v) for to in g[v]: stack.append(to) print(*ansP) print(*ansQ) # inf.close() ```
output
1
36,958
9
73,917
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,959
9
73,918
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` import os from io import BytesIO import sys import threading sys.setrecursionlimit(10 ** 9) threading.stack_size(67108864) def main(): # input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def ad(i, j): nonlocal g if j in g[i]: g[i].remove(j) g[j].remove(i) else: g[i].add(j) g[j].add(i) def dfs(v): nonlocal used, g, nans used[v] = True nans.append(v + 1) for el in g[v]: if not used[el]: dfs(el) for _ in range(int(input())): n = int(input()) cnt = [set() for i in range(n)] g = [set() for i in range(n)] used = [False] * n triangles = [] for i in range(n - 2): a, b, c = map(int, input().split()) a -= 1 b -= 1 c -= 1 cnt[a].add(i) cnt[b].add(i) cnt[c].add(i) triangles.append((a, b, c)) ad(a, b) ad(b, c) ad(a, c) q = [] ones = [] for i in range(n): if len(cnt[i]) == 1: ones.append(i) ans = [] nans = [] for i in range(n - 2): t = ones.pop() ind = cnt[t].pop() ans.append(ind + 1) cnt[triangles[ind][0]].discard(ind) cnt[triangles[ind][1]].discard(ind) cnt[triangles[ind][2]].discard(ind) if len(cnt[triangles[ind][0]]) == 1: ones.append(triangles[ind][0]) if len(cnt[triangles[ind][1]]) == 1: ones.append(triangles[ind][1]) if len(cnt[triangles[ind][2]]) == 1: ones.append(triangles[ind][2]) dfs(0) print(*nans) print(*ans) tt = threading.Thread(target = main) tt.start() ```
output
1
36,959
9
73,919
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,960
9
73,920
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` class Union: def __init__(self, n): self.p = [i for i in range(n+1)] self.rank = [0] * (n+1) def find(self, x): if self.p[x] != x: self.p[x] = self.find(self.p[x]) return self.p[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: self.p[x] = y self.rank[y] += self.rank[x] else: self.p[y] = x self.rank[x] += self.rank[y] def push(g, u, v): if u not in g: g[u] = [] if v not in g: g[v] = [] g[u].append(v) g[v].append(u) def push_c(cnt, u, i): if u not in cnt: cnt[u] = set() cnt[u].add(i) def process(cnt, tup, deg0, order, g, U, u): if len(cnt[u]) > 0: i = next(iter(cnt[u])) else: return for v in tup[i]: cnt[v].remove(i) if len(cnt[v]) == 1: deg0.append(v) v, w = None, None for x in tup[i]: if x == u: continue if v is None: v = x else: w = x order.append(i) if U.find(u) != U.find(v): U.union(u, v) push(g, u, v) if U.find(u) != U.find(w): U.union(u, w) push(g, u, w) def solve(): n = int(input()) tup = [list(map(int, input().split())) for _ in range(n-2)] g = {} cnt={} order = [] for i, [u,v,w] in enumerate(tup): push_c(cnt, u, i) push_c(cnt, v, i) push_c(cnt, w, i) U = Union(n) deg0 = [x for x, num in cnt.items() if len(num) == 1] while len(deg0) > 0: u = deg0.pop() process(cnt, tup, deg0, order, g, U, u) used = [0] * (n-2) for i in order: used[i] = 1 for i, x in enumerate(used): if x == 0: order.append(i) circle=[] used = [0] * (n+1) for u in g: if len(g[u]) == 1: circle.append(u) used[u]=1 break i=0 while i<len(circle): u=circle[i] for v in g[u]: if used[v]==0: used[v]=1 circle.append(v) i+=1 print(' '.join([str(x) for x in circle])) print(' '.join([str(x+1) for x in order])) for _ in range(int(input())): solve() ```
output
1
36,960
9
73,921
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,961
9
73,922
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` import heapq t = int(input()) for _ in range(t): n = int(input()) counts = [0] * n triangles = [set() for _ in range(n)] assign_order = {} for i in range(n - 2): a, b, c = map(lambda x: x - 1, map(int, input().split())) t = (a, b, c) assign_order[t] = i for x in t: counts[x] += 1 triangles[x].add(t) not_edges = set() edges = set() order = [] que = [i for i in range(n) if counts[i] == 1] index = 0 while index < n - 2: curr = que[index] tt = triangles[curr].pop() # should remain one order.append(assign_order[tt]) t = set(tt) t.remove(curr) a, b = t.pop(), t.pop() for e in (curr, a), (curr, b): if e not in not_edges: edges.add(e) if index < n - 3: not_edges.add((a, b)) not_edges.add((b, a)) else: if (a, b) not in not_edges: edges.add((a, b)) for x in a, b: counts[x] -= 1 if counts[x] == 1: que.append(x) triangles[x].remove(tt) index += 1 e = [[] for _ in range(n)] for a, b in edges: e[a].append(b) e[b].append(a) visited = [False] * n a = 0 answer = [] for i in range(n): visited[a] = True answer.append(a) for b in e[a]: if not visited[b]: a = b break print(' '.join(map(str, map(lambda x: x + 1, answer)))) print(' '.join(map(str, map(lambda x: x + 1, order)))) ```
output
1
36,961
9
73,923
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,962
9
73,924
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` def get_edge(vertex1, vertex2): return (vertex1, vertex2) if vertex1 < vertex2 else (vertex2, vertex1) def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp if __name__ == '__main__': T = int(input()) for t in range(T): n = int(input()) pieces = [] for c in range(n-2): inp = input().rstrip().split(" ") pieces.append([int(inp[0]), int(inp[1]), int(inp[2])]) # Preparing the graph G = {} piece_index = 0 while piece_index < len(pieces): for vertex in pieces[piece_index]: if vertex not in G: G[vertex] = {} G[vertex][piece_index] = True piece_index += 1 # prepare list of vertices associated with only one piece # That piece can be safely removed next_vertices = [] for vertex in G: if len(G[vertex]) == 1: next_vertices.append(vertex) q = [] border_edges = {} non_border_edges = {} while len(next_vertices) > 0: v = next_vertices.pop() if len(G[v]) > 0: piece_index = list(G[v].keys()).pop() q.append(str(piece_index+1)) piece = pieces[piece_index] G.pop(v) for vertex_index in range(3): vertex = piece[vertex_index] if vertex != v: G[vertex].pop(piece_index) if len(G[vertex]) == 1: next_vertices.append(vertex) edge = get_edge(v, vertex) if edge not in non_border_edges: border_edges[edge] = True else: swap(piece, 0, vertex_index) edge = get_edge(piece[1], piece[2]) non_border_edges[edge] = True border_edges = list(border_edges.keys()) vertices = {} for a, b in border_edges: if a not in vertices: vertices[a] = {} if b not in vertices: vertices[b] = {} vertices[a][b] = True vertices[b][a] = True start = None start_val = 5000000000 for vertex in vertices: if len(vertices[vertex]) < start_val: start = vertex start_val = len(vertices[vertex]) v = start p = [] while len(p) < n: p.append(str(v)) assert len(vertices[v]) <= 1 if len(vertices[v]) == 1: neighbor = list(vertices[v].keys()).pop() vertices[neighbor].pop(v) v = neighbor print(" ".join(p)) print(" ".join(q)) ```
output
1
36,962
9
73,925
Provide tags and a correct Python 3 solution for this coding contest problem. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1
instruction
0
36,963
9
73,926
Tags: constructive algorithms, data structures, dfs and similar, graphs Correct Solution: ``` from sys import stdin, stdout from collections import deque t = int(stdin.readline().strip()) lines = [] for _ in range(t): n = int(stdin.readline().strip()) verts = {} pieces = {} for i in range(1,n-2+1): a,b,c = stdin.readline().split() verts.setdefault(a, set()).add(i) verts.setdefault(b, set()).add(i) verts.setdefault(c, set()).add(i) pieces[i] = set([a,b,c]) #print(verts) root,r1,r2,rootp = None, None, None, None for v,s in verts.items(): if len(s) == 1: root = v rootp = s.copy().pop() rvs = pieces[rootp].copy() rvs.remove(root) r1 = rvs.pop() r2 = rvs.pop() break #print(pieces) stk = deque([(0, root), (1, rootp), (0, r2), (2, r1, r2, rootp), (0, r1)]) vertord, pieceord = [], [] while stk: cmd = stk.pop() t = cmd[0] if t == 0: vertord.append(cmd[1]) elif t == 1: pieceord.append(cmd[1]) else: _,v1,v2,p1 = cmd isect = verts[v1] & verts[v2] isect.remove(p1) if not isect: continue p2 = isect.pop() pvs = pieces[p2] pvs.remove(v1) pvs.remove(v2) v3 = pvs.pop() stk.append((1,p2)) stk.append((2, v3,v2,p2)) stk.append((0, v3)) stk.append((2, v1,v3,p2)) lines.append(' '.join(vertord) + '\n') lines.append(' '.join(map(str, pieceord)) + '\n') stdout.writelines(lines) ```
output
1
36,963
9
73,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1 Submitted Solution: ``` def fau(a, k): for i in range(len(a)): for j in range(3): if k == a[i][j]: return a[i] def skl(s, trk, c): trk.remove(c) for i in range(len(s)): if s[i] == trk[0] and s[i - 1] == trk[1] or s[i] == trk[1] and s[i - 1] == trk[0]: s.insert(i, c) return s kl = int(input()) for l in range(kl): n = int(input()) dic = {} for i in range(n): dic[i + 1] = 0 a = [[0 for i in range(3)] for j in range(n - 2)] for i in range(n - 2): a[i] = [int(i) for i in input().split()] dic[a[i][0]] += 1 dic[a[i][1]] += 1 dic[a[i][2]] += 1 q = [] b = [] for k in range(n - 3): for key in dic.keys(): if dic[key] == 1: tr = fau(a, key) for ij in range(3): dic[tr[ij]] -= 1 q += [key] b += [tr] a.remove(tr) del dic[key] break vr = [a[0][0]] s = a[0] for i in range(len(q) - 1, -1, -1): s = skl(s, b[i], q[i]) q += vr for i in range(len(s)): print(s[i], '', end='') print() for i in range(len(q)): print(q[i], '', end='') print() ```
instruction
0
36,964
9
73,928
No
output
1
36,964
9
73,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1 Submitted Solution: ``` import sys values = [line.splitlines() for line in sys.stdin] no_tests = int(values[0][0]) counter = 0 #what a mess val = 1 def solve_test(slovnik, no_vertices, all_triples): final = print_vertices(slovnik, no_vertices, all_triples) print_components(slovnik, no_vertices, all_triples, final) def print_right_order(sl, no_vertices): # dvojice s value 1 su pri sebe, treba to dat do poradia numbers = [i for i in range(1, no_vertices + 1)] for prvok in sl: if numbers[prvok[0] - 1] is not None: numbers[prvok[0] - 1] = None final = [] used = set() for prvok in numbers: if prvok is not None: final.append(prvok) current = prvok break while len(final) != no_vertices: for prvok in sl: if prvok[0] == current and prvok not in used and sl[prvok] == 1: final.append(prvok[1]) current = prvok[1] used.add(prvok) break elif prvok[1] == current and prvok not in used and sl[prvok] == 1: final.append(prvok[0]) current = prvok[0] used.add(prvok) break cou = 0 for pr in final: if cou == len(final) - 1: print(pr) else: print(pr, end=" ") cou += 1 return final def print_vertices(slovnik, no_vertices, all_triples): sl = dict() for triple in all_triples: for i in range(3): triple[i] = int(triple[i]) triple = sorted(triple) for vals in [(triple[1], triple[0]), (triple[2], triple[0]), (triple[2], triple[1])]: try: sl[vals] += 1 except: sl[vals] = 1 return print_right_order(sl, no_vertices) def print_components(slovnik, no_vertices, all_triples, final): max_val = max(slovnik) del slovnik[max_val] max_val = max(slovnik) del slovnik[max_val] cou = 0 for prvok in final: if prvok in slovnik: if cou == len(slovnik) - 1: print(prvok) else: print(prvok, end=" ") cou += 1 not_last = True while counter != no_tests: slovnik = dict() no_vertices = int(values[val][0]) for i in range(1, no_vertices + 1): slovnik[i] = 0 val += 1 all_triples = [] while not_last and len(values[val][0].split()) == 3: triple = values[val][0].split() all_triples.append(triple) for v in triple: int_v = int(v) slovnik[int_v] += 1 val += 1 if len(values) <= val: not_last = False solve_test(slovnik, no_vertices, all_triples) counter += 1 ```
instruction
0
36,965
9
73,930
No
output
1
36,965
9
73,931
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1 Submitted Solution: ``` a=8 ```
instruction
0
36,966
9
73,932
No
output
1
36,966
9
73,933
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We are committed to the well being of all participants. Therefore, instead of the problem, we suggest you enjoy a piece of cake. Uh oh. Somebody cut the cake. We told them to wait for you, but they did it anyway. There is still some left, though, if you hurry back. Of course, before you taste the cake, you thought about how the cake was cut. It is known that the cake was originally a regular n-sided polygon, each vertex of which had a unique number from 1 to n. The vertices were numbered in random order. Each piece of the cake is a triangle. The cake was cut into n - 2 pieces as follows: each time one cut was made with a knife (from one vertex to another) such that exactly one triangular piece was separated from the current cake, and the rest continued to be a convex polygon. In other words, each time three consecutive vertices of the polygon were selected and the corresponding triangle was cut off. A possible process of cutting the cake is presented in the picture below. <image> Example of 6-sided cake slicing. You are given a set of n-2 triangular pieces in random order. The vertices of each piece are given in random order — clockwise or counterclockwise. Each piece is defined by three numbers — the numbers of the corresponding n-sided cake vertices. For example, for the situation in the picture above, you could be given a set of pieces: [3, 6, 5], [5, 2, 4], [5, 4, 6], [6, 3, 1]. You are interested in two questions. * What was the enumeration of the n-sided cake vertices? * In what order were the pieces cut? Formally, you have to find two permutations p_1, p_2, ..., p_n (1 ≤ p_i ≤ n) and q_1, q_2, ..., q_{n - 2} (1 ≤ q_i ≤ n - 2) such that if the cake vertices are numbered with the numbers p_1, p_2, ..., p_n in order clockwise or counterclockwise, then when cutting pieces of the cake in the order q_1, q_2, ..., q_{n - 2} always cuts off a triangular piece so that the remaining part forms one convex polygon. For example, in the picture above the answer permutations could be: p=[2, 4, 6, 1, 3, 5] (or any of its cyclic shifts, or its reversal and after that any cyclic shift) and q=[2, 4, 1, 3]. Write a program that, based on the given triangular pieces, finds any suitable permutations p and q. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then there are t independent sets of input data. The first line of each set consists of a single integer n (3 ≤ n ≤ 10^5) — the number of vertices in the cake. The following n - 2 lines describe the numbers of the pieces vertices: each line consists of three different integers a, b, c (1 ≤ a, b, c ≤ n) — the numbers of the pieces vertices of cake given in random order. The pieces are given in random order. It is guaranteed that the answer to each of the tests exists. It is also guaranteed that the sum of n for all test cases does not exceed 10^5. Output Print 2t lines — answers to given t test cases in the order in which they are written in the input. Each answer should consist of 2 lines. In the first line of an answer on a test case print n distinct numbers p_1, p_2, ..., p_n(1 ≤ p_i ≤ n) — the numbers of the cake vertices in clockwise or counterclockwise order. In the second line of an answer on a test case print n - 2 distinct numbers q_1, q_2, ..., q_{n - 2}(1 ≤ q_i ≤ n - 2) — the order of cutting pieces of the cake. The number of a piece of the cake corresponds to its number in the input. If there are several answers, print any. It is guaranteed that the answer to each of the tests exists. Example Input 3 6 3 6 5 5 2 4 5 4 6 6 3 1 6 2 5 6 2 5 1 4 1 2 1 3 5 3 1 2 3 Output 1 6 4 2 5 3 4 2 3 1 1 4 2 6 5 3 3 4 2 1 1 3 2 1 Submitted Solution: ``` t = int(input()) for i in range(t): lines = [] p = [] q = [] n = int(input()) for j in range(n - 2): a, b, c = map(int, input().split()) lines.append((a, b, c)) # 计数 count = {} for tup in lines: for m in tup: if count.__contains__(m): count[m] += 1 else: count[m] = 1 # 连续边 cons = [] # 弃用边 rub = [] # 顺序记录 raw_lines = {j: i + 1 for i, j in enumerate(lines)} while len(lines) != 0: # print("rub:") # print(rub) tup = lines.pop(0) flag = 1 if count[tup[0]] == 1: q.append(raw_lines[tup]) for line in [(tup[1], tup[0]), (tup[0], tup[2])]: if line not in rub and (line[1], line[0]) not in rub: cons.append(line) rub.append((tup[1], tup[2])) elif count[tup[1]] == 1: q.append(raw_lines[tup]) for line in [(tup[0], tup[1]), (tup[1], tup[2])]: if line not in rub and (line[1], line[0]) not in rub: cons.append(line) rub.append((tup[0], tup[2])) elif count[tup[2]] == 1: q.append(raw_lines[tup]) for line in [(tup[0], tup[2]), (tup[2], tup[1])]: if line not in rub and (line[1], line[0]) not in rub: cons.append(line) rub.append((tup[0], tup[1])) else: # 这个扔到后面处理 lines.append(tup) flag = 0 # 处理完一轮之后要减去计数 if flag == 1: for m in tup: count[m] -= 1 # 连接连续边 link = {i: [] for i in range(1, n + 1)} for (o, t) in cons: link[o].append(t) link[t].append(o) last = -1 nex = 1 p.append(1) while len(p) < n: for m in link[nex]: if m != last: break p.append(m) last = nex nex = m if n == 3: p = [1, 2, 3] q = [1] for j in p: print(j, end=' ') print() for j in q: print(j, end=' ') print() ```
instruction
0
36,967
9
73,934
No
output
1
36,967
9
73,935
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,523
9
75,046
"Correct Solution: ``` a, b, k = map(int, input().split()) print(max(a-k, 0), max(b-max((k-a), 0), 0)) ```
output
1
37,523
9
75,047
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,524
9
75,048
"Correct Solution: ``` A, B, K = map(int, input().split()) print(max(0, A-K), max(A+B-K-max(0, A-K), 0)) ```
output
1
37,524
9
75,049
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,525
9
75,050
"Correct Solution: ``` A, B, K = map(int, input().split()) k = max(K - A, 0) print(max(0, A - K), max(0, B - k)) ```
output
1
37,525
9
75,051
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,526
9
75,052
"Correct Solution: ``` a, b, k = map(int, input().split()) print(max(0, a-k), max(0, b-max(0, k-a))) ```
output
1
37,526
9
75,053
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,527
9
75,054
"Correct Solution: ``` a, b, k = map(int, input().split()) c = min(a,k) a -= c k -= c b -= min(b, k) print(a, b) ```
output
1
37,527
9
75,055
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,528
9
75,056
"Correct Solution: ``` a,b,k=map(int,input().split()) if a>=k: print(a-k,b) else: print(0,max(b+a-k,0)) ```
output
1
37,528
9
75,057
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,529
9
75,058
"Correct Solution: ``` ## B A,B,K = map(int,input().split()) print(max(0, A-K), max(0, min(B,A+B-K) )) ```
output
1
37,529
9
75,059
Provide a correct Python 3 solution for this coding contest problem. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0
instruction
0
37,530
9
75,060
"Correct Solution: ``` a,b,k=map(int,input().split()) if a>k: print(a-k,b) else: print(0,max(b-(k-a),0)) ```
output
1
37,530
9
75,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` a,b,k=map(int,input().split()) a-=k if a<0: b+=a print(max(0,a),max(0,b)) ```
instruction
0
37,531
9
75,062
Yes
output
1
37,531
9
75,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` t,a,k = map(int,input().split()) t = t-k if t<0: a += t t = 0 if a<0: a = 0 print(t,a) ```
instruction
0
37,532
9
75,064
Yes
output
1
37,532
9
75,065
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` a,b,k = map(int, input().split()) t = a - min(a,k) k -= min(a,k) q = b - min(k,b) print(t,q) ```
instruction
0
37,533
9
75,066
Yes
output
1
37,533
9
75,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` A, B, K = list(map(int, input().split())) k = min(A, K) print(A-k, max(0,B-(K-k))) ```
instruction
0
37,534
9
75,068
Yes
output
1
37,534
9
75,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` A,B,K = list(map(int,input().split(" "))) if K > A: K -= A A = 0 else: A -= K print(str(A) +" "+ str(B)) exit() B -= K print(str(A) +" " +str(B)) ```
instruction
0
37,535
9
75,070
No
output
1
37,535
9
75,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` n=int(input()) if n==1: print("Hello World") else: a=int(input()) b=int(input()) print(a+b) ```
instruction
0
37,536
9
75,072
No
output
1
37,536
9
75,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` def main(): a, b, k = map(int, input().split()) if k <= a: a -= k else: b -= k - a a = 0 print(a, b) if __name__ == '__main__': main() ```
instruction
0
37,537
9
75,074
No
output
1
37,537
9
75,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively? Constraints * 0 \leq A \leq 10^{12} * 0 \leq B \leq 10^{12} * 0 \leq K \leq 10^{12} * All values in input are integers. Input Input is given from Standard Input in the following format: A B K Output Print the numbers of Takahashi's and Aoki's cookies after K actions. Examples Input 2 3 3 Output 0 2 Input 500000000000 500000000000 1000000000000 Output 0 0 Submitted Solution: ``` a , b ,c =map(int,input().split()) for k in range(c): if a >= 1: a -= 1 elif b >= 1: b -= 1 ans = str(a) +str(" ") + str(b) print(ans) ```
instruction
0
37,538
9
75,076
No
output
1
37,538
9
75,077
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,636
9
75,272
"Correct Solution: ``` import sys N,C=map(int,input().split()) A=[int(i) for i in input().split()] B=[int(i) for i in input().split()] mod=10**9+7 table=[[ pow(j,i,mod) for j in range(405)] for i in range(405)] ntable=[[0]*405 for i in range(405)] for i in range(405): t=0 for j in range(1,405): t+=table[i][j] t%=mod ntable[i][j]=t F=[B[i]-A[i]+1 for i in range(N)] G=[0]*N t=1 for i in range(N): t*=F[i] t%=mod for i in range(N): G[i]=(t*pow(F[i],mod-2,mod))%mod #print(G) dp=[[0]*(C+1) for i in range(N)] for i in range(C+1): dp[0][i]=((ntable[i][B[0]]-ntable[i][A[0]-1]))%mod#*G[0] for i in range(1,N): for k in range(C+1): for l in range(k+1): dp[i][k]+=dp[i-1][l]*(ntable[k-l][B[i]]-ntable[k-l][A[i]-1])#*G[i] dp[i][k]%=mod #print(dp) print(dp[N-1][C]) ```
output
1
37,636
9
75,273
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,637
9
75,274
"Correct Solution: ``` MOD = 10**9+7 n, c = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) sig = [[0 for _ in range(max(b)+1)] for _ in range(c+1)] for i in range(c+1): for j in range(1, max(b)+1): sig[i][j] = sig[i][j-1] + pow(j, i, MOD) sig[i][j] %= MOD def sigma(C, A, B): return (sig[C][B] - sig[C][A-1]) % MOD dp = [[0 for _ in range(c+1)] for _ in range(n)] for j in range(c+1): dp[0][j] = sigma(j, a[0], b[0]) for i in range(1, n): for j in range(c+1): for k in range(j+1): dp[i][j] += dp[i-1][k] * sigma(j-k, a[i], b[i]) dp[i][j] %= MOD print(dp[n-1][c]) ```
output
1
37,637
9
75,275
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,638
9
75,276
"Correct Solution: ``` n,c = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) mod = 10**9+7 ex400 = [[1] * 401 for _ in range(401)] for i in range(2,401): for j in range(1,401): ex400[i][j] = (ex400[i][j-1] * i) % mod cumsum400 = [[1] * 401 for _ in range(401)] for i in range(1,401): for j in range(401): cumsum400[i][j] = (cumsum400[i-1][j] + ex400[i][j]) % mod dp = [[0] * (c+1) for _ in range(n+1)] dp[0][0] = 1 for i in range(1,n+1): for j in range(c+1): for k in range(j+1): dp[i][j] += dp[i-1][j-k] * (cumsum400[b[i-1]][k] - cumsum400[a[i-1]-1][k]) dp[i][j] %= mod print(dp[-1][-1]) ```
output
1
37,638
9
75,277
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,639
9
75,278
"Correct Solution: ``` MOD = 10**9 + 7 n, m = [int(item) for item in input().split()] a = [int(item) for item in input().split()] b = [int(item) for item in input().split()] cumsum = [[1] * 410 for _ in range(410)] for order in range(405): for i in range(1, 405): cumsum[order][i] = pow(i, order, MOD) + cumsum[order][i-1] cumsum[order][i] %= MOD dp = [[0] * (m + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(1, n+1): for j in range(0, m+1): for k in range(j+1): l = a[i - 1] r = b[i - 1] x = (cumsum[j-k][r] - cumsum[j-k][l-1] + MOD) % MOD dp[i][j] += dp[i-1][k] * x dp[i][j] %= MOD print(dp[-1][-1]) ```
output
1
37,639
9
75,279
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,640
9
75,280
"Correct Solution: ``` N, C = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) mod = 10**9+7 acc = [[0] for _ in range(401)] for i in range(401): for j in range(1, 401): acc[i].append(((acc[i][-1] + pow(j, i, mod)) % mod)) dp = [[0 for _ in range(C+1)] for _ in range(N+1)] dp[0][0] = 1 for i in range(N): for candy_cur in range(C+1): for candy_plus in range(C - candy_cur+1): dp[i+1][candy_cur + candy_plus] = (dp[i+1][candy_cur + candy_plus] + (dp[i][candy_cur]\ * ((acc[candy_plus][B[i]] - acc[candy_plus][A[i]-1])%mod)%mod)) % mod print(dp[-1][C]) ```
output
1
37,640
9
75,281
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,641
9
75,282
"Correct Solution: ``` import sys input = sys.stdin.readline # modを取りながらべき乗する def power_func(a,n,mod): bi=str(format(n,"b"))#2進表現に res=1 for i in range(len(bi)): res=(res*res) %mod if bi[i]=="1": res=(res*a) %mod return res def main(): N, C = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) mod = 10**9+7 L = 400 dp = [[0]*(L+1) for _ in range(C+1)] count = B[0] - A[0] + 1 for c in range(C+1): a, b = A[0], B[0] dp[c][0] = power_func(a, c, mod) for k in range(1, b-a+1): dp[c][k] = (dp[c][k-1] + power_func(a+k, c, mod)) % mod dp[c][L] = dp[c][b-a] for i, (a, b) in enumerate(zip(A, B)): if i == 0: continue for k in range(b-a+1): dp[0][k] = count * (k+1) % mod dp[0][L] = dp[0][b-a] for c in range(1, C+1): dp[c][0] = (dp[c][L] + a*dp[c-1][0]) % mod for k in range(1, b-a+1): R = dp[c][k-1] + dp[c][L] + (a+k)*(dp[c-1][k]-dp[c-1][k-1]) if R < 0: R += mod dp[c][k] = R%mod dp[c][L] = dp[c][b-a] count = (count * (b-a+1)) % mod print(dp[C][L]) if __name__ == "__main__": main() ```
output
1
37,641
9
75,283
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,642
9
75,284
"Correct Solution: ``` import sys input = sys.stdin.buffer.readline N, C = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [0] * (N * (C + 1)) mod = 10 ** 9 + 7 for i in range(N): c[i * (C + 1)] = b[i] - a[i] + 1 for i in range(N): for k in range(a[i], b[i] + 1): t = 1 for j in range(C): t *= k t %= mod c[i * (C + 1) + j + 1] += t c[i * (C + 1) + j + 1] %= mod dpx = [0] * (C + 1) dpy = [0] * (C + 1) dpx[0] = 1 for i in range(N): if i % 2: dpx = [0] * (C + 1) else: dpy = [0] * (C + 1) for j in range(C + 1): for k in range(j, C + 1): if i % 2: dpx[k] += dpy[j] * c[i * (C + 1) + k - j] dpx[k] %= mod else: dpy[k] += dpx[j] * c[i * (C + 1) + k - j] dpy[k] %= mod if N % 2: print(dpy[-1] % mod) else: print(dpx[-1] % mod) ```
output
1
37,642
9
75,285
Provide a correct Python 3 solution for this coding contest problem. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a, where x_i is the child's excitement level. The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N, thus we call it f(x_1,..,x_N). You are given integers A_i,B_i (1≦i≦N). Find <image> modulo 10^9+7. Constraints * 1≦N≦400 * 1≦C≦400 * 1≦A_i≦B_i≦400 (1≦i≦N) Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of <image> modulo 10^9+7. Examples Input 2 3 1 1 1 1 Output 4 Input 1 2 1 3 Output 14 Input 2 3 1 1 2 2 Output 66 Input 4 8 3 1 4 1 3 1 4 1 Output 421749 Input 3 100 7 6 5 9 9 9 Output 139123417
instruction
0
37,643
9
75,286
"Correct Solution: ``` def main(): mod = 10**9+7 n, c = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) dp = [0]*(c+1) dp[0] = 1 ans = 0 p = [[0]*(401) for _ in [0]*401] # p[i][j]でj^i for i in range(401): for j in range(401): p[i][j] = pow(j, i, mod) for a, b in zip(A, B): dp2 = [0]*(c+1) q = [0]*(c+1) for i in range(c+1): q[i] = sum(p[i][a:b+1]) % mod for i in range(c+1): temp = 0 for j in range(i+1): temp += dp[i-j]*q[j] dp2[i] = temp % mod dp = dp2 ans += dp[-1] print(ans % mod) main() ```
output
1
37,643
9
75,287