text
stringlengths
198
433k
conversation_id
int64
0
109k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i. He can rearrange the balls by performing the following two operations any number of times, in any order: * Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls. * Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls. How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7. Constraints * 1 ≤ N ≤ 2 × 10^5 * 1 ≤ X, Y ≤ 10^9 * 1 ≤ c_i ≤ N * 1 ≤ w_i ≤ 10^9 * X, Y, c_i, w_i are all integers. Input Input is given from Standard Input in the following format: N X Y c_1 w_1 : c_N w_N Output Print the answer. Examples Input 4 7 3 3 2 4 3 2 1 4 4 Output 2 Input 1 1 1 1 1 Output 1 Input 21 77 68 16 73 16 99 19 66 2 87 2 16 7 17 10 36 10 68 2 38 10 74 13 55 21 21 3 7 12 41 13 88 18 6 2 12 13 87 1 9 2 27 13 15 Output 129729600 Submitted Solution: ``` from collections import defaultdict n,x,y=map(int,input().split()) mod=10**9+7 f=[1] for i in range(1,n+7):f.append(f[-1]*i%mod) wc=[list(map(int,input().split()))[::-1]for _ in range(n)] if n==1:exit(print(1)) if len(set(c for w,c in wc))==1:exit(print(1)) wc.sort() mw,mc=wc[0] i=1 while wc[i][1]==mc:i+=1 mmw,mmc=wc[i] flag=False for w,c in wc: if ((c==mc and w+mw<=x)or(c!=mc and w+mw<=y))and((c==mmc and w+mmw<=x)or(c!=mmc and w+mmw<=y)):flag=True if flag: d=defaultdict(int) dc=0 for w,c in wc: if(c==mc and w+mw<=x)or(c!=mc and w+mw<=y)or(c==mmc and w+mmw<=x)or(c!=mmc and w+mmw<=y): d[c]+=1 dc+=1 ans=f[dc] for i in d: ans*=pow(f[d[i]],mod-2,mod) ans%=mod else: d=defaultdict(int) dc=0 md=defaultdict(int) mdc=0 for w,c in wc: if (c==mc and w+mw<=x)or(c!=mc and w+mw<=y): d[c]+=1 dc+=1 if (c==mmc and w+mmw<=x)or(c!=mmc and w+mmw<=y): md[c]+=1 mdc+=1 ans=f[dc] for i in d: ans*=pow(f[d[i]],mod-2,mod) ans%=mod anss=f[mdc] for i in md: anss*=pow(f[md[i]],mod-2,mod) anss%=mod ans=(ans*anss)%mod print(ans) ``` No
90,000
Provide a correct Python 3 solution for this coding contest problem. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 "Correct Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,D,X = map(int,read().split()) answer = 0 for n in range(N,0,-1): mean = D + X * (n+n-1) / 2 answer += mean D = ((n+n+2) * D + 5 * X) / (2*n) X = (n + 2) * X / n print(answer) ```
90,001
Provide a correct Python 3 solution for this coding contest problem. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 "Correct Solution: ``` N,D,X = map(int,input().split()) """ ・玉の位置は無視できる ・等差数列なので左右反転して平均化→完全等間隔に帰着 ・ひとつ取り去ったあとの平均化→それも完全等間隔の定数倍 ・すべての間隔が1であるN区間の場合の期待値を求める """ x = .5 for n in range(2,N+1): x += .5 + x/n answer = x * (2*D+X*(2*N-1)) print(answer) ```
90,002
Provide a correct Python 3 solution for this coding contest problem. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 "Correct Solution: ``` def solve(n, d, x): ans = 0 while n: ans += d + (2 * n - 1) * x / 2 d = ((n + 1) * d + 5 * x / 2) / n x *= (n + 2) / n n -= 1 return ans print('{:.10f}'.format(solve(*map(float, input().split())))) ```
90,003
Provide a correct Python 3 solution for this coding contest problem. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 "Correct Solution: ``` from decimal import Decimal, getcontext getcontext().prec = 200 n, d, x = map(Decimal, input().split()) ans = 0 for i in range(1, int(n) + 1): i = Decimal(str(i)) ans += Decimal(str((int(n) - int(i) + 1))) / Decimal(str(i)) * (d + x * Decimal(str(int(n) * 2 - 1)) / Decimal("2")) print(ans) ```
90,004
Provide a correct Python 3 solution for this coding contest problem. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 "Correct Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, d, x = map(int, read().split()) def main(N, d, x): ret = 0 while N: ret += d + (N-0.5) * x d = d + (d/N) + (5*x)/(2*N) x += 2*x/N N -= 1 return ret print(main(N, d, x)) ```
90,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 Submitted Solution: ``` import sys sys.setrecursionlimit(200000) def solve(n, d, x): if not n: return 0 return d + (2 * n - 1) * x / 2 + solve(n - 1, ((n + 1) * d + 5 * x / 2) / n, (n + 2) * x / n) print(solve(*map(int, input().split()))) ``` No
90,006
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 Submitted Solution: ``` from decimal import Decimal N=0;A=Decimal('.0');X=Decimal('.0');M=0; A2=Decimal('.0');X2=Decimal('.0');M2=Decimal('.0'); S=Decimal('.0');E=Decimal('.0');Ans=Decimal('.0'); cin = input().split() N=int(cin[0]) A=Decimal(cin[1]) X=Decimal(cin[2]) M=2*N for i in range(1, N): A2 = ((M+2)*A + 5*X) / M; X2 = (M+4) * X / M; M2 = M-2; S = A*M + M*(M-1)*X/2; E = A2*M2 + M2*(M2-1)*X2/2; Ans+=S/M; A=A2; X=X2; M=M2; Ans+=(A*2+X)/2; print(Ans) ``` No
90,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 Submitted Solution: ``` import sys from decimal import Decimal sys.setrecursionlimit(200000) def solve(n, d, x): if not n: return 0 return d + (2 * n - 1) * x / 2 + solve(n - 1, ((n + 1) * d + 5 * x / 2) / n, (n + 2) * x / n) print(solve(*map(Decimal, input().split()))) ``` No
90,008
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N). We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.) In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process. For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario: c9264131788434ac062635a675a785e3.jpg * first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3. * second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9. * third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6. So the total distance in this scenario is 18. Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end. Constraints * 1 \leq N \leq 200,000 * 1 \leq d_1 \leq 100 * 0 \leq x \leq 100 * All input values are integers. Input The input is given from Standard Input in the following format: N d_1 x Output Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}. Examples Input 1 3 3 Output 4.500000000000000 Input 2 1 0 Output 2.500000000000000 Input 1000 100 100 Output 649620280.957660079002380 Submitted Solution: ``` memo = {0: 0} def left(s, i): hall_i = i while s & 1 << hall_i: hall_i -= 1 return balls[i] - halls[hall_i] def right(s, i): hall_i = i + 1 while s & 1 << hall_i: hall_i += 1 return halls[hall_i] - balls[i] def solve(s): # print(('solve {0:0' + str(N) + 'b}').format(s)) if s not in memo: ans = 0 cnt = 0 for i in range(N + 1): if s & 1 << i: sp = s ^ 1 << i ans += solve(sp) + (left(sp, i) + right(sp, i)) / 2 cnt += 1 memo[s] = ans / cnt # print(('solve {0:0' + str(N) + 'b}').format(s), '=', memo[s]) return memo[s] N, d1, x = [int(x) for x in input().split()] intervals = [d1 + i * x for i in range(N * 2)] balls = [d1] for i in range(1, N): balls.append(balls[-1] + intervals[2 * i - 1] + intervals[2 * i]) halls = [0] for i in range(N): halls.append(halls[-1] + intervals[2 * i] + intervals[2 * i + 1]) for i in range((1 << N) - 1): solve(i) print(solve((1 << N) - 1)) ``` No
90,009
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` if __name__ == '__main__': while True: try: n = int(input()) ans = [] for i in range(9,-1,-1): if n >= 2**i: ans.append(2**i) n -= 2**i print(*sorted(ans)) except EOFError: break ```
90,010
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` # AOJ 0031 Weight # Python3 2018.6.14 bal4u w = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]; while True: try: a = int(input()) ans = [] i = 0 while a > 0: if a & 1: ans.append(w[i]) a >>= 1 i += 1 print(*ans) except EOFError: break ```
90,011
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` import sys for line in sys.stdin: weight = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] ans = [] n = bin(int(line))[2:] for i, x in enumerate(n[::-1]): if x == "1": ans.append(str(weight[i])) print(" ".join(ans)) ```
90,012
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` def solve(x): B=list(map(int,x)) B.reverse() for i in range(len(B)): B[i]=B[i]*(2**i) #remove 0 while 0 in B: B.remove(0) print(" ".join(map(str,B))) while True: try: x=int(input()) solve(format(x,'b')) except EOFError: break ```
90,013
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` while True: try: w = int(input()) except: break ans = [2 ** i if w // 2 ** i % 2 else 0 for i in range(10)] while ans.count(0): del ans[ans.index(0)] print(*ans) ```
90,014
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` def get_input(): while True: try: yield ''.join(input()) except EOFError: break N = list(get_input()) w = [1,2,4,8,16,32,64,128,256,512] w.reverse() for l in range(len(N)): n = int(N[l]) ans = [] for i in range(10): if n >= w[i]: n = n - w[i] ans.append(w[i]) ans.sort() print(ans[0], end="") for i in range(1,len(ans)): print(" " + str(ans[i]), end="") print("") ```
90,015
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` import sys W = [] N = [1,2,4,8,16,32,64,128,256,512] for line in sys.stdin: W.append(int(line)) for x in W: ans = [] for y in N: if x & y: ans.append(str(y)) print(' '.join(ans)) ```
90,016
Provide a correct Python 3 solution for this coding contest problem. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 "Correct Solution: ``` def solve(num, l): if num == 0: return l l.append(num % 2) return solve(num // 2, l) while True: try: num = int(input()) nums = solve(num, []) ans = "" for i, v in enumerate(nums): if v: ans += str(2 ** i) + " " print(ans.rstrip()) except EOFError: break ```
90,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` b = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] b.reverse() try: while 1: n = int(input()) l = [] for i in b: if i <= n: l.insert(0, i) n -= i print(*l) except: pass ``` Yes
90,018
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` import sys for line in sys.stdin: g = int(line) now = 512 ans = [] while True: if g == 0: break elif g >= now: g -= now ans.append(now) now //= 2 temp = '' for i in ans[::-1]: temp += str(i) + ' ' print(temp[:-1]) ``` Yes
90,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` import sys for d in sys.stdin: c=0 a=[] for b in bin(int(d))[2:][::-1]: if int(b):a+=[int(b)*2**c] c+=1 print(*a) ``` Yes
90,020
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` import sys bundo = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] bundo.reverse() for line in sys.stdin: n = int(line) ans = '' for i in bundo: if n >= i: n -= i ans = str(i) + ' ' + ans print(ans[:-1]) ``` Yes
90,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` # -*- coding: utf-8 -*- # !/usr/bin/env python # vim: set fileencoding=utf-8 : """ # # Author: Noname # URL: https://github.com/pettan0818 # License: MIT License # Created: 木 10/26 19:32:38 2017 # Usage # """ import sys WEIGHTS = [2 ** i for i in range(9)] def solver_greedy(target_weight: int): """ >>> print(solver_greedy(127)) [1, 2, 4, 8, 16, 32, 64] """ res = [] for w in sorted(WEIGHTS, reverse=True): if w <= target_weight: res.append(w) target_weight = target_weight - w if target_weight == 0: return sorted(res) if __name__ == '__main__': data = [] for line in sys.stdin: data.append(int(line)) for i in data: res = solver_greedy(i) for x,n in enumerate(res): sys.stdout.write(str(n)) if x + 1 == len(data): sys.stdout.write("\n") break sys.stdout.write(" ") ``` No
90,022
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` def solve(x): B=list(map(int,x)) B.reverse() for i in range(len(B)): B[i]=B[i]*(2**i) if 0 in B: B.remove(0) print(" ".join(map(str,B))) while True: try: x=int(input()) solve(format(x,'b')) except EOFError: break ``` No
90,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` while True: g = int(input()) now = 512 ans = [] while True: if g == 0: break elif g >= now: g -= now ans.append(now) now //= 2 temp = '' for i in ans[::-1]: temp += str(i) + ' ' print(temp[:-1]) ``` No
90,024
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness. My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?" Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g). Hint The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g. Input Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50. Output For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line. Example Input 5 7 127 Output 1 4 1 2 4 1 2 4 8 16 32 64 Submitted Solution: ``` def bin(w, l):   if w == 0:     return l     l.append(w % 2)   return bin(w // 2, l)   while True:   try:     w = int(input())     w_bin = bin(w, [])     ans = ""     for i, v in enumerate(w_bin):       if v:         ans += str(2 ** i) + " "     print(ans.rstrip())     except EOFError:     break ``` No
90,025
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0162 """ import sys from sys import stdin from bisect import bisect_right, bisect_left from math import ceil, log input = stdin.readline def main(args): hammings = [] temp = set() for i in range(ceil(log(1e6, 2)) + 1): for j in range(ceil(log(1e6, 3)) + 1): for k in range(ceil(log(1e6, 5)) + 1): ans = 2**i * 3**j * 5**k temp.add(ans) hammings = list(temp) hammings.sort() while True: try: m, n = map(int, input().split(' ')) except ValueError: break s = bisect_left(hammings, m) t = bisect_right(hammings, n) print(t - s) if __name__ == '__main__': main(sys.argv[1:]) ```
90,026
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` while 1: n=list(map(int,input().split())) if n[0]==0:break a=0 for i in range(n[0],n[1]+1): b=i while b%5==0: b/=5 while b%3==0: b/=3 while b%2==0: b/=2 if b==1:a+=1 print(a) ```
90,027
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` while True: A = list(map(int, input().split())) if A[0] == 0: break n, m = A[0], A[1] ans = 0 for i in range(n, m+1): b = i while b % 5 == 0: b //= 5 while b % 3 == 0: b //= 3 while b % 2 == 0: b //= 2 if b == 1: ans += 1 print(ans) ```
90,028
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` MAX = 1000000 hamming_list = [False] * (MAX + 1) hamming_list[0] = False hamming_list[1] = True for index in range(2, MAX + 1): if index % 2 == 0: if hamming_list[index // 2]: hamming_list[index] = True elif index % 3 == 0: if hamming_list[index // 3]: hamming_list[index] = True elif index % 5 == 0: if hamming_list[index // 5]: hamming_list[index] = True while True: input_data = input() if input_data == "0": break start, end = [int(item) for item in input_data.split(" ")] count = sum(hamming_list[start:end + 1]) print(count) ```
90,029
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` MAX = 1000000 hamming_list = [False] * (MAX + 1) hamming_list[0] = False hamming_list[1] = True for index in range(2, MAX + 1): if index / 2 % 1 == 0: if hamming_list[index // 2]: hamming_list[index] = True elif index / 3 % 1 == 0: if hamming_list[index // 3]: hamming_list[index] = True elif index / 5 % 1 == 0: if hamming_list[index // 5]: hamming_list[index] = True while True: input_data = input() if input_data == "0": break start, end = [int(item) for item in input_data.split(" ")] count = sum(hamming_list[start:end + 1]) print(count) ```
90,030
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` H = [False for i in range(1000001)] H[1] = True for i in range(20): for j in range(13): for k in range(9): if (2 ** i) * (3 ** j) * (5 ** k) < 1000001: H[(2 ** i) * (3 ** j) * (5 ** k)] = True else: break while True: L = input() if L == "0": break a, b = [int(i) for i in L.split()] ans = 0 for i in range(a, b+1): if H[i]: ans += 1 print(ans) ```
90,031
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` while 1: n=list(map(int,input().split())) if n[0]==0:break a=0 for i in range(n[0],n[1]+1): b=i while b%2==0: b/=2 while b%3==0: b/=3 while b%5==0: b/=5 if b==1:a+=1 print(a) ```
90,032
Provide a correct Python 3 solution for this coding contest problem. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 "Correct Solution: ``` while 1: datas = list(map(int, input().split())) if datas[0] == 0: break n, m = datas[0], datas[1] cnt = 0 for i in range(n, m+1): b = i while b % 5 == 0: b //= 5 while b % 3 == 0: b //= 3 while b % 2 == 0: b //= 2 if b == 1: cnt += 1 print(cnt) ```
90,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 Submitted Solution: ``` # AOJ 0162 Hamming Numbers # Python3 2018.6.23 bal4u MAX = 1000000 t = [0]*(MAX+5) a5 = 1 for i in range(9): a3 = 1 for j in range(13): a35 = a5*a3 if a35 > MAX: break a2 = 1 for k in range(20): if a35*a2 > MAX: break t[a35*a2] = 1 a2 <<= 1 a3 *= 3 a5 *= 5 while 1: a = input() if a == '0': break m, n = map(int, a.split()) print(sum(t[m:n+1])) ``` Yes
90,034
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 Submitted Solution: ``` isHamming = [] def judge(): global isHamming; isHamming[1] = True i = 1 while True: if (i * 2 > 1000000): break if (isHamming[i]): isHamming[i * 2] = True i += 1 i = 1 while True: if (i * 3 > 1000000): break if (isHamming[i]): isHamming[i * 3] = True i += 1 i = 1 while True: if (i * 5 > 1000000): break if (isHamming[i]): isHamming[i * 5] = True i += 1 def init(): global isHamming for i in range(1000000 + 1): isHamming.append(False) init() judge() while True: m = [int(num) for num in input().split()] if m == [0]: break; count = 0 for i in range(m[0], m[1] + 1): if (isHamming[i]): count += 1; print(count) ``` Yes
90,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 Submitted Solution: ``` twos = [2 ** i for i in range(21) if 2 ** i <= 1000000] threes = [3 ** i for i in range(21) if 2 ** i <= 1000000] fives = [5 ** i for i in range(21) if 2 ** i <= 1000000] muls = [x * y * z for x in twos for y in threes for z in fives] muls.sort() def under(n): cnt = 0 for i in muls: if i <= n: cnt += 1 else: break return cnt while True: s = input() if s == "0": break m, n = map(int, s.split()) print(under(n) - under(m - 1)) ``` Yes
90,036
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0162 """ import sys from sys import stdin from bisect import bisect_right, bisect_left input = stdin.readline def main(args): hammings = [] temp = set() for i in range(21): for j in range(14): for k in range(9): ans = 2**i * 3**j * 5**k temp.add(ans) hammings = list(temp) hammings.sort() while True: try: m, n = map(int, input().split(' ')) except ValueError: break s = bisect_left(hammings, m) t = bisect_right(hammings, n) print(t - s) if __name__ == '__main__': main(sys.argv[1:]) ``` Yes
90,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers. All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48. Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. For each dataset, two integers m and n (1 ≤ m, n ≤ 1000000, m ≤ n) are given on one line, separated by blanks. The number of datasets does not exceed 20. Output Outputs the number of humming numbers from m to n for each data set on one line. Example Input 3 8 1 27 1 86 0 Output 5 17 31 Submitted Solution: ``` import sys def main(): for line in sys.stdin: mn = list(line) if mn[0] == "0": break else: num = [str(i) for i in range(0, 10)] d = "" for x in range(len(mn)): if mn[x] not in num: dd = x break else: d += mn[x] m = int(d) d = "" for y in range(dd + 1, len(mn) - 1): d += mn[y] n = int(d) a2 = [] for i in range(1, n): hoge = 2 ** i if hoge <= n: a2.append(hoge) else: break a3 = [] for i in range(1, n): hoge = 3 ** i if hoge <= n: a3.append(hoge) else: break a5 = [] for i in range(1, n): hoge = 5 ** i if hoge <= n: a5.append(hoge) else: break a23 = [] for i in range(len(a2)): for j in range(len(a3)): fuga = a2[i] * a3[j] if fuga <= n: a23.append(fuga) else: break a35 = [] for i in range(len(a3)): for j in range(len(a5)): fuga = a3[i] * a5[j] if fuga <= n: a35.append(fuga) else: break a52 = [] for i in range(len(a5)): for j in range(len(a2)): fuga = a5[i] * a2[j] if fuga <= n: a52.append(fuga) else: break a2335 = [] for i in range(len(a23)): for j in range(len(a35)): fuga = a23[i] * a35[j] if fuga <= n: a2335.append(fuga) else: break a3552 = [] for i in range(len(a35)): for j in range(len(a52)): fuga = a35[i] * a52[j] if fuga <= n: a3552.append(fuga) else: break a23353552 = [] for i in range(len(a2335)): for j in range(len(a3552)): fuga = a2335[i] * a3552[j] if fuga <= n: a23353552.append(fuga) else: break a30 = [] i = 1 while 1: fuga = 30 * i if fuga <= n: a30.append(fuga) i += 1 else: break a = a2 + a3 + a5 + a23 + a35 + a52 + a2335 + a3552 +\ a23353552 + a30 if m == 1: a.append(1) else: pass a = sorted(set(a)) for x in range(len(a)): if a[x] >= m: c = x break else: pass cnt = 0 for x in range(c, len(a)): cnt += 1 print(cnt) if __name__ == "__main__": main() ``` No
90,038
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` def main(): number_of_team = int(input()) #チーム数 result_matrix = [list(map(int, input().split())) for l in range(int(number_of_team*(number_of_team-1)/2))] #入力される試合の結果 points_of_team = [0 for l in range(number_of_team)] #勝ち点を保存するリスト #勝ち点の計算 for low in result_matrix: if low[2] == low[3]: points_of_team[int(low[0])-1] += 1 points_of_team[int(low[1])-1] += 1 elif low[2] > low[3]: points_of_team[int(low[0])-1] += 3 else: points_of_team[int(low[1])-1] += 3 sort_list = sorted(points_of_team,reverse=True) result_list = [0 for i in range(number_of_team)]#出力用のリスト rank = 1 pred = sort_list[0] for i in range(number_of_team): max_index = points_of_team.index(sort_list[i]) if pred != sort_list[i]: pred = sort_list[i] rank = i+1 result_list[max_index] = rank points_of_team[max_index] = -1 for i in range(number_of_team): print(result_list[i]) if __name__ == '__main__': main() ```
90,039
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` def f(): from heapq import heappop, heappush N=int(input()) r=[0]*N for _ in[0]*(N*~-N//2): a,b,c,d=map(int,input().split()) r[a-1]+=3*(c>d)+(c==d) r[b-1]+=3*(d>c)+(d==c) b=[[]for _ in[0]*N*3] for i in range(N):b[r[i]]+=[i] pq = [] for i, s in enumerate(r):heappush(pq,[-s,i]) rank=1 display_rank=1 prev_score=float('inf') while pq: s,i=heappop(pq) if s!=prev_score:rank=display_rank r[i]=rank display_rank+=1 prev_score=s print(*r,sep='\n') f() ######################################################################################################################## ##################################################v ################################################################################ ##########v####################v##############################v##########v ```
90,040
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` n = int(input()) score = [list(map(lambda x: int(x) - 1 , input().split())) for _ in range(int(n*(n-1)/2))] points = [0 for _ in range(n)] for a,b,c,d in score: if c > d: points[a] += 3 elif c < d: points[b] += 3 else: points[a] += 1 points[b] += 1 rank = sorted(points, reverse=True) for p in points: print(rank.index(p) + 1) ```
90,041
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` n=int(input());s=[list(map(int,input().split())) for _ in range(int(n*(n-1)/2))];p=[0]*n for a,b,c,d in s: if c>d:p[a-1]+=3 elif c<d:p[b-1]+=3 else:p[a-1]+=1;p[b-1]+=1 r=sorted(p,reverse=True) for q in p:print(r.index(q)+1) ```
90,042
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` # AOJ 0566: Soccer # Python3 2018.6.30 bal4u n = int(input()) m = n*(n-1)>>1 team = [[0 for j in range(3)] for i in range(n)] #[id,win,lost] for i in range(n): team[i][0] = i for i in range(m): a, b, c, d = map(int, input().split()) a, b = a-1, b-1 if c > d: team[a][1] += 3 elif c < d: team[b][1] += 3 else: team[a][1] += 1 team[b][1] += 1 team.sort(key=lambda x:(-x[1],x[0])) team[0][2] = 1 for i in range(1, n): if team[i][1] == team[i-1][1]: team[i][2] = team[i-1][2] else: team[i][2] = i+1 team.sort() for i in range(n): print(team[i][2]) ```
90,043
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` n = int(input()) R = {} for i in range(n): R[i] = 0 for _ in range(n*(n-1)//2): a, b, c, d = map(int, input().split()) if c>d: R[a-1] += 3 elif c==d: R[a-1] += 1 R[b-1] += 1 else: R[b-1] += 3 rank, temp = 1, -1 ranks = [] R = sorted(R.items(), key=lambda x:-x[1]) #print(R) for i in range(len(R)): if temp!=R[i][1]: rank = i+1 ranks.append([R[i][0], i+1]) else: ranks.append([R[i][0], rank]) temp = R[i][1] ranks = sorted(ranks) for i in ranks: print(i[1]) ```
90,044
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` t = int(input()) point_l = [0 for i in range(t)] for i in range(int(t*(t-1)/2)): tmp = [int(x) for x in input().split()] if tmp[2] > tmp[3]: point_l[tmp[0]-1] += 3 elif tmp[3] > tmp[2]: point_l[tmp[1]-1] += 3 elif tmp[2] == tmp[3]: point_l[tmp[0]-1] += 1 point_l[tmp[1]-1] += 1 rank_l = [0 for i in range(t)] rank = 1 for l in sorted(point_l, reverse=True): dup = point_l.count(l) for j in range(dup): rank_l[point_l.index(l)] += rank point_l[point_l.index(l)] = -1 rank += dup for l in rank_l: print(l) ```
90,045
Provide a correct Python 3 solution for this coding contest problem. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 "Correct Solution: ``` n=int(input());p=[0]*n for i in range(n*(n-1)//2): a,b,c,d=map(int,input().split()) if c>d:p[a-1]+=3 elif c<d:p[b-1]+=3 else:p[a-1]+=1;p[b-1]+=1 r=sorted(p,reverse=True) for q in p:print(r.index(q)+1) ```
90,046
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0566 """ import sys from sys import stdin from heapq import heappop, heappush input = stdin.readline def main(args): N = int(input()) scores = [0] * (N+1) scores[0] = -1 results = [-1] * (N+1) for _ in range(N*(N-1)//2): a, b, c, d = [int(x) for x in input().split()] if c > d: scores[a] += 3 elif c < d: scores[b] += 3 else: scores[a] += 1 scores[b] += 1 pq = [] for i, s in enumerate(scores[1:], start=1): heappush(pq, [-s, i]) rank = 1 display_rank = 1 prev_score = float('inf') while pq: s, i = heappop(pq) if s == prev_score: results[i] = rank else: rank = display_rank results[i] = rank display_rank += 1 prev_score = s for r in results[1:]: print(r) if __name__ == '__main__': main(sys.argv[1:]) ``` Yes
90,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 Submitted Solution: ``` n = int(input()) point = [0] * n for i in range(n * (n - 1) // 2): A, B, X, Y = map(int, input().split()) if X > Y: point[A - 1] += 3 elif Y > X: point[B - 1] += 3 else: point[A - 1] += 1 point[B - 1] += 1 point_sorted = sorted(point, reverse=True) for i in range(n): print(point_sorted.index(point[i]) + 1) ``` Yes
90,048
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 Submitted Solution: ``` def f(): from heapq import heappop, heappush N=int(input()) r=[0]*N for _ in[0]*(N*~-N//2): a,b,c,d=map(int,input().split()) r[a-1]+=3*(c>d)+(c==d) r[b-1]+=3*(d>c)+(d==c) b=[[]for _ in[0]*N*3] for i in range(N):b[r[i]]+=[i] pq = [] for i, s in enumerate(r):heappush(pq,[-s,i]) rank=1 display_rank=1 prev_score=float('inf') while pq: s,i=heappop(pq) if s!=prev_score:rank=display_rank r[i]=rank display_rank+=1 prev_score=s print(*r,sep='\n') f() ``` Yes
90,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 Submitted Solution: ``` #B N = int(input()) ABCD = [list(map(int,input().split())) for i in range(N*(N-1)//2)] point = [[0,i] for i in range(N)] for abcd in ABCD: a,b,c,d = abcd if c > d: point[a-1][0]+=3 elif c < d: point[b-1][0]+=3 else: point[a-1][0]+=1 point[b-1][0]+=1 rank = [0]*N point.sort(reverse=True) mae = 0 now = 0 for i in range(N): p = point[i][0] ind = point[i][1] if p != mae: mae = p now = i rank[ind] = now+1 else: rank[ind] = now+1 for r in rank: print(r) ``` Yes
90,050
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 Submitted Solution: ``` def f(): N=int(input()) s=[0]*N for _ in[0]*(N*~-N//2): a,b,c,d=map(int,input().split()) s[a-1]+=3*(c>d)+(c==d) s[b-1]+=3*(d>c)+(d==c) b=[[]for _ in[0]*N*3] for i in range(N):b[s[i]]+=[i] r=1 for x in b[::-1]: for y in x:s[y]=r;r+=1 print(*s,sep='\n') f() ``` No
90,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem Soccer is popular in JOI, and a league match called the JOI League is held every week. There are N teams in the JOI league, numbered from 1 to N. All combinations of matches are played exactly once. In other words, N × (N -1) / 2 games are played. The outcome of each match is determined by the score of each team. The winning team has 3 points and the losing team has 0 points. In the case of a draw, both teams have one point. The ranking is determined by the total points earned by each team, and the difference in points is not considered. Teams with the same total points will be ranked higher. As an example, consider a league match with four teams. 4 × (4-1) / 2 = 6 Matches will be played. Suppose those results are as shown in the table below. The left side of the hyphen is the score of the team next to it, and the right side is the score of the team vertically. Team 1 | Team 2 | Team 3 | Team 4 | Wins | Loss | Draws | Points --- | --- | --- | --- | --- | --- | --- | --- | --- Team 1 | --- | 0 --1 | 2 --1 | 2 --2 | 1 | 1 | 1 | 4 Team 2 | 1 --0 | --- | 1 --1 | 3 --0 | 2 | 0 | 1 | 7 Team 3 | 1 --2 | 1 --1 | --- | 1 --3 | 0 | 2 | 1 | 1 Team 4 | 2 --2 | 0 --3 | 3 --1 | --- | 1 | 1 | 1 | 4 At this time, Team 2 with the most points is in first place. The teams with the next most points are Team 1 and Team 4, and both teams are in second place. Team 3 with the fewest points is in 4th place. Create a program to find the ranking of each team given the results of all matches. input The number of teams N (2 ≤ N ≤ 100) is written on the first line of the input file. The following N × (N -1) / 2 lines describe the results of each match. The integers Ai, Bi, Ci, Di (1 ≤ Ai ≤ N, 1 ≤ Bi ≤ N, 0 ≤ Ci ≤ 100, 0) are in the first line (1 ≤ i ≤ N x (N-1) / 2). ≤ Di ≤ 100) is written with a blank as a delimiter, indicating that Team Ai and Team Bi played against each other, and Team Ai scored Ci points and Team Bi scored Di points. Ai ≠ Bi for all i, and the same combination of matches is never written. output The output consists of N lines. Each row consists of one integer, and the integer on the i-th row (1 ≤ i ≤ N) represents the rank of team i. Input / output example Input example 1 Four 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output example 1 2 1 Four 2 Input / output example 1 corresponds to the example in the problem statement. Input example 2 Five 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 Output example 2 2 Four 1 Four 3 The results of input / output example 2 are as follows. | Wins | Loss | Draws | Points --- | --- | --- | --- | --- Team 1 | 2 | 1 | 1 | 7 Team 2 | 0 | 1 | 3 | 3 Team 3 | 3 | 0 | 1 | 10 Team 4 | 1 | 3 | 0 | 3 Team 5 | 1 | 2 | 1 | 4 The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics. Example Input 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 Output 2 1 4 2 Submitted Solution: ``` t = int(input()) point_l = [0 for i in range(t)] for i in range((t*(t-1))/2): input_line = input() tmp = [int(x) for x in input_line.rstrip().split(' ')] if tmp[2] > tmp[3]: point_l[tmp[0]-1] += 3 elif tmp[3] > tmp[2]: point_l[tmp[1]-1] += 3 elif tmp[2] == tmp[3]: point_l[tmp[0]-1] += 1 point_l[tmp[1]-1] += 1 rank_l = [0 for i in range(t)] rank = 1 for l in sorted(point_l, reverse=True): dup = point_l.count(l) for j in range(dup): rank_l[point_l.index(l)] += rank point_l[point_l.index(l)] = -1 rank += dup for l in rank_l: print(l) ``` No
90,052
Provide a correct Python 3 solution for this coding contest problem. Example Input anagram grandmother Output 4 "Correct Solution: ``` s1 = input() s2 = input() cA = ord('a') s1 = [ord(e) - cA for e in s1] l1 = len(s1) s2 = [ord(e) - cA for e in s2] l2 = len(s2) ans = 0 for l in range(1, min(l1, l2)+1): s = set() use = [0]*26 for i in range(l-1): use[s1[i]] += 1 for i in range(l-1, l1): use[s1[i]] += 1 s.add(tuple(use)) use[s1[i-l+1]] -= 1 cnt = [0]*26 for i in range(l-1): cnt[s2[i]] += 1 for i in range(l-1, l2): cnt[s2[i]] += 1 if tuple(cnt) in s: ans = l break cnt[s2[i-l+1]] -= 1 print(ans) ```
90,053
Provide a correct Python 3 solution for this coding contest problem. Example Input anagram grandmother Output 4 "Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): mod2 = 10**9+9 sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] r = 0 for si in range(2): s = sa[si] a = [0] a2 = [0] b = [set() for _ in range(ml)] b2 = [set() for _ in range(ml)] for c in s: k = 97 ** (ord(c) - ord('a')) a.append((a[-1] + k) % mod) a2.append((a2[-1] + k) % mod2) if si == 1: for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break if j - i <= r: continue if (a[j]-a[i]) % mod in ss[0][j-i-1] and (a2[j]-a2[i]) % mod2 in ss[1][j-i-1]: r = j-i else: for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add((a[j]-a[i]) % mod) b2[j-i-1].add((a2[j]-a2[i]) % mod2) ss = [b,b2] return r print(main()) ```
90,054
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] for s in sa: a = [[0] * 26] b = [set() for _ in range(ml)] for c in s: t = a[-1][:] t[ord(c) - ord('a')] += 1 a.append(t) for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add(tuple(map(lambda x: a[j][x]-a[i][x], range(26)))) ss.append(b) for i in range(ml-1,-1,-1): if ss[0][i] & ss[1][i]: return i + 1; return 0 print(main()) ``` No
90,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` print(4) ``` No
90,056
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): mod2 = 10**9+9 sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] for s in sa: a = [0] a2 = [0] b = [set() for _ in range(ml)] b2 = [set() for _ in range(ml)] for c in s: k = 97 ** (ord(c) - ord('a')) a.append((a[-1] + k) % mod) a2.append((a2[-1] + k) % mod2) for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add((a[j]-a[i]) % mod) b2[j-i-1].add((a2[j]-a2[i]) % mod2) ss.append([b,b2]) for i in range(ml-1,-1,-1): if ss[0][0][i] & ss[1][0][i] and ss[0][1][i] & ss[1][1][i]: return i + 1; return 0 print(main()) ``` No
90,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Example Input anagram grandmother Output 4 Submitted Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): mod2 = 10**9+9 sa = [S() for _ in range(2)] ml = min(map(len, sa)) ss = [] for s in sa: a = [0] a2 = [0] b = [set() for _ in range(ml)] b2 = [set() for _ in range(ml)] for c in s: k = 97 ** (ord(c) - ord('a')) a.append((a[-1] + k) % mod) a2.append((a2[-1] + k) % mod2) for i in range(len(a)): for j in range(i+1,len(a)): if j - i > ml: break b[j-i-1].add(a[j]-a[i]) b2[j-i-1].add(a2[j]-a2[i]) ss.append([b,b2]) for i in range(ml-1,-1,-1): if ss[0][0][i] & ss[1][0][i] and ss[0][1][i] & ss[1][1][i]: return i + 1; return 0 print(main()) ``` No
90,058
Provide a correct Python 3 solution for this coding contest problem. There are n rabbits, one in each of the huts numbered 0 through n − 1. At one point, information came to the rabbits that a secret organization would be constructing an underground passage. The underground passage would allow the rabbits to visit other rabbits' huts. I'm happy. The passages can go in both directions, and the passages do not intersect. Due to various circumstances, the passage once constructed may be destroyed. The construction and destruction of the passages are carried out one by one, and each construction It is assumed that the rabbit stays in his hut. Rabbits want to know in advance if one rabbit and one rabbit can play at some stage of construction. Rabbits are good friends, so they are free to go through other rabbit huts when they go out to play. Rabbits who like programming tried to solve a similar problem in the past, thinking that it would be easy, but they couldn't write an efficient program. Solve this problem instead of the rabbit. Input The first line of input is given n and k separated by spaces. 2 ≤ n ≤ 40 000, 1 ≤ k ≤ 40 000 In the following k lines, construction information and questions are combined and given in chronological order. * “1 u v” — A passage connecting huts u and v is constructed. Appears only when there is no passage connecting huts u and v. * “2 u v” — The passage connecting huts u and v is destroyed. Appears only when there is a passage connecting huts u and v. * “3 u v” — Determine if the rabbits in the hut u and v can be played. 0 ≤ u <v <n Output For each question that appears in the input, output "YES" if you can play, or "NO" if not. Example Input 4 10 1 0 1 1 0 2 3 1 2 2 0 1 1 2 3 3 0 1 1 0 1 2 0 2 1 1 3 3 0 2 Output YES NO YES "Correct Solution: ``` from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, K = map(int, readline().split()) ES = [list(map(int, readline().split())) for i in range(K)] emp = {} sq = int(K**.5) + 1 def root(x): if x == p[x]: return x p[x] = y = root(p[x]) return y def unite(x, y): px = root(x); py = root(y) if px < py: p[py] = px else: p[px] = py que = deque() used = [0]*N lb = 0 p = [0]*N for i in range(sq): s = set() for j in range(i*sq, min(i*sq+sq, K)): t, a, b = ES[j] if t == 3: continue e = (a, b) if emp.get(e, 0): s.add(e) emp[e] = 0 p[:] = range(N) for (v, w), d in emp.items(): if d == 1: unite(v, w) G0 = [[] for i in range(N)] emp0 = {} for a, b in s: pa = root(a); pb = root(b) if pa == pb: continue e = (pa, pb) if pa < pb else (pb, pa) if e in emp0: e1, e2 = emp0[e] e1[1] = e2[1] = e1[1] + 1 else: e1 = [pb, 1]; e2 = [pa, 1] G0[pa].append(e1) G0[pb].append(e2) emp0[e] = e1, e2 for j in range(i*sq, min(i*sq+sq, K)): t, a, b = ES[j] pa = root(a); pb = root(b) e = (pa, pb) if pa < pb else (pb, pa) if t == 1: emp[a, b] = 1 if pa == pb: continue if e not in emp0: e1 = [pb, 1]; e2 = [pa, 1] G0[pa].append(e1) G0[pb].append(e2) emp0[e] = e1, e2 else: e1, e2 = emp0[e] e1[1] = e2[1] = e1[1] + 1 elif t == 2: emp[a, b] = 0 if pa == pb: continue e1, e2 = emp0[e] e1[1] = e2[1] = e1[1] - 1 elif t == 3: if pa == pb: write("YES\n") else: lb += 1 que.append(pa) used[pa] = lb while que: v = que.popleft() for w, d in G0[v]: if d and used[w] != lb: used[w] = lb que.append(w) if used[pb] == lb: write("YES\n") else: write("NO\n") solve() ```
90,059
Provide a correct Python 3 solution for this coding contest problem. D: Anipero 2012 Anipero Summer Live, commonly known as Anipero, is the largest anime song live event in Japan where various anime song artists gather. 2D, who loves anime songs, decided to go to Anipero this year as well as last year. He has already purchased m of psyllium to enjoy Anipero. Psyllium is a stick that glows in a chemical reaction when folded. By shaking the psyllium in time with the rhythm, you can liven up the live performance and increase your satisfaction. All the psylliums he purchased this time have the following properties. * The psyllium becomes darker as time passes after it is folded, and loses its light in 10 minutes. * Very bright for 5 minutes after folding (hereinafter referred to as "level 2"). * It will be a little dark 5 minutes after folding (hereinafter referred to as "level 1"). * The speed at which light is lost does not change whether it is shaken or not. 2D decided to consider the following problems as to how satisfied he would be with this year's Anipero by properly using the limited psyllium depending on the song. He anticipates n songs that will be played during the live. The length of each song is 5 minutes. n songs continue to flow, and the interval between songs can be considered as 0 minutes. The following three parameters are given to each song. * Satisfaction that increases when only one level 2 is shaken for a certain song * Satisfaction that increases when only one level 1 is shaken for a certain song * Satisfaction increases when no song is shaken in a certain song Shaking the glow stick does not necessarily increase satisfaction. If you shake it, it may disturb the atmosphere of the venue and reduce your satisfaction. The same can be said when not shaking. Psyllium must be used according to the following rules. * You can fold only when the song starts, and you can fold as many as you like at one time. The time it takes to fold the psyllium can be ignored. * Up to 8 songs can be played at the same time in one song. * When shaking multiple psylliums, calculate the satisfaction level to be added by the following formula. * (Number of Level 1) x (Satisfaction per level 1) + (Number of Level 2) x (Satisfaction per Level 2) * If no psyllium is shaken, only the satisfaction level when no one is shaken is added. * Once you decide to shake the psyllium, you cannot change it until the end of one song. * The psyllium can be left unshaken. Also, it is not necessary to use up all the psyllium. 2D had finished predicting the live song, but he was tired of it and didn't feel like solving the problem. Your job is to write a program for him that seeks the maximum satisfaction you're likely to get at this year's live concert. Input Satisfaction information for the expected song list of the live is input. On the first line, the number of songs n (1 <= n <= 50) sung live and the number m (0 <= m <= 50) of new psyllium that 2D has at the start of the live are separated by spaces. Is entered in. In the following n lines, the information of one song is input line by line. The i-th (1 <= i <= n) song information is * Satisfaction level when one level 2 psyllium is shaken for song i ai * Satisfaction level bi when swinging one level 1 psyllium for song i * Satisfaction ci when no psyllium is shaken in song i Are entered separated by spaces (-100 <= ai, bi, ci <= 100). Output Output the prediction of 2D's maximum satisfaction at the end of the live in one line. Please note that the maximum satisfaction level may be negative. Output a line break at the end of the line. Sample Input 1 1 5 2 3 8 Sample Output 1 Ten Sample Input 2 2 10 2 2 20 2 3 -10 Sample Output 2 44 Sample Input 3 3 10 5 1 9 -3 2 1 1 11 0 Sample Output 3 102 Example Input 1 5 2 3 8 Output 10 "Correct Solution: ``` INF = 10 ** 20 n, m = map(int, input().split()) dp = [[[-INF] * 9 for _ in range(m + 1)] for _ in range(n + 1)] dp[0][m][0] = 0 for i in range(n): a, b, c = map(int, input().split()) for rest in range(m + 1): for l1 in range(9): for l2 in range(min(9, rest + 1)): if l1 == 0 and l2 == 0:add = c elif l2 == 0: if b <= 0:add = max(b, c) else:add = max(b * l1, c) elif l1 == 0: if a <= 0:add = max(a, c) else:add = max(a * l2, c) else: if a <= 0 and b <= 0:add = max(a, b, c) elif a <= 0:add = max(b * l1, c) elif b <= 0:add = max(a * l2, c) elif a <= b:add = max(b * l1 + a * min(l2, 8 - l1), c) else:add = max(a * l2 + b * min(l1, 8 - l2), c) dp[i + 1][rest - l2][l2] = max(dp[i + 1][rest - l2][l2], dp[i][rest][l1] + add) ans = -INF for y in range(m + 1): for x in range(9): ans = max(ans, dp[n][y][x]) print(ans) ```
90,060
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. C: AA グラフ (AA Graph) Problem Given a graph as an ASCII Art (AA), please print the length of shortest paths from the vertex s to the vertex t. The AA of the graph satisfies the following constraints. A vertex is represented by an uppercase alphabet and symbols `o` in 8 neighbors as follows. ooo oAo ooo Horizontal edges and vertical edges are represented by symbols `-` and `|`, respectively. Lengths of all edges are 1, that is, it do not depends on the number of continuous symbols `-` or `|`. All edges do not cross each other, and all vertices do not overlap and touch each other. For each vertex, outgoing edges are at most 1 for each directions top, bottom, left, and right. Each edge is connected to a symbol `o` that is adjacent to an uppercase alphabet in 4 neighbors as follows. ..|.. .ooo. -oAo- .ooo. ..|.. Therefore, for example, following inputs are not given. .......... .ooo..ooo. .oAo..oBo. .ooo--ooo. .......... (Edges do not satisfies the constraint about their position.) oooooo oAooBo oooooo (Two vertices are adjacent each other.) Input Format H W s t a_1 $\vdots$ a_H * In line 1, two integers H and W, and two characters s and t are given. H and W is the width and height of the AA, respectively. s and t is the start and end vertices, respectively. They are given in separating by en spaces. * In line 1 + i where 1 \leq i \leq H, the string representing line i of the AA is given. Constraints * 3 \leq H, W \leq 50 * s and t are selected by uppercase alphabets from `A` to `Z`, and s \neq t. * a_i (1 \leq i \leq H) consists of uppercase alphabets and symbols `o`, `-`, `|`, and `.`. * Each uppercase alphabet occurs at most once in the AA. * It is guaranteed that there are two vertices representing s and t. * The AA represents a connected graph. Output Format Print the length of the shortest paths from s to t in one line. Example 1 14 16 A L ooo.....ooo..... oAo-----oHo..... ooo.....ooo..ooo .|.......|...oLo ooo..ooo.|...ooo oKo--oYo.|....|. ooo..ooo.|....|. .|....|.ooo...|. .|....|.oGo...|. .|....|.ooo...|. .|....|.......|. ooo..ooo.....ooo oFo--oXo-----oEo ooo..ooo.....ooo Output 1 5 Exapmple 2 21 17 F L ................. .....ooo.....ooo. .....oAo-----oBo. .....ooo.....ooo. ......|.......|.. .ooo..|..ooo..|.. .oCo..|..oDo.ooo. .ooo.ooo.ooo.oEo. ..|..oFo..|..ooo. ..|..ooo..|...|.. ..|...|...|...|.. ..|...|...|...|.. ..|...|...|...|.. .ooo.ooo.ooo..|.. .oGo-oHo-oIo..|.. .ooo.ooo.ooo..|.. ..|...........|.. .ooo...ooo...ooo. .oJo---oKo---oLo. .ooo...ooo...ooo. ................. Output 2 4 Example Input Output Submitted Solution: ``` #include <bits/stdc++.h> int alf_to_num(char c) { return (int)c - (int)'A'; } int main() { int H, W, i, j, k, nowv; char s, t; scanf("%d %d %c %c", &H, &W, &s, &t); char **a = (char **)malloc(sizeof(char *) * (H + 2)); for (i = 0; i <= H + 1; i++) { a[i] = (char *)malloc(sizeof(char) * (W + 2)); if (i == 0 || i == H + 1) { for (j = 0; j <= W + 1; j++) { a[i][j] = '.'; } } else { a[i][0] = '.'; scanf("%s", &a[i][1]); a[i][W + 1] = '.'; } } int **dis = (int **)malloc(sizeof(int *) * 26); for (i = 0; i < 26; i++) { dis[i] = (int *)malloc(sizeof(int) * 26); for (j = 0; j < 26; j++) { dis[i][j] = (int)(1e8); } } for (i = 0; i <= H + 1; i++) { for (j = 0; j <= W + 1; j++) { nowv = alf_to_num(a[i][j]); if (0 <= nowv && nowv < 26) { if (a[i - 2][j] == '|') { for (k = 2;; k++) { if (a[i - k][j] == 'o') { dis[nowv][alf_to_num(a[i - k - 1][j])] = 1; dis[alf_to_num(a[i - k - 1][j])][nowv] = 1; break; } else { a[i - k][j] = '.'; } } } if (a[i + 2][j] == '|') { for (k = 2;; k++) { if (a[i + k][j] == 'o') { dis[nowv][alf_to_num(a[i + k + 1][j])] = 1; dis[alf_to_num(a[i + k + 1][j])][nowv] = 1; break; } else { a[i + k][j] = '.'; } } } if (a[i][j - 2] == '-') { for (k = 2;; k++) { if (a[i][j - k] == 'o') { dis[nowv][alf_to_num(a[i][j - k - 1])] = 1; dis[alf_to_num(a[i][j - k - 1])][nowv] = 1; break; } else { a[i][j - k] = '.'; } } } if (a[i][j + 2] == '-') { for (k = 2;; k++) { if (a[i][j + k] == 'o') { dis[nowv][alf_to_num(a[i][j + k + 1])] = 1; dis[alf_to_num(a[i][j + k + 1])][nowv] = 1; break; } else { a[i][j + k] = '.'; } } } } } } for (k = 0; k < 26; k++) { for (i = 0; i < 26; i++) { for (j = 0; j < 26; j++) { if (dis[i][j] > dis[i][k] + dis[k][j]) { dis[i][j] = dis[i][k] + dis[k][j]; } } } } printf("%d\n", dis[alf_to_num(s)][alf_to_num(t)]); return 0; } ``` No
90,061
Provide a correct Python 3 solution for this coding contest problem. Problem Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even. Constraints The input satisfies the following conditions. * 1 ≤ n ≤ 1018 Input The input is given in the following format. n Output Output the minimum m such that nCm is an even number on one line. Examples Input 2 Output 1 Input 111 Output 16 Input 3 Output 4 "Correct Solution: ``` n = int(input()) print((n+1) &- (n+1)) ```
90,062
Provide a correct Python 3 solution for this coding contest problem. Problem Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even. Constraints The input satisfies the following conditions. * 1 ≤ n ≤ 1018 Input The input is given in the following format. n Output Output the minimum m such that nCm is an even number on one line. Examples Input 2 Output 1 Input 111 Output 16 Input 3 Output 4 "Correct Solution: ``` n=int(input())+1;print(n&-~~n) ```
90,063
Provide a correct Python 3 solution for this coding contest problem. Problem Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even. Constraints The input satisfies the following conditions. * 1 ≤ n ≤ 1018 Input The input is given in the following format. n Output Output the minimum m such that nCm is an even number on one line. Examples Input 2 Output 1 Input 111 Output 16 Input 3 Output 4 "Correct Solution: ``` n = int(input()) + 1 print(n &- n) ```
90,064
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem Given the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even. Constraints The input satisfies the following conditions. * 1 ≤ n ≤ 1018 Input The input is given in the following format. n Output Output the minimum m such that nCm is an even number on one line. Examples Input 2 Output 1 Input 111 Output 16 Input 3 Output 4 Submitted Solution: ``` def nCm(n, k): C = [1] + [0 for i in range(1, k+1)] for i in range(1, n+1): j = min(i, k) while j > 0: C[j] += C[j-1] j -= 1 return C[k] n = int(input()) k = 1 while nCm(n, k) % 2: k += 1 print(k) ``` No
90,065
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` A = list(map(int,input().split())) a=A[0] b=A[1] while b: a,b=b,a%b print(a) ```
90,066
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` # 76 import math x,y = (int(x) for x in input().split()) print(math.gcd(x, y)) ```
90,067
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` X, Y = map(int, input().split()) x = min(X, Y) y = max(X, Y) while x > 0: r = y % x y = x x = r print(y) ```
90,068
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` x, y = map(int, input().split()) if x < y: x, y = y, x while y > 0: x, y = y, (x%y) print(x) ```
90,069
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` import math line=input().split() x=int(line[0]) y=int(line[1]) print(math.gcd(x,y)) ```
90,070
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` a, b = map(int, input().split()) if a <= b: a, b = b, a while a % b != 0: a, b = b, a % b print(b) ```
90,071
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` a,b = map(int,input().split()) if a < b: a,b = b,a while b != 0: c = a % b a,b = b,c print(a) ```
90,072
Provide a correct Python 3 solution for this coding contest problem. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 "Correct Solution: ``` x, y = map(int, input(). split()) while True: if x % y == 0: break tmp = x % y x = y y = tmp print(y) ```
90,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` import math x,y = map(int,input().split()) ans = math.gcd(x,y) print(ans) ``` Yes
90,074
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` # coding: utf-8 # Your code here! import math a, b = map(int,input().split()) print(math.gcd(a,b)) ``` Yes
90,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` L=input().split( ) x=int(L[0]) y=int(L[1]) if x<y: w=x x=y y=w while x%y!=0: w=y y=x%y x=w print(y) ``` Yes
90,076
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` x,y = map(int,input().split()) while x%y != 0: x,y = y,x%y print(y) ``` Yes
90,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` x, y = map(int,input().split()) while True if x >= y: x %= y else y %= x if x == y: print(x) break ``` No
90,078
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` def gcd(x_y): tmp = list(map(int, x_y.split())) x = tmp[0] y = tmp[1] xcd = set([ n for n in range(1, x+1) if x % n == 0]) # xの約数 ycd = set([ n for n in range(1, y+1) if y % n == 0]) # yの約数 cd = list(xcd & ycd) # xとyの公約数 return max(cd) # xとyの最大公約数 x_y = input() print(gcd(x_y)) ``` No
90,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` def gc(x, y): while y > 0: x %= y x, y = y, x return x a = int(input()) b = int(input()) print(gc(a,b)) ``` No
90,080
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which finds the greatest common divisor of two natural numbers a and b Hint You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Constrants 1 ≤ a, b ≤ 109 Input a and b are given in a line sparated by a single space. Output Output the greatest common divisor of a and b. Examples Input 54 20 Output 2 Input 147 105 Output 21 Submitted Solution: ``` x,y=map(int,input().split()) while x%y!=0: tmp=y y=x%y x=tmp print(y,end='') ``` No
90,081
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True: h,w = map(int, input().split()) if (w + h) == 0: break print("#"*w) for i in range(h-2): print("#"+"."*(w-2)+"#") print("#"*w) print("") ```
90,082
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True: y,x = map(int,input().split()) if y == 0 and x == 0: break print("#"*x) for j in range(y-2): print("#"+"."*(x-2)+"#") print("#"*x) print() ```
90,083
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True: h, w = map(int, input().split()) if(h==0): break print('#'*w) [print('#'+'.'*(w-2)+'#') for i in range(h-2)] print('#'*w) print() ```
90,084
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True: H,W = map(int,input().split()) if H==0 and W==0: break print("#"*W) for i in range(H-2): print("#","."*(W-2),"#",sep='') print("#"*W) print() ```
90,085
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` for i in range(100000): h,w = map(int,input().split(" ")) if h + w == 0: break print("#"*w) for j in range(h-2): print("#" + "."*(w-2) + "#") print("#"*w) print("") ```
90,086
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True : H,W=map(int,input().split()) if H==0 and W==0 : break print("#"*W) for i in range (H-2): print("{}{}{}".format("#",(".")*(W-2),"#")) print("#"*W) print() ```
90,087
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True: H,W = map(int,input().split(' ')) if not(H or W):break print('#'*W) for h in range(H-2): print(f'#{"."*(W-2)}#') print('#'*W) print() ```
90,088
Provide a correct Python 3 solution for this coding contest problem. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### "Correct Solution: ``` while True: h, w = [int(i) for i in input().split()] if w == h == 0: break print("#" * w, end="") print(("\n#" + "." * (w - 2) + "#") * (h - 2)) print("#" * w, end="\n\n") ```
90,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while True: H,W = map(int,input().split()) if H==W==0: break; print("#"*W) for i in range(0,H-2): print("#"+"."*(W-2)+"#") print("#"*W) print() ``` Yes
90,090
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while(1): h,w = [int(i) for i in input().split()] if h == 0 and w == 0: break print("#"*w) for i in range(h-2): print("#"+"."*(w-2)+"#") print("#"*w) print("") ``` Yes
90,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while True: h, w = map(int, input().split()) if h == w == 0: break print('#' * w) for _ in range(h - 2): print('#' + '.'*(w-2) + '#') print('#' * w) print() ``` Yes
90,092
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while True: h, w = map(int, input().strip().split()) if h == w == 0: break print('#'*w) for i in range(h - 2): print('#'+'.'*(w-2)+'#') print('#'*w) print() ``` Yes
90,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while True: a,b=map(int,input().split()) if a==0 and b==0:break f=[[0 for i in range(a)]for j in range(b)] for i in range(a): for j in range(b): if i==0 or i==a-1 or j==0 or j==b-1: f[i][j]=1 for i in range(a): for j in range(b): if f[i][j]==1: print('#') else : print('.') print() print() ``` No
90,094
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while True: H, W = [int(x) for x in input().split(" ")] if H == W == 0: break for i in range(H): if i == 0 or i == (H - 1): print("#" * W) else: print("#" + "." * (W - 2) + "#") print("\n") ``` No
90,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` while True: a,b = map(int, input().split()) if a ==0 and b == 0: break for i in range(a): if i ==0 or i == (a-1): print("#", end = "") print("#"*(a-2), end = "") print("#") else: print("#"*b, end = "") print() print() ``` No
90,096
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ........# ........# ........# ........# Constraints * 3 ≤ H ≤ 300 * 3 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Example Input 3 4 5 6 3 3 0 0 Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ### Submitted Solution: ``` h,w = map(int,input().split()) print('#'*w) print(('#' + '.'*(w-2) + '#\n')*(h-2),end ='') print('#'*w + '\n') ``` No
90,097
Provide tags and a correct Python 3 solution for this coding contest problem. Tanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total cost is k burles. How many ways to do that does she have? Each toy appears in the shop exactly once. Pairs (a, b) and (b, a) are considered equal. Pairs (a, b), where a=b, are not allowed. Input The first line of the input contains two integers n, k (1 ≤ n, k ≤ 10^{14}) — the number of toys and the expected total cost of the pair of toys. Output Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is k burles. Examples Input 8 5 Output 2 Input 8 15 Output 1 Input 7 20 Output 0 Input 1000000000000 1000000000001 Output 500000000000 Note In the first example Tanechka can choose the pair of toys (1, 4) or the pair of toys (2, 3). In the second example Tanechka can choose only the pair of toys (7, 8). In the third example choosing any pair of toys will lead to the total cost less than 20. So the answer is 0. In the fourth example she can choose the following pairs: (1, 1000000000000), (2, 999999999999), (3, 999999999998), ..., (500000000000, 500000000001). The number of such pairs is exactly 500000000000. Tags: math Correct Solution: ``` """ def Find(naj, mesto, dl): if naj >= 2: dl += 1 Find(naj-2, mesto, dl) if naj >= 3: dl += 1 Find(naj-3, mesto, dl) if naj >= 4 and len(mesto) == 4: dl += 1 Find(naj-4, mesto, dl) dl += 1 Find(naj-4, mesto, dl) global perem, kolvo if str(dl) in perem: kolvo[perem.index(str(dl))] += 1 else: perem.append(str(dl)) kolvo.append(1) dlina = int(input()) sms = str(input()) KLAVA = ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ'] najatiya = [] for i in sms: for f in range(len(KLAVA)): if i in KLAVA[f]: kek = KLAVA[f].index(i)+1 if KLAVA[f].index(i)+1 <= 3: kek += 1 najatiya.append([kek, KLAVA[f]]) #print(najatiya) k = [] k.append(najatiya[0]) for i in range(1, len(najatiya)): if najatiya[i][1] == k[len(k)-1][1]: k[len(k)-1][0]+=najatiya[i][0] else: k.append(najatiya[i]) print(k) gotovo = [] for i in range(len(k)): perem = [] kolvo = [] Find(k[i][0], k[i][1], 0) gotovo.append([perem, kolvo]) #Даю ему кол-во нажатий и кнопку нажатия, #записываю длину сообщения, #записываю в массив длины сообщений, #набранных на одной кнопке и количество #одинаковых длин #решаю задачу цифры проходя по массиву длин #собираю количество возможных комбинаций #вывожу print(gotovo) def NaytiChisla(stroka): kek = "" chislo = [] koef = 1 for i in range(len(stroka)): if stroka[i] == '-': koef = -1 if stroka[i] == '0' or stroka[i] == '1' or stroka[i] == '2' or stroka[i] == '3' or stroka[i] == '4' or stroka[i] == '5' or stroka[i] == '6' or stroka[i] == '7' or stroka[i] == '8' or stroka[i] == '9': kek+=stroka[i] if stroka[i] == ' ': chislo.append(int(kek)*koef) koef = 1 kek = "" chislo.append(int(kek)*koef) koef = 1 return chislo su = int(input()) coins = NaytiChisla(str(input())) su = int(input()) min = 10000000 mass = [] mass.append(0) for i in range(su): lol = [] for f in coins: if len(mass)-f-1 > 0 and len(mass)-f < len(mass)-1: lol.append(mass[len(mass)-f-1]) try: kek = sorted(lol)[0] except: kek = 1000000 mass.append(kek) print(mass) """ def Kek(): n, m = map(int, input().split()) if n > m: i = 1 f = m-1 #print(f, i, f-i) print(int((f-i+1)/2)) else: if m <= 2*n: i = m-n f = n if i == 0: i = 2 #print(f, i, f - i) print(int((f-i+1)/2)) else: print(0) return return Kek() ```
90,098
Provide tags and a correct Python 3 solution for this coding contest problem. Tanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total cost is k burles. How many ways to do that does she have? Each toy appears in the shop exactly once. Pairs (a, b) and (b, a) are considered equal. Pairs (a, b), where a=b, are not allowed. Input The first line of the input contains two integers n, k (1 ≤ n, k ≤ 10^{14}) — the number of toys and the expected total cost of the pair of toys. Output Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is k burles. Examples Input 8 5 Output 2 Input 8 15 Output 1 Input 7 20 Output 0 Input 1000000000000 1000000000001 Output 500000000000 Note In the first example Tanechka can choose the pair of toys (1, 4) or the pair of toys (2, 3). In the second example Tanechka can choose only the pair of toys (7, 8). In the third example choosing any pair of toys will lead to the total cost less than 20. So the answer is 0. In the fourth example she can choose the following pairs: (1, 1000000000000), (2, 999999999999), (3, 999999999998), ..., (500000000000, 500000000001). The number of such pairs is exactly 500000000000. Tags: math Correct Solution: ``` n,k=map(int,input().split()) print(max(min(n-k//2,(k-1)//2),0)) ```
90,099