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. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` from itertools import accumulate def solve(n, rev): def existence_right(rev_c): n2 = n * 2 acc = [[0] * n2] row = [0] * n2 for x in rev_c: row[n2 - x - 1] += 1 acc.append(list(reversed(list(accumulate(row))))) return acc # How many white/black ball lower than 'k' righter than index x? (0<=x<=2N-1) # cost[color][k][x] cost = list(map(existence_right, rev)) dp = [[0] * (n + 1) for _ in range(n + 1)] for w, x in enumerate(rev[0]): dp[w + 1][0] = dp[w][0] + cost[0][w][x] for b, y in enumerate(rev[1]): dp[0][b + 1] = dp[0][b] + cost[1][b][y] for w, x in enumerate(rev[0]): dpw0, dpw1 = dp[w], dp[w + 1] cost_wx, cost_w1 = cost[0][w][x], cost[0][w + 1] for b, y in enumerate(rev[1]): dpw1[b + 1] = min(dpw0[b + 1] + cost_wx + cost[1][b + 1][x], dpw1[b] + cost_w1[y] + cost[1][b][y]) return dp[n][n] n = int(input()) # White/Black 'k' ball is what-th in whole row? rev = [[0] * n, [0] * n] for i in range(n * 2): c, a = input().split() a = int(a) - 1 rev[int(c == 'B')][a] = i print(solve(n, rev)) ``` Yes
108,500
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` from itertools import accumulate n = int(input()) b = [] # iがあるインデックス bc = {} wc = {} for i in range(2*n): c,a = input().split() a = int(a) b.append((c,a)) if c == "B": bc[a]=i else: wc[a]=i # black[i][j] : 黒のi(1-indexed)のある位置より左にある、i未満の個数 + 白のj以下の個数 black = [[0]*(n+1) for i in range(n+1)] white = [[0]*(n+1) for i in range(n+1)] for i in range(2*n): c,a = b[i] # 同色でa未満の個数 cnt cnt = 0 num = [0]*(n+1) for j in range(i): if b[j][0] == c: if b[j][1] < a: cnt += 1 else: num[b[j][1]] += 1 # 累積和 num = list(accumulate(num)) if c == "B": black[a] = [j+cnt for j in num] else: white[a] = [j+cnt for j in num] DP = [[float("inf")]*(n+1) for i in range(n+1)] DP[0][0] = 0 for i in range(n+1): for j in range(n+1): # 黒がi個、白がj個→i+1, j or i, j+1 if i+1 <= n: DP[i+1][j] = min(DP[i+1][j], DP[i][j]+bc[i+1]-black[i+1][j]) if j+1 <= n: DP[i][j+1] = min(DP[i][j+1], DP[i][j]+wc[j+1]-white[j+1][i]) print(DP[n][n]) ``` Yes
108,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` N = int(input()) balls = [] for i in range(2 * N): c, a = input().split() balls += [(c, int(a))] # numB[i][b]: 初期状態において、i番目の玉より右にある、1~bが書かれた黒玉の数 numB = [[0] * (N + 1) for i in range(2 * N)] numW = [[0] * (N + 1) for i in range(2 * N)] for i in reversed(range(1, 2 * N)): c, a = balls[i] numB[i - 1] = list(numB[i]) numW[i - 1] = list(numW[i]) if c == 'B': for b in range(a, N + 1): numB[i - 1][b] += 1 else: for w in range(a, N + 1): numW[i - 1][w] += 1 # costB[b][w]: 黒玉1~b、白玉1~wのうち、初期状態において、黒玉[b+1]より右にある玉の数 costB = [[0] * (N + 1) for i in range(N + 1)] costW = [[0] * (N + 1) for i in range(N + 1)] for i in reversed(range(2 * N)): c, a = balls[i] if c == 'B': cost = numB[i][a - 1] for w in range(N + 1): costB[a - 1][w] = cost + numW[i][w] else: cost = numW[i][a - 1] for b in range(N + 1): costW[b][a - 1] = cost + numB[i][b] dp = [[float('inf')] * (N + 1) for i in range(N + 1)] dp[0][0] = 0 for b in range(N + 1): for w in range(N + 1): if b > 0: dp[b][w] = min(dp[b][w], dp[b - 1][w] + costB[b - 1][w]) if w > 0: dp[b][w] = min(dp[b][w], dp[b][w - 1] + costW[b][w - 1]) print(dp[N][N]) ``` Yes
108,502
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` import sys input = sys.stdin.readline N = int(input()) black = [None] * (N+1) # 数字 -> 場所 white = [None] * (N+1) for i in range(1,2*N+1): c,a = input().split() a = int(a) if c == 'W': white[a] = i else: black[a] = i after = [] b = 1 w = 1 while True: if b <= N and w <= N: ib = black[b] iw = white[w] if ib < iw: after.append(ib) b += 1 else: after.append(iw) w += 1 elif b <= N: after.append(black[b]) b += 1 elif w <= N: after.append(white[w]) w += 1 else: break # あとは転倒数を数えて終わり def BIT_update(tree,x): L = len(tree) while x < L: tree[x] += 1 x += x & (-x) def BIT_sum(tree,x): L = len(tree) s = 0 while x: s += tree[x] x -= x & (-x) return s tree = [0] * (2*N+10) answer = 0 for i,x in enumerate(after): answer += i - BIT_sum(tree,x) BIT_update(tree,x) print(answer) ``` No
108,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` def main(): from sys import stdin input = stdin.readline # 一点更新・一点取得の加法BIT class BIT(): def __init__(self, n): self.n = n self.bit = [0]*(n+1) # 位置iに値vを足す def add(self, i): x, n, bit = i+1, self.n, self.bit while x < n+1: bit[x] += 1 x += x & (-x) # 位置0からiまでの和(sum(bit[:i]))を計算する def sum(self, i): ret, x, bit = 0, i, self.bit while x > 0: ret += bit[x] x -= x & (-x) return ret n = int(input()) ab = [list(input().split()) for _ in [0]*(2*n)] ab = [(a, int(b)-1) for a, b in ab] f_B = [[0]*(n+1) for _ in [0]*n] # f_B[i][j] = Bがi個、Wがj個あるときのBを置く手数 f_W = [[0]*(n+1) for _ in [0]*n] # f_W[i][j] = Bがi個、Wがj個あるときのWを置く手数 dp = [10**9]*(n+1) # dp[i][j] = Bをi個、Wをj個置くための最小手数 dp[0] = 0 # まずf_Bから出す for i in range(n+1): bit = BIT(n) cnt = 0 for a, b in ab: if a == "B": f_B[b][i] = bit.sum(n-b-1)+cnt bit.add(n-b-1) else: if b >= i: cnt += 1 # f_Wも同様 for i in range(n+1): bit = BIT(n) cnt = 0 for a, b in ab: if a == "W": f_W[b][i] = bit.sum(n-b-1)+cnt bit.add(n-b-1) else: if b >= i: cnt += 1 for i in range(n): dp2 = [10**9]*(n+1) for j in range(n+1): d = dp[j] try: dp2[j] = min(dp2[j], d+f_B[i][j]) except: pass try: dp[j+1] = min(dp[j+1], d+f_W[j][i]) except: pass dp = dp2 print(dp[n]) main() ``` No
108,504
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` def main(): from sys import stdin input = stdin.readline n = int(input()) ab = [list(input().split()) for _ in [0]*(2*n)] ab = [(a, int(b)-1) for a, b in ab] dct = {(a, b): i for i, (a, b) in enumerate(ab)} dp = [[10**9]*(n+1) for _ in [0]*(n+1)] # dp[i][j] = Bをi個、Wをj個置くための最小手数 dp[0][0] = 0 # 左i個にあるj以上のボールの数 lb = [[0]*(n+1) for _ in [0]*(2*n)] lw = [[0]*(n+1) for _ in [0]*(2*n)] for j in range(n): cnt1, cnt2 = 0, 0 for i, (a, b) in enumerate(ab): lb[i][j] = cnt1 lw[i][j] = cnt2 if a == "B": if b >= j: cnt1 += 1 else: if b >= j: cnt2 += 1 for i in range(n+1): try: t = dct[("B", i)] except: pass for j in range(n+1): d = dp[i][j] try: dp[i+1][j] = min(dp[i+1][j], d+lb[t][i]+lw[t][j]) except: pass try: t2 = dct[("W", j)] dp[i][j+1] = min(dp[i][j+1], d+lb[t2][i]+lw[t2][j]) except: pass print(dp[n][n]) main() ``` No
108,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are 2N balls, N white and N black, arranged in a row. The integers from 1 through N are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the i-th ball from the left (1 ≤ i ≤ 2N) is a_i, and the color of this ball is represented by a letter c_i. c_i = `W` represents the ball is white; c_i = `B` represents the ball is black. Takahashi the human wants to achieve the following objective: * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the white ball with i written on it is to the left of the white ball with j written on it. * For every pair of integers (i,j) such that 1 ≤ i < j ≤ N, the black ball with i written on it is to the left of the black ball with j written on it. In order to achieve this, he can perform the following operation: * Swap two adjacent balls. Find the minimum number of operations required to achieve the objective. Constraints * 1 ≤ N ≤ 2000 * 1 ≤ a_i ≤ N * c_i = `W` or c_i = `B`. * If i ≠ j, (a_i,c_i) ≠ (a_j,c_j). Input Input is given from Standard Input in the following format: N c_1 a_1 c_2 a_2 : c_{2N} a_{2N} Output Print the minimum number of operations required to achieve the objective. Examples Input 3 B 1 W 2 B 3 W 1 W 3 B 2 Output 4 Input 4 B 4 W 4 B 3 W 3 B 2 W 2 B 1 W 1 Output 18 Input 9 W 3 B 1 B 4 W 1 B 5 W 9 W 2 B 6 W 5 B 3 W 8 B 9 W 7 B 2 B 8 W 4 W 6 B 7 Output 41 Submitted Solution: ``` class BinaryIndexedTree: def __init__(self,n): self.bit=[0]*n def add(self,i,x): i+=1 while i<=len(self.bit): self.bit[i-1]+=x i+=i&-i def sum_sub(self,i): a=0 i+=1 while i: a+=self.bit[i-1] i-=i&-i return a def sum(self,i,j): a=self.sum_sub(j) if i!=0:a-=self.sum_sub(i-1) return a n=int(input()) b=[0]*n w=[0]*n for i in range(2*n): c,a=input().split() if c=="B":b[int(a)-1]=i else:w[int(a)-1]=i bit=[BinaryIndexedTree(2*n)for _ in range(n+1)] dp=[(n+1)*[10**10]for _ in range(n+1)] dp[0][0]=0 for i in range(n+1): dp[i][0]=0 for k in range(i): dp[i][0]+=w[k]+bit[i].sum(w[k],2*n-1)-k bit[i].add(w[k],1) for j in range(n): for i in range(n+1): if i==0: dp[i][j+1]=dp[i][j]+b[j]+bit[i].sum(b[j],2*n-1)-(i+j) else: dp[i][j+1]=dp[i][j]+(b[j]+bit[i].sum(b[j],2*n-1)-(i+j)) dp[i][j+1]=min(dp[i][j+1],dp[i-1][j+1]+(w[i-1]+bit[i-1].sum(w[i-1],2*n-1)-(i+j))) bit[i].add(b[j],1) print(dp[n][n]) ``` No
108,506
Provide a correct Python 3 solution for this coding contest problem. Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i. The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices. For each vertex, calculate the niceness when the headquarters are set up in that vertex. The niceness when the headquarters are set up in Vertex i is calculated as follows: * Let X=0. * For each integer j between 1 and N (inclusive) except i, do the following: * Add c to X, where c is the smallest joyfulness of an edge on the path from Vertex i to Vertex j. * The niceness is the final value of X. Constraints * 1 \leq N \leq 10^{5} * 1 \leq a_i,b_i \leq N * 1 \leq c_i \leq 10^{9} * The given graph is a tree. * All input values are integers. Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Output Print N lines. The i-th line must contain the niceness when the headquarters are set up in Vertex i. Examples Input 3 1 2 10 2 3 20 Output 20 30 30 Input 15 6 3 2 13 3 1 1 13 2 7 1 2 8 1 1 2 8 2 2 12 2 5 2 2 2 11 2 10 2 2 10 9 1 9 14 2 4 14 1 11 15 2 Output 16 20 15 14 20 15 16 20 15 20 20 20 16 15 20 Input 19 19 14 48 11 19 23 17 14 30 7 11 15 2 19 15 2 18 21 19 10 43 12 11 25 3 11 4 5 19 50 4 11 19 9 12 29 14 13 3 14 6 12 14 15 14 5 1 6 8 18 13 7 16 14 Output 103 237 71 263 370 193 231 207 299 358 295 299 54 368 220 220 319 237 370 "Correct Solution: ``` import sys from operator import itemgetter read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class UnionFind: def __init__(self, N): self.root = list(range(N + 1)) def __getitem__(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self[x] y = self[y] if x == y: return # 番号の大きい頂点を根にする if x < y: x, y = y, x self.root[y] = x N = int(readline()) m = map(int, read().split()) ABC = sorted(zip(m, m, m), key=itemgetter(2), reverse=True) uf = UnionFind(N + N) parent = [0] * (N + N) value = [0] * (N + N) for n, (a, b, c) in enumerate(ABC, N + 1): ra = uf[a] rb = uf[b] parent[ra] = n parent[rb] = n value[n] = c uf.merge(ra, n) uf.merge(rb, n) size = [0] + [1] * N + [0] * (N - 1) for n in range(N + N): p = parent[n] size[p] += size[n] for n in range(N + N): p = parent[n] value[n] = 0 if not p: continue value[n] = value[p] * (size[p] - size[n]) for n in range(N + N - 2, 0, -1): p = parent[n] value[n] += value[p] print('\n'.join(map(str, value[1:N + 1]))) ```
108,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i. The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices. For each vertex, calculate the niceness when the headquarters are set up in that vertex. The niceness when the headquarters are set up in Vertex i is calculated as follows: * Let X=0. * For each integer j between 1 and N (inclusive) except i, do the following: * Add c to X, where c is the smallest joyfulness of an edge on the path from Vertex i to Vertex j. * The niceness is the final value of X. Constraints * 1 \leq N \leq 10^{5} * 1 \leq a_i,b_i \leq N * 1 \leq c_i \leq 10^{9} * The given graph is a tree. * All input values are integers. Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Output Print N lines. The i-th line must contain the niceness when the headquarters are set up in Vertex i. Examples Input 3 1 2 10 2 3 20 Output 20 30 30 Input 15 6 3 2 13 3 1 1 13 2 7 1 2 8 1 1 2 8 2 2 12 2 5 2 2 2 11 2 10 2 2 10 9 1 9 14 2 4 14 1 11 15 2 Output 16 20 15 14 20 15 16 20 15 20 20 20 16 15 20 Input 19 19 14 48 11 19 23 17 14 30 7 11 15 2 19 15 2 18 21 19 10 43 12 11 25 3 11 4 5 19 50 4 11 19 9 12 29 14 13 3 14 6 12 14 15 14 5 1 6 8 18 13 7 16 14 Output 103 237 71 263 370 193 231 207 299 358 295 299 54 368 220 220 319 237 370 Submitted Solution: ``` import sys sys.setrecursionlimit(10**6) N = int(input()) G = [[] for i in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) G[a-1].append((b-1, c)) G[b-1].append((a-1, c)) memo = {} def dfs(u, p, co): if (u, p, co) in memo: return memo[u, p, co] res = co for v, c in G[u]: if v == p: continue res += dfs(v, u, min(co, c)) memo[u, p, co] = res return res for i in range(N): INF = 10**18 print(dfs(i, -1, INF) - INF) ``` No
108,508
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i. The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices. For each vertex, calculate the niceness when the headquarters are set up in that vertex. The niceness when the headquarters are set up in Vertex i is calculated as follows: * Let X=0. * For each integer j between 1 and N (inclusive) except i, do the following: * Add c to X, where c is the smallest joyfulness of an edge on the path from Vertex i to Vertex j. * The niceness is the final value of X. Constraints * 1 \leq N \leq 10^{5} * 1 \leq a_i,b_i \leq N * 1 \leq c_i \leq 10^{9} * The given graph is a tree. * All input values are integers. Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Output Print N lines. The i-th line must contain the niceness when the headquarters are set up in Vertex i. Examples Input 3 1 2 10 2 3 20 Output 20 30 30 Input 15 6 3 2 13 3 1 1 13 2 7 1 2 8 1 1 2 8 2 2 12 2 5 2 2 2 11 2 10 2 2 10 9 1 9 14 2 4 14 1 11 15 2 Output 16 20 15 14 20 15 16 20 15 20 20 20 16 15 20 Input 19 19 14 48 11 19 23 17 14 30 7 11 15 2 19 15 2 18 21 19 10 43 12 11 25 3 11 4 5 19 50 4 11 19 9 12 29 14 13 3 14 6 12 14 15 14 5 1 6 8 18 13 7 16 14 Output 103 237 71 263 370 193 231 207 299 358 295 299 54 368 220 220 319 237 370 Submitted Solution: ``` import sys def solve(): n = int(sys.stdin.readline()) adj = [[] for i in range(n + 1)] dp = [dict() for i in range(n + 1)] cnt = [dict() for i in range(n + 1)] for i in range(n - 1): ai, bi, ci = map(int, sys.stdin.readline().split()) if ci > 2: return adj[ai].append((bi, ci)) adj[bi].append((ai, ci)) def cnt_node(v, p): if p in cnt[v]: return cnt[v][p] cnt[v][p] = 1 for (u, c) in adj[v]: if u == p: continue cnt[v][p] += cnt_node(u, v) return cnt[v][p] def dfs(v, p): if p in dp[v]: return dp[v][p] dp[v][p] = 0 for (u, c) in adj[v]: if u == p: continue if c == 1: dp[v][p] += cnt_node(u, v) else: dp[v][p] += dfs(u, v) + 2 return dp[v][p] for i in range(1, n + 1): # print(dp) # print(cnt) ans = dfs(i, -1) print(ans) if __name__ == '__main__': solve() ``` No
108,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i. The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices. For each vertex, calculate the niceness when the headquarters are set up in that vertex. The niceness when the headquarters are set up in Vertex i is calculated as follows: * Let X=0. * For each integer j between 1 and N (inclusive) except i, do the following: * Add c to X, where c is the smallest joyfulness of an edge on the path from Vertex i to Vertex j. * The niceness is the final value of X. Constraints * 1 \leq N \leq 10^{5} * 1 \leq a_i,b_i \leq N * 1 \leq c_i \leq 10^{9} * The given graph is a tree. * All input values are integers. Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Output Print N lines. The i-th line must contain the niceness when the headquarters are set up in Vertex i. Examples Input 3 1 2 10 2 3 20 Output 20 30 30 Input 15 6 3 2 13 3 1 1 13 2 7 1 2 8 1 1 2 8 2 2 12 2 5 2 2 2 11 2 10 2 2 10 9 1 9 14 2 4 14 1 11 15 2 Output 16 20 15 14 20 15 16 20 15 20 20 20 16 15 20 Input 19 19 14 48 11 19 23 17 14 30 7 11 15 2 19 15 2 18 21 19 10 43 12 11 25 3 11 4 5 19 50 4 11 19 9 12 29 14 13 3 14 6 12 14 15 14 5 1 6 8 18 13 7 16 14 Output 103 237 71 263 370 193 231 207 299 358 295 299 54 368 220 220 319 237 370 Submitted Solution: ``` N = int(input()) G = [[] for i in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) G[a-1].append((b-1, c)) G[b-1].append((a-1, c)) memo = {} def dfs(u, p, co): if (u, p, co) in memo: return memo[u, p, co] res = co for v, c in G[u]: if v == p: continue res += dfs(v, u, min(co, c)) memo[u, p, co] = res return res for i in range(N): INF = 10**18 print(dfs(i, -1, INF) - INF) ``` No
108,510
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i. The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices. For each vertex, calculate the niceness when the headquarters are set up in that vertex. The niceness when the headquarters are set up in Vertex i is calculated as follows: * Let X=0. * For each integer j between 1 and N (inclusive) except i, do the following: * Add c to X, where c is the smallest joyfulness of an edge on the path from Vertex i to Vertex j. * The niceness is the final value of X. Constraints * 1 \leq N \leq 10^{5} * 1 \leq a_i,b_i \leq N * 1 \leq c_i \leq 10^{9} * The given graph is a tree. * All input values are integers. Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Output Print N lines. The i-th line must contain the niceness when the headquarters are set up in Vertex i. Examples Input 3 1 2 10 2 3 20 Output 20 30 30 Input 15 6 3 2 13 3 1 1 13 2 7 1 2 8 1 1 2 8 2 2 12 2 5 2 2 2 11 2 10 2 2 10 9 1 9 14 2 4 14 1 11 15 2 Output 16 20 15 14 20 15 16 20 15 20 20 20 16 15 20 Input 19 19 14 48 11 19 23 17 14 30 7 11 15 2 19 15 2 18 21 19 10 43 12 11 25 3 11 4 5 19 50 4 11 19 9 12 29 14 13 3 14 6 12 14 15 14 5 1 6 8 18 13 7 16 14 Output 103 237 71 263 370 193 231 207 299 358 295 299 54 368 220 220 319 237 370 Submitted Solution: ``` import sys sys.setrecursionlimit(10**6) N = int(input()) G = [[] for i in range(N)] mc = 100 for i in range(N-1): a, b, c = map(int, input().split()) G[a-1].append((b-1, c)) G[b-1].append((a-1, c)) mc = min(c, mc) if N <= 1000: memo = {} def dfs(u, p, co): if (u, p, co) in memo: return memo[u, p, co] res = co for v, c in G[u]: if v == p: continue res += dfs(v, u, min(co, c)) memo[u, p, co] = res return res for i in range(N): INF = 10**18 print(dfs(i, -1, INF) - INF) elif mc <= 2: used = [0]*N gu = 0 g = [-1] def dfs(u, p): used[i] = gu res = 1 for v, c in G[v]: if c == 2: res += dfs(v, u) return res for i in range(N): if not used[i]: gu += 1 nn = dfs(i, -1) g.append(nn) else: nn = g[used[i]] print(N + nn) else: exit(1) ``` No
108,511
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. For a non-empty string S, we will define f(S) as the shortest even string that can be obtained by appending one or more characters to the end of S. For example, f(`abaaba`)=`abaababaab`. It can be shown that f(S) is uniquely determined for a non-empty string S. You are given an even string S consisting of lowercase English letters. For each letter in the lowercase English alphabet, find the number of its occurrences from the l-th character through the r-th character of f^{10^{100}} (S). Here, f^{10^{100}} (S) is the string f(f(f( ... f(S) ... ))) obtained by applying f to S 10^{100} times. Constraints * 2 \leq |S| \leq 2\times 10^5 * 1 \leq l \leq r \leq 10^{18} * S is an even string consisting of lowercase English letters. * l and r are integers. Input Input is given from Standard Input in the following format: S l r Output Print 26 integers in a line with spaces in between. The i-th integer should be the number of the occurrences of the i-th letter in the lowercase English alphabet from the l-th character through the r-th character of f^{10^{100}} (S). Examples Input abaaba 6 10 Output 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Input xx 1 1000000000000000000 Output 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0 Input vgxgpuamkvgxgvgxgpuamkvgxg 1 1000000000000000000 Output 87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0 Submitted Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import Counter """ ・実験すると、何回かやるとFibonacci(未証明) """ S = readline().rstrip() l,r = map(int,read().split()) def double_naive(S): L = len(S) for i in range(1,L+1): T = S[:i] * 2 if len(T) > L and T[:L] == S: return T def Z_algorithm(S): # 共通接頭辞の長さを返す N=len(S) arr = [0]*N arr[0] = N i,j = 1,0 while i<N: while i+j<N and S[j]==S[i+j]: j += 1 arr[i]=j if not j: i += 1 continue k = 1 while i+k<N and k+arr[k]<j: arr[i+k] = arr[k] k += 1 i += k; j -= k return arr def F(S): N = len(S) opt_len = N Z = Z_algorithm(S) for x in range(N//2+1,N): z = Z[x] if x + z >= N: opt_len = x break return S[:opt_len] * 2 S = F(S) T = F(S) # S,T,TS,TST,... L = [len(S), len(T)] for _ in range(100): L.append(L[-1] + L[-2]) ctr = [Counter(S), Counter(T)] for _ in range(100): ctr.append(ctr[-1] + ctr[-2]) def get_dist(N,R): # S_NにおけるR番目以下 if N == 0: return Counter(S[:R]) if N == 1: return Counter(T[:R]) if L[N-1] >= R: return get_dist(N-1,R) return ctr[N-1] + get_dist(N-2,R-L[N-1]) ctr = get_dist(99,r) - get_dist(99,l-1) answer = [ctr[x + ord('a')] for x in range(26)] print(*answer) ``` No
108,512
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. For a non-empty string S, we will define f(S) as the shortest even string that can be obtained by appending one or more characters to the end of S. For example, f(`abaaba`)=`abaababaab`. It can be shown that f(S) is uniquely determined for a non-empty string S. You are given an even string S consisting of lowercase English letters. For each letter in the lowercase English alphabet, find the number of its occurrences from the l-th character through the r-th character of f^{10^{100}} (S). Here, f^{10^{100}} (S) is the string f(f(f( ... f(S) ... ))) obtained by applying f to S 10^{100} times. Constraints * 2 \leq |S| \leq 2\times 10^5 * 1 \leq l \leq r \leq 10^{18} * S is an even string consisting of lowercase English letters. * l and r are integers. Input Input is given from Standard Input in the following format: S l r Output Print 26 integers in a line with spaces in between. The i-th integer should be the number of the occurrences of the i-th letter in the lowercase English alphabet from the l-th character through the r-th character of f^{10^{100}} (S). Examples Input abaaba 6 10 Output 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Input xx 1 1000000000000000000 Output 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0 Input vgxgpuamkvgxgvgxgpuamkvgxg 1 1000000000000000000 Output 87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0 Submitted Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import Counter """ ・実験すると、何回かやるとFibonacci(未証明) """ S = readline().rstrip() l,r = map(int,read().split()) def double_naive(S): L = len(S) for i in range(1,L+1): T = S[:i] * 2 if len(T) > L and T[:L] == S: return T def Z_algorithm(S): # 共通接頭辞の長さを返す N=len(S) arr = [0]*N arr[0] = N i,j = 1,0 while i<N: while i+j<N and S[j]==S[i+j]: j += 1 arr[i]=j if not j: i += 1 continue k = 1 while i+k<N and k+arr[k]<j: arr[i+k] = arr[k] k += 1 i += k; j -= k return arr def F(S): N = len(S) opt_len = N Z = Z_algorithm(S) for x in range(N//2+1,N): z = Z[x] if x + z >= N: opt_len = x break return S[:opt_len] * 2 S = F(S) S = F(S) T = F(S) # S,T,TS,TST,... L = [len(S), len(T)] for _ in range(100): L.append(L[-1] + L[-2]) ctr = [Counter(S), Counter(T)] for _ in range(100): ctr.append(ctr[-1] + ctr[-2]) def get_dist(N,R): # S_NにおけるR番目以下 if N == 0: return Counter(S[:R]) if N == 1: return Counter(T[:R]) if L[N-1] >= R: return get_dist(N-1,R) return ctr[N-1] + get_dist(N-2,R-L[N-1]) ctr = get_dist(99,r) - get_dist(99,l-1) answer = [ctr[x + ord('a')] for x in range(26)] print(*answer) ``` No
108,513
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. For a non-empty string S, we will define f(S) as the shortest even string that can be obtained by appending one or more characters to the end of S. For example, f(`abaaba`)=`abaababaab`. It can be shown that f(S) is uniquely determined for a non-empty string S. You are given an even string S consisting of lowercase English letters. For each letter in the lowercase English alphabet, find the number of its occurrences from the l-th character through the r-th character of f^{10^{100}} (S). Here, f^{10^{100}} (S) is the string f(f(f( ... f(S) ... ))) obtained by applying f to S 10^{100} times. Constraints * 2 \leq |S| \leq 2\times 10^5 * 1 \leq l \leq r \leq 10^{18} * S is an even string consisting of lowercase English letters. * l and r are integers. Input Input is given from Standard Input in the following format: S l r Output Print 26 integers in a line with spaces in between. The i-th integer should be the number of the occurrences of the i-th letter in the lowercase English alphabet from the l-th character through the r-th character of f^{10^{100}} (S). Examples Input abaaba 6 10 Output 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Input xx 1 1000000000000000000 Output 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0 Input vgxgpuamkvgxgvgxgpuamkvgxg 1 1000000000000000000 Output 87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0 Submitted Solution: ``` #!/usr/bin/env python3 M = 10 ** 9 + 7 a = ord('a') def check_cycle(t, p): len_t = len(t) if len_t % p != 0: return False pre = t[: p] for i in range(p, len_t, p): if t[i: i + p] != pre: return False return True def solve_cycle(t, l, r): len_t = len(t) ql = (l - 1) // len_t rl = (l - 1) % len_t qr = r // len_t rr = r % len_t ans = [0] * 26 for ch in t: ans[ord(ch) - a] += 1 for j in range(26): ans[j] *= (qr - ql) for ch in t[: rr + 1]: ans[ord(ch) - a] += 1 for ch in t[: rl + 1]: ans[ord(ch) - a] -= 1 return ans def calc_part(tp, tm, len_p, len_m, dp0, dp1, r, ir): num_p = 0 num_m = 0 for i in range(ir, -1, -1): n = dp0[i] * len_p + dp1[i] * len_m if n <= r: num_p += dp0[i] num_m += dp1[i] r -= n vec = [0] * 26 tr = tp if len_p + len_m < r: num_p += 1 num_m += 1 r -= len_p + len_m elif len_p < r: num_p += 1 r -= len_p tr = tm for ch in tp: vec[ord(ch) - a] += num_p for ch in tm: vec[ord(ch) - a] += num_m for ch in tr[: r]: vec[ord(ch) - a] += 1 return vec def solve_part(t, len_p, l, r): len_t = len(t) len_m = len_t - 2 * len_p dp0 = [0] * 121 dp1 = [0] * 121 dp0[0] = 2 dp1[0] = 1 for i in range(1, 121): dp0[i] = dp0[i - 1] + dp1[i - 1] dp1[i] = dp0[i - 1] n = dp0[i] * len_p + dp1[i] * len_m if l - 1 <= n: il = i - 1 if r <= n: ir = i - 1 break vec_l = calc_part(t[: len_p], t[len_p: len_p + len_m], len_p, len_m, dp0, dp1, l - 1, il) vec_r = calc_part(t[: len_p], t[len_p: len_p + len_m], len_p, len_m, dp0, dp1, r, ir) ans = [vec_r[j] - vec_l[j] for j in range(26)] return ans def solve(s, l, r): t = s[: len(s) // 2] len_t = len(t) if len_t == 1: return solve_cycle(t, l, r) len_p = 0 ph = 0 sh = 0 base = 1 for i in range(len_t // 2): ph *= 26 ph += ord(s[i]) - a ph %= M sh += base * (ord(s[-1 - i]) - a) sh %= M if ph == sh: if check_cycle(t, i + 1): return sovle_cycle(t[: i + 1], l, r) elif t[: i + 1] == t[-1 - i:]: len_p = i + 1 base *= 26 if len_p == 0: return solve_cycle(t, l, r) return solve_part(t, len_p, l, r) def main(): s = input() l, r = input().split() l = int(l) r = int(r) print(' '.join(list(map(str, solve(s, l, r))))) if __name__ == '__main__': main() ``` No
108,514
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We will call a string that can be obtained by concatenating two equal strings an even string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. For a non-empty string S, we will define f(S) as the shortest even string that can be obtained by appending one or more characters to the end of S. For example, f(`abaaba`)=`abaababaab`. It can be shown that f(S) is uniquely determined for a non-empty string S. You are given an even string S consisting of lowercase English letters. For each letter in the lowercase English alphabet, find the number of its occurrences from the l-th character through the r-th character of f^{10^{100}} (S). Here, f^{10^{100}} (S) is the string f(f(f( ... f(S) ... ))) obtained by applying f to S 10^{100} times. Constraints * 2 \leq |S| \leq 2\times 10^5 * 1 \leq l \leq r \leq 10^{18} * S is an even string consisting of lowercase English letters. * l and r are integers. Input Input is given from Standard Input in the following format: S l r Output Print 26 integers in a line with spaces in between. The i-th integer should be the number of the occurrences of the i-th letter in the lowercase English alphabet from the l-th character through the r-th character of f^{10^{100}} (S). Examples Input abaaba 6 10 Output 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Input xx 1 1000000000000000000 Output 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0 Input vgxgpuamkvgxgvgxgpuamkvgxg 1 1000000000000000000 Output 87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0 Submitted Solution: ``` def getSS(S): helfLength = int(len(S) / 2) + 1 while S[:int(len(S[helfLength:]))] != S[helfLength:]: helfLength += 1 return S[:helfLength] * 2 result = "" S = input() SS = S lr = [int(i) for i in input().split()] i = 0 while i < 10: SS = getSS(SS) i += 1 cList = [chr(i) for i in range(97, 97+26)] for c in cList: result += str(SS[lr[0]-1:lr[1]].count(c)) + " " print(result.rstrip()) ``` No
108,515
Provide a correct Python 3 solution for this coding contest problem. There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness. Constraints * All input values are integers. * 2≤N≤5×10^3 * 1≤M≤200 * 1≤A_i≤10^9 * 1≤B_{i,j}≤10^9 Input The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M} Output Print Joisino's maximum possible eventual happiness. Examples Input 3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 Output 11 Input 5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 Output 20 "Correct Solution: ``` import sys readline = sys.stdin.readline N, M = map(int, readline().split()) A = [0] + list(map(int, readline().split())) for i in range(1, N): A[i] += A[i-1] INF = 10**9+7 B = [list(map(int, readline().split())) for _ in range(N)] + [[INF]*M] + [[0]*M] right = [[0]*M for _ in range(N)] for m in range(M): L = list(range(N)) L.sort(key = lambda x: B[x][m]) RR = list(range(1, N+3)) LL = list(range(-1, N+1)) for vn in L: vn += 1 right[vn-1][m] = RR[vn]-1 RR[LL[vn]] = RR[vn] LL[RR[vn]] = LL[vn] diff = [0]*(N+1) for m in range(M): diff[0] += B[0][m] pre = B[0][m] for i in range(1, N): if B[i][m] > pre: diff[i] += B[i][m]-pre pre = B[i][m] offset = 0 ans = 0 for l in range(N): offset += diff[l] for m in range(M): if B[l][m] < B[l-1][m]: oldr = right[l-1][m] diff[oldr] -= B[oldr][m] - B[l-1][m] offset += B[l][m] - B[l-1][m] cnt = l while cnt < N and right[cnt][m] <= oldr: rcm = right[cnt][m] diff[rcm] += B[rcm][m] - B[cnt][m] cnt = rcm ans = max(ans, offset) roff = offset for r in range(l+1, N): roff += diff[r] ans = max(ans, roff - (A[r]-A[l])) #print(l, r, roff - (A[r] - A[l])) print(ans) ```
108,516
Provide a correct Python 3 solution for this coding contest problem. There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness. Constraints * All input values are integers. * 2≤N≤5×10^3 * 1≤M≤200 * 1≤A_i≤10^9 * 1≤B_{i,j}≤10^9 Input The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M} Output Print Joisino's maximum possible eventual happiness. Examples Input 3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 Output 11 Input 5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 Output 20 "Correct Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools INF=10**10 N,M = map(int,readline().split()) A = [0,0]+list(map(int,readline().split())) B = [[INF]*M]+[list(map(int,line.split())) for line in readlines()] for i in range(1,N+1): A[i] += A[i-1] answer = 0 INF = 10**12 diff = [INF]+[0]*N left = [list(range(-1,N)) for m in range(M)] arr = [INF,2,1,2] for i in range(1,N+1): for m in range(M): p=i; prev_val=0 q=left[m][p] x = B[i][m] while prev_val<=x: diff[p] += x-prev_val diff[q] -= x-prev_val p=q; q=left[m][p] prev_val=B[p][m] left[m][i]=p # 出発地点ごとの収入 ticket_sum = list(itertools.accumulate(diff[::-1]))[::-1] for start in range(1,i+1): happy = ticket_sum[start] + A[start]-A[i] if answer < happy: answer = happy print(answer) ```
108,517
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness. Constraints * All input values are integers. * 2≤N≤5×10^3 * 1≤M≤200 * 1≤A_i≤10^9 * 1≤B_{i,j}≤10^9 Input The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M} Output Print Joisino's maximum possible eventual happiness. Examples Input 3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 Output 11 Input 5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 Output 20 Submitted Solution: ``` import sys readline = sys.stdin.readline class Sparsetable: def __init__(self, B): self.B = B self.N = len(B) A = list(range(self.N)) self.bn = self.N.bit_length() self.res = [[None]*self.bn for _ in range(self.N)] for i in range(self.N): self.res[i][0] = A[i] for dn in range(1, self.bn): rn = 1<<(dn-1) for h in range(self.N-2*rn+1): self.res[h][dn] = self.spf(self.res[h][dn-1], self.res[h+rn][dn-1]) def spf(self, x, y): if self.B[x] > self.B[y]: return x return y def query(self, h1, h2): h2 -= 1 hl = h2-h1+1 bh = hl.bit_length()-1 rh = 1<<bh return self.spf(self.res[h1][bh], self.res[h2-rh+1][bh]) N, M = map(int, readline().split()) A = [0] + list(map(int, readline().split())) + [0] for i in range(1, N): A[i] += A[i-1] B = [list(map(int, readline().split())) for _ in range(N)] B = list(map(list, zip(*B))) table = [[0]*(N+1) for _ in range(N+1)] for j in range(M): St = Sparsetable(B[j]) stack = [(0, N)] while stack: l, r = stack.pop() am = St.query(l, r) b = B[j][am] table[l][r-1] += b table[l][am-1] -= b table[am+1][r-1] -= b table[am+1][am-1] += b if am != l: stack.append((l, am)) if am+1 != r: stack.append((am+1, r)) for r in range(N-1, -1, -1): for l in range(1, r+1): table[l][r] += table[l-1][r] for r in range(N-2, -1, -1): for l in range(r+1): table[l][r] += table[l][r+1] ans = 0 for i in range(N): for j in range(i+1, N+1): ans = max(ans, table[i][j-1] - (A[j-1] - A[i])) print(ans) ``` No
108,518
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness. Constraints * All input values are integers. * 2≤N≤5×10^3 * 1≤M≤200 * 1≤A_i≤10^9 * 1≤B_{i,j}≤10^9 Input The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M} Output Print Joisino's maximum possible eventual happiness. Examples Input 3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 Output 11 Input 5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 Output 20 Submitted Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from numba import jit import numpy as np n,m = map(int,readline().split()) a = list(map(int,readline().split())) a += [0,0,0] b = list(map(int,read().split())) @jit def solve(n,m,a,b): # imos = [[0] * (n+2) for _ in range(n+2)] imos = np.zeros((n+2,n+2)) for i in range(m): left = list(range(-1,n+1)) right = list(range(1,n+3)) bi = [(val,j) for j,val in enumerate(b[i::m], 1)] bi.sort() for val,j in bi: l = left[j] r = right[j] imos[l+1,j] += val imos[l+1,r] -= val imos[j+1,j] -= val imos[j+1,r] += val right[l] = r left[r] = l for i in range(n+1): for j in range(1,n+1): imos[i,j] += imos[i,j-1] for i in range(1,n+1): for j in range(n+1): imos[i,j] += imos[i-1,j] ans = 0 for i in range(1,n+1): dif = 0 for j in range(i,n+1): ans = max(ans,imos[i,j] - dif) dif += a[j-1] print(int(ans)) solve(n,m,a,b) ``` No
108,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness. Constraints * All input values are integers. * 2≤N≤5×10^3 * 1≤M≤200 * 1≤A_i≤10^9 * 1≤B_{i,j}≤10^9 Input The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M} Output Print Joisino's maximum possible eventual happiness. Examples Input 3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 Output 11 Input 5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 Output 20 Submitted Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,M = map(int,readline().split()) A = [0]+list(map(int,readline().split())) B = list(map(int,read().split())) N,M for i in range(1,N): A[i] += A[i-1] ticket_sum = [0]*(N*N) # 各区間 [L,R] に対して、採用される点数を見る for n in range(M): arr = B[n::M] # 安いチケットから入れていく -> 連結成分上で採用される left = list(range(N)) right = list(range(N)) filled = [False]*N for i in sorted(range(N), key=arr.__getitem__): filled[i] = True l = i if (i==0) or (not filled[i-1]) else left[i-1] r = i if (i==N-1) or (not filled[i+1]) else right[i+1] left[r] = l; right[l] = r # [l,i] x [i,r] に arr[i] を加える x = arr[i] ticket_sum[l*N+i]+=x if i<N-1: ticket_sum[(i+1)*N+i]-=x if r<N-1: ticket_sum[l*N+r+1]-=x if i<N-1 and r<N-1: ticket_sum[(i+1)*N+r+1]+=x ``` No
108,520
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant. Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness. Constraints * All input values are integers. * 2≤N≤5×10^3 * 1≤M≤200 * 1≤A_i≤10^9 * 1≤B_{i,j}≤10^9 Input The input is given from Standard Input in the following format: N M A_1 A_2 ... A_{N-1} B_{1,1} B_{1,2} ... B_{1,M} B_{2,1} B_{2,2} ... B_{2,M} : B_{N,1} B_{N,2} ... B_{N,M} Output Print Joisino's maximum possible eventual happiness. Examples Input 3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 Output 11 Input 5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 Output 20 Submitted Solution: ``` def main(): from sys import stdin read = stdin.buffer.read readline = stdin.buffer.readline from collections import defaultdict from itertools import accumulate n,m = map(int,readline().split()) a = tuple(map(int,readline().split())) b = tuple(map(int,read().split())) query = [defaultdict(int) for _ in range(n+2)] for i in range(m): left = list(range(-1,n+1)) right = list(range(1,n+3)) bi = [(val,j) for j,val in enumerate(b[i::m], 1)] bi.sort() for val,j in bi: l = left[j] r = right[j] query[l+1][j] += val query[l+1][r] -= val query[j+1][j] -= val query[j+1][r] += val right[l] = r left[r] = l imos = [0] * (n+2) for i,ai in enumerate(a,2): imos[i] = imos[i-1] - ai query[i][i] += ai ans = 0 for i in range(1,n+1): next = [0] * (n+3-i) for j,val in query[i].items(): next[j+1-i] += val for j,val in enumerate(accumulate(next),i-1): imos[j] += val ans = max(ans, max(imos[i:n+1])) print(ans) if __name__ == '__main__': main() ``` No
108,521
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` A, B, C= [list(reversed(input())) for i in range(3)] d = {'a':A, 'b':B, 'c':C} x = 'a' while len(d[x]) != 0: x = d[x].pop() print(x.upper()) ```
108,522
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` cards = dict((x, list(input())) for x in 'abc') turn = 'a' while len(cards[turn]): turn = cards[turn].pop(0) print(turn.upper()) ```
108,523
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` s ={} s["a"] = list(input()) s["b"] = list(input()) s["c"] = list(input()) turn = "a" while True: if len(s[turn]) == 0: break turn = s[turn].pop(0) print(turn.upper()) ```
108,524
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` s={i:list(input()) for i in 'abc'} tmp='a' while s[tmp]: tmp=s[tmp].pop(0) print(tmp.upper()) # (#4130525) ```
108,525
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` S = {"a": input(), "b": input(), "c": input()} t = "a" while S[t]: nt = S[t][0] S[t] = S[t][1:] t = nt else: print(t.upper()) ```
108,526
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` a=[input(),input(),input()] now=0 while a[now]: y=a[now][0];a[now]=a[now][1:];now=ord(y)-ord('a') print("ABC"[now]) ```
108,527
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` sa = list(input()) sb = list(input()) sc = list(input()) s = {'a':sa, 'b':sb, 'c':sc} nxt = 'a' while 1: if len(s[nxt]) == 0: break nxt = s[nxt].pop(0) print(chr(ord(nxt)-32)) ```
108,528
Provide a correct Python 3 solution for this coding contest problem. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C "Correct Solution: ``` x = [input() for _ in range(3)] l = [0] * 3 k = 0 while l[k] < len(x[k]): n = ord(x[k][l[k]]) - ord('a') l[k] += 1 k = n print(['A', 'B', 'C'][k]) ```
108,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` S = {c: list(input()) for c in 'abc'} s = 'a' while S[s]: s = S[s].pop(0) print(s.upper()) ``` Yes
108,530
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` s = {c: input() for c in ['a', 'b', 'c']} turn = 'a' while True: n = s[turn] if n == '': break s[turn] = n[1:] turn = n[0] print(turn.upper()) ``` Yes
108,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` s = { 'a': input(), 'b': input(), 'c': input(), } p = 'a' while s[p] != '': n = s[p][0] s[p] = s[p][1:] p = n print(p.upper()) ``` Yes
108,532
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` S = dict() S["a"] = list(input())[::-1] S["b"] = list(input())[::-1] S["c"] = list(input())[::-1] p = "a" while S[p]: p = S[p].pop() print(p.upper()) ``` Yes
108,533
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` a=list(input()) b=list(input()) c=list(input()) S=[a,b,c] s=a while True: s=S[s].pop() print(s.upper()) ``` No
108,534
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` Sa = list(input()) Sb = list(input()) Sc = list(input()) n = {'A':len(Sa), 'B':len(Sb), 'C':len(Sc)} get = lambda S, i: S[i] if len(S) > i else '*' for i in range(max(n.values())): ch = get(Sa, i) + get(Sb, i) + get(Sc, i) n['A'] -= ch.count('a') n['B'] -= ch.count('b') n['C'] -= ch.count('c') if 0 in n.values(): print([k for k, v in n.items() if v==0][0]) break ``` No
108,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` s=input() t=input() u=input() a=b=c=0 now = 0 while 1: if now == 0: if s[a] == 'a': now = 0 elif s[a] == 'b': now = 1 else: now = 2 a+=1 if a==len(s): print('A') break elif now == 1: if s[b] == 'a': now = 0 elif s[b] == 'b': now = 1 else: now = 2 b+=1 if b==len(t): print('B') break else: if s[c] == 'a': now = 0 elif s[c] == 'b': now = 1 else: now = 2 c+=1 if c==len(u): print('C') break ``` No
108,536
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints * 1≦|S_A|≦100 * 1≦|S_B|≦100 * 1≦|S_C|≦100 * Each letter in S_A, S_B, S_C is `a`, `b` or `c`. Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. Examples Input aca accc ca Output A Input abcb aacb bccc Output C Submitted Solution: ``` a = input() b = input() c = input() cur = "a" while True: if cur == "a": cur = a[-1] a = a[:-1] if len(a) == 0: print("A") break elif cur == "b": cur = b[-1] b = b[:-1] if len(b) == 0: print("B") break else: cur = c[-1] c = c[:-1] if len(c) == 0: print("C") break ``` No
108,537
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` while True: try: d = {} while True: a, b = map(int, input().split()) if a == 0: break if a in d: d[a] += 1 else: d[a] = 1 if b in d: d[b] += 1 else: d[b] = 1 if d[1]%2 == 1 and d[2]%2 == 1: del d[1], d[2] for node in d: if d[node]%2 == 1: print("NG") break else: print("OK") else: print("NG") except: break ```
108,538
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` while 1: try: v = [0]*101 a, b = map(int, input().split()) v[a] += 1 v[b] += 1 while 1: a, b = map(int, input().split()) if a == 0: break v[a] += 1 v[b] += 1 flag = 0 for num in v[3:]: if num % 2 == 1: flag = 1 if v[1] % 2 and v[2] % 2 and (not flag): print('OK') else: print('NG') except: break ```
108,539
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` import sys readlines = sys.stdin.readlines write = sys.stdout.write def solve(): L = 100 G = [[] for i in range(L)] for line in readlines(): a, b = map(int, line.split()) if a != 0 != b: G[a-1].append(b-1) G[b-1].append(a-1) continue ok = 1 if len(G[0]) % 2 == 0 and len(G[1]) % 2 == 0: ok = 0 else: for i in range(2, L): if len(G[i]) == 0: continue if len(G[i]) % 2 == 1: ok = 0 write("OK\n" if ok else "NG\n") G = [[] for i in range(L)] solve() ```
108,540
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` def ap(i): if len(root)<i: for _ in range(i-len(root)):root.append(0) root[i-1]=[0,1][root[i-1]==0] while 1: try: root=[0,0] while 1: n,m=map(int,input().split()) if n==m==0:break ap(n) ap(m) if root.pop(0)+root.pop(0)==2 and sum(root)==0:print("OK") else:print("NG") except:break ```
108,541
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` import sys from collections import defaultdict data_list = [] for line in sys.stdin: data_list.append(list(map(int, line.split()))) def is_half_euler_graph(node_list): for node in node_list: isBool = True for dic_key, dic_value in node.items(): if dic_key != 1 and dic_key != 2: if dic_value % 2 != 0: isBool = False break else : if dic_value % 2 == 0: isBool = False break if isBool : print("OK") else : print("NG") if __name__ == '__main__' : node_data_lists = [] tmp_list = [] count_lists = [] tmp_dic = {} tmp_dic = defaultdict(int) for i in range(0, len(data_list)): if data_list[i][0] == 0 and data_list[i][1] == 0: node_data_lists.append(tmp_list[:]) tmp_list.clear() else : tmp_list.append(data_list[i]) for node_data_list in node_data_lists : tmp_dic.clear() for i in range(0, len(node_data_list)): tmp_dic[node_data_list[i][0]] += 1 tmp_dic[node_data_list[i][1]] += 1 count_lists.append(tmp_dic.copy()) is_half_euler_graph(count_lists) ```
108,542
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` # AOJ 0086 Patrol # Python3 2018.6.17 bal4u while True: try: a, b = list(map(int, input().split())) except: break c = [0]*105 n = 0 while True: if a != b: c[a] += 1 c[b] += 1 if a > n: n = a if b > n: n = b a, b = list(map(int, input().split())) if a == 0: break f = False if (c[1]&1) and (c[2]&1): i = 3 while i <= n: if (c[i]&1): break; i += 1 if i > n: f = True print("OK" if f else "NG") ```
108,543
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` def solve(): dic = {} while True: a, b = map(int, input().split()) if not a: break if a in dic: dic[a] += 1 else: dic[a] = 1 if b in dic: dic[b] += 1 else: dic[b] = 1 #スタートとゴールの次数が偶数ならNG if not dic[1] % 2 or not dic[2] % 2: print("NG") else: #それ以外の頂点の次数が奇数ならNG for k in dic: if not k in (1,2) and dic[k] % 2: print("NG") break #それ以外はOK else: print("OK") while True: try: solve() except EOFError: break ```
108,544
Provide a correct Python 3 solution for this coding contest problem. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG "Correct Solution: ``` import sys v=[0]*100 for e in sys.stdin: a,b=map(int,e.split()) v[a]+=1;v[b]+=1 if a==0: print(['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2]) v=[0]*100 ```
108,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0086 """ import sys from sys import stdin input = stdin.readline def main(args): for line in sys.stdin: routes = [] a, b = map(int, line.split()) if a == 0 and b == 0: break while a != 0 or b!= 0: routes.append([a, b]) a, b = map(int, input().split()) degrees = [0] * 101 for a, b in routes: degrees[a] += 1 degrees[b] += 1 odds = [x for x in degrees if x%2==1] # evens = [x for x in degrees if x%2==0] # print(degrees) if len(odds) == 2 and degrees[1]%2==1 and degrees[2]%2==1: print('OK') else: print('NG') if __name__ == '__main__': main(sys.argv[1:]) ``` Yes
108,546
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` import sys ab = [] for line in sys.stdin: temp = list(map(int, line.split())) if temp == [0, 0]: v = [0 for i in range(max(ab)+1)] for i in ab: v[i] += 1 odd = 0 for i in v: if i % 2 == 1: odd += 1 if odd == 2 and ((v[1] % 2) == (v[2] % 2) == 1): print('OK') else: print('NG') ab = [] else: ab += temp ``` Yes
108,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` import sys v=[0]*101 for e in sys.stdin: a,b=map(int,e.split()) v[a]+=1;v[b]+=1 if a==0: print(['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2]) v=[0]*101 ``` Yes
108,548
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` import sys v=[0]*101 for e in sys.stdin: a,b=map(int,e.split()) v[a]+=1;v[b]+=1 if a==0: print(['NG','OK'][1&v[1]and 1&v[2]and sum(x&1 for x in v)==2]) v=[0]*101 ``` Yes
108,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` import sys data_list = [] for line in sys.stdin: data_list.append(list(map(int, line.split()))) def is_half_euler_graph(node_list): for node in node_list: odd_num_counter = 0 for dic_value in node.values(): if dic_value % 2 != 0: odd_num_counter = odd_num_counter + 1 if odd_num_counter > 2: print("NG") break; if odd_num_counter == 2 : print("OK") if __name__ == '__main__' : node_data_lists = [] tmp_list = [] count_lists = [] tmp_dic = {} for i in range(0, len(data_list)): if data_list[i][0] == 0 and data_list[i][1] == 0: node_data_lists.append(tmp_list[:]) tmp_list.clear() else : tmp_list.append(data_list[i]) for node_data_list in node_data_lists : tmp_dic.clear() for i in range(0, len(node_data_list)): if node_data_list[i][0] in tmp_dic.keys(): tmp_dic[node_data_list[i][0]] = tmp_dic[node_data_list[i][0]] + 1 else : tmp_dic[node_data_list[i][0]] = 1 if node_data_list[i][1] in tmp_dic.keys(): tmp_dic[node_data_list[i][1]] = tmp_dic[node_data_list[i][1]] + 1 else : tmp_dic[node_data_list[i][1]] = 1 count_lists.append(tmp_dic.copy()) is_half_euler_graph(count_lists) ``` No
108,550
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` # -*- coding: utf-8 -*- import sys import os import math # adjacent list M = [] for i in range(105): M.append([]) def solve(M): odd_num = 0 even_num = 0 for m in M: if len(m) % 2 == 0: even_num += 1 else: odd_num += 1 if odd_num == 0 or odd_num == 2: print('OK') else: print('NG') for s in sys.stdin: a, b = map(int, s.split()) if a == b == 0: solve(M) # reset M = [] for i in range(105): M.append([]) else: a -= 1 b -= 1 M[a].append(b) M[b].append(a) ``` No
108,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` import sys ab = [] for line in sys.stdin: temp = list(map(int, line.split())) if temp == [0, 0]: v = [0 for i in range(max(ab)+1)] v[0] = 2 for i in ab: v[i] += 1 even = 0 odd = 0 for i in v: if i % 2 == 1: odd += 1 if odd == 0 or (odd == 2 and (v[1] % 2) == (v[2] % 2) == 1): print('OK') else: print('NG') ab = [] else: ab += temp ``` No
108,552
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing route, the following order was received from a stubborn old man who is famous among his vassals. <image> It was a big deal. Even the lord cannot ignore the statement of this vassal. Depending on the selection of the sharing route, it will be "the samurai's face is not noticeable". So, please make a program to judge whether the above three conditions are met by inputting the information of the start point, the goal point, and the intersection, and give it to the lord. The start point is represented by 1, the goal point is represented by 2, and other intersections are represented by integers of 3 or more. A road is represented by a set of intersection numbers that the roads connect to. The number of intersections shall be 100 or less, and there shall be one or more routes from all intersections to the start point and goal point. input Given multiple datasets. Each dataset is given in the following format: a1 b1 a2 b2 : : 0 0 The two integers in each row indicate that there is a road connecting intersection ai and intersection bi. When both ai and bi are 0, it indicates the end of inputting intersection information. The number of datasets does not exceed 50. output For each data set, if the samurai's face stands out (if the three conditions are met), OK, otherwise (if the three conditions are not met), output NG on one line. Example Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output OK NG Submitted Solution: ``` while True: try: path = [0]*100 while True: a,b = map(int, raw_input().split()) if a == 0: break path[a-1] += 1; path[b-1] += 1 if (path[0]%2 == 1 and path[1]%2 == 1 ): print "OK" else: print "NG" except: break ``` No
108,553
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` while True: N = int(input()) if N == 0: break for _ in range(N): m, e, j = map(int, input().split()) me, mej = (m+e)//2, (m+e+j)//3 if 100 in (m, e, j) or me >= 90 or mej >= 80: print('A') elif mej >= 70 or (mej >= 50 and m >= 80 or e >= 80): print('B') else: print('C') ```
108,554
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` while(True): n = int(input()) if not n: break for _ in range(n): m,e,j = map(int, input().split()) if 100 in [m,e,j]: print("A"); continue elif (m+e)/2 >= 90: print("A"); continue elif (m+e+j)/3 >= 80: print("A"); continue elif (m+e+j)/3 >= 70: print("B"); continue elif (m+e+j)/3 >= 50 and (m>=80 or e>=80): print("B"); continue else: print("C"); continue ```
108,555
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` def rank_a(m,e,j): if m == 100 or e == 100 or j==100:return True if (float(m) + e) /2 >= 90:return True if (float(m) + e + j) / 3 >= 80: return True return False def rank_b(m,e,j): if (float(m) + e + j) / 3 >= 70: return True if (float(m) + e + j) / 3 >= 50 and \ (m >= 80 or e >= 80): return True while True: n = int(input()) if n == 0: break for i in range(n): pm,pe,pj = list(map(int,input().split())) if rank_a(pm,pe,pj): print("A") elif rank_b(pm,pe,pj): print("B") else: print("C") ```
108,556
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` while 1: n = int(input()) if n == 0: break l = [list(map(int,input().split())) for i in range(n)] for i in range(n): if l[i][0] == 100 or l[i][1] == 100 or l[i][2] == 100: print("A") elif l[i][0] + l[i][1] >= 180: print("A") elif l[i][0] + l[i][1] + l[i][2] >= 240: print("A") elif l[i][0] + l[i][1] + l[i][2] >= 210: print("B") elif l[i][0] + l[i][1] + l[i][2] >= 150 and (l[i][0] >=80 or l[i][1] >=80) : print("B") else: print("C") ```
108,557
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` def rank(pm, pe, pj): ave_me = (pm + pe) // 2 ave_all = (pm + pe + pj) // 3 if 100 == pm or 100 == pe or 100 == pj or 90 <= ave_me or 80 <= ave_all: return 'A' if 70 <= ave_all or 50 <= ave_all and (80 <= pm or 80 <= pe): return 'B' return 'C' import sys f = sys.stdin while True: n = int(f.readline()) if n == 0: break for _ in range(n): pm, pe, pj = map(int, f.readline().split()) print(rank(pm, pe, pj)) ```
108,558
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` while True: n = int(input()) if n == 0: break dataset = [list(map(int, input().split())) for _ in range(n)] for p in dataset: x = sum(p) // 3 if 100 in p: print("A") elif (p[0] + p[1]) // 2 >= 90: print("A") elif x >= 80: print("A") elif x >= 70: print("B") elif x >= 50 and (p[0] >= 80 or p[1] >= 80): print("B") else: print("C") ```
108,559
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` while True: N = int(input()) if N == 0: break for l in range(N): m,e,j = [int(i) for i in input().split()] ans = "" if m == 100 or e == 100 or j == 100: ans = "A" elif m + e >= 180: ans = "A" elif m + e + j >= 240: ans = "A" elif m + e + j >= 210: ans = "B" elif (m + e + j >= 150) and (m >= 80 or e >= 80): ans = "B" else: ans = "C" print(ans) ```
108,560
Provide a correct Python 3 solution for this coding contest problem. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B "Correct Solution: ``` while True: n = int(input()) if n==0: break for i in range(n): m,e,j = map(int,input().split()) if (m==100 or e==100 or j ==100) or ((m+e)/2 >= 90) or ((m+e+j)/3 >=80): print("A") elif((m+e+j)/3 >=70) or (((m+e+j)/3>=50) and (m>=80 or e>=80)): print("B") else: print("C") ```
108,561
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` while 1: n=int(input()) if n==0: break for _ in range(n): a=list(map(int,input().split())) c=sum(a) if sum(a[:2])/2>=90 or c/3>=80 or 100 in a: b='A' elif c/3>=70 or (c/3>=50 and (a[0]>=80 or a[1]>=80)): b='B' else: b='C' print(b) ``` Yes
108,562
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` # Aizu Problem 0218: Dividing Students import sys, math, os, fractions # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") def grade(m, e, j): if m + e >= 180 or m + e + j >= 240 or max(e, j, m) == 100: return 'A' elif m + e + j >= 210: return 'B' elif m + e + j >= 150 and max(m, e) >= 80: return 'B' return 'C' while True: n = int(input()) if n == 0: break for _ in range(n): m, e, j = [int(__) for __ in input().split()] print(grade(m, e, j)) ``` Yes
108,563
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` while 1: n=int(input()) if n==0:break for i in range(n): a,b,c=map(int,input().split()) if a==100 or b==100 or c==100 or a+b>=180 or a+b+c>=240: print("A") elif a+b+c>=210 or a+b+c>=150 and (a>=80 or b>=80): print("B") else: print("C") ``` Yes
108,564
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` while 1: n = int(input()) if n == 0: break i = 0 while True: if i == n: break m, e, j = map(int, input().split()) sum = m + e + j if m==100 or e==100 or j==100: print("A") elif (m+e)/2 >= 90: print("A") elif sum/3 >= 80: print("A") elif sum/3 >= 70: print("B") elif sum/3 >= 50 and m >= 80 or e >= 80: print("B") else: print("C") i += 1 ``` Yes
108,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` while True: n = int(input()) if n == 0: break dataset = [map(int, input().split()) for _ in range(n)] for map_ in dataset: pm, pe, pj = map_ x = (pm + pe + pj) // 3 if 100 in p: print("A") elif (pm + pe) // 2 >= 90: print("A") elif x >= 80: print("A") elif x >= 70: print("B") elif x >= 50 and (pm >= 80 or pe >= 80): print("B") else: print("C") ``` No
108,566
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` while True: n = int(input()) if n == 0: break dataset = [map(int, input().split()) for _ in range(n)] for map_ in dataset: pm, pe, pj = map_ x = (pm + pe + pj) // 3 if 100 in map_: print("A") elif (pm + pe) // 2 >= 90: print("A") elif x >= 80: print("A") elif x >= 70: print("B") elif x >= 50 and (pm >= 80 or pe >= 80): print("B") else: print("C") ``` No
108,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` while 1: n=int(input()) if n=='0': break for _ in range(n): a=list(map(int,input().split())) c=sum(a) if sum(a[:2])/2>=90 or c/3>=80 or 100 in a: b='A' elif c/3>=70 or (c/3>=50 and (a[0]>=80 or a[1]>=80)): b='B' else: b='C' print(b) ``` No
108,568
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. At Aizu Shingakujuku, students are divided into classes by conducting a proficiency test when they enter the cram school. The test consists of three subjects: Mathematics, English, and Japanese, and students are divided into A, B, and C classes. The level of class A is the highest and then decreases in order. The classification decision is based on the table below. Condition | Class --- | --- There are 100 subjects | A Average score of math and English is 90 points or more | A Average score of 3 subjects is 80 points or more | A Average score of 3 subjects is 70 points or more | B Average score of 3 subjects is 50 points or more and math or English is 80 points or more | B Does not meet the above conditions | C If you meet multiple conditions, you will be divided into higher level classes. Number of students n (1 ≤ n ≤ 10000), math score pmi (0 ≤ pmi ≤ 100) for each student, English score pei (0 ≤ pei ≤ 100), national language score pji (0 ≤ pji ≤ 100) Create a program that outputs classes A, B, and C (half-width alphabetic characters) for each student. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n pm1 pe1 pj1 pm2 pe2 pj2 :: pmn pen pjn All inputs are given as integers. The number of datasets does not exceed 1000. Output Outputs each student's class in turn for each input dataset. Example Input 4 100 70 20 98 86 55 80 34 36 65 79 65 2 99 81 20 66 72 90 0 Output A A B C A B Submitted Solution: ``` n=int(input()) while True: if n==0: break for i in range(n): m,e,j=map(int,input().split()) if m==100 or e==100 or j==100: print('{}'.format('A')) elif (m+e)/2>=90: print('{}'.format('A')) elif (m+e+j)/3>=80: print('{}'.format('A')) elif (m+e+j)/3>=70: print('{}'.format('B')) elif (m+e+j)/3>=50: if m>=80 or e>=80: print('{}'.format('B')) else: print('{}'.format('C')) else: print('{}'.format('C')) ``` No
108,569
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` a,b,x=map(int,input().split()) pay=0 if a//2<b: if x==1000: pay=a elif x==500: if b>a: pay=a else: pay=b else: aa=x//1000 aaa=x%1000 if aaa>500: pay=(aa+1)*a elif aaa==0: pay=aa*a else: pay=aa*a+b else: if x==500: pay=b else: bb=x//500 bbb=x%500 if bbb==0: pay=bb*b else: pay=(bb+1)*b print(pay) ```
108,570
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` a,b,x = list(map(int, input().split())) t = a * (x // 1000) + b * -(-(x % 1000) // 500) print(min(a * -(-x // 1000), b * -(-x // 500), t)) ```
108,571
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` A, B, X = map(int, input().split()) A = min(A, B * 2) B = min(A, B) n = -(-X // 500) print(n // 2 * A + n % 2 * B) ```
108,572
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` #標準入力 a,b,c = map(int,input().split()) #必要量を500で割った商を出力する i = c // 500 #商が500で割り切れないなら個数を1足す if c % 500 != 0:i += 1 #aよりb*2のほうが小さいなら1Lを買わないで500mlで個数を買った計算にしaの方が大きいなら両方を買う計算をする if a >= b * 2:print(b * i) elif a < b and c <= 1000:print(a) else:print((i // 2) * a + (i % 2) * b) ```
108,573
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` a,b,x=map(int,input().split()) ans=10**9 for i in range(21): for j in range(41): if i*1000+j*500>=x: ans=min(ans,i*a+j*b) print(ans) ```
108,574
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` x, y, z = map(int, input().split()) lit = z // 500 if z % 500 != 0: lit += 1 ans = min(y * lit, x * (lit // 2 + 1), x *(lit // 2) + y * (lit % 2)) print(ans) ```
108,575
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` A, B, X = map(int, input().split()) if A > 2 * B: A = 2 * B if A < B: B = A ans = X // 1000 * A X %= 1000 # print(ans + (B if X <= 500 else A)) a, b, x = A, B, X wa = ans + (0 if X == 0 else (B if X <= 500 else A)) print(wa) ```
108,576
Provide a correct Python 3 solution for this coding contest problem. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 "Correct Solution: ``` a, b, x = map(int, input().split()) if a > b * 2: m = (x + 499) // 500 * b elif a < b or ((x - 1) % 1000) >= 500: m = (x + 999) // 1000 * a else: m = x // 1000 * a + b print(m) ```
108,577
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` A, B, X = map(int, input().split()) k = (X // 1000) ans = k * min(A, 2*B) r = X - 1000*k if 0 < r <= 500: ans += min(A, B) elif 500 < r: ans += min(A, 2*B) print(ans) ``` Yes
108,578
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` import math a, b, x = map(int,input().split()) ans = 0 if a < b: ans = math.ceil(x/1000)* a print(ans) elif a >= b*2: print(math.ceil(x/500)*b) else: ans = (x // 1000)*a if (x % 1000) > 500: ans += a elif x % 1000 == 0: pass else: ans += b print(ans) ``` Yes
108,579
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` import math A, B, X = map(int, input().split()) ans = float('inf') for a in range(math.ceil(X/1000)+1): if X-1000*a < 0: b = 0 else: b = math.ceil((X-1000*a)/500) ans = min(ans, A*a+B*b) print(ans) ``` Yes
108,580
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` a,b,x = map(int, input().split()) if a >= b*2: print(((x-1)//500+1)*b) elif x%1000 > 500: print(((x-1)//1000+1)*a) else: print(min(((x-1)//1000+1)*a, x//1000*a+b)) ``` Yes
108,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` a,b,n=list(map(int,input().split())) if a>b*2: print(((n+499)//500)*b) elif a<b: print(((n+999)//1000)*a) elif n%1000>500: print(((n+500)//1000)*a) else: print(((n//1000)*a)+b) ``` No
108,582
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` a,b,n=list(map(int,input().split())) if n%500!=0:n=n+500-n%500 if a>b*2: print((n//500)*b) elif a<b: print((n//1000)*a) else: print(((n//1000)*a)+((n%1000)//500)*b) ``` No
108,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` a,b,n=list(map(int,input().split())) if a>b*2: print(((n+499)//500)*b) if n%1000>500: print(((n+500)//1000)*a) if a<b: print(((n+999)//1000)*a) else: print(((n//1000)*a)+b) ``` No
108,584
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Submitted Solution: ``` import math A, B, X = list(map(int, input().split(' '))) amount, cost = 0, 0 if A <= 2*B: amount = math.floor(X/1000)*1000 cost = math.floor(X/1000)*A if 0 < X-amount: cost += A else: amount = math.floor(X/500)*500 cost = math.floor(X/500)*B if 0 < X-amount: cost += B print(cost) ``` No
108,585
Provide a correct Python 3 solution for this coding contest problem. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No "Correct Solution: ``` class UnionFind(): def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y else: self.parent[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) while True: try: n = int(input()) except EOFError: break tree = UnionFind(7) nums = [0] * 7 for dominoes in input().split(): x, y = divmod(int(dominoes), 10) tree.unite(x, y) nums[x] += 1 nums[y] += 1 if all(tree.same(x, i) for i in range(1, 7) if nums[i]) and \ sum(1 for x in nums if x % 2) <= 2: print('Yes') else: print('No') ```
108,586
Provide a correct Python 3 solution for this coding contest problem. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No "Correct Solution: ``` import sys def subset(line): l = line.strip().split(" ") a = list(map(int, l)) xy = list(map(lambda x: [x // 10, x % 10], a)) dominos = [[2 if [x, y] in xy and x == y else \ 1 if [x, y] in xy else \ 1 if [y, x] in xy else 0 \ for x in range(0, 7)] for y in range(0, 7)] digits = [] for i in xy: digits.extend(i) digits = list(set(digits)) digits.sort() return digits, dominos def add_matrix(a, b): c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)] return c def mul_matrix(a, b): c = [[0 for i in range(0, 7)] for j in range(0, 7)] for j in range(0, 7): for i in range(0, 7): for k in range(0, 7): c[j][i] += a[j][k] * b[k][i] return c def is_connected(d, g): a = g[:] z = [[0 for i in range(0, 7)] for j in range(0, 7)] b = a for i in range(0, 7): z = add_matrix(z, b) b = mul_matrix(b, a) zeros = 0 for i in d: if z[d[0]][i] == 0: zeros += 1 return zeros == 0 lno = 0 for line in sys.stdin: lno += 1 if lno == 1: n = int(line) else: digits, dominos = subset(line) if not is_connected(digits, dominos): print("No") else: order = [sum(dominos[i]) for i in range(0, 7)] odd = 0 for i in digits: if order[i] % 2 != 0: odd += 1 if odd <= 2: print("Yes") else: print("No") lno = 0 ```
108,587
Provide a correct Python 3 solution for this coding contest problem. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No "Correct Solution: ``` # AOJ 1010: Dominoes Arrangement # Python3 2018.7.5 bal4u while True: try: n = int(input()) except: break f, g = [0]*7, [0]*7 p = list(input().split()) for x in p: if x[0] == x[1]: g[int(x[0])] = 1 else: f[int(x[0])] += 1 f[int(x[1])] += 1 if n == 1: print("Yes") continue ans = 1 for i in range(7): if g[i] and f[i] == 0: ans = 0 break if ans: k = 0 for i in range(7): if f[i] & 1: k += 1 ans = (k == 0 or k == 2) print("Yes" if ans else "No") ```
108,588
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No Submitted Solution: ``` import sys def subset(line): l = line.strip().split(" ") a = list(map(int, l)) xy = list(map(lambda x: [x // 10, x % 10], a)) dominos = [[1 if x != y and ([x, y] in xy or [y, x] in xy) else 0 \ for x in range(0, 7)] for y in range(0, 7)] digits = [] for i in xy: digits.extend(i) digits = list(set(digits)) digits.sort() return digits, dominos def add_matrix(a, b): c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)] return c def mul_matrix(a, b): c = [[0 for i in range(0, 7)] for j in range(0, 7)] for j in range(0, 7): for i in range(0, 7): for k in range(0, 7): c[j][i] += a[j][k] * b[k][i] return c def is_connected(d, g): a = g[:] z = [[0 for i in range(0, 7)] for j in range(0, 7)] b = a for i in range(0, 7): z = add_matrix(z, b) b = mul_matrix(b, a) zeros = 0 for i in d: if z[d[0]][i] == 0: zeros += 1 return zeros == 0 lno = 0 for line in sys.stdin: lno += 1 if lno == 1: n = int(line) else: digits, dominos = subset(line) if not is_connected(digits, dominos): print("No") else: order = np.sum(dominos, axis = 0) order = order % 2 if np.all(order == 0): print("Yes") elif len(order[order == 1]) <= 2: print("Yes") else: print("No") lno = 0 ``` No
108,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No Submitted Solution: ``` import sys def subset(line): l = line.strip().split(" ") a = list(map(int, l)) xy = list(map(lambda x: [x // 10, x % 10], a)) dominos = [[1 if ([x, y] in xy or [y, x] in xy) else 0 \ for x in range(0, 7)] for y in range(0, 7)] digits = [] for i in xy: digits.extend(i) digits = list(set(digits)) digits.sort() return digits, dominos def add_matrix(a, b): c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)] return c def mul_matrix(a, b): c = [[0 for i in range(0, 7)] for j in range(0, 7)] for j in range(0, 7): for i in range(0, 7): for k in range(0, 7): c[j][i] += a[j][k] * b[k][i] return c def is_connected(d, g): a = g[:] z = [[0 for i in range(0, 7)] for j in range(0, 7)] b = a for i in range(0, 7): z = add_matrix(z, b) b = mul_matrix(b, a) zeros = 0 for i in d: if z[d[0]][i] == 0: zeros += 1 return zeros == 0 lno = 0 for line in sys.stdin: lno += 1 if lno == 1: n = int(line) else: digits, dominos = subset(line) if not is_connected(digits, dominos): print("No") else: order = [sum(dominos[i]) for i in range(0, 7)] odd = 0 for i in digits: if order[i] % 2 != 0: odd += 1 if odd <= 2: print("Yes") else: print("No") lno = 0 ``` No
108,590
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No Submitted Solution: ``` import sys def subset(line): l = line.strip().split(" ") a = list(map(int, l)) xy = list(map(lambda x: [x // 10, x % 10], a)) dominos = [[1 if x != y and ([x, y] in xy or [y, x] in xy) else 0 \ for x in range(0, 7)] for y in range(0, 7)] digits = [] for i in xy: digits.extend(i) digits = list(set(digits)) digits.sort() return digits, dominos def add_matrix(a, b): c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)] return c def mul_matrix(a, b): c = [[0 for i in range(0, 7)] for j in range(0, 7)] for j in range(0, 7): for i in range(0, 7): for k in range(0, 7): c[j][i] += a[j][k] * b[k][i] return c def is_connected(d, g): a = g[:] z = [[0 for i in range(0, 7)] for j in range(0, 7)] b = a for i in range(0, 7): z = add_matrix(z, b) b = mul_matrix(b, a) zeros = 0 for i in d: if z[d[0]][i] == 0: zeros += 1 return zeros == 0 lno = 0 for line in sys.stdin: lno += 1 if lno == 1: n = int(line) else: digits, dominos = subset(line) #print("line=", line) if not is_connected(digits, dominos): print("No") else: order = np.sum(dominos, axis = 0) #print("order=", order) order = order % 2 if np.all(order == 0): print("Yes") elif len(order[order == 1]) <= 2: print("Yes") else: print("No") lno = 0 ``` No
108,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). Input Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 ≤ N ≤ 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. The number of pairs (datasets) is less than 30. Output For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. Example Input 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 Output Yes No Submitted Solution: ``` import sys from functools import reduce def subset(line): l = line.strip().split(" ") a = list(map(int, l)) xy = list(map(lambda x: [x // 10, x % 10], a)) dominos = [[1 if x != y and ([x, y] in xy or [y, x] in xy) else 0 \ for x in range(0, 7)] for y in range(0, 7)] digits = list(set(reduce(lambda x, y: x + y, xy))) digits.sort() return digits, dominos def add_matrix(a, b): c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)] return c def mul_matrix(a, b): c = [[0 for i in range(0, 7)] for j in range(0, 7)] for j in range(0, 7): for i in range(0, 7): for k in range(0, 7): c[j][i] += a[j][k] + b[k][i] return c def is_connected(d, g): a = g[:] z = [[0 for i in range(0, 7)] for j in range(0, 7)] b = a for i in range(0, 7): z = add_matrix(z, b) b = mul_matrix(b, a) zeros = 0 for i in d: if z[d[0]][i] == 0: zeros += 1 return zeros == 0 lno = 0 for line in sys.stdin: lno += 1 if lno == 1: n = int(line) else: digits, dominos = subset(line) #print("line=", line) if not is_connected(digits, dominos): print("No") else: order = np.sum(dominos, axis = 0) #print("order=", order) order = order % 2 if np.all(order == 0): print("Yes") elif len(order[order == 1]) <= 2: print("Yes") else: print("No") lno = 0 ``` No
108,592
Provide a correct Python 3 solution for this coding contest problem. The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post office is intended from that post office via several post offices. Delivered to the post office. Mail "forwarding" is only done between specific post offices. However, the transfer is bidirectional between the post offices where the transfer is performed. If there are multiple routes for forwarding mail from a post office to the destination, use the route that minimizes the distance to the destination. Therefore, the forwarding destination will be the next post office on such a shortest path. If there are multiple routes with the shortest total distance, the postal office number that is the direct transfer destination is transferred to the younger one. <image> <image> By the way, the region is suffering from a serious labor shortage, and each post office has only one transfer person to transfer between post offices. They are doing their best to go back and forth. Of course, if the forwarding agent belonging to a post office has paid the mail when the mail arrives at that post office, the forwarding from that post office will be temporarily stopped. When they are at their post office, they depart immediately if there is mail that has not been forwarded from that post office, and return immediately after delivering it to the forwarding destination. When he returns from the destination post office, he will not carry the mail that will be forwarded to his post office, even if it is at that post office (the mail will be forwarded to that mail). It is the job of the post office transferman). If multiple mail items are collected at the time of forwarding, the mail that was delivered to the post office earliest is transferred first. Here, if there are multiple mail items that arrived at the same time, the mail is forwarded from the one with the youngest post office number that is the direct forwarding destination. If there is mail that has the same forwarding destination, it will also be forwarded together. Also, if the mail that should be forwarded to the same post office arrives at the same time as the forwarding agent's departure time, it will also be forwarded. It should be noted that they all take 1 time to travel a distance of 1. You will be given information about the transfer between post offices and a list of the times when the mail arrived at each post office. At this time, simulate the movement of the mail and report the time when each mail arrived at the destination post office. It can be assumed that all the times required during the simulation of the problem are in the range 0 or more and less than 231. Input The input consists of multiple datasets, and the end of the input is represented by a single line with only 0 0. The format of each dataset is as follows. The first line of the dataset is given the integers n (2 <= n <= 32) and m (1 <= m <= 496), separated by a single character space. n represents the total number of post offices and m represents the number of direct forwarding routes between post offices. There can never be more than one direct forwarding route between two post offices. On the next m line, three integers containing information on the direct transfer route between stations are written. The first and second are the postal numbers (1 or more and n or less) at both ends of the transfer route, and the last integer represents the distance between the two stations. The distance is greater than or equal to 1 and less than 10000. The next line contains the integer l (1 <= l <= 1000), which represents the number of mail items to process, followed by the l line, which contains the details of each piece of mail. Three integers are written at the beginning of each line. These are, in order, the sender's postal office number, the destination postal office number, and the time of arrival at the sender's postal office. At the end of the line, a string representing the label of the mail is written. This label must be between 1 and 50 characters in length and consists only of letters, numbers, hyphens ('-'), and underscores ('_'). Information on each of these mail items is written in chronological order of arrival at the post office of the sender. At the same time, the order is not specified. In addition, there is no mail with the same label, mail with the same origin and destination, or mail without a delivery route. Each number or string in the input line is separated by a single character space. Output Output l lines for each dataset. Each output follows the format below. For each mail, the time when the mail arrived is output on one line. On that line, first print the label of the mail, then with a one-character space, and finally print the time when the mail arrived at the destination post office. These are output in order of arrival time. If there are multiple mails arriving at the same time, the ASCII code of the label is output in ascending order. A blank line is inserted between the outputs corresponding to each dataset. Example Input 4 5 1 2 10 1 3 15 2 3 5 2 4 3 3 4 10 2 1 4 10 LoveLetter 2 3 20 Greetings 3 3 1 2 1 2 3 1 3 1 1 3 1 2 1 BusinessMailC 2 3 1 BusinessMailB 3 1 1 BusinessMailA 0 0 Output Greetings 25 LoveLetter 33 BusinessMailA 2 BusinessMailB 2 BusinessMailC 2 "Correct Solution: ``` def solve(): from sys import stdin f_i = stdin ans = '' while True: n, m = map(int, f_i.readline().split()) if n == 0: break # prep for warshall-floyd algorithm inf = 10000 * 31 + 1 dist = [[inf] * n for i in range(n)] for i in range(n): dist[i][i] = 0 for i in range(m): s, t, d = map(int, f_i.readline().split()) s -= 1 t -= 1 dist[s][t] = d dist[t][s] = d # table for path reconstruction next_p = [list(range(n)) for i in range(n)] # Warshall-Floyd algorithm for k in range(n): for i in range(n): for j in range(n): d_ikj = dist[i][k] + dist[k][j] d_ij = dist[i][j] if d_ikj < d_ij: dist[i][j] = d_ikj next_p[i][j] = next_p[i][k] # for restore the smallest path in lexicographic order elif k != i and d_ikj == d_ij: if next_p[i][k] < next_p[i][j]: next_p[i][j] = next_p[i][k] l = int(f_i.readline()) paths = [] mails = set() messages = [] goals = [] for i in range(l): start, goal, at, msg = f_i.readline().split() start = int(start) - 1 goal = int(goal) - 1 at = int(at) messages.append(msg) goals.append(goal) # path reconstruction path = [] cur = start while cur != goal: path.append(cur) cur = next_p[cur][goal] path.append(goal) paths.append(path) # mail: (time, arrivalTime, next, cur, number) mails.add((at, at, path[1], start, i)) step = [1] * l deliv_time = [0] * n # mail forwarding tmp_ans = [] while mails: t, at, nxt, cur, num = min(mails) to_forward = set(filter(lambda x: x[0] == t and x[2] == nxt and x[3] == cur, mails)) mails = mails.difference(to_forward) dt = deliv_time[cur] # transferable if t >= dt: cost = dist[cur][nxt] new_t = t + cost for t, at, nxt, cur, num in to_forward: if nxt == goals[num]: tmp_ans.append((new_t, messages[num])) else: step[num] += 1 new_nxt = paths[num][step[num]] mails.add((new_t, new_t, new_nxt, nxt, num)) deliv_time[cur] = t + cost * 2 # non-transferable else: for t, at, nxt, cur, num in to_forward: mails.add((dt, at, nxt, cur, num)) tmp_ans.sort() tmp_ans = (f"{label} {time}" for time, label in tmp_ans) ans += '\n'.join(tmp_ans) + '\n\n' print(ans.rstrip()) solve() ```
108,593
Provide a correct Python 3 solution for this coding contest problem. The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post office is intended from that post office via several post offices. Delivered to the post office. Mail "forwarding" is only done between specific post offices. However, the transfer is bidirectional between the post offices where the transfer is performed. If there are multiple routes for forwarding mail from a post office to the destination, use the route that minimizes the distance to the destination. Therefore, the forwarding destination will be the next post office on such a shortest path. If there are multiple routes with the shortest total distance, the postal office number that is the direct transfer destination is transferred to the younger one. <image> <image> By the way, the region is suffering from a serious labor shortage, and each post office has only one transfer person to transfer between post offices. They are doing their best to go back and forth. Of course, if the forwarding agent belonging to a post office has paid the mail when the mail arrives at that post office, the forwarding from that post office will be temporarily stopped. When they are at their post office, they depart immediately if there is mail that has not been forwarded from that post office, and return immediately after delivering it to the forwarding destination. When he returns from the destination post office, he will not carry the mail that will be forwarded to his post office, even if it is at that post office (the mail will be forwarded to that mail). It is the job of the post office transferman). If multiple mail items are collected at the time of forwarding, the mail that was delivered to the post office earliest is transferred first. Here, if there are multiple mail items that arrived at the same time, the mail is forwarded from the one with the youngest post office number that is the direct forwarding destination. If there is mail that has the same forwarding destination, it will also be forwarded together. Also, if the mail that should be forwarded to the same post office arrives at the same time as the forwarding agent's departure time, it will also be forwarded. It should be noted that they all take 1 time to travel a distance of 1. You will be given information about the transfer between post offices and a list of the times when the mail arrived at each post office. At this time, simulate the movement of the mail and report the time when each mail arrived at the destination post office. It can be assumed that all the times required during the simulation of the problem are in the range 0 or more and less than 231. Input The input consists of multiple datasets, and the end of the input is represented by a single line with only 0 0. The format of each dataset is as follows. The first line of the dataset is given the integers n (2 <= n <= 32) and m (1 <= m <= 496), separated by a single character space. n represents the total number of post offices and m represents the number of direct forwarding routes between post offices. There can never be more than one direct forwarding route between two post offices. On the next m line, three integers containing information on the direct transfer route between stations are written. The first and second are the postal numbers (1 or more and n or less) at both ends of the transfer route, and the last integer represents the distance between the two stations. The distance is greater than or equal to 1 and less than 10000. The next line contains the integer l (1 <= l <= 1000), which represents the number of mail items to process, followed by the l line, which contains the details of each piece of mail. Three integers are written at the beginning of each line. These are, in order, the sender's postal office number, the destination postal office number, and the time of arrival at the sender's postal office. At the end of the line, a string representing the label of the mail is written. This label must be between 1 and 50 characters in length and consists only of letters, numbers, hyphens ('-'), and underscores ('_'). Information on each of these mail items is written in chronological order of arrival at the post office of the sender. At the same time, the order is not specified. In addition, there is no mail with the same label, mail with the same origin and destination, or mail without a delivery route. Each number or string in the input line is separated by a single character space. Output Output l lines for each dataset. Each output follows the format below. For each mail, the time when the mail arrived is output on one line. On that line, first print the label of the mail, then with a one-character space, and finally print the time when the mail arrived at the destination post office. These are output in order of arrival time. If there are multiple mails arriving at the same time, the ASCII code of the label is output in ascending order. A blank line is inserted between the outputs corresponding to each dataset. Example Input 4 5 1 2 10 1 3 15 2 3 5 2 4 3 3 4 10 2 1 4 10 LoveLetter 2 3 20 Greetings 3 3 1 2 1 2 3 1 3 1 1 3 1 2 1 BusinessMailC 2 3 1 BusinessMailB 3 1 1 BusinessMailA 0 0 Output Greetings 25 LoveLetter 33 BusinessMailA 2 BusinessMailB 2 BusinessMailC 2 "Correct Solution: ``` from heapq import heappush, heappop, heapify from collections import defaultdict import sys readline = sys.stdin.readline write = sys.stdout.write def solve(q): N, M = map(int, readline().split()) if N == M == 0: return False if q: write("\n") INF = 10**18 G = [[] for i in range(N)] E = [[INF]*N for i in range(N)] for i in range(M): a, b, c = map(int, readline().split()) G[a-1].append((b-1, c)) G[b-1].append((a-1, c)) E[a-1][b-1] = E[b-1][a-1] = c prv = [-1]*N L = int(readline()) P = []; R = []; I = [0]*L B = [0]*L que = [] for i in range(L): a, b, c, s = readline().strip().split() P.append(s) a = int(a)-1; b = int(b)-1; c = int(c) dist = [INF] * N dist[b] = 0 que1 = [(0, b)] while que1: cost, v = heappop(que1) if dist[v] < cost: continue for w, d in G[v]: r = cost + d if r < dist[w]: dist[w] = r prv[w] = v heappush(que1, (r, w)) elif r == dist[w]: prv[w] = min(prv[w], v) rt = [] B[i] = b v = a while v != b: rt.append(v) v = prv[v] rt.append(b) R.append(rt) que.append((c, 1, i)) heapify(que) res = [0]*L QS = [[] for i in range(N)]; rest = L D = [defaultdict(list) for i in range(N)] F = [{} for i in range(N)] U = [1]*N while rest: t = que[0][0] while que and que[0][0] == t: _, p, i = heappop(que) if p: v = R[i][I[i]] I[i] += 1 if B[i] == v: rest -= 1 res[i] = t else: w = R[i][I[i]] heappush(QS[v], (t, w, i)) D[v][w].append(i) F[v][i] = 0 else: U[i] = 1 for v in range(N): if QS[v]: qv = QS[v] while qv and F[v][qv[0][2]]: heappop(qv) if not U[v] or not QS[v]: continue _, w, k = heappop(QS[v]) d = E[v][w] for k0 in D[v][w]: F[v][k0] = 1 heappush(que, (t+d, 1, k0)) D[v][w] = [] heappush(que, (t+d+d, 0, v)) U[v] = 0 ans = [] for i in range(L): ans.append((res[i], P[i])) ans.sort() for e, s in ans: write("%s %d\n" % (s, e)) return True q = 0 while solve(q): q += 1 ```
108,594
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are in a fantasy monster-ridden world. You are a slayer fighting against the monsters with magic spells. The monsters have hit points for each, which represent their vitality. You can decrease their hit points by your magic spells: each spell gives certain points of damage, by which monsters lose their hit points, to either one monster or all monsters in front of you (depending on the spell). Monsters are defeated when their hit points decrease to less than or equal to zero. On the other hand, each spell may consume a certain amount of your magic power. Since your magic power is limited, you want to defeat monsters using the power as little as possible. Write a program for this purpose. Input The input consists of multiple datasets. Each dataset has the following format: N HP1 HP2 ... HPN M Name1 MP1 Target1 Damage1 Name2 MP2 Target2 Damage2 ... NameM MPM TargetM DamageM N is the number of monsters in front of you (1 ≤ N ≤ 100); HPi is the hit points of the i-th monster (1 ≤ HPi ≤ 100000); M is the number of available magic spells (1 ≤ M ≤ 100); Namej is the name of the j-th spell, consisting of up to 16 uppercase and lowercase letters; MPj is the amount of magic power consumed by the j-th spell (0 ≤ MPj ≤ 99); Targetj is either "Single" or "All", where these indicate the j-th magic gives damage just to a single monster or to all monsters respectively; Damagej is the amount of damage (per monster in case of "All") made by the j-th magic (0 ≤ Damagej ≤ 999999). All the numbers in the input are integers. There is at least one spell that gives non-zero damage to monsters. The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. Output For each dataset, Print in a line the minimum amount of magic power consumed to defeat all the monsters in the input. Example Input 3 8000 15000 30000 3 Flare 45 Single 8000 Meteor 62 All 6000 Ultimate 80 All 9999 0 Output 232 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(): rr = [] def f(n): h = LI() hm = max(h) m = I() ms = [] ma = [] for _ in range(m): nama,mp,target,damege = LS() mp = int(mp) damege = int(damege) if damege == 0: continue if mp == 0: return 0 if target == 'All': ma.append((mp,damege)) else: ms.append((mp,damege)) ds = [inf] * (hm+1) ds[0] = 0 for mp, dm in ms: for i in range(dm,hm+1): if ds[i] > mp + ds[i-dm]: ds[i] = mp + ds[i-dm] t = min(ds[-dm+1:]) if ds[-1] > t + dm: ds[-1] = t + dm da = [inf] * (hm+1) da[0] = 0 for mp, dm in ma: for i in range(dm,hm+1): if da[i] > mp + da[i-dm]: da[i] = mp + da[i-dm] t = min(da[-dm+1:]) if da[-1] > t + dm: da[-1] = t + dm for i in range(hm-1,-1,-1): if ds[i] > ds[i+1]: ds[i] = ds[i+1] if da[i] > da[i+1]: da[i] = da[i+1] mm = r = inf for i in range(hm,-1,-1): if mm <= da[i]: continue mm = tp = da[i] for hi in h: if hi > i: tp += ds[hi-i] if r > tp: r = tp return r while True: n = I() if n == 0: break rr.append(f(n)) return '\n'.join(map(str,rr)) print(main()) ``` No
108,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are in a fantasy monster-ridden world. You are a slayer fighting against the monsters with magic spells. The monsters have hit points for each, which represent their vitality. You can decrease their hit points by your magic spells: each spell gives certain points of damage, by which monsters lose their hit points, to either one monster or all monsters in front of you (depending on the spell). Monsters are defeated when their hit points decrease to less than or equal to zero. On the other hand, each spell may consume a certain amount of your magic power. Since your magic power is limited, you want to defeat monsters using the power as little as possible. Write a program for this purpose. Input The input consists of multiple datasets. Each dataset has the following format: N HP1 HP2 ... HPN M Name1 MP1 Target1 Damage1 Name2 MP2 Target2 Damage2 ... NameM MPM TargetM DamageM N is the number of monsters in front of you (1 ≤ N ≤ 100); HPi is the hit points of the i-th monster (1 ≤ HPi ≤ 100000); M is the number of available magic spells (1 ≤ M ≤ 100); Namej is the name of the j-th spell, consisting of up to 16 uppercase and lowercase letters; MPj is the amount of magic power consumed by the j-th spell (0 ≤ MPj ≤ 99); Targetj is either "Single" or "All", where these indicate the j-th magic gives damage just to a single monster or to all monsters respectively; Damagej is the amount of damage (per monster in case of "All") made by the j-th magic (0 ≤ Damagej ≤ 999999). All the numbers in the input are integers. There is at least one spell that gives non-zero damage to monsters. The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. Output For each dataset, Print in a line the minimum amount of magic power consumed to defeat all the monsters in the input. Example Input 3 8000 15000 30000 3 Flare 45 Single 8000 Meteor 62 All 6000 Ultimate 80 All 9999 0 Output 232 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(): rr = [] def f(n): h = [I() for _ in range(n)] hm = max(h) m = I() ms = [] ma = [] zf = False for _ in range(m): nama,mp,target,damege = LS() mp = int(mp) damege = int(damege) if damege == 0: continue if mp == 0: zf = True continue if target == 'All': ma.append((mp,damege)) else: ms.append((mp,damege)) if zf: return 0 ds = [inf] * (hm+1) ds[0] = 0 for mp, dm in ms: for i in range(dm,hm+1): if ds[i] > mp + ds[i-dm]: ds[i] = mp + ds[i-dm] t = min(ds[-dm+1:]) if ds[-1] > t + dm: ds[-1] = t + dm da = [inf] * (hm+1) da[0] = 0 for mp, dm in ma: for i in range(dm,hm+1): if da[i] > mp + da[i-dm]: da[i] = mp + da[i-dm] t = min(da[-dm+1:]) if da[-1] > t + dm: da[-1] = t + dm for i in range(hm-1,-1,-1): if ds[i] > ds[i+1]: ds[i] = ds[i+1] if da[i] > da[i+1]: da[i] = da[i+1] mm = r = inf for i in range(hm,-1,-1): if mm <= da[i]: continue mm = tp = da[i] for hi in h: if hi > i: tp += ds[hi-i] if r > tp: r = tp return r while True: n = I() if n == 0: break rr.append(f(n)) return '\n'.join(map(str,rr)) print(main()) ``` No
108,596
Provide a correct Python 3 solution for this coding contest problem. Problem C: Earn Big A group of N people is trying to challenge the following game to earn big money. First, N participants are isolated from each other. From this point, they are not allowed to contact each other, or to leave any information for other participants. The game organizer leads each participant, one by one, to a room with N boxes. The boxes are all closed at the beginning of the game, and the game organizer closes all the boxes whenever a participant enters the room. Each box contains a slip of paper on which a name of a distinct participant is written. The order of the boxes do not change during the game. Each participant is allowed to open up to M boxes. If every participant is able to open a box that contains a paper of his/her name, then the group wins the game, and everybody in the group earns big money. If anyone is failed to open a box that contains a paper of his/her name, then the group fails in the game, and nobody in the group gets money. Obviously, if every participant picks up boxes randomly, the winning probability will be (M/N)N. However, there is a far more better solution. Before discussing the solution, let us define some concepts. Let P = {p1, p2, ..., pN} be a set of the participants, and B = {b1, b2, ..., bN} be a set of the boxes. Let us define f, a mapping from B to P, such that f(b) is a participant whose name is written on a paper in a box b. Here, consider a participant pi picks up the boxes in the following manner: 1. Let x := i. 2. If pi has already opened M boxes, then exit as a failure. 3. pi opens bx. 1. If f(bx) = pi, then exit as a success. 2. If f(bx) = pj (i != j), then let x := j, and go to 2. Assuming every participant follows the algorithm above, the result of the game depends only on the initial order of the boxes (i.e. the definition of f). Let us define g to be a mapping from P to B, such that g(pi) = bi. The participants win the game if and only if, for every i ∈ {1, 2, ..., N}, there exists k(<=M) such that (f<image>g)k (pi) = pi. Your task is to write a program that calculates the winning probability of this game. You can assume that the boxes are placed randomly. Input The input consists of one line. It contains two integers N and M (1 <= M <= N <= 1,000) in this order, delimited by a space. Output For given N and M, your program should print the winning probability of the game. The output value should be in a decimal fraction and should not contain an error greater than 10-8. Examples Input 2 1 Output 0.50000000 Input 100 50 Output 0.31182782 "Correct Solution: ``` dp=[1]+[0]*1000 n,m=map(int,input().split()) for i in range(n): j=1 while i+j<=n and j<=m:dp[i+j]+=dp[i]/(n-i);j+=1 print('%.10f'%dp[n]) ```
108,597
Provide a correct Python 3 solution for this coding contest problem. Sunuke received a d-dimensional hypercube with a side length of l1 × ... × ld as a birthday present. Sunuke placed this rectangular parallelepiped so that the range of the i-th coordinate was 0 or more and li or less, and ate the part that satisfied x1 + ... + xd ≤ s. However, xi represents the i-th coordinate. If the volume of the part eaten by Sunuke is V, it can be proved that d! V (V multiplied by the factorial of d) is an integer. Find the remainder of d! V divided by 1,000,000,007. Constraints * 2 ≤ d ≤ 300 * 1 ≤ li ≤ 300 * 0 ≤ s ≤ $ \ sum l_ {i} $ * All inputs are integers Input d l1 .. .. ld s Output Output d! V divided by 1,000,000,007. Examples Input 2 6 3 4 Output 15 Input 5 12 34 56 78 90 123 Output 433127538 "Correct Solution: ``` import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): MOD = 10**9 + 7 D = int(readline()) L = [int(readline()) for i in range(D)] S = int(readline()) dp = [0]*(S+1) dp[S] = 1 for i in range(D): l = L[i] for i in range(l, S+1): dp[i-l] -= dp[i] ans = 0 for i in range(S+1): ans += pow(i, D, MOD) * dp[i] ans %= MOD write("%d\n" % ans) solve() ```
108,598
Provide a correct Python 3 solution for this coding contest problem. Problem There are $ M $ type characters. Use them to create a string of length $ N $. How many strings are used that have $ K $ or more? Find too much divided by $ 998244353 $. Here, the difference between two strings of length $ N $ is defined as follows. * If the two strings are $ S = S_1S_2 \ ldots S_N $, $ T = T_1T_2 \ ldots T_N $, then $ i $$ (1 \ leq i \ leq N) becomes $ S_i \ neq T_i $ ) $ Exists. Constraints The input satisfies the following conditions. * $ 1 \ leq M \ leq 10 ^ {18} $ * $ 1 \ leq N \ leq 10 ^ {18} $ * $ 1 \ leq K \ leq 1000 $ * All inputs are integers Input The input is given in the following format. $ M $ $ N $ $ K $ $ M, N, K $ are given on one line, separated by blanks. Output Output the remainder of the number of characters used in a string of length $ N $ that is greater than or equal to $ K $ divided by $ 998244353 $. Examples Input 2 10 1 Output 1024 Input 1 1 2 Output 0 Input 5 10 3 Output 9755400 Input 7 8 3 Output 5759460 Input 1000000000000000000 1000000000000000000 1000 Output 133611974 "Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 998244353 def solve(): m,n,k = LI() if n < k: print(0) return if m < k: print(0) return ans = pow(m,n,mod) p = [pow(i,n,mod) for i in range(k+1)] c = m comb = [[0 for i in range(i+1)] for i in range(k+1)] comb[0][0] = 1 for i in range(k): for j in range(i+1): comb[i+1][j] += comb[i][j] comb[i+1][j+1] += comb[i][j] for i in range(1,k): k = 0 for j in range(1,i+1)[::-1]: if (i+j)&1: k -= comb[i][j]*p[j] else: k += comb[i][j]*p[j] k *= c c *= (m-i) c *= pow(i+1,mod-2,mod) c %= mod ans -= k ans %= mod print(ans) return if __name__ == "__main__": solve() ```
108,599