output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s811462678
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
i = int(input()).split(" ") print((i[0] * i[1]) + " " + (i[0] * 2 + i[1] * 2))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s334139318
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x = int(input()) ** 2 y = int(input()) ** 2 print("{0:d} {1:d}".format(x, y))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s860696508
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
a = input.split() print(int(a[0]) * int(a[1]) + " " + 2 * (int(a[0]) + int(a[1])))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s404247801
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x1 = input() x2 = input() x1 = int(x1) x2 = int(x2) x3 = x1 + x2 print(x3)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s829394619
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x = int(input().split()) s = x[0] * x[1] l = 2 * x[0] + 2 * x[1] print("{0} {1}", format(x[0], x[1]))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s875182525
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
row = input().split() print(row[0] * row[1], 2 * (row[0] + row[1]))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s444834696
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x = map(int, input().split(" ")) z = x[0] * x[1] a = (x[0] + x[1]) * 2 print(z, a)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s361298096
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
str = input() a = str[0] b = str[2] print(a*b, end='') print((a+b)*2)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s658632885
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
n, m = map(int, input().split()) print(n * m, 2 * n + 2 * m)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s026751046
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
ary = input().split(" ") print(ary(0) * ary(1))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s532808266
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
print(3 * 5, 2 * (3 + 5))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s002792504
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
dim = list(map(int, input().split(" "))) w, h = dim[0], dim[1] print(w * h) print(2 * (w + h))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s658640866
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
c = input() csp = c.split() print(int(csp[0]) * int(csp[1]), (int(csp[0]) + int(csp[1])) * 2)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s018380801
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
l, w = list(map(int, input().split(" "))) print(f"{l * w} {(l + w) * 2}")
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s569447673
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
y, z = map(int, input().split()) print((y * z), ((y + z) * 2), sep=" ")
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s277195317
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
w, h = map(int, input().split()) print("{} {}".format(w * h, (w + h) * 2))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s965495355
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
list1 = [int(i) for i in input().split()] print("{0} {1}")
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s211270757
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x = str(input()) n = x.split(" ", 2) a = int(n[0]) b = int(n[1]) ab = a * b a_b = (a + b) * 2 print("ab", end=" ") print("a_b")
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s328475741
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x, y = input().split(" ") z = (x + y) * 2 print(z)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s382977535
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
line = list(map(int, input().split())) a = line[0] b = line[1] result1 = str(a * b) result2 = str((a + b) * 2) print(result1 + " " + result2)
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]
Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. * * *
s903488378
Wrong Answer
p02673
Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N
n = int(input()) print(n**2)
Statement You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? **Note** : The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a _finite_ number of turns.
[{"input": "5\n 4 2 6 3 5\n 1 1 1 1 1", "output": "4.700000000000\n \n\n* * *"}, {"input": "4\n 100 0 100 0\n 0 100 0 100", "output": "50.000000000000\n \n\n* * *"}, {"input": "14\n 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912\n 34 54 61 32 52 61 21 43 65 12 45 21 1 4", "output": "7047.142857142857\n \n\n* * *"}, {"input": "10\n 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951\n 26 83 30 59 100 88 84 91 54 61", "output": "815899161079.400024414062"}]
Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. * * *
s869155002
Accepted
p02673
Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N
from bisect import bisect_right def det(p1, p2, p3): area = (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) return area > 0 def convex_hull(pts): pts = sorted(pts) n = len(pts) extsize = 0 extpts = [] for i in range(n): while extsize > 1: if det(extpts[-2], extpts[-1], pts[i]): break extsize -= 1 extpts.pop() extpts.append(pts[i]) extsize += 1 t = extsize for i in range(n - 1, -1, -1): while extsize > t: if det(extpts[-2], extpts[-1], pts[i]): break extsize -= 1 extpts.pop() extpts.append(pts[i]) extsize += 1 return extpts[:-1] n = int(input()) aa = [int(x) for x in input().split()] bb = [int(x) for x in input().split()] ma = max(aa) ind = -1 for i in range(n): if ma == aa[i]: ind = i break a = aa[i:] + aa[: i + 1] b = bb[i:] + bb[: i + 1] c = [0] * (n + 1) for i in range(2, n + 1): c[i] = 2 * (c[i - 1] + b[i - 1]) - c[i - 2] pts = [] for i in range(n + 1): pts.append((i, a[i] - c[i])) f = [-(10**15)] * (n + 1) ext = [] for i, val in convex_hull(pts): if val * n < (a[0] - c[0]) * (n - i) + (a[n] - c[n]) * i: continue f[i] = val ext.append(i) ext = sorted(ext) for i in range(n + 1): if f[i] == -(10**15): t = bisect_right(ext, i) l = ext[t - 1] r = ext[t] f[i] = f[l] + (i - l) * (f[r] - f[l]) / (r - l) ans = 0 for i in range(1, n + 1): ans += f[i] + c[i] print(f"{ans/n:.12f}")
Statement You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? **Note** : The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a _finite_ number of turns.
[{"input": "5\n 4 2 6 3 5\n 1 1 1 1 1", "output": "4.700000000000\n \n\n* * *"}, {"input": "4\n 100 0 100 0\n 0 100 0 100", "output": "50.000000000000\n \n\n* * *"}, {"input": "14\n 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912\n 34 54 61 32 52 61 21 43 65 12 45 21 1 4", "output": "7047.142857142857\n \n\n* * *"}, {"input": "10\n 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951\n 26 83 30 59 100 88 84 91 54 61", "output": "815899161079.400024414062"}]
Print the sum of the page numbers of the pages he has to check, as modulo 10^9 + 7. * * *
s809828357
Wrong Answer
p03961
The input is given from Standard Input in the following format: N P_1 P_2 ... P_N
import math import itertools def read(): return int(input()) def reads(sep=None): return list(map(int, input().split(sep))) cache = {} def fact(n): if n not in cache: cache[n] = math.factorial(n) return cache[n] def f(p, l): r = 0 x = list(range(1, l + 1)) for i in range(l - 2): r += x.index(p[i]) * fact(l - i - 1) x.remove(p[i]) if 2 <= len(p): if p[-1] < p[-2]: r += 1 return r + 1 def main(): m = 10**9 + 7 n = read() p = reads() if 3000 < n: return r = 0 a = set(range(1, n + 1)) - set(p) for x in itertools.permutations(a): np = p[:] i = 0 for j in range(n): if np[j] == 0: np[j] = x[i] i += 1 r = (r + f(np, n)) % m print(r) main()
Statement One day Mr. Takahashi picked up a dictionary containing all of the N! permutations of integers 1 through N. The dictionary has N! pages, and page i (1 ≤ i ≤ N!) contains the i-th permutation in the lexicographical order. Mr. Takahashi wanted to look up a certain permutation of length N in this dictionary, but he forgot some part of it. His memory of the permutation is described by a sequence P_1, P_2, ..., P_N. If P_i = 0, it means that he forgot the i-th element of the permutation; otherwise, it means that he remembered the i-th element of the permutation and it is P_i. He decided to look up all the possible permutations in the dictionary. Compute the sum of the page numbers of the pages he has to check, modulo 10^9 + 7.
[{"input": "4\n 0 2 3 0", "output": "23\n \n\nThe possible permutations are [1, 2, 3, 4] and [4, 2, 3, 1]. Since the former\nis on page 1 and the latter is on page 22, the answer is 23.\n\n* * *"}, {"input": "3\n 0 0 0", "output": "21\n \n\nSince all permutations of length 3 are possible, the answer is 1 + 2 + 3 + 4 +\n5 + 6 = 21.\n\n* * *"}, {"input": "5\n 1 2 3 5 4", "output": "2\n \n\nMr. Takahashi remembered all the elements of the permutation.\n\n* * *"}, {"input": "1\n 0", "output": "1\n \n\nThe dictionary consists of one page.\n\n* * *"}, {"input": "10\n 0 3 0 0 1 0 4 0 0 0", "output": "953330050"}]
Print the sum of the page numbers of the pages he has to check, as modulo 10^9 + 7. * * *
s397380981
Wrong Answer
p03961
The input is given from Standard Input in the following format: N P_1 P_2 ... P_N
""" https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_e ページの合計に与える寄与を考えればよい ある位置iにある数字の与える寄与は (自分より右にある数字の数)! * 自分より右にあるより小さい数字の数 元からおかれている数字同士に関しての寄与はBITで終わり 元からおかれている数字 & 自由な数字の寄与は 順列の総数 * 自由な数字の中で自分より小さいものの数 * 右にある空欄の数 / 全ての空欄の数 * fac[N-1-i] 順列の総数 * 自由な数字の中で自分より大きいものの数 * 左にある空欄の数 / 全ての空欄の数 * fac[N-1-i] で求まる 自由同士は、半分になるはずなので fac[N-1-i] * 右にある0の数 // 2 それより左にあるfacの平均を出す?→avrage 順列の総数 * 自由な数字の中で自分より大きいものの数 * 左にある空欄の数 / 全ての空欄の数 * average """ mod = 10**9 + 7 # 逆元 def inverse(a, mod): # aのmodを法にした逆元を返す return pow(a, mod - 2, mod) # modのn!と、n!の逆元を格納したリストを返す(拾いもの) # factorialsには[1, 1!%mod , 2!%mod , 6!%mod… , n!%mod] が入っている # invsには↑の逆元が入っている def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m inv %= MOD invs[m - 1] = inv return factorials, invs def modnCr( n, r, mod, fac, inv ): # 上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる) return fac[n] * inv[n - r] * inv[r] % mod def bitadd(a, w, bit): # aにwを加える(1-origin) x = a while x <= (len(bit) - 1): bit[x] += w x += x & (-1 * x) def bitsum(a, bit): # ind 1~aまでの和を求める ret = 0 x = a while x > 0: ret += bit[x] x -= x & (-1 * x) return ret import sys from sys import stdin N = int(stdin.readline()) a = list(map(int, stdin.readline().split())) BIT = [0] * (N + 1) fac, inv = modfac(N + 10, mod) zeronum = 0 ans1 = 0 RZ = [0] * N app = [False] * (N + 1) app[0] = True for i in range(N - 1, -1, -1): if a[i] != 0: ans1 += fac[N - 1 - i] * (bitsum(a[i], BIT)) ans1 %= mod bitadd(a[i], 1, BIT) app[a[i]] = True else: zeronum += 1 RZ[i] = zeronum mEX = [0] * (N + 1) # 数字x以下の数がいくつあるか for i in range(1, N + 1): if app[i] == False: mEX[i] = mEX[i - 1] + 1 else: mEX[i] = mEX[i - 1] ans1 *= fac[zeronum] ans2 = 0 ans3 = 0 tmpinv = inverse(zeronum, mod) tmpsum = 0 for i in range(N): if a[i] != 0: ans2 += fac[zeronum] * mEX[a[i]] * RZ[i] * tmpinv * fac[N - 1 - i] ans2 += fac[zeronum] * (zeronum - mEX[a[i]]) * tmpinv * tmpsum ans2 %= mod else: ans3 += fac[N - 1 - i] * fac[zeronum] * (RZ[i] - 1) // 2 tmpsum += fac[N - 1 - i] print(ans1, ans2, ans3, fac[zeronum], file=sys.stderr) print((ans1 + ans2 + ans3 + fac[zeronum]) % mod)
Statement One day Mr. Takahashi picked up a dictionary containing all of the N! permutations of integers 1 through N. The dictionary has N! pages, and page i (1 ≤ i ≤ N!) contains the i-th permutation in the lexicographical order. Mr. Takahashi wanted to look up a certain permutation of length N in this dictionary, but he forgot some part of it. His memory of the permutation is described by a sequence P_1, P_2, ..., P_N. If P_i = 0, it means that he forgot the i-th element of the permutation; otherwise, it means that he remembered the i-th element of the permutation and it is P_i. He decided to look up all the possible permutations in the dictionary. Compute the sum of the page numbers of the pages he has to check, modulo 10^9 + 7.
[{"input": "4\n 0 2 3 0", "output": "23\n \n\nThe possible permutations are [1, 2, 3, 4] and [4, 2, 3, 1]. Since the former\nis on page 1 and the latter is on page 22, the answer is 23.\n\n* * *"}, {"input": "3\n 0 0 0", "output": "21\n \n\nSince all permutations of length 3 are possible, the answer is 1 + 2 + 3 + 4 +\n5 + 6 = 21.\n\n* * *"}, {"input": "5\n 1 2 3 5 4", "output": "2\n \n\nMr. Takahashi remembered all the elements of the permutation.\n\n* * *"}, {"input": "1\n 0", "output": "1\n \n\nThe dictionary consists of one page.\n\n* * *"}, {"input": "10\n 0 3 0 0 1 0 4 0 0 0", "output": "953330050"}]
If no arrangements satisfy the conditions, print `-1`. If such arrangements exist, print the lexicographically smallest such arrangement, in the following format: b_1 b_2 \ldots b_N Here, b_i represents the i-th card from the left. * * *
s682308465
Wrong Answer
p02809
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") n = int(input()) a = list(map(int, input().split())) if n == 2: ans = -1 else: from collections import Counter c = Counter(a) from heapq import heappush as hp, heappop as hpp h = [] for i in range(1, n + 1): hp(h, i) ans = [1] ban = a[0] done = [False] * (n + 1) done[1] = True c[a[0]] -= 1 for i in range(n - 1): if len(c) == 2 and max(c.values()) == sum(c.values()) - 1: # print(c, ans) hp(h, ans.pop()) if c[a[0]] == n - 1: v0 = a[0] else: v0 = a[1] ans.append(v0) while h: u = hpp(h) if u != v0: ans.append(u) break flg = False # print(h, done) while h: num = hpp(h) # print(num) if num == ban: flg = True elif done[num]: pass else: # print("hoge") break if flg: hp(h, ban) # print(ban, num, h) ans.append(num) done[num] = True c[a[num - 1]] -= 1 if c[a[i]] == 0: del c[a[i]] ban = a[num - 1] if ans == -1: print(ans) else: write(" ".join(map(str, ans)))
Statement Niwango has N cards, numbered 1,2,\ldots,N. He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement. * To the immediate right of Card 1 (if any) is NOT Card a_1. * To the immediate right of Card 2 (if any) is NOT Card a_2. * \vdots * To the immediate right of Card N (if any) is NOT Card a_N.
[{"input": "4\n 2 3 4 1", "output": "1 3 2 4\n \n\n * The arrangement (1,2,3,4) is lexicographically smaller than (1,3,2,4), but is invalid, since it violates the condition \"to the immediate right of Card 1 is not Card 2.\"\n\n* * *"}, {"input": "2\n 2 1", "output": "-1\n \n\n * If no arrangements satisfy the conditions, print `-1`.\n\n* * *"}, {"input": "13\n 2 3 4 5 6 7 8 9 10 11 12 13 12", "output": "1 3 2 4 6 5 7 9 8 10 12 11 13"}]
If no arrangements satisfy the conditions, print `-1`. If such arrangements exist, print the lexicographically smallest such arrangement, in the following format: b_1 b_2 \ldots b_N Here, b_i represents the i-th card from the left. * * *
s616802038
Wrong Answer
p02809
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N
def main(): N = int(input()) a = [int(s) for s in input().split()] cards = list(a) cards.sort() output = [1] cards = list(range(2, N + 1)) for i in range(1, N): found = False for c in cards: if c != a[output[i - 1] - 1]: cards.remove(c) output.append(c) found = True break if not found: print(-1) return print(" ".join([str(i) for i in output])) if __name__ == "__main__": main()
Statement Niwango has N cards, numbered 1,2,\ldots,N. He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement. * To the immediate right of Card 1 (if any) is NOT Card a_1. * To the immediate right of Card 2 (if any) is NOT Card a_2. * \vdots * To the immediate right of Card N (if any) is NOT Card a_N.
[{"input": "4\n 2 3 4 1", "output": "1 3 2 4\n \n\n * The arrangement (1,2,3,4) is lexicographically smaller than (1,3,2,4), but is invalid, since it violates the condition \"to the immediate right of Card 1 is not Card 2.\"\n\n* * *"}, {"input": "2\n 2 1", "output": "-1\n \n\n * If no arrangements satisfy the conditions, print `-1`.\n\n* * *"}, {"input": "13\n 2 3 4 5 6 7 8 9 10 11 12 13 12", "output": "1 3 2 4 6 5 7 9 8 10 12 11 13"}]
If no arrangements satisfy the conditions, print `-1`. If such arrangements exist, print the lexicographically smallest such arrangement, in the following format: b_1 b_2 \ldots b_N Here, b_i represents the i-th card from the left. * * *
s293992409
Wrong Answer
p02809
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N
N = int(input()) a_list = list(map(lambda a: int(a) - 1, input().strip().split())) data = list(range(N)) def move(): for i in range(0, N - 1): a0 = data[i] a1 = data[i + 1] if a_list[a0] == a1: if i < N - 2: data[i + 1] = data[i + 2] data[i + 2] = a1 else: return False return True if move(): print(" ".join([str(d + 1) for d in data])) else: print("-1")
Statement Niwango has N cards, numbered 1,2,\ldots,N. He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement. * To the immediate right of Card 1 (if any) is NOT Card a_1. * To the immediate right of Card 2 (if any) is NOT Card a_2. * \vdots * To the immediate right of Card N (if any) is NOT Card a_N.
[{"input": "4\n 2 3 4 1", "output": "1 3 2 4\n \n\n * The arrangement (1,2,3,4) is lexicographically smaller than (1,3,2,4), but is invalid, since it violates the condition \"to the immediate right of Card 1 is not Card 2.\"\n\n* * *"}, {"input": "2\n 2 1", "output": "-1\n \n\n * If no arrangements satisfy the conditions, print `-1`.\n\n* * *"}, {"input": "13\n 2 3 4 5 6 7 8 9 10 11 12 13 12", "output": "1 3 2 4 6 5 7 9 8 10 12 11 13"}]
If no arrangements satisfy the conditions, print `-1`. If such arrangements exist, print the lexicographically smallest such arrangement, in the following format: b_1 b_2 \ldots b_N Here, b_i represents the i-th card from the left. * * *
s105990868
Wrong Answer
p02809
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N
print(-1)
Statement Niwango has N cards, numbered 1,2,\ldots,N. He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement. * To the immediate right of Card 1 (if any) is NOT Card a_1. * To the immediate right of Card 2 (if any) is NOT Card a_2. * \vdots * To the immediate right of Card N (if any) is NOT Card a_N.
[{"input": "4\n 2 3 4 1", "output": "1 3 2 4\n \n\n * The arrangement (1,2,3,4) is lexicographically smaller than (1,3,2,4), but is invalid, since it violates the condition \"to the immediate right of Card 1 is not Card 2.\"\n\n* * *"}, {"input": "2\n 2 1", "output": "-1\n \n\n * If no arrangements satisfy the conditions, print `-1`.\n\n* * *"}, {"input": "13\n 2 3 4 5 6 7 8 9 10 11 12 13 12", "output": "1 3 2 4 6 5 7 9 8 10 12 11 13"}]
Print the minimum total cost to achieve Evi's objective. * * *
s089080330
Accepted
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
# Nの入力受付 N = int(input()) # aの入力受付 aN = list(map(int, input().split())) # 平均の値を計算 S = 0 A = 0 for i in aN: S += i A = S / N if A - int(A) < 0.5: A = int(A) else: A = int(A) + 1 # Aにすべて書き換えるときのコストを計算 R = 0 for i in aN: R += (i - A) ** 2 print(R)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s155513473
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = input() a = list(map(int,input().split())) b,c= 0,0 s =[] a.sort() for i in range(0,N): b += a[i] for i in range(0,N): c += a[i]**2 for i in range(a[0]a[N]): s.append = 3*(i**2)-2*b+c m = min(s) print(m)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s717609511
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = int(input()) list = [int(a) for a in input().split()] A = sum(list)//N for i in range(-100:100): for j in range(N): sum = 0 sum_new = 0 sum = sum + (list[j] - A) ** 2 sum_new = sum_new + (list[j] - i) ** 2 if(sum > sum_new): sum = sum_new print(sum)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s421207641
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = int(input()) list = [int(a) for a in input().split()] A = sum(list)//N for i in range(-100:100): for j in range(N): sum = (list[j] - A) ** 2 sum_new = (list[j] - i) ** 2 if(sum > sum_new): sum = sum_new print(sum)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s461117161
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = int(input()) list = [int(a) for a in input().split()] A = sum(list)//N for i in range(-100:100): sum = (list[i] - A) ** 2 sum_new = (list[i] - i) ** 2 if(sum > sum_new): sum = sum_new print(sum)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s553861703
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = int(input()) list = [int(a) for a in input().split()] A = sum(list)//N sum = 0 sum_new = 0 for i in range(-100:100): for j in range(N): sum = sum + (list[j] - A) ** 2 sum_new = sum_new + (list[j] - i) ** 2 if(sum > sum_new): sum = sum_new print(sum)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s127585555
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = int(input()) list = [int(a) for a in input().split()] A = sum(list)//N sum = 0 sum_new = 0 for i in range(-100:100): for j in range(N): sum = sum + (list[j] - A) ** 2 sum_new = (list[j] - i) ** 2 if(sum > sum_new): sum = sum_new print(sum)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s188535407
Wrong Answer
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
x = int() y = int() sum = x + y transform = (sum - x) * (sum - y) print(transform)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s221262358
Wrong Answer
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) num = list(map(int, input().split())) set_num = set(num) mid = sum(set_num) / len(set_num) sol = 0 for i in num: sol += (i - mid) ** 2 print(int(sol))
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s930718146
Accepted
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = int(input()) A = [int(x) for x in input().split()] def solve(A): def cost(x): return sum((x - a) ** 2 for a in A) l = min(A) r = max(A) l = -100 r = 100 while r - l >= 3: d = (r - l) // 3 m1 = l + d m2 = m1 + d # print(cost(l), cost(r), "d=%d"%d, (l, m1, m2, r)) L = [(cost(l), l), (cost(r), r), (cost(m1), m1), (cost(m2), m2)] # print(L) (_, r), (_, l) = sorted(L)[:2] if l > r: r, l = l, r # print("l=%d, r=%d" % (l,r)) c, a = sorted([(cost(i), i) for i in range(l, r + 1)])[0] print(c) solve(A)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s972841752
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) l = list(map(int, input().split())) mn = min(l) mx = max(l) ms = 10**9 ll = [0]*n for j in range(mn, mx+1): for i in range(n): ll[i] = (l[i] - j)**2 s = sum(ll) ms = min(ms, s) print(ms)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s451917256
Accepted
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
N = input() list1 = list(map(int, input().split())) list2 = [] for i in range(min(list1), max(list1) + 1): a = 0 for j in range(len(list1)): a += (list1[j] - i) ** 2 list2.append(a) print(min(list2))
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s720670278
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
# include <algorithm> # include <cassert> # include <cctype> # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <iostream> # include <map> # include <queue> # include <set> # include <sstream> # include <stack> # include <string> # include <vector> # include <iomanip> # define rep(i, n) for (int i = 0; i < (int)(n); i++) # define irep(i, n) for (int i = int(n) - 1; i >= 0; i--) # define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<int> A(N); rep (i, N) cin >> A[i]; double mean = 0.0; rep (i, N) mean += A[i]; mean /= A.size(); mean = roundf(mean); ll ans = 0; rep (i, N) { ans += pow(A[i] - mean, 2); } cout << ans << endl; }
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s407733706
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
a,b=int(input()),list(map(int,input().split()));b.sort();c=(b[0]+b[-1])//2;if (b[0]+b[-1])%2==1 and c+1 in b:c+=1;d=[(b[i]-c)**2 for i in range(a)];print(sum(d))
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s404177338
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import statistics n = int(input()) a = list(map(int, input().split()) me = statistics.median(a) ans = 0 for i in range(n): ans += (abs(me, a[i]))**2 print(ans)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s586430448
Accepted
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
""" kari1 = '2' kari2 = '4 8' #8 #kari1 = '3' #kari2 = '1 1 3' #3 #kari1 = '3' #kari2 = '4 2 5' #5 #kari1 = '4' #kari2 = '-100 -100 -100 -100' #0 in1 = kari1 in2 = kari2.split() """ in1 = input() in2 = input().split() AVEa = 0 RC = 0 for item in in2: AVEa = AVEa + int(item) AVEa = round(AVEa / len(in2)) for item in in2: if int(item) != AVEa: RC = RC + ((int(item) - AVEa) ** 2) print(RC)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s111565158
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import math n = int(input()) nums = list(map(int, input().split())) avg_ceil = math.ceil(sum(nums) / len(nums)) avg_floor = math.floor(sum(nums) / len(nums)) cost_ceil = 0 cost_floor = 0 for x in nums: if x == avg_ceil: continue cost_ceil += (x - avg_ceil)**2 for x in nums: if x == avg_floor: continue cost_floor += (x - avg_floor)**2 if cost_ceil <= cost_floor: print(cost_ceil) else print(cost_floor)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s459202690
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
def main(): n = int(input()) nums = list(map(int, input())) cmin = 0 for x in nums: cmin += (x - min(nums)) ** 2 for i in range(min(nums), max(nums)+1): c = getcost(i, nums) if c < cmin: cmin = c print(cmin) def getcost(x, nums): c = 0 for n in nums: c += (n - x) ** 2 return c if __name__ == '__main__': main()
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s044128535
Accepted
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) s = list(map(int, input().split())) total = sum(s) lower_mean = total // n upper_mean = total // n + 1 r1 = sum([(x - lower_mean) ** 2 for x in s]) r2 = sum([(x - upper_mean) ** 2 for x in s]) r = min(r1, r2) print(r)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s154272517
Runtime Error
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import math N = int(input()) a = list(map(int,input().split()) s = 0 t = 0 for i in range(N): s += a[i] t += (a[i])**2 a = math.floor(s/N) if (s/N) - a > 0.5: a += 1 ans = N*a**2 - 2*s*a + t print(ans)
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s881520383
Wrong Answer
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import sys import math def i(): return int(sys.stdin.readline().replace("\n", "")) def i2(): return map(int, sys.stdin.readline().replace("\n", "").split()) def s(): return str(sys.stdin.readline().replace("\n", "")) def l(): return list(sys.stdin.readline().replace("\n", "")) def intl(): return [int(k) for k in sys.stdin.readline().replace("\n", "").split()] def lx(): return list( map(lambda x: int(x) * -1, sys.stdin.readline().replace("\n", "").split()) ) def t(): return tuple(map(int, sys.stdin.readline().replace("\n", "").split())) if __name__ == "__main__": pass n = i() a = intl() if n == 1: print(0) else: s = max(a) + min(a) k1 = s // 2 k2 = s // 2 + s % 2 k3 = s // 2 - 1 c1 = 0 c2 = 0 c3 = 0 for i in range(n): c3 += (a[i] - k3) ** 2 c2 += (a[i] - k2) ** 2 c1 += (a[i] - k1) ** 2 print(min(c1, c2, c3))
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the minimum total cost to achieve Evi's objective. * * *
s157363576
Wrong Answer
p04031
The input is given from Standard Input in the following format: N a_1 a_2 ... a_N
# # Written by NoKnowledgeGG @YlePhan # ('ω') # # import math # mod = 10**9+7 # import itertools # import fractions # import numpy as np # mod = 10**4 + 7 def kiri(n, m): r_ = n / m if (r_ - (n // m)) > 0: return (n // m) + 1 else: return n // m """ n! mod m 階乗 mod = 1e9 + 7 N = 10000000 fac = [0] * N def ini(): fac[0] = 1 % mod for i in range(1,N): fac[i] = fac[i-1] * i % mod""" """mod = 1e9+7 N = 10000000 pw = [0] * N def ini(c): pw[0] = 1 % mod for i in range(1,N): pw[i] = pw[i-1] * c % mod""" """ def YEILD(): yield 'one' yield 'two' yield 'three' generator = YEILD() print(next(generator)) print(next(generator)) print(next(generator)) """ """def gcd_(a,b): if b == 0:#結局はc,0の最大公約数はcなのに return a return gcd_(a,a % b) # a = p * b + q""" """def extgcd(a,b,x,y): d = a if b!=0: d = extgcd(b,a%b,y,x) y -= (a//b) * x print(x,y) else: x = 1 y = 0 return d""" def readInts(): return list(map(int, input().split())) def main(): n = int(input()) A = readInts() SPLIT = kiri(sum(A), n) ANS = 0 # print(SPLIT) for i in range(n): ANS += abs(SPLIT - A[i]) ** 2 print(ANS) if __name__ == "__main__": main()
Statement Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
[{"input": "2\n 4 8", "output": "8\n \n\nTransforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is\nthe minimum.\n\n* * *"}, {"input": "3\n 1 1 3", "output": "3\n \n\nTransforming the all into 2s will cost (1-2)^2+(1-2)^2+(3-2)^2=3 dollars. Note\nthat Evi has to pay (1-2)^2 dollar separately for transforming each of the two\n1s.\n\n* * *"}, {"input": "3\n 4 2 5", "output": "5\n \n\nLeaving the 4 as it is and transforming the 2 and the 5 into 4s will achieve\nthe total cost of (2-4)^2+(5-4)^2=5 dollars, which is the minimum.\n\n* * *"}, {"input": "4\n -100 -100 -100 -100", "output": "0\n \n\nWithout transforming anything, Evi's objective is already achieved. Thus, the\nnecessary cost is 0."}]
Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS. * * *
s960609764
Accepted
p03561
Input is given from Standard Input in the following format: K N
N, K = map(int, input().split()) # 1 2 3...N if N % 2 == 0: L = [str(N)] * K L[0] = str(N // 2) print(" ".join(L)) exit() # L[0]=N//2+1 # N//2のずれ? L = [(N // 2) + 1] * K for i in range(K // 2): if L[-1] == 1: L.pop(-1) elif len(L) != K: L[-1] -= 1 L += [N] * (K - len(L)) else: L[-1] -= 1 L = list(map(str, L)) print(" ".join(L))
Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.
[{"input": "3 2", "output": "2 1 \n \n\nThere are 12 sequences listed in FEIS:\n(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3). The (12/2 =\n6)-th lexicographically smallest one among them is (2,1).\n\n* * *"}, {"input": "2 4", "output": "1 2 2 2\n \n\n* * *"}, {"input": "5 14", "output": "3 3 3 3 3 3 3 3 3 3 3 3 2 2"}]
Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS. * * *
s102760926
Runtime Error
p03561
Input is given from Standard Input in the following format: K N
import sys sys.setrecursionlimit(100500) def F(n): return (k**n - 1) // (k - 1) l = 0 def go(x, n): global l if (x == 1): return x -= 1 t = F(n) c = ((x - 1) // t) print(c + 1, end = ' ') go(x - c * t, n - 1) k, n = [int(i) for i in input().split()] if k % 2 == 0: print(k // 2. end = ' ') for i in range(n - 1): print(k, end = ' ') exit() res = F(n) * k go((res + 1) // 2 + 1, n)
Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.
[{"input": "3 2", "output": "2 1 \n \n\nThere are 12 sequences listed in FEIS:\n(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3). The (12/2 =\n6)-th lexicographically smallest one among them is (2,1).\n\n* * *"}, {"input": "2 4", "output": "1 2 2 2\n \n\n* * *"}, {"input": "5 14", "output": "3 3 3 3 3 3 3 3 3 3 3 3 2 2"}]
Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS. * * *
s103731463
Wrong Answer
p03561
Input is given from Standard Input in the following format: K N
# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline sys.setrecursionlimit(10**5) k, n = map(int, read().split()) if k % 2 == 0: print(*([k // 2] + [k] * (n - 1))) exit() if k == 1: print(*[1] * ((n + 1) // 2)) exit() ans = [(k + 1) // 2] * n d = 0 def f(k, i, d): # d <= 1+k+...+k^i? v = 1 for j in range(i): v *= k v += 1 if v > d: return True return False def g(k, i): # 1+k+...+k^i v = 1 for j in range(i): v *= k v += 1 return v for i in range(1, n): if f(k, n - i - 1, d): d += 1 continue """ 以下 300000 >= d >= 1+k+...+k^(n-i-1) i 番目の項から真ん中にならない v 番目を目指す """ v = (g(k, n - i) + d) // 2 - d - 1 for j in range(i, n): # print(v) if v == 0: ans[j] = 0 continue p = g(k, n - j - 1) q = (v - 1) // p # print(v,j,p,q) ans[j] = q + 1 v -= 1 + q * p break while ans[-1] == 0: ans.pop() print(ans)
Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.
[{"input": "3 2", "output": "2 1 \n \n\nThere are 12 sequences listed in FEIS:\n(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3). The (12/2 =\n6)-th lexicographically smallest one among them is (2,1).\n\n* * *"}, {"input": "2 4", "output": "1 2 2 2\n \n\n* * *"}, {"input": "5 14", "output": "3 3 3 3 3 3 3 3 3 3 3 3 2 2"}]
Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS. * * *
s599691788
Runtime Error
p03561
Input is given from Standard Input in the following format: K N
import sys sys.setrecursionlimit(100500) def F(n): return (k**n - 1) // (k - 1) l = 0 def go(x, n): global l if x == 1: return x -= 1 t = F(n) c = (x - 1) // t print(c + 1, end=" ") go(x - c * t, n - 1) k, n = [int(i) for i in input().split()] res = F(n) * k go((res + 1) // 2 + 1, n)
Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.
[{"input": "3 2", "output": "2 1 \n \n\nThere are 12 sequences listed in FEIS:\n(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3). The (12/2 =\n6)-th lexicographically smallest one among them is (2,1).\n\n* * *"}, {"input": "2 4", "output": "1 2 2 2\n \n\n* * *"}, {"input": "5 14", "output": "3 3 3 3 3 3 3 3 3 3 3 3 2 2"}]
Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS. * * *
s725967436
Runtime Error
p03561
Input is given from Standard Input in the following format: K N
from math import ceil k, n = [int(x) for x in input().strip().split()] li = [pow(k, i) for i in range(1, n + 1)] for i in range(1, n): li[i] += li[i - 1] li.reverse() li.append(0) li.append(-1) target = ceil(li[0] / 2) results = [] # print(li) def f(i, target): if target == 0: return if li[i] == -1: return div = (target - 1) // (li[i] + 1) results.append(div + 1) # print(i, target, results) f(i + 1, (target - 1) % (li[i] + 1)) f(1, target) print(" ".join(map(str, results)))
Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.
[{"input": "3 2", "output": "2 1 \n \n\nThere are 12 sequences listed in FEIS:\n(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3). The (12/2 =\n6)-th lexicographically smallest one among them is (2,1).\n\n* * *"}, {"input": "2 4", "output": "1 2 2 2\n \n\n* * *"}, {"input": "5 14", "output": "3 3 3 3 3 3 3 3 3 3 3 3 2 2"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s274317962
Accepted
p03131
Input is given from Standard Input in the following format: K A B
k, a, b = map(int, input().split()) i = a - 1 c = a j = k - i c += b * (j // 2) c -= a * (j // 2) print(max(k + 1, c + j % 2))
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s506338361
Wrong Answer
p03131
Input is given from Standard Input in the following format: K A B
S, A, B = map(int, input().split()) K = S bis = 0 while K > 0: K -= A bis //= A bis += B * max(bis // A, 1) print(bis - 1)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s132895795
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
k,a,b=map(int, input().split()) #aaaabできる。cが… if a+3<=b and k>=a+1: # if a%2==0 and k%2==0: print(b+1) if a%2==0 and not k%2==0: print(2b+a) if not a%2==0 and k%2==0: print(a+1) if not a%2==0 and not k%2==0: print(2b+a) if not a+3<=b or not k>=a+1: print(a+1)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s623066096
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
k,a,b=map(int, input().split()) #aaaabできる。cが… if a+3<=b and k>=a+1: # if a%2==0 and k%2==0: print(b+1) if a%2==0 and not k%2==0: print(2b+a) if not a%2==0 and k%2==0: print(a+1) if not a%2==0 and not k%2==0: print(2b+a)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s953576379
Accepted
p03131
Input is given from Standard Input in the following format: K A B
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# K, A, B = IL() if B - A <= 2: print(1 + K) else: if K <= A: print(1 + K) else: L = K - (A - 1) print(A + (B - A) * (L // 2) + L % 2)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s597874817
Wrong Answer
p03131
Input is given from Standard Input in the following format: K A B
from math import log k, a, b = [int(i) for i in input().split()] N = [] for n in range(1, (k + 1) // a + 1): x = n * a - 1 # y = int(log((b/a-1)*k+1, b/a)) # z = y # m = 1 + x - a*y + b*z # y = y+1 # z= z+1 # mm = 1 + x - a*y + b*z # mmm = [m, mm] # N.append(max(mmm)) y = (k - x) // 2 z = y N.append(1 + x - a * y + b * z) N.append(k + 1) print(max(N))
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s539261043
Wrong Answer
p03131
Input is given from Standard Input in the following format: K A B
k, a, b = map(int, input().split()) bisc = 1 yen = 0 if b - a >= 2: k -= a while k - yen > 0: k -= a yen += 1 bisc += k bisc += yen * b else: bisc += k print(bisc)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s767658252
Wrong Answer
p03131
Input is given from Standard Input in the following format: K A B
a = input() b = a.split() k = int(b[0]) A = int(b[1]) B = int(b[2]) count = 1 coin = 0 for i in range(k): if coin == 1: count += B coin -= 1 elif count <= A and i != k: count += 1 else: count -= A coin += 1 print(count)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s656878216
Wrong Answer
p03131
Input is given from Standard Input in the following format: K A B
a = list(map(int, input().split())) t = a[0] + 1 gett = a[1] + 2 cycle = t // gett amari = t % gett biske = 0 if a[2] / gett > 1: biske = a[2] * cycle + amari else: biske = t print(biske)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s279979059
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
import math K,A,B = map(int, input().split()) cookie = 0 if K >= A or B > 1 + 2A : cookie = B K = K-A-1 if K%2==0: cookie += (B-A)* math.floor(K/2) print(cookie) else: cookie += (B-A)*math.floor((K-1)/2) print(cookie + 1) else: print(K + 1)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s568934153
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
k,a,b = map(int,input().split()) n=1 e=0 for i in range(k): if (k-i)%2=0: if e=1: n=n+b continue if n>=a: e=1 n=n-a continue else n=n+1 continue print(n)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s265401482
Accepted
p03131
Input is given from Standard Input in the following format: K A B
# _*_ coding:utf-8 _*_ # Atcoder_YahooMinnanoProcon_Contest-C # TODO https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_c def solveProblem(operation, bis2moneyone, onemoney2bis): if (onemoney2bis - bis2moneyone) <= 1: # This case all hit pocket answer = operation + 1 else: # まず、お金と交換できるまでのビスケットが起点になる answer = bis2moneyone # たたいて後から出来る操作数 remainOperation = operation - (bis2moneyone - 1) # ビスケット⇔お金の操作可能数。 changeMoney2Bis = remainOperation // 2 # その分ビスケット→お金→ビスケットにしたときの差が増やせる answer = answer + changeMoney2Bis * (onemoney2bis - bis2moneyone) # さらに操作が可能か。可能であればプラスする answer = answer + remainOperation % 2 return answer if __name__ == "__main__": K, A, B = map(int, input().strip().split(" ")) solution = solveProblem(K, A, B) print("{}".format(solution))
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s087967971
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
in_list = input().split() K = int(in_list[0]) A = int(in_list[1]) B = int(in_list[2]) if(A>=B): print(K) else: if(B/A<2): rest = 2 bis = K-1 else: rest = K-A+1 bis = A coin = 0 if(rest%2==1): bis = A+1 rest-=1 print(bis,rest) for i in range(rest): %print(bis,coin) if(i%2==0): change = int(bis/A) bis -= A*change coin = 1*change else: bis += B*coin coin = 0 print(bis)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s160641628
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
K, A, B = map(int, input().split()) K1 = K - (A + 1) n = K1 // 2 print(max(K + 1, ((n + 1) * B - n * A + K1 % 2))) # K, A, B = map(int, input().split()) ( print(A + ((K - A + 1) // 2) * (B - A) + (K - A + 1) % 2) if (B - A > 2 and K - A > 0) else print(K + 1) ) # k, a, b = map(int, input().split()) if a + 2 > b: print(k + 1) else: print(a - 1 + (b - a) * (k - a + 1) // 2 + (k - a + 1) % 2)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s274728952
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
import math k,a,b=map(int,input().split()) s=1: if b-a<=2 or k-1<2: print(k+1) else: t=max(0,math.ceil((k−(a−1))/2)) ans=a k-=a-1 if k%2==1: ans+=1 k-=1 ans+=(b-a)*k print(ans)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s963885940
Accepted
p03131
Input is given from Standard Input in the following format: K A B
# -*- coding: utf-8 -*- def f(k, a, b): if b - a <= 0: return k + 1 elif k + 1 < a: return k + 1 else: res1 = k + 1 res2 = b k -= 1 + a # print(k,res2) if k > 0: res2 += (b - a) * (k // 2) res2 += k % 2 elif k < 0: res2 = -1 return max(res1, res2) def f2(k, a, b): k_ = k res = 1 while k > 0 and res < a: res += 1 k -= 1 res += (b - a) * (k // 2) res += k % 2 return max(res, k_ + 1) if __name__ == "__main__": k, a, b = map(int, input().split()) print(f(k, a, b)) # print(f(3,3,5)) # from random import randint # for _ in range(1000): # k = randint(1,100) # a = randint(1,100) # b = randint(1,100) # res1 = f(k,a,b) # res2 = f2(k,a,b) # if res1!=res2: # print(k,a,b) # print(res1,res2) # break
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
Print the maximum possible number of biscuits in Snuke's pocket after K operations. * * *
s655650026
Runtime Error
p03131
Input is given from Standard Input in the following format: K A B
N = int(input()) b = input().split() b = [int(i) for i in b] ans = 1 def check(n): global b global ans for i in range(1, n + 1): if not b[0] == 1: ans = 0 elif b[i - 1] <= i: b[i - 1 - (b[i - 1])], b[i - 1] = b[i - 1], b[i - 1 - (b[i - 1])] else: ans = 0 return b b = check(N) if ans == 0: print(-1) else: for i in b: print(i)
Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
[{"input": "4 2 6", "output": "7\n \n\nThe number of biscuits in Snuke's pocket after K operations is maximized as\nfollows:\n\n * Hit his pocket. Now he has 2 biscuits and 0 yen.\n * Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen.\n * Hit his pocket. Now he has 1 biscuits and 1 yen.\n * Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen.\n\n* * *"}, {"input": "7 3 4", "output": "8\n \n\n* * *"}, {"input": "314159265 35897932 384626433", "output": "48518828981938099"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s037608481
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
def play(): card_a = input() card_b = input() card_c = input() s = 0 while 1: if s == 0: if card_a[0] == a: s = 0 if card_a[0] == b: s = 1 if card_a[0] == c: s = 2 card_a = card_a[1:] if card_a == "": print("A") break if s == 1: if card_b[0] == a: s = 0 if card_b[0] == b: s = 1 if card_b[0] == c: s = 2 card_b = card_b[1:] if card_a == "": print("B") break if (s == 2) if card_c[0] == a: s = 0 if card_c[0] == b: s = 1 if card_c[0] == c: s = 2 card_c = card_c[1:] if card_a == "": print("C") break play()
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s989552287
Wrong Answer
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
# encoding:utf-8 import copy import random import bisect # bisect_left これで二部探索の大小検索が行える import fractions # 最小公倍数などはこっち import math import sys mod = 10**9 + 7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 S = [0, 0, 0] for i in range(3): S[i] = str(input()) a, b, c = 0, 0, 0 next = "a" def check(a, b, c, next): if next == "a": a += 1 try: next = S[0][a] except: return 0, 0, 0, 0, "A" elif next == "b": b += 1 try: next = S[1][b] except: return 0, 0, 0, 0, "B" else: c += 1 try: next = S[2][c] except: return 0, 0, 0, 0, "C" return a, b, c, next, 0 while True: a, b, c, next, ans = check(a, b, c, next) if ans != 0: break print(ans)
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s664499110
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
A = list(input()) B = list(input()) C = list(input()) li = [A, B, C] sw = True k = 0 while sw == True: if li[k][0] == "a": del li[k][0] k = 0 elif li[k][0] == "b": del li[k][0] k = 1 elif li[k][0] == "c": del li[k][0] k = 2 if li[k] == []: sw = False ans = ["A", "B", "C"] print(ans[k])
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s011658056
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
dic = {} dic.setdefault("a", str(input()) + "E") dic.setdefault("b", str(input()) + "E") dic.setdefault("c", str(input()) + "E") dare = dic["a"][0] dic["a"] = dic["a"][1:] while len(dic["a"]) > 0 and len(dic["b"]) > 0 and len(dic["c"]) > 0: tmp = dic[dare][0] dic[dare] = dic[dare][1:] if tmp == "E": ans = dare.upper() dare = tmp print(ans)
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s208088283
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
lis = [input() for _ in range(3)] len = [len(lis[i]) for i in range(3)] idx = [0,0,0] name = ['a','b','c'] turn = 0 while 1: if len[turn] <= idx[turn]: print(name(turn)) exit() else: tmp = ord(lis[turn][idx[turn]])-ord('a') idx[turn] += 1 turn = tmp
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s396494275
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
A, B, C = [input() for _ in range(3)] T = {"a": A, "b": B, "c": C} player = "a" card = "a" while len(T[player]) > 0: card = T[player][0] T[player] = T[player][1:] player = card else: print(player.upper())
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s246446223
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
S = {p: list(input().upper()) for p in "ABC"} p = "A" while S[p]: p = S[p].pop(0) print(p)
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s690778089
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
ma=input() mb=input() mc=input() mdic={"a":ma,"b":mb,"c":mc} m="a" i=0 ndic={"a":0,"b":0,"c":0} while ndic[m]=<len(mdic[m]): m=mdic[m][ndic[m]] ndic[m]+=1 print(m.upper())
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s867583426
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
lis=[] ll=["a","b","c"] for i in range(3): lis.append(list(input())) turn=0 while 1: x=ll.index(lis[turn].pop()) if lis[turn]=[]: print(ll[turn].upper()) break turn=x
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s016795967
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
def solve(a,b,c,turn): if turn == "a": if a == "": return "A" else: next_turn = a[0] a = a[1:] elif turn == "b": if b == "": return "B" else: next_turn = b[0] b = b[1:] else if c == "": return "C" else: next_turn = c[0] c = c[1:] return solve(a,b,c, next_turn) a=input().strip() b=input().strip() c=input().strip() print(solve(a,b,c,"a"))
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s046324645
Wrong Answer
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
class Player: def __init__(self, name): # 名前 self.name = name self._cards = [] def setcards(self, cards): # 手札 for card in cards: self._cards.insert(0, card) def getcards(self): return self._cards cards = property(getcards, setcards) def putDown(self): """ カードがある場合はカードを出します。 ない場合はNoneを返します。 """ if len(self.cards) != 0: return self._cards.pop() else: return None class Game: def __init__(self, players): self.players = players def start(self): ret = self.play(self.players[0].name) return ret def play(self, name): target = self.searchTarget(name) card = target.putDown() if card != None: return self.play(card) # 勝者を返す return name def searchTarget(self, name): for player in self.players: if player.name == name: return player if __name__ == "__main__": a = Player("a") a.cards = input() b = Player("b") b.cards = input() c = Player("c") c.cards = input() g = Game([a, b, c]) winner = g.start() print(winner)
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s683539823
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
alice = input() bob = input() charlie = input() for i in range(len(alice)): if alice[i] == "a": while alice[i] == "a": alice.pop(i) elif alice[i] == "b": alice.pop(i) if bob[i] == "b": while bob[i] == "b": bob.pop(i) elif bob[i] == "a": while bob[i] == "a": alice.pop(i) elif bob[i] == "c": while bob[i] == "c": charlie.pop(i) elif alice[i] == "c": alice.pop(i) if charlie[i] == "c": while charlie[i] == "c": charlie.pop(i) elif charlie[i] == "b": while charlie[i] == "b": bob.pop(i) elif charlie[i] == "a": while charlie[i] == "a": alice.pop(i) for i in range(len(alice)): if len(alice) == 0 and alice[
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s053289798
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
def play(): card_a = input() card_b = input() card_c = input() s = 0 while 1: if s == 0: if card_a[0] == a: s = 0 if card_a[0] == b: s = 1 if card_a[0] == c: s = 2 card_a = card_a[1:] if card_a == "": print("A") break if s == 1: if card_b[0] == a: s = 0 if card_b[0] == b: s = 1 if card_b[0] == c: s = 2 card_b = card_b[1:] if card_b == "": print("B") break if (s == 2) if card_c[0] == a: s = 0 if card_c[0] == b: s = 1 if card_c[0] == c: s = 2 card_c = card_c[1:] if card_c == "": print("C") break play()
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s619059614
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
def play(): card_a = input() card_b = input() card_c = input() s = 0 while 1: if s == 0: s = card_a[0] - 48 card_a = card_a[1:] if card_a == "": print("A") break if s == 1: s = card_b[0] - 48 card_b = card_b[1:] if card_a == "": print("B") break if (s == 2) s = card_c[0] - 48 card_c = card_c[1:] if card_a == "": print("C") break def test(): play() test()
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s437297138
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
alice = list(input()) bob = list(input()) charlie = list(input()) current = alice while(len(alice) > 0 and len(bob) > 0 and len(charlie) > 0): if(current[0] == 'a'): del current[0] current = alice elif(current[0] == 'b'): del current[0] currrent = bob elif(current[0] == 'c'): del current[0] current = charlie if(len(alice) == 0): print('A') elif(len(bob) == 0): print('B') elif(len(charlie) == 0): print('C')
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s745207816
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
a = input() b = input() c = input() target = a while a!="" and b!="" and c!="": if target[0] == "a": a.pop(0) if a == "": print("a") target = a elif target[0] = "b": b.pop(0) if b == "": print("b") target = b else: c.pop(0) if c == "": print("c") target = c
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s079720067
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
( a, b, c, ) = ( list(input()), list(input()), list(input()), ) d = a[0] e = 0 a.remove(d) while True: if eval(d) == []: break e = eval(d)[0] eval(d).remove(e) d = e print(str.upper(d))
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s073288481
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
A = str(input()) B = str(input()) C = str(input()) turn = "A" while True: if turn = "A": turn = A[0].upper() if len(A) == 1: print(A) break A = A[1:len(A)] if turn = "B": turn = B[0].upper() if len(B) == 1: print(B) break B = B[1:len(B)] if turn = "C": turn = C[0].upper() if len(C) == 1: print(C) break C = C[1:len(C)]
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s534231307
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
s_a=list(input()) s_b=list(input()) s_c=list(input()) tmp ='' tmp=s_a.pop(0) while 1: if tmp=='a': if s_a: tmp=s_a.pop(0) else: print('A') break elif tmp=='b': if s_b: tmp=s_b.pop(0) else: print('B') break else tmp=='c': if s_c: tmp=s_c.pop(0) else: print('C') break
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s200280564
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
A = input() B = input() C = input() owner = 'a' while True: if owner == 'a' if len(A): owner = A[0] del(A[0]) else: print('a') break if owner == 'b' if len(B): owner = B[0] del(B[0]) else: print('b') break if owner == 'c' if len(C): owner = C[0] del(C[0]) else: print('c') break
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s263393344
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
SA = [ord(i) - ord("a") for i in list(input())] SB = [ord(i) - ord("a") for i in list(input())] SC = [ord(i) - ord("a") for i in list(input())] S = [SA, SB, SC] N = [[0, len(SA)], [0, len(SB)], [0, len(SC)]] P = ["A", "B", "C"] p = 0 while N[p][0] != N[p][1]: n = S[p][N[p][0]] N[p][0] += 1 p = n print(P[p])
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s756470203
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
# cards = [input() for _ in range(3)] dict = {"a": 0, "b": 1, "c": 2} inv = ["A", "B", "C"] turn = "a" game = True while game: turn = cards[dict[turn]][0] cards[dict[turn]] = cards[dict[turn]][1:] for i in range(3): if cards[i] == "": print(inv[i]) game = False
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s384173175
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
# input S = [list(input()) for _ in range(3)] P_curr = 0 while S[P_curr] != [] if S[P_curr][0] == 'a': P_curr = 0 if S[P_curr][0] == 'b': P_curr = 1 if S[P_curr][0] == 'c': P_curr = 2 del S[P_curr][0] if P_curr == 0: print('A') if P_curr == 1: print('B') if P_curr == 2: print('C')
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s194191277
Wrong Answer
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
S_a = str(input()) S_b = str(input()) S_c = str(input()) count_a = 0 count_b = 0 count_c = 0 word = S_a[0] while count_a < len(S_a) and count_b < len(S_b) and count_c < len(S_c): if word == "a": word = S_a[count_a] count_a += 1 elif word == "b": word = S_b[count_b] count_b += 1 elif word == "c": word = S_c[count_c] count_c += 1 print(word.upper())
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s504167870
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
lis = [list(input()) for _ in range(3)] x = 0 while len(lis[x]): rem = lis[x].pop(0) if rem == "a": x = 0 elif rem == "b": x = 1 else: x = 2 print(rem.upper())
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s408194948
Accepted
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
arr = [list(reversed(input())) for _ in range(3)] curr = 0 while arr[curr] != []: curr = "abc".index(arr[curr].pop()) print("ABC"[curr])
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s999991115
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
s = [ str( input() ) for x in range(3) ] flag = 0 t = 0 while flag == 0 if len( s[t] ) != 0 t = s[t][0] s[t] = s[t][1:] else : print( char( ord("A")+ t ) )
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]
If Alice will win, print `A`. If Bob will win, print `B`. If Charlie will win, print `C`. * * *
s827659338
Runtime Error
p03998
The input is given from Standard Input in the following format: S_A S_B S_C
S = dict() S['a'] = list(input())[::-1] S['b'] = list(input())[::-1] S['c'] = list(input())[::-1] p = 'a' while S[]: p = S[p].pop() print(player.upper())
Statement 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.
[{"input": "aca\n accc\n ca", "output": "A\n \n\nThe game will progress as below:\n\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `c`. Charlie takes the next turn.\n * Charlie discards the top card in his deck, `a`. Alice takes the next turn.\n * Alice discards the top card in her deck, `a`. Alice takes the next turn.\n * Alice's deck is empty. The game ends and Alice wins the game.\n\n* * *"}, {"input": "abcb\n aacb\n bccc", "output": "C"}]