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 x_{N,1}. * * *
s631812735
Runtime Error
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
n = input() res = list(map(int, input())) d = len(res) res2 = [] while d > 1: for i in range(len(res) - 1): res2.append(abs(res[i] - res[i + 1])) d -= 1 res = res2.copy() res2.clear() print(res[0])
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s590745734
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
# -*- coding: utf-8 -*- """ Created on Sat Mar 21 20:58:03 2020 @author: naoki """ # f = open("C:/Users/naoki/Desktop/Atcoder/input.txt") N = int(input()) a = list(map(int, list(input()))) flag1 = [-100, -100] flag2 = [-100, -100] flag3 = [-100, -100] for i in range(N // 2): if a[i] == 2: flag1[0] = i if a[N - i - 1] == 2: flag1[1] = N - i - 1 if (a[i] == 1 and a[i + 1] == 3) or (a[i] == 3 and a[i + 1] == 1): flag2[0] = i if (a[N - i - 1] == 1 and a[N - i - 2] == 3) or ( a[N - i - 1] == 3 and a[N - i - 2] == 1 ): flag2[1] = N - i - 1 if flag1[0] >= 0 and flag1[1] >= 0: b = [] b.extend(a[0 : flag1[0] + 1]) b.extend(a[flag1[1] :]) break if flag2[0] >= 0 and flag2[1] >= 0: b = [] b.extend(a[0 : flag2[0] + 1]) b.extend(a[flag2[1] - 1 :]) break else: b = a last = [] if b[0] != b[1]: last.append(b[0]) for i in range(len(b) - 1): if b[i] != b[i + 1]: last.append(b[i + 1]) for i in range(len(last) - 1): for p in range(len(last) - i - 1): last[p] = abs(last[p + 1] - last[p]) if len(last) > 0: print(last[0]) else: print(0)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s996936594
Accepted
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) n = ni() l = list(map(lambda x: int(x) - 1, list(ns()))) f = 1 if 1 not in l: l = [x // 2 for x in l] f += 1 def Cmod2(n, r): return n & r == r s = sum(Cmod2(n - 1, i) * l[i] for i in range(n)) % 2 print(f * s)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s129014290
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
N = int(input()) ints = [int(c) for c in input()] while len(ints) > 1: new = [] for i in range(1, len(ints)): a = abs(ints[i - 1] - ints[i]) if a > 0: new.append(a) ints = new if len(ints) == 1: print(ints[0]) else: print(0)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s637243090
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
s = int(input()) t = input() a = 0 for i in range(s - 1): b = int(t[i + 1]) c = int(t[i]) a = a + abs(b - c) print(a % 3)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s532260666
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
N = int(input()) S = input() A = list(map(int, str(S))) for j in range(N): for i in range(N - 1): k = A[i] - A[i + 1] A[i] = abs(k) print(A[0])
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s071481883
Runtime Error
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
import math N = int(input()) a = input() u = int(math.sqrt(N)) u2 = int(math.sqrt(u)) dic = {} dic2 = {} def calc(s: str) -> int: dp = [[0] * len(s) for i in range(len(s))] for i in range(len(s)): for j in range(len(s) - i): if i == 0: dp[i][j] = int(s[j]) else: dp[i][j] = abs(dp[i - 1][j] - dp[i - 1][j + 1]) return dp[len(s) - 1][0] preva = a for i in range(1, N // u): preva_list = [] for j in range(N - (u - 1)): s = preva[j : j + u] ans = 0 if s in dic: ans = dic[s] else: # ans = calc(s) # dic[s] = ans # print('s: ', s) preva2 = s for i2 in range(1, u // u2): preva2_list = [] for j2 in range(len(s) - (u2 - 1)): s2 = preva2[j2 : j2 + u2] ans2 = 0 if s2 in dic2: ans2 = dic2[s2] else: ans2 = calc(s2) dic2[s2] = ans2 preva2_list.append(str(ans2)) # print('s2: ', s2) # print('ans2: ', ans2) preva2 = "".join(preva2_list) ans = calc(preva2) dic[s] = ans # print('ans: ', ans) preva_list.append(str(ans)) preva = "".join(preva_list) ans = calc(preva) print(ans)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s981399205
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
n = int(input()) l = input() d = [[] for i in range(n)] for i in range(n): d[0].append(l[i]) if n == 1: print(int(l)) elif n == 2: print(abs(int(d[0][1]) - int(d[0][0]))) elif n == 3: print(abs(abs(int(d[0][1]) - int(d[0][0]) - abs(int(d[0][2]) - int(d[0][1]))))) else: for i in range(1, 3): for j in range(0, n - i): d[i].append(str(abs(int(d[i - 1][j]) - int(d[i - 1][j + 1])))) for i in range(2, n - 1): if len(d[i]) == 3: if ( d[i][0] + d[i][1] + d[i][2] == "000" or d[i][0] + d[i][1] + d[i][2] == "010" or d[i][0] + d[i][1] + d[i][2] == "101" or d[i][0] + d[i][1] + d[i][2] == "111" ): print(0) break else: print(1) break elif len(d[i]) == 2: if d[i][0] + d[i][1] == "00" or d[i][0] + d[i][1] == "11": print(0) break else: print(1) break elif len(d[i]) == 1: print(int(d[i][0])) break else: for j in range(0, len(d[i]) // 4): if ( (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "0000") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "1111") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "0011") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "1100") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "0101") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "0110") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "1010") or (d[i][0] + d[i][1] + d[i][2] + d[i][3] == "1001") ): d[i + 1].append("0") else: d[i + 1].append("1") for j in range(0, len(d[i]) % 4): d[i + 1].append(d[i][(len(d[i]) // 4) * 4 + j])
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s906165146
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
input() z = list(map(int, input().split())) while len(z) != 1: t = [] for x, y in zip(z[:-1], z[1:]): t += [abs(x - y)] z = t print(*z)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s649020801
Wrong Answer
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
# ------------------------------------------------------------------- import sys def p(*_a): _s = " ".join(map(str, _a)) # print(_s) sys.stderr.write(_s + "\n") # ------------------------------------------------------------------- from collections import defaultdict d = defaultdict(str) d["00"] = "0" d["01"] = "1" d["02"] = "2" d["03"] = "3" d["10"] = "1" d["11"] = "0" d["12"] = "1" d["13"] = "2" d["20"] = "2" d["21"] = "1" d["22"] = "0" d["23"] = "1" d["30"] = "3" d["31"] = "2" d["32"] = "1" d["33"] = "0" # p(d) x = "" iLen = 2 iLenMax = 5 L = [] for k, v in d.items(): if len(k) == iLen: L.append([k, v]) while iLen < iLenMax: di = list(L) L = [] for k, v in di: # p(k,v) if len(k) < iLen: continue for c01 in ["0", "1", "2", "3"]: x = k + c01 while len(x) > 1: a = v b = d[x[1:-1]] x = a + b d[k + c01] = x L.append([k + c01, x]) iLen += 1 ##p(d) # for k, v in d.items(): # if len(k)>11: p(k,v) # ------------------------------------------------------------------- N = int(input()) # 5 s = input() if len(s) < iLenMax: g = [] g.append(s) z = 0 # for i in range(N): for j in range(N - 1): s = g[j] x = "" for k in range(1, len(s)): a = int(s[k - 1]) b = int(s[k - 0]) c = abs(a - b) x = x + str(c) g.append(x) # p(g) print(g[N - 1]) else: z = s # p(z,len(z)) while len(z) > 1: iLen = min(iLenMax, len(z)) # p("iLen, len(z), ",iLen, len(z)) y = "" for i in range(len(z) - iLen + 1): a = b = e = f = h = "" a = z[i + 0 : i + 0 + iLen] b = z[i + 1 : i + 1 + iLen] e = str(d[a]) f = str(d[b]) h = e + f y = y + d[h] # p("i,a,b,e,f,h,y, ",i,a,b,e,f,h,y) z = y print(z)
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s701008076
Runtime Error
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
class Solution: def solve(self, N, number): dp = [[0] * N for _ in range(N)] for i, num in enumerate(number): dp[0][i] = num for i in range(1, N): for j in range(N - i): dp[i][j] = abs(dp[i - 1][j] - dp[i - 1][j + 1]) return dp[N - 1][0] sol = Solution() N = int(input().strip()) number = [int(ch) for ch in input().strip()] print(sol.solve(N, number))
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print x_{N,1}. * * *
s580752519
Runtime Error
p02736
Input is given from Standard Input in the following format: N a_1a_2\ldotsa_N
import numpy as np def array_subtraction(arr): if len(arr) == 1: return arr arr = np.array(arr) arr = np.abs(arr) x = np.array(arr[1:]) y = np.array(arr[:-1]) return array_subtraction(x - y) input() z = [int(i) for i in input()] print(*array_subtraction(z))
Statement Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}.
[{"input": "4\n 1231", "output": "1\n \n\nx_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.\n\nx_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.\n\nx_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.\n\nFinally, x_{4,1} = |0-1| = 1, so the answer is 1.\n\n* * *"}, {"input": "10\n 2311312312", "output": "0"}]
Print the minimum k such that the given tree is a tree of uninity k. * * *
s027198288
Wrong Answer
p03824
The input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) m = map(int, read().split()) AB = zip(m, m) graph = [[] for _ in range(N + 1)] for a, b in AB: graph[a].append(b) graph[b].append(a) graph root = 1 parent = [0] * (N + 1) order = [] stack = [root] while stack: x = stack.pop() order.append(x) for y in graph[x]: if y == parent[x]: continue parent[y] = x stack.append(y) uninity = [0] * (N + 1) dp = [(1 << 60) - 1] * (N + 1) # 使用可能なbitの集合 for x in order[::-1]: p = parent[x] # 使用可能なmin lsb = dp[x] & (-dp[x]) uninity[x] = lsb dp[x] ^= lsb dp[x] |= lsb - 1 dp[p] &= dp[x] x = max(uninity).bit_length() - 1 print(x)
Statement We will recursively define _uninity_ of a tree, as follows: (_Uni_ is a Japanese word for sea urchins.) * A tree consisting of one vertex is a tree of uninity 0. * Suppose there are zero or more trees of uninity k, and a vertex v. If a vertex is selected from each tree of uninity k and connected to v with an edge, the resulting tree is a tree of uninity k+1. It can be shown that a tree of uninity k is also a tree of uninity k+1,k+2,..., and so forth. You are given a tree consisting of N vertices. The vertices of the tree are numbered 1 through N, and the i-th of the N-1 edges connects vertices a_i and b_i. Find the minimum k such that the given tree is a tree of uninity k.
[{"input": "7\n 1 2\n 2 3\n 2 4\n 4 6\n 6 7\n 7 5", "output": "2\n \n\nA tree of uninity 1 consisting of vertices 1, 2, 3 and 4 can be constructed\nfrom the following: a tree of uninity 0 consisting of vertex 1, a tree of\nuninity 0 consisting of vertex 3, a tree of uninity 0 consisting of vertex 4,\nand vertex 2.\n\nA tree of uninity 1 consisting of vertices 5 and 7 can be constructed from the\nfollowing: a tree of uninity 1 consisting of vertex 5, and vertex 7.\n\nA tree of uninity 2 consisting of vertices 1, 2, 3, 4, 5, 6 and 7 can be\nconstructed from the following: a tree of uninity 1 consisting of vertex 1, 2,\n3 and 4, a tree of uninity 1 consisting of vertex 5 and 7, and vertex 6.\n\n* * *"}, {"input": "12\n 1 2\n 2 3\n 2 4\n 4 5\n 5 6\n 6 7\n 7 8\n 5 9\n 9 10\n 10 11\n 11 12", "output": "3"}]
Print the minimum k such that the given tree is a tree of uninity k. * * *
s496979761
Wrong Answer
p03824
The input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1}
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def calc(rt): e = edge[rt] f[rt] = 1 g[rt] = 1 g1 = 0 g2 = 0 for son in e: if f[son] == 0: calc(son) res = f[son] if res > f[rt]: f[rt] = res res = g[son] if res + 1 > g[rt]: g[rt] = res + 1 if res > g1: g2 = g1 g1 = res elif res > g2: g2 = res if g1 + g2 + 1 > f[rt]: f[rt] = g1 + g2 + 1 if g[rt] > f[rt]: f[rt] = g[rt] n = int(input()) edge = [] f = [] g = [] for i in range(0, n): edge.append(set()) f.append(0) g.append(0) for i in range(1, n): e = input().split(" ") y = int(e[0]) - 1 x = int(e[1]) - 1 edge[x].add(y) edge[y].add(x) calc(0) length = f[0] ans = 0 l = 1 while l < length: ans = ans + 1 l = l + l + 1 print(ans)
Statement We will recursively define _uninity_ of a tree, as follows: (_Uni_ is a Japanese word for sea urchins.) * A tree consisting of one vertex is a tree of uninity 0. * Suppose there are zero or more trees of uninity k, and a vertex v. If a vertex is selected from each tree of uninity k and connected to v with an edge, the resulting tree is a tree of uninity k+1. It can be shown that a tree of uninity k is also a tree of uninity k+1,k+2,..., and so forth. You are given a tree consisting of N vertices. The vertices of the tree are numbered 1 through N, and the i-th of the N-1 edges connects vertices a_i and b_i. Find the minimum k such that the given tree is a tree of uninity k.
[{"input": "7\n 1 2\n 2 3\n 2 4\n 4 6\n 6 7\n 7 5", "output": "2\n \n\nA tree of uninity 1 consisting of vertices 1, 2, 3 and 4 can be constructed\nfrom the following: a tree of uninity 0 consisting of vertex 1, a tree of\nuninity 0 consisting of vertex 3, a tree of uninity 0 consisting of vertex 4,\nand vertex 2.\n\nA tree of uninity 1 consisting of vertices 5 and 7 can be constructed from the\nfollowing: a tree of uninity 1 consisting of vertex 5, and vertex 7.\n\nA tree of uninity 2 consisting of vertices 1, 2, 3, 4, 5, 6 and 7 can be\nconstructed from the following: a tree of uninity 1 consisting of vertex 1, 2,\n3 and 4, a tree of uninity 1 consisting of vertex 5 and 7, and vertex 6.\n\n* * *"}, {"input": "12\n 1 2\n 2 3\n 2 4\n 4 5\n 5 6\n 6 7\n 7 8\n 5 9\n 9 10\n 10 11\n 11 12", "output": "3"}]
A list of _articulation points_ of the graph G ordered by name.
s266637210
Accepted
p02366
|V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target verticess of i-th edge (undirected).
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**7) class LowLinks: def __init__(self, edges, edges_num: int): """edges[u]: all vertexes connected with vertex 'u' edges_num: number of edges of graph the root of DFS-tree is vertex 0 """ self.edges = edges self.V = len(edges) self.order = [-1] * V self.low = [float("inf")] * V self.bridges = [] # if degreee(root) > 1 and graph is tree: root is articulation self.articulations = [] if len(edges[0]) > 1 and edges_num == self.V - 1: self.articulations.append(0) self.k = 0 def build(self): self.dfs(0, 0) def get_bridges(self) -> tuple: return self.bridges def get_articulations(self) -> tuple: return self.articulations def dfs(self, v: int, prev: int): self.order[v] = self.k self.k += 1 self.low[v] = self.order[v] is_articulation = False for to in self.edges[v]: if self.order[to] < 0: # not visited self.dfs(to, v) self.low[v] = min(self.low[v], self.low[to]) if self.low[v] < self.low[to]: self.bridges.append((v, to)) is_articulation |= self.order[v] <= self.low[to] elif to != prev: self.low[v] = min(self.low[v], self.order[to]) if v > 0 and is_articulation: self.articulations.append(v) if __name__ == "__main__": V, E = map(int, readline().split()) edges = [[] for _ in range(V)] for _ in range(E): s, t = map(int, readline().split()) edges[s].append(t) edges[t].append(s) lowlinks = LowLinks(edges, E) lowlinks.build() articulations = lowlinks.get_articulations() if articulations: print(*sorted(articulations), sep="\n")
Articulation Points Find articulation points of a given undirected graph G(V, E). A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.
[{"input": "4 4\n 0 1\n 0 2\n 1 2\n 2 3", "output": "2"}, {"input": "5 4\n 0 1\n 1 2\n 2 3\n 3 4", "output": "1\n 2\n 3"}]
A list of _articulation points_ of the graph G ordered by name.
s674001603
Runtime Error
p02366
|V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target verticess of i-th edge (undirected).
from sys import stdin n, m = map(int, stdin.readline().split()) edges = [set() for _ in range(n)] for _ in [0] * m: s, t = map(int, stdin.readline().split()) edges[s].add(t) edges[t].add(s) prenum = [None] * n parent = [None] * n lowest = [None] * n counter = 0 def dfs(cur, prev): global counter prenum[cur] = lowest[cur] = counter counter += 1 for edge in edges[cur]: if prenum[edge] is not None: if edge != prev: lowest[cur] = min(lowest[cur], prenum[edge]) continue parent[edge] = cur dfs(edge, cur) lowest[cur] = min(lowest[cur], lowest[edge]) dfs(0, 1) ap = [False] * n r = 0 for _ in filter(lambda x: x == 0, parent): r += 1 if r > 1: ap[0] = True break for i in range(1, n): p = parent[i] if p and prenum[p] <= lowest[i]: ap[p] = True for i, e in enumerate(ap): if e: print(i)
Articulation Points Find articulation points of a given undirected graph G(V, E). A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.
[{"input": "4 4\n 0 1\n 0 2\n 1 2\n 2 3", "output": "2"}, {"input": "5 4\n 0 1\n 1 2\n 2 3\n 3 4", "output": "1\n 2\n 3"}]
A list of _articulation points_ of the graph G ordered by name.
s841753773
Accepted
p02366
|V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target verticess of i-th edge (undirected).
def cut_vertices(E, s): N = len(E) preorder = [-1] * N # a dfs preordering of each vertex lowpt = [N] * N # for finding a cut-vertex cut_vertex = [False] * N root_children = 0 # #(children of the root in the dfs search tree) stack = [(s, -1, 0)] # (vertex, parent, status) pre_num = 0 # current preordering while stack: v, p, st = stack.pop() if st == 0 and preorder[v] < 0: # visited v for the first time preorder[v] = pre_num lowpt[v] = pre_num pre_num += 1 n_children = 0 for u in E[v]: if preorder[u] >= 0: if ( u != p ): # the edge (v, u) is a back edge, which is not in dfs search tree lowpt[v] = min(lowpt[v], preorder[u]) continue if n_children == 0: stack += [(v, p, 2), (u, v, 0)] n_children += 1 else: stack += [(v, p, 1), (u, v, 0)] n_children += 1 if n_children == 0: # v is a leaf of the dfs search tree lowpt[p] = min(lowpt[p], lowpt[v]) if lowpt[v] >= preorder[p] != 0: cut_vertex[p] = True elif preorder[p] == 0: root_children += 1 elif st == 0 and preorder[v] >= 0: # the edge (v, p) is a back edge continue elif st == 1: # now searching continue else: # search finished if p != -1: lowpt[p] = min(lowpt[p], lowpt[v]) if lowpt[v] >= preorder[p] != 0: cut_vertex[p] = True elif preorder[p] == 0: root_children += 1 else: if root_children >= 2: cut_vertex[v] = True return cut_vertex N, M = map(int, input().split()) E = [[] for _ in range(N)] for _ in range(M): s, t = map(int, input().split()) E[s].append(t) E[t].append(s) temp = cut_vertices(E, 0) cut_vs = [v for v in range(N) if temp[v]] if cut_vs: print(*cut_vs, sep="\n")
Articulation Points Find articulation points of a given undirected graph G(V, E). A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.
[{"input": "4 4\n 0 1\n 0 2\n 1 2\n 2 3", "output": "2"}, {"input": "5 4\n 0 1\n 1 2\n 2 3\n 3 4", "output": "1\n 2\n 3"}]
A list of _articulation points_ of the graph G ordered by name.
s276444840
Accepted
p02366
|V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target verticess of i-th edge (undirected).
import sys sys.setrecursionlimit(10**7) v, e = list(map(int, input().split())) G = [[] for _ in range(v)] for _ in range(e): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) def solve(): used = [False for _ in range(v)] ord = [0 for _ in range(v)] low = [float("inf") for _ in range(v)] is_articulation = [False for _ in range(v)] def dfs(v, prev, k): if used[v]: return used[v] = True k = k + 1 ord[v] = k low[v] = ord[v] cnt = 0 for u in G[v]: if not used[u]: cnt += 1 dfs(u, v, k) low[v] = min(low[v], low[u]) if prev >= 0 and ord[v] <= low[u]: is_articulation[v] = True elif u != prev: low[v] = min(low[v], ord[u]) if prev == -1 and cnt >= 2: is_articulation[v] = True return k dfs(0, -1, 0) for i in range(v): if is_articulation[i]: print(i) solve()
Articulation Points Find articulation points of a given undirected graph G(V, E). A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.
[{"input": "4 4\n 0 1\n 0 2\n 1 2\n 2 3", "output": "2"}, {"input": "5 4\n 0 1\n 1 2\n 2 3\n 3 4", "output": "1\n 2\n 3"}]
Print the minimum possible final health of the last monster alive. * * *
s756348593
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) A = list(map(int, input().split())) x = min(A) noend = True while noend: a = x for i in range(n): if A[i] % x != 0 and A[i] % x < x: x = A[i] % x break if x == a: noend = False print(x)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s725777627
Runtime Error
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
def Gcd(a,b): if a<b: return Gcd(b,a) else: if a%b: return Gcd(b, a%b): else: return b N = int(input()) arr = list(map(int,input().split())) gcd = arr[0] for i in arr: gcd = Gcd(gcd, i) print(gcd)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s979118163
Runtime Error
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
4 2 10 8 40
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s618079104
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
print("1")
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s942961863
Runtime Error
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#include <iostream> #include <algorithm> #include <vector> //動的配列 #include <string> #include <list> //双方向リスト #include <map> //連想配列 #include <set> //集合 #include <stack> #include <queue> #include <deque> #include <cmath> #include <bitset> #include <numeric> #include <tuple> typedef long long ll; using namespace std; typedef pair<int, int> P; #define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i ) #define rep(i,n) FOR(i,0,n) #define sz(x) int(x.size()) template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} // n次元配列の初期化。第2引数の型のサイズごとに初期化していく。 template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } //小さい順から取り出すヒープ //priority_queue<ll, vector<ll>, greater<ll> > pque1; int gcd(int a,int b){ if (a==0) return b; else return gcd(b%a,a); } int inf=1001001001; int main(){ int n; cin>>n; vector<int> v(n); rep(i,n) { int a; cin>>a; v[i]=a; } sort(v.begin(),v.end()); int tmp=gcd(v[0],v[1]); //cout<<tmp<<endl; //int ans=inf; for (int i=2;i<n;i++){ tmp=gcd(tmp,v[i]); } cout<<tmp; return 0; }
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s894005127
Runtime Error
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) monsters = list(map(int, input().split())) def gcd(a, b): if b > 0 : return gcd(b , a % b) else : return x if len(monster) == 1 : print(monster[0]) else : mon = gcd(monster[0], monster[1]) if len(monster) >= 2 for i in range(2 , N) : mon = gcd(mon, monster[i]) print(mon)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s679290169
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s391837768
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N, *A = map(int, open(0).read().split()) A.sort() B = [[] for i in range(100)] B[0] = A # print(B) for i in range(99): B[i + 1].append(B[i][0]) for j in range(1, len(B[i])): x = B[i][j] % B[i][0] if x != 0: B[i + 1].append(x) B[i + 1] = sorted(B[i + 1]) if len(B[i]) <= 1: break print(B[i][0])
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s819909572
Runtime Error
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n, m = map(int, input().split()) list1 = list(map(int, input().split())) list1.sort() list2 = [] for i in range(m - 1): list2.append(list1[i + 1] - list1[i]) list2.sort(reverse=True) cut = 0 for j in range(n - 1): cut += list2[j] print(max(list1) - min(list1) - cut)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s962991706
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n, *a = map(int, open(0).read().split()) m = min(a) while len(a) > 1: m = min(a) f = 0 for i in range(len(a)): if a[i] != m or f: a[i] %= m else: f = 1 (*a,) = filter(lambda x: x, a) print(m)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s071018674
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = sorted(list(map(int, input().split()))) a_min = a[-1] for element in a: if not element % a_min == 0 and element % a_min <= a_min: a_min = element % a_min elif element <= a_min: a_min = element print(a_min)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s006625656
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = list(map(int, input().split())) sort = sorted(A) # amari = [] # while len(amari) != 1: # amari.clear() # if 0 in sort: sort.remove(0) # for item in sort: # if item%sort[0] not in amari: # amari.append(item%sort[0]) # last_sort0 = sort[0] # sort = sorted(amari[:]) # sort.append(last_sort0) # print(last_sort0-amari[0]) while len(sort) != 1: for i in range(1, len(sort)): sort[i] = sort[i] % sort[0] sort = [j for j in sorted(sort) if j != 0] print(sort[0])
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s205856837
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) lista = sorted(list(map(int, input().split()))) length = 2 while length > 1: # print(length) # print(lista) for n in range(1, length): lista[n] = lista[n] % lista[0] # print(lista) lista = list(set(lista)) lista.sort() if lista[0] == 0: lista.remove(0) # print(lista) length = len(lista) print(lista[0])
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s042082799
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/2/16 Solved on 2019/2/16 @author: shinjisu """ # ABC 118 def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] def zeros(n): return [0] * n def getIntLines(n): return [int(input()) for i in range(n)] def getIntMat(n): mat = [] for i in range(n): mat.append(getIntList()) return mat def zeros2(n, m): return [zeros(m)] * n def dmp(x): global debug if debug: print(x) return x def gcd(x, y): # 最大公約数 m = max(x, y) n = min(x, y) while m % n != 0: w = m % n m = n n = w return n def probC(): N = getInt() A = getIntList() dmp((N, A)) hp = A[N - 1] for i in range(N - 1): hp = gcd(hp, A[i]) dmp(hp) return hp debug = False # True False print(probC()) def probD(): N = getInt() A = getIntList() dmp((N, A)) return 123 def probA(): A, B = getIntList() dmp((A, B)) if B % A == 0: return A + B else: return B - A def probB(): N, M = getIntList() A = getIntMat(N) dmp((N, M)) dmp(A) food = set([]) food = set(A[0][1:]) dmp(food) for i in range(N): food2 = set(A[i][1:]) food = food & food2 dmp(food) return len(food)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s841183726
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) Mo = [int(x) for x in input().split()] Mo.sort() Mo.reverse() last = Mo.pop(0) for i in range(len(Mo) - 1): if last % Mo[i] != 0: if last > last - (int(last / Mo[i]) * Mo[i]): last = last - (int(last / Mo[i]) * Mo[i]) else: if last > last - (int(last / Mo[i]) * Mo[i]): last = last - (int(last / Mo[i] - 1) * Mo[i]) Mo.reverse() if sum(Mo) % Mo[0] < last and sum(Mo) % Mo[0] != 0: print(sum(Mo) % Mo[0]) else: print(last)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s905585598
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- """ 参考:https://img.atcoder.jp/abc118/editorial.pdf """ import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10 if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect import bisect_left, bisect_right from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul, xor from copy import copy, deepcopy from functools import reduce, partial from fractions import Fraction from string import ascii_lowercase, ascii_uppercase, digits def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def round(x): return int((x * 2 + 1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD - 2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(nums): return reduce(lcm, nums, 1) def gcd_list(nums): return reduce(gcd, nums, nums[0]) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N = INT() A = LIST() print(gcd_list(A))
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s099318475
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
(N,) = list(map(int, input().split())) A = list(map(int, input().split())) b = set(A) while len(b) > 1: m = min(b) c = set((m,)) for bi in b: if bi % m > 0: c.add(bi % m) b = c print(list(b)[0])
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s323732948
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
mod = 10**9 + 7 mod2 = 2**61 + 1 from collections import deque import heapq from bisect import bisect_left, insort_left, bisect_right _NUMINT_ALL = list(range(10)) def main(): ans = solve() if ans is not None: print(ans) def solve(): N = iip(False) A = iip() l = len(A) while True: m = min(A) mx = max(A) if m == mx: return m for i in range(l): if A[i] % m == 0: A[i] = m else: A[i] %= m #####################################################ライブラリ集ここから def iip(listed=True, num_only=True): # 数字のinputをlistで受け取る if num_only: ret = [int(i) for i in input().split()] else: ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()] if len(ret) == 1 and not listed: return ret[0] return ret def saidai_kouyakusuu(a, b): # 最大公約数 for i in soinsuu_bunkai(a): if b % i == 0: b //= i return a * b def sort_tuples(l, index): # タプルのリストを特定のインデックスでソートする if isinstance(l, list): l.sort(key=lambda x: x[index]) return l else: l = list(l) return sorted(l, key=lambda x: x[index]) def count_elements(l): # リストの中身の個数を種類分けして辞書で返す d = {} for i in l: if i in d: d[i] += 1 else: d[i] = 1 return d def safeget( l, index, default="exception" ): # listの中身を取り出す時、listからはみ出たり if index >= len(l): # マイナスインデックスになったりするのを防ぐ if default == "exception": raise Exception( "".join( [ "safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です", ] ) ) else: return default elif index < 0: if default == "exception": raise Exception( "".join( [ "safegetに不正な値 ", index, "が渡されました。負の値は許可されていません", ] ) ) else: return default else: return l[index] def iipt( l, listed=False, num_only=True ): # 縦向きに並んでいるデータをリストに落とし込む(iip利用) ret = [] for i in range(l): ret.append(iip(listed=listed, num_only=num_only)) return ret def sortstr(s): # 文字列をソートする return "".join(sorted(s)) def iip_ord(startcode="a"): # 文字列を数字の列に変換する(数字と文字は1:1対応) if isinstance(startcode, str): startcode = ord(startcode) return [ord(i) - startcode for i in input()] def YesNo(s): # TrueFalseや1, 0をYesNoに変換する if s: print("Yes") else: print("No") def fprint(s): # リストを平たくしてprintする(二次元リストを見やすくしたりとか) for i in s: print(i) def bitall(N): # ビット全探索用のインデックスを出力 ret = [] for i in range(2**N): a = [] for j in range(N): a.append(i % 2) i //= 2 ret.append(a) return ret def split_print_space(s): # リストの中身をスペース区切りで出力する print(" ".join([str(i) for i in s])) def split_print_enter(s): # リストの中身を改行区切りで出力する print("\n".join([str(i) for i in s])) def soinsuu_bunkai(n): # 素因数分解 ret = [] for i in range(2, int(n**0.5) + 1): while n % i == 0: n //= i ret.append(i) if i > n: break if n != 1: ret.append(n) return ret def conbination(n, r, mod, test=False): # nCrをmodを使って計算する if n <= 0: return 0 if r == 0: return 1 if r < 0: return 0 if r == 1: return n ret = 1 for i in range(n - r + 1, n + 1): ret *= i ret = ret % mod bunbo = 1 for i in range(1, r + 1): bunbo *= i bunbo = bunbo % mod ret = (ret * inv(bunbo, mod)) % mod if test: # print(f"{n}C{r} = {ret}") pass return ret def inv(n, mod): # modnにおける逆元を計算 return power(n, mod - 2) def power(n, p, mod_=mod): # 繰り返し二乗法でn**p % modを計算 if p == 0: return 1 if p % 2 == 0: return (power(n, p // 2, mod_) ** 2) % mod_ if p % 2 == 1: return (n * power(n, p - 1, mod_)) % mod_ if __name__ == "__main__": main()
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s119860637
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) L = [int(i) for i in input().split()] l = sorted(L) # print(l) while len(l) > 1: for i in range(1, len(l)): l[i] = l[i] % l[0] while 0 in l: l.remove(0) l.sort() print(l[0])
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s222205178
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int, input().split())) a.sort() nums = n nin = a[0] next_nin = a[0] while nums != 1: for i in range(n - nums + 1, n): a[i] %= nin if a[i] != 0: next_nin = min(next_nin, a[i]) else: nums -= 1 a.sort() nin = next_nin print(nin)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s762221622
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) ai = list(map(int, input().split(" "))) while len(ai) > 1: print(ai) ai = list(sorted(ai)) ai_head = ai[0] ai = list(filter(lambda x: x != 0, map(lambda x: x % ai_head, list(ai[1:])))) ai.append(ai_head) print(ai[0])
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s601420002
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# 各モンスターの組み合わせで余りの最小値を求める A = input() L = list(map(int, input().split())) L.reverse() # print(L) ans = 1000000 for i in range(len(L)): for j in range(len(L)): # print('ans:', ans) # print('L[', i, '] % L[', j, ']') # print(L[i], '%', L[j]) # print(L[i] % L[j]) B = L[i] % L[j] if B != 0 and B < ans: ans = B C = L[j] % ans if C != 0 and C < ans: ans = C print(ans)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s880915516
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import random N = int(input()) hps = list(map(int, input().split())) def is_fighting(hps): suverve = 0 for hp in hps: if hp > 0: suverve += 1 if suverve == 1: return False return True def can_atack(hp): if hp <= 0: return False return True while is_fighting(hps): a = random.randrange(N) b = random.randrange(N) while a == b: b = random.randrange(N) if not can_atack(hps[a]) or not can_atack(hps[b]): continue hps[b] = hps[b] - hps[a] for hp in hps: if hp > 0: print(hp) exit()
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s221675026
Wrong Answer
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
a = int(input()) b = list(map(int, input().split())) c = [] d = 1000000000 for i in range(a): for j in range(a): if b[i] > b[j] and b[i] % b[j] != 0: if d > b[i] % b[j]: d = b[i] % b[j] if b[i] > d and b[i] % d != 0: if d > b[i] % d: d = b[i] % d print(d)
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the minimum possible final health of the last monster alive. * * *
s547436313
Accepted
p03127
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# coding: utf-8 import sys # import bisect # import math # import itertools # import numpy as np """Template""" class IP: """ 入力を取得するクラス """ def __init__(self): self.input = sys.stdin.readline def I(self): """ 1文字の取得に使います :return: int """ return int(self.input()) def S(self): """ 1文字の取得(str :return: str """ return self.input() def IL(self): """ 1行を空白で区切りリストにします(int :return: リスト """ return list(map(int, self.input().split())) def SL(self): """ 1行の文字列を空白区切りでリストにします :return: リスト """ return list(map(str, self.input().split())) def ILS(self, n): """ 1列丸々取得します(int :param n: 行数 :return: リスト """ return [int(self.input()) for _ in range(n)] def SLS(self, n): """ 1列丸々取得します(str :param n: 行数 :return: リスト """ return [self.input() for _ in range(n)] def SILS(self, n): """ Some Int LineS 横に複数、縦にも複数 :param n: 行数 :return: list """ return [self.IL() for _ in range(n)] def SSLS(self, n): """ Some String LineS :param n: 行数 :return: list """ return [self.SL() for _ in range(n)] class Idea: def __init__(self): pass def HF(self, p): """ Half enumeration 半分全列挙です pの要素の和の組み合わせを作ります。 ソート、重複削除行います :param p: list : 元となるリスト :return: list : 組み合わせられた和のリスト """ return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p)))) def Bfs2(self, a): """ bit_full_search2 bit全探索の改良版 全探索させたら2進数のリストと10進数のリストを返す :return: list2つ : 1個目 2進数(16桁) 2個目 10進数 """ # 参考 # https://blog.rossywhite.com/2018/08/06/bit-search/ # https://atcoder.jp/contests/abc105/submissions/4088632 value = [] for i in range(1 << len(a)): output = [] for j in range(len(a)): if self.bit_o(i, j): """右からj+1番目のiが1かどうか判定""" # output.append(a[j]) output.append(a[j]) value.append([format(i, "b").zfill(16), sum(output)]) value.sort(key=lambda x: x[1]) bin = [value[k][0] for k in range(len(value))] val = [value[k][1] for k in range(len(value))] return bin, val def S(self, s, r=0, m=-1): """ ソート関係行います。色々な設定あります。 :param s: 元となるリスト :param r: reversするかどうか 0=False 1=True :param m: (2次元配列)何番目のインデックスのソートなのか :return: None """ r = bool(r) if m == -1: s.sort(reverse=r) else: s.sort(reverse=r, key=lambda x: x[m]) def bit_n(self, a, b): """ bit探索で使います。0以上のときにTrue出します 自然数だからn :param a: int :param b: int :return: bool """ return bool((a >> b & 1) > 0) def bit_o(self, a, b): """ bit探索で使います。1のときにTrue出すよ oneで1 :param a: int :param b: int :return: bool """ return bool(((a >> b) & 1) == 1) def ceil(self, x, y): """ Round up 小数点切り上げ割り算 :param x: int :param y: int :return: int """ return -(-x // y) def ave(self, a): """ 平均を求めます :param a: list :return: int """ return sum(a) / len(a) def gcd(self, x, y): if y == 0: return x else: return self.gcd(y, x % y) """ここからメインコード""" def main(): # 1文字に省略 r, e = range, enumerate ip = IP() id = Idea() """この下から書いてね""" n = ip.I() a = ip.IL() res = max(a) for i in r(1, n): res = min(res, id.gcd(a[0], a[i])) print(res) main()
Statement There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: * A random alive monster attacks another random alive monster. * As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive.
[{"input": "4\n 2 10 8 40", "output": "2\n \n\nWhen only the first monster keeps on attacking, the final health of the last\nmonster will be 2, which is minimum.\n\n* * *"}, {"input": "4\n 5 13 8 1000000000", "output": "1\n \n\n* * *"}, {"input": "3\n 1000000000 1000000000 1000000000", "output": "1000000000"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s140345431
Accepted
p03577
Input is given from Standard Input in the following format: S
print(input().strip()[:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s735933382
Accepted
p03577
Input is given from Standard Input in the following format: S
#!/usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list(map(lambda x: int(x) - 1, input().split())) def II(): return int(input()) def IF(): return float(input()) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = 1e10 # solve def solve(): s = S() print(s[:-8]) return # main if __name__ == "__main__": solve()
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s669599965
Runtime Error
p03577
Input is given from Standard Input in the following format: S
n = int(input()) dp = input().split() m = int(input()) tp = input().split() d = dict() ans = "YES" for di in dp: if di in d: d[di] += 1 else: d[di] = 1 for ti in tp: if ti not in dp or d[ti] == 0: ans = "NO" break else: d[ti] -= 1 print(ans)
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s493412118
Runtime Error
p03577
Input is given from Standard Input in the following format: S
N, M = map(int, input().split()) edges = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) edges[a - 1] += [b - 1] edges[b - 1] += [a - 1] # print(edges) ans = 0 # 奇数へいろを検出する0から(N//2)*2+1ステップ進んだ時, 0に戻れたらアウト m = (N // 2) * 2 + 1 plist = [[] for i in range(m + 1)] plist[0] = [0] for i in range(m): # iはステップ数 for label in plist[i]: plist[i + 1] += edges[label] plist[i + 1] = list(set(plist[i + 1])) print(plist, plist[m]) if 0 in plist[m]: print((N * (N - 1)) // 2 - M) # 奇数要素の閉路があった場合は全ての頂点を結べる. else: if N % 2 == 0: n = N // 2 print(n, n * (n - 1) - M) else: n1 = N // 2 n2 = N // 2 + 1 print(n1, n2) print((n1 * (n1 - 1)) // 2 + (n2 * (n2 - 1)) // 2 - M)
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s605175689
Runtime Error
p03577
Input is given from Standard Input in the following format: S
s=input() print(s[:-8]
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s222668966
Accepted
p03577
Input is given from Standard Input in the following format: S
A = input() print(A[0:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s266024339
Accepted
p03577
Input is given from Standard Input in the following format: S
N = input() print(N[0:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s974358676
Accepted
p03577
Input is given from Standard Input in the following format: S
l = input() print(l[:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s341652895
Accepted
p03577
Input is given from Standard Input in the following format: S
inp = input() print(inp[:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s893130973
Accepted
p03577
Input is given from Standard Input in the following format: S
str = input()[:-8] print(str)
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s188393929
Runtime Error
p03577
Input is given from Standard Input in the following format: S
s = input() print(s[:len(s)-8]
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s275700088
Runtime Error
p03577
Input is given from Standard Input in the following format: S
s = input() print(s[:(len(s)-8)]
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s604800692
Runtime Error
p03577
Input is given from Standard Input in the following format: S
s=input() s_len=len(s) print([:s_len-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s694513743
Wrong Answer
p03577
Input is given from Standard Input in the following format: S
print(input().replace("FESTIVAL", "", 1))
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s492153840
Runtime Error
p03577
Input is given from Standard Input in the following format: S
prunt(input[:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s945774460
Runtime Error
p03577
Input is given from Standard Input in the following format: S
z = input print(z[:-8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the answer to the question: "Rng is going to a festival of what?" * * *
s117407186
Wrong Answer
p03577
Input is given from Standard Input in the following format: S
print(input()[:8])
Statement Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
[{"input": "CODEFESTIVAL", "output": "CODE\n \n\nThis is the same as the example in the statement.\n\n* * *"}, {"input": "CODEFESTIVALFESTIVAL", "output": "CODEFESTIVAL\n \n\nThis string is obtained by appending `FESTIVAL` to the end of `CODEFESTIVAL`,\nso it is a festival of `CODEFESTIVAL`.\n\n* * *"}, {"input": "YAKINIKUFESTIVAL", "output": "YAKINIKU"}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s900362066
Accepted
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
_, a = open(0) b, c = zip(*[(abs(i), i < 0) for i in map(int, a.split())]) print(sum(b) - sum(c) % 2 * min(b) * 2)
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s964269001
Accepted
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
x = int(input()) y = list(map(int, input().split(" "))) for i in range(x - 1): if y[i] < 0: y[i] *= -1 y[i + 1] *= -1 if y[-1] < 0 and abs(min(y[0:-1])) < abs(y[-1]): y[-1] *= -1 y[y.index(min(y[0:-1]))] *= -1 print(sum(y))
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s780752060
Accepted
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
input() a = [int(i) for i in input().split()] print( sum(map(lambda x: abs(x), a)) - (0 if sum(map(lambda x: 1 if x < 0 else 0, a)) % 2 == 0 else 2) * (min(map(lambda x: abs(x), a))) )
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s143577030
Runtime Error
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
a = int(input()) lis = list(map(int, input().split())) lis = sorted(lis) i = 0 while lis[i] < 0: if lis[i] <= 0 and lis[i + 1] >= 0: if -1 * lis[i] > lis[i + 1]: lis[i], lis[i + 1] = -lis[i], -lis[i + 1] elif lis[i] <= 0 and lis[i + 1] <= 0: lis[i], lis[i + 1] = -lis[i], -lis[i + 1] i += 2 print(sum(lis))
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s232445084
Wrong Answer
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# 入力が10**5とかになったときに100ms程度早い import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_matrix(H): """ H is number of rows """ return [list(map(int, read().split())) for _ in range(H)] def read_map(H): """ H is number of rows 文字列で与えられた盤面を読み取る用 """ return [read() for _ in range(H)] def read_col(H, n_cols): """ H is number of rows n_cols is number of cols A列、B列が与えられるようなとき """ ret = [[] for _ in range(n_cols)] for _ in range(H): tmp = list(map(int, read().split())) for col in range(n_cols): ret[col].append(tmp[col]) return ret N = read_a_int() A = read_ints() # 最初にすべてのマイナスが外せないか試して、 # abs最小の数に-をつけて合計すればいいんだ! # 問題はどうやってすべてのマイナスがはずせるか判別するか # +-+,---っていうパターンがあったらアウト flg = False for a1, a2, a3 in zip(A, A[1:], A[2:]): if a1 > -1 and a2 < 0 and a3 > -1: flg = True if a1 < 0 and a2 < 0 and a3 < 0: flg = True anstmp = sum([abs(a) for a in A]) if not flg: print(anstmp) exit() # else mi = 10**9 for a in A: mi = min(mi, abs(a)) print(anstmp - 2 * mi)
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s633941106
Wrong Answer
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) A = list(map(int, input().split())) if n == 2: i = 0 if (A[i] >= 0 and A[i + 1] <= 0) and abs(A[i]) < abs(A[i + 1]): A[i] = -A[i] A[i + 1] = -A[i + 1] elif (A[i] <= 0 and A[i + 1] >= 0) and abs(A[i]) > abs(A[i + 1]): A[i] = -A[i] A[i + 1] = -A[i + 1] elif A[i] <= 0 and A[i + 1] <= 0: A[i] = -A[i] A[i + 1] = -A[i + 1] else: for i in range(n - 2): if A[i] >= 0 and A[i + 1] >= 0 and A[i + 2] >= 0: continue elif A[i] >= 0 and A[i + 1] >= 0 and A[i + 2] <= 0: continue elif A[i] >= 0 and A[i + 1] <= 0 and A[i + 2] >= 0: if abs(A[i + 2]) <= abs(A[i + 1]) and A[i + 2] <= A[i]: A[i + 2] = -A[i + 2] A[i + 1] = -A[i + 1] elif abs(A[i]) <= abs(A[i + 1]) and A[i] <= A[i + 2]: A[i] = -A[i] A[i + 1] = -A[i + 1] elif A[i] <= 0 and A[i + 1] >= 0 and A[i + 2] >= 0: if abs(A[i]) >= abs(A[i + 1]): A[i] = -A[i] A[i + 1] = -A[i + 1] elif A[i] >= 0 and A[i + 1] <= 0 and A[i + 2] <= 0: A[i + 1] = -A[i + 1] A[i + 2] = -A[i + 2] elif A[i] <= 0 and A[i + 1] >= 0 and A[i + 2] <= 0: A[i] = -A[i] A[i + 2] = -A[i + 2] elif A[i] <= 0 and A[i + 1] <= 0 and A[i + 2] >= 0: A[i] = -A[i] A[i + 1] = -A[i + 1] elif A[i] <= 0 and A[i + 1] <= 0 and A[i + 2] <= 0: A[i] = -A[i] A[i + 1] = -A[i + 1] i = n - 2 if (A[i] >= 0 and A[i + 1] <= 0) and abs(A[i]) < abs(A[i + 1]): A[i] = -A[i] A[i + 1] = -A[i + 1] elif (A[i] <= 0 and A[i + 1] >= 0) and abs(A[i]) > abs(A[i + 1]): A[i] = -A[i] A[i + 1] = -A[i + 1] elif A[i] <= 0 and A[i + 1] <= 0: A[i] = -A[i] A[i + 1] = -A[i + 1] # print(A) print(sum(A))
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s054577855
Accepted
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N, *A = map(int, open(0).read().split()) x, y = 0, -1e10 for a in A: x, y = max(x + a, y - a), max(x - a, y + a) print(x)
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s733053374
Wrong Answer
p03062
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())) g = 0 for i in range(1, n): if ( i == n - 1 and num[i - 1] * -1 < num[i] * -1 or i != n - 1 and num[i - 1] * -1 > num[i] * -1 ): num[i - 1] *= -1 num[i] *= -1 print(sum(num))
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s860763214
Wrong Answer
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() n = ni() li = na() if n == 2: print(abs(sum(li))) else: for i in range(n - 2): if li[i] < 0: if li[i + 1] < 0: if li[i + 2] > 0: li[i] *= -1 li[i + 1] *= -1 else: if li[i] < li[i + 2]: li[i] *= -1 li[i + 1] *= -1 else: li[i + 1] *= -1 li[i + 2] *= -1 else: if li[i + 2] < 0: li[i] *= -1 li[i + 2] *= -1 else: if abs(li[i]) > abs(li[i + 1]): li[i] *= -1 li[i + 1] *= -1 else: if li[i + 1] < 0: if li[i + 2] < 0: li[i + 1] *= -1 li[i + 2] *= -1 else: li[i + 1] *= -1 else: if li[i + 2] < 0: if abs(li[i + 2]) > abs(li[i + 1]): li[i + 1] *= -1 li[i + 2] *= -1
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the maximum possible value of B_1 + B_2 + ... + B_N. * * *
s135768091
Accepted
p03062
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
_, *a = map(int, open(0).read().split()) (*z,) = map(abs, a) s = sum(z) print(s if len([i for i in a if i < 0]) % 2 == 0 or 0 in a else s - min(z) * 2)
Statement There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1. Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N.
[{"input": "3\n -10 5 -4", "output": "19\n \n\nIf we perform the operation as follows:\n\n * Choose 1 as i, which changes the sequence to 10, -5, -4.\n * Choose 2 as i, which changes the sequence to 10, 5, 4.\n\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4\n= 19, is the maximum possible result.\n\n* * *"}, {"input": "5\n 10 -4 -8 -11 3", "output": "30\n \n\n* * *"}, {"input": "11\n -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000", "output": "10000000000\n \n\nThe output may not fit into a 32-bit integer type."}]
Print the number of triples (A,B,C), modulo 998244353. * * *
s901771567
Runtime Error
p03432
Input is given from Standard Input in the following format: N M
def burger(l): if not l: return "P" s = "B" + burger(l - 1) + "P" + burger(l - 1) + "B" return s s = "" n, x = map(int, input().split()) print(burger(n)[:x].count("P"))
Statement We have an N \times M grid. The square at the i-th row and j-th column will be denoted as (i,j). Particularly, the top-left square will be denoted as (1,1), and the bottom-right square will be denoted as (N,M). Takahashi painted some of the squares (possibly zero) black, and painted the other squares white. We will define an integer sequence A of length N, and two integer sequences B and C of length M each, as follows: * A_i(1\leq i\leq N) is the minimum j such that (i,j) is painted black, or M+1 if it does not exist. * B_i(1\leq i\leq M) is the minimum k such that (k,i) is painted black, or N+1 if it does not exist. * C_i(1\leq i\leq M) is the maximum k such that (k,i) is painted black, or 0 if it does not exist. How many triples (A,B,C) can occur? Find the count modulo 998244353.
[{"input": "2 3", "output": "64\n \n\nSince N=2, given B_i and C_i, we can uniquely determine the arrangement of\nblack squares in each column. For each i, there are four possible pairs\n(B_i,C_i): (1,1), (1,2), (2,2) and (3,0). Thus, the answer is 4^M=64.\n\n* * *"}, {"input": "4 3", "output": "2588\n \n\n* * *"}, {"input": "17 13", "output": "229876268\n \n\n* * *"}, {"input": "5000 100", "output": "57613837"}]
Print the number of triples (A,B,C), modulo 998244353. * * *
s703154652
Runtime Error
p03432
Input is given from Standard Input in the following format: N M
a = int(input()) b = int(input()) ans = pow(2, a * b) % 998244353 print(ans)
Statement We have an N \times M grid. The square at the i-th row and j-th column will be denoted as (i,j). Particularly, the top-left square will be denoted as (1,1), and the bottom-right square will be denoted as (N,M). Takahashi painted some of the squares (possibly zero) black, and painted the other squares white. We will define an integer sequence A of length N, and two integer sequences B and C of length M each, as follows: * A_i(1\leq i\leq N) is the minimum j such that (i,j) is painted black, or M+1 if it does not exist. * B_i(1\leq i\leq M) is the minimum k such that (k,i) is painted black, or N+1 if it does not exist. * C_i(1\leq i\leq M) is the maximum k such that (k,i) is painted black, or 0 if it does not exist. How many triples (A,B,C) can occur? Find the count modulo 998244353.
[{"input": "2 3", "output": "64\n \n\nSince N=2, given B_i and C_i, we can uniquely determine the arrangement of\nblack squares in each column. For each i, there are four possible pairs\n(B_i,C_i): (1,1), (1,2), (2,2) and (3,0). Thus, the answer is 4^M=64.\n\n* * *"}, {"input": "4 3", "output": "2588\n \n\n* * *"}, {"input": "17 13", "output": "229876268\n \n\n* * *"}, {"input": "5000 100", "output": "57613837"}]
Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space.
s760460439
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
length = list(map(int, input().split(" "))) print(length[0] * length[1], 2 * (length[0] + length[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.
s799427841
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
length, width = map(int, input().split()) print(length * width, (length + width) * 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.
s442711898
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
arg = input().split() a = arg[0] b = arg[1] o = str(int(a) * int(b)) o2 = str(2 * (int(a) * int(b))) print(o + " " + o2)
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.
s918846329
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
i = list(map(int, input().split())) a = i[0] * i[1] b = 2 * (i[0] * i[1]) print("{0} {1}".format(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.
s558726514
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
a,b=map(int,input().split()) print(a*b,(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.
s557170145
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
A, B = map(int, input().split()) print(A * B, (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.
s597621606
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x, y = (int(i) for i in input().split()) res = x * y print(res)
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.
s495774633
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
a = list(map(int, input().split(" "))) ans = [str(a[0] * a[1]), str((a[0] + a[1]) * 2)] print(" ".join(ans))
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.
s438139882
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
data_str = input() data = data_str.split(" ") print(int(data[0]) * int(data[1]), 2 * (int(data[0]) + int(data[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.
s098961731
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
values = input() height, width = [int(x) for x in values.split()] print(height * width, height * 2 + width * 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.
s748970172
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
data = list(map(int, input().split(" "))) n = m = 0 for v in data: n = v if n == 0 else n * v m += 2 * v print(n, 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.
s376871984
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
# -*- coding:UTF-8 -*- num = input().split() print(int(num[0]) * int(num[1]), int(num[0]) * 2 + int(num[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.
s966881826
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
input_num = [int(i) for i in input().split(" ")] m = input_num[0] * input_num[1] print(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.
s420743695
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
a = input() b = a.split(" ") c = b[0] d = b[1] cint = int(c) dint = int(d) ans = cint * dint print(ans)
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.
s864114050
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
a, b = [ int(i) for i in input( "Enter two numbers concatenated by a single space, e.g. '3 5': " ).split() ] print(str(a * b) + " " + str((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.
s425499607
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
input_height_width = input() height, width = [int(x) for x in input_height_width.split()] print(height * width)
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.
s687378719
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
input = input().split(" ") a = int(input[0]) b = int(input[1]) x = a * b y = (a + b) * 2 print("{} {}".format(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.
s547657438
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x = list(map(int, input().split(" "))) print("{} {}".format(x[0] * x[1], 2 * (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.
s746505119
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
t, y = (int(x) for x in input().split()) men = t * y syu = 2 * (t + y) print(men, syu)
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.
s110764497
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x, y = [int(s) for s in input().split()] print("%d %d" % (x * y, (x + y) * 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.
s189541458
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
n = input().rstrip().split(" ") w = int(n[0]) l = int(n[1]) print(w * l, 2 * w + 2 * l)
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.
s702038513
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
s = [int(i) for i in input().split()] print(s[0] * s[1], s[0] * 2 + s[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.
s952569946
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
list = [int(i) for i in input().split()] print(list[0] * list[1], 2 * (list[0] + list[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.
s341826485
Accepted
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
x, y = [int(x) for x in input().split()] m = x * y l = 2 * x + 2 * y print(f"{m} {l}")
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.
s675835911
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
numbers = list(map(int, input().split())) print((numbers[0] + numbers[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.
s087827754
Wrong Answer
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
def main(a, b): print(a * b, 2 * (a + b), "\n")
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.
s863164920
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
a = map(int, input().split()) b = [0 for i in range(2)] b[0] = a[0] * a[1] b[1] = (a[0] + a[1]) * 2 print(*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.
s565247856
Runtime Error
p02389
The length a and breadth b of the rectangle are given in a line separated by a single space.
n = input().split() print(str(n[0] * n[1]) + " " + str((n[0] * 2) + (n[1] * 2)))
Rectangle Write a program which calculates the area and perimeter of a given rectangle.
[{"input": "3 5", "output": "15 16"}]