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
If the assignment is possible, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s880277511
Wrong Answer
p03650
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
print("POSSIBLE")
Statement There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N. The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i. * Each a_i is a non-negative integer. * For each edge (i, j), a_i \neq a_j holds. * For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment.
[{"input": "4\n 2 3 4 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {0, 1, 0, 1} or {a_i} = {1, 0, 1, 0}.\n\n* * *"}, {"input": "3\n 2 3 1", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "4\n 2 3 1 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {2, 0, 1, 0}.\n\n* * *"}, {"input": "6\n 4 5 6 5 6 4", "output": "IMPOSSIBLE"}]
If the assignment is possible, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s166586633
Runtime Error
p03650
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
from collections import defaultdict import heapq as hq def helper(n): q = child_L[n] del child_L[n] hq.heapify(q) i = 0 while q: t = hq.heappop(q) if i < t: break else: i += i == t j = i + 1 while q: t = hq.heappop(q) if j < t: break else: j += j == t return (i, j) if __name__ == "__main__": N = int(input()) P = list(map(lambda x: int(x) - 1, input().split())) # D:出している辺の本数 D = [0] * N for p in P: D[p] += 1 # print(D) child_L = defaultdict(list) # S:辺を出してないものリスト S = [p for p in range(N) if D[p] == 0] L = [None] * N while S: # print(child_L) n = S.pop() q = child_L[n] print(q) del child_L[n] # listのqをヒープキューに変換 hq.heapify(q) i = 0 while q: t = hq.heappop(q) if i < t: break else: i += i == t L[n] = i print(L) m = P[n] print("m:" + str(m)) child_L[m].append(i) D[m] -= 1 if D[m] == 0: S.append(m) print(D) # cycle check try: start = D.index(1) except ValueError: print("POSSIBLE") exit() s1, s2 = helper(start) G = [] n = P[start] while n != start: G.append(helper(n)) n = P[n] # del N, P, D, child_L, S, L # 可能な初期値をそれぞれシミュレート # 1 n = s1 for g in G: if g[0] == n: n = g[1] else: n = g[0] if n != s1: print("POSSIBLE") exit() # 2 n = s2 for g in G: if g[0] == n: n = g[1] else: n = g[0] if n == s1: print("POSSIBLE") exit() print("IMPOSSIBLE")
Statement There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N. The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i. * Each a_i is a non-negative integer. * For each edge (i, j), a_i \neq a_j holds. * For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment.
[{"input": "4\n 2 3 4 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {0, 1, 0, 1} or {a_i} = {1, 0, 1, 0}.\n\n* * *"}, {"input": "3\n 2 3 1", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "4\n 2 3 1 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {2, 0, 1, 0}.\n\n* * *"}, {"input": "6\n 4 5 6 5 6 4", "output": "IMPOSSIBLE"}]
If the assignment is possible, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s298413564
Runtime Error
p03650
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
# coding: utf-8 from collections import defaultdict def II(): return int(input()) def ILI(): return list(map(int, input().split())) def read(): N = II() p = ILI() return N, p def solve(N, p): ans = None edges = defaultdict(list) for i in range(N): edges[p[i]].append(i + 1) nodes_has_branch = [] for i in range(1, N + 1): if len(edges[i]) == 2: nodes_has_branch.append(i) if len(nodes_has_branch) == 0: if N % 2 == 0: ans = "POSSIBLE" else: ans = "IMPOSSIBLE" else: first_node = nodes_has_branch[0] edges_reverse = defaultdict(list) for fro, to in edges.items(): for i in to: edges_reverse[i].append(fro) circles = [] next_node = edges_reverse[first_node] while True: if next_node[0] == first_node: break circles.append(next_node[0]) next_node = edges_reverse[next_node[0]] circles = [first_node] + list(reversed(circles)) s_circles = set(circles) s_branch = set(range(1, N + 1)) - s_circles circles_depth = [0] * len(circles) for i, node in enumerate(circles): next_node = edges[node] if len(next_node) == 1: continue else: next_node = list((set(next_node) & s_branch))[0] while True: circles_depth[i] += 1 next_node = edges[next_node] if len(next_node) == 0: break if not 0 in circles_depth: ans = "IMPOSSIBLE" else: ans = "POSSIBLE" return ans def main(): params = read() print(solve(*params)) if __name__ == "__main__": main()
Statement There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N. The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i. * Each a_i is a non-negative integer. * For each edge (i, j), a_i \neq a_j holds. * For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment.
[{"input": "4\n 2 3 4 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {0, 1, 0, 1} or {a_i} = {1, 0, 1, 0}.\n\n* * *"}, {"input": "3\n 2 3 1", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "4\n 2 3 1 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {2, 0, 1, 0}.\n\n* * *"}, {"input": "6\n 4 5 6 5 6 4", "output": "IMPOSSIBLE"}]
If the assignment is possible, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s061305866
Wrong Answer
p03650
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
import sys sys.setrecursionlimit(10**7) N = int(input()) p = [i - 1 for i in map(int, input().split())] G = [[] for i in range(N)] for i, a in enumerate(p): G[a].append(i) visited = [False] * N Circle_ = [0] while not visited[Circle_[-1]]: visited[Circle_[-1]] = True Circle_.append(p[Circle_[-1]]) Circle = [Circle_[-1]] inCircle = [False] * N for i in Circle_[: len(Circle_) - 1][::-1]: inCircle[i] = True Circle.append(i) if i == Circle_[-1]: break # print(Circle) # print(G) num = [[]] * N def dfs(x): List = [False] * N for a in G[x]: if inCircle[a]: continue List[dfs(a)] = True if inCircle[x]: res = [] for i in range(N + 1): if not List[i]: if not res: res.append(i) else: res.append(i) num[x] = res return res else: for i in range(N + 1): if not List[i]: num[x] = [i] return i for i in Circle: dfs(i) # print(inCircle) # print(num) s, t = num[Circle[-1]][0], num[Circle[-1]][0] for i in Circle[: len(Circle) - 1][::-1]: if num[i][0] == t: t = num[i][1] else: t = num[i][0] # print(i,t) if t == s: print("POSSIBLE") exit() s, t = num[Circle[-1]][1], num[Circle[-1]][1] for i in Circle[: len(Circle) - 1][::-1]: if num[i][0] == t: t = num[i][1] else: t = num[i][0] # print(i,t) if t == s: print("POSSIBLE") else: print("INPOSSIBLE")
Statement There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N. The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i. * Each a_i is a non-negative integer. * For each edge (i, j), a_i \neq a_j holds. * For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment.
[{"input": "4\n 2 3 4 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {0, 1, 0, 1} or {a_i} = {1, 0, 1, 0}.\n\n* * *"}, {"input": "3\n 2 3 1", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "4\n 2 3 1 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {2, 0, 1, 0}.\n\n* * *"}, {"input": "6\n 4 5 6 5 6 4", "output": "IMPOSSIBLE"}]
Print one way to rearrange the numbers in the following format: B_{11} B_{12} ... B_{1M} : B_{N1} B_{N2} ... B_{NM} C_{11} C_{12} ... C_{1M} : C_{N1} C_{N2} ... C_{NM} Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2. * * *
s284879991
Accepted
p02942
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} : A_{N1} A_{N2} ... A_{NM}
from collections import defaultdict, deque N, M = map(int, input().split()) A = [[0] * M for _ in range(N)] B = [[0] * M for _ in range(N)] C = [[0] * M for _ in range(N)] G = defaultdict(lambda: defaultdict(int)) F = defaultdict(lambda: defaultdict(int)) rows = [0] * (N * M + 1) for i in range(N): A_list = list(map(int, input().split())) A[i] = A_list for a in A_list: G[i + 1][N + (a + M - 1) // M] += 1 G[N + (a + M - 1) // M][i + 1] = 0 # dfs for t1 in range(M): for i in range(1, N + 1): G[0][i] = 1 F[0][i] = 0 G[N + i][2 * N + 1] = 1 F[N + i][2 * N + 1] = 0 for t2 in range(N): queue = deque([0]) searched = [0] * (2 * N + 2) searched[0] = 1 parent = [0] * (2 * N + 2) while len(queue) > 0: p = queue.pop() for q in G[p].keys(): if (G[p][q] > 0 or F[q][p] > 0) and searched[q] == 0: parent[q] = p searched[q] = 1 queue.append(q) if searched[2 * N + 1] == 1: break path = [2 * N + 1] while True: path.append(parent[path[-1]]) if path[-1] == 0: break for i in range(len(path) - 1, 0, -1): p, q = path[i], path[i - 1] if G[p][q] > 0: G[p][q] -= 1 F[p][q] += 1 elif F[q][p] > 0: F[q][p] -= 1 G[q][p] += 1 for i in range(1, N + 1): ji = 0 for j in range(N + 1, 2 * N + 1): if F[i][j] == 1: ji = j break F[i][ji] -= 1 for a in A[i - 1]: if N + (a + M - 1) // M == ji: A[i - 1].remove(a) B[i - 1][t1] = a break for j in range(M): c_j = list(sorted([B[i][j] for i in range(N)])) for i in range(N): C[i][j] = c_j[i] if __name__ == "__main__": for i in range(N): print(*B[i]) for i in range(N): print(*C[i])
Statement We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}. You need to rearrange these numbers as follows: 1. First, for each of the N rows, rearrange the numbers written in it as you like. 2. Second, for each of the M columns, rearrange the numbers written in it as you like. 3. Finally, for each of the N rows, rearrange the numbers written in it as you like. After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.
[{"input": "3 2\n 2 6\n 4 3\n 1 5", "output": "2 6 \n 4 3 \n 5 1 \n 2 1 \n 4 3 \n 5 6 \n \n\n* * *"}, {"input": "3 4\n 1 4 7 10\n 2 5 8 11\n 3 6 9 12", "output": "1 4 7 10 \n 5 8 11 2 \n 9 12 3 6 \n 1 4 3 2 \n 5 8 7 6 \n 9 12 11 10"}]
Print one way to rearrange the numbers in the following format: B_{11} B_{12} ... B_{1M} : B_{N1} B_{N2} ... B_{NM} C_{11} C_{12} ... C_{1M} : C_{N1} C_{N2} ... C_{NM} Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2. * * *
s318499011
Wrong Answer
p02942
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} : A_{N1} A_{N2} ... A_{NM}
n, m = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] import numpy as np b = a[:] for i in range(n): b[i].sort() b[i] = b[i][i:] + b[i][:i] c = np.array(b[:]) for j in range(m): c[:, j].sort() c = c.tolist() for i in b: print(*i, sep=" ") for i in c: print(*i, sep=" ")
Statement We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}. You need to rearrange these numbers as follows: 1. First, for each of the N rows, rearrange the numbers written in it as you like. 2. Second, for each of the M columns, rearrange the numbers written in it as you like. 3. Finally, for each of the N rows, rearrange the numbers written in it as you like. After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.
[{"input": "3 2\n 2 6\n 4 3\n 1 5", "output": "2 6 \n 4 3 \n 5 1 \n 2 1 \n 4 3 \n 5 6 \n \n\n* * *"}, {"input": "3 4\n 1 4 7 10\n 2 5 8 11\n 3 6 9 12", "output": "1 4 7 10 \n 5 8 11 2 \n 9 12 3 6 \n 1 4 3 2 \n 5 8 7 6 \n 9 12 11 10"}]
Print one way to rearrange the numbers in the following format: B_{11} B_{12} ... B_{1M} : B_{N1} B_{N2} ... B_{NM} C_{11} C_{12} ... C_{1M} : C_{N1} C_{N2} ... C_{NM} Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2. * * *
s421189961
Wrong Answer
p02942
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} : A_{N1} A_{N2} ... A_{NM}
N, M = map(int, input().split()) arr = [] for i in range(N): arr.append(list(map(int, input().split()))) arr[-1].sort(key=lambda x: x % M, reverse=True) print(*arr[-1], sep=" ") rev = (sorted(arr_) for arr_ in map(list, zip(*arr))) for hogehoge in map(list, zip(*rev)): print(*hogehoge, sep=" ")
Statement We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}. You need to rearrange these numbers as follows: 1. First, for each of the N rows, rearrange the numbers written in it as you like. 2. Second, for each of the M columns, rearrange the numbers written in it as you like. 3. Finally, for each of the N rows, rearrange the numbers written in it as you like. After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.
[{"input": "3 2\n 2 6\n 4 3\n 1 5", "output": "2 6 \n 4 3 \n 5 1 \n 2 1 \n 4 3 \n 5 6 \n \n\n* * *"}, {"input": "3 4\n 1 4 7 10\n 2 5 8 11\n 3 6 9 12", "output": "1 4 7 10 \n 5 8 11 2 \n 9 12 3 6 \n 1 4 3 2 \n 5 8 7 6 \n 9 12 11 10"}]
Print one way to rearrange the numbers in the following format: B_{11} B_{12} ... B_{1M} : B_{N1} B_{N2} ... B_{NM} C_{11} C_{12} ... C_{1M} : C_{N1} C_{N2} ... C_{NM} Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2. * * *
s288621221
Runtime Error
p02942
Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} : A_{N1} A_{N2} ... A_{NM}
from collections import defaultdict def solve(n, m, aaa): def find(si, used, matched): for ti in targets[si]: if ti in used: continue used.add(ti) if matched[ti] == -1 or find(matched[ti], used, matched): matched[ti] = si return True return False targets = [set() for _ in range(n)] numbers = defaultdict(set) for si, row in enumerate(aaa): for a in row: ti = (a - 1) // m targets[si].add(ti) numbers[si, ti].add(a) bbb = [[0] * m for _ in range(n)] ccc = [[0] * m for _ in range(n)] for j in range(m): matched = [-1] * n assert all(find(si, set(), matched) for si in range(n)) for si, ti in enumerate(matched): a = numbers[si, ti].pop() bbb[si][j] = a ccc[ti][j] = a if len(numbers[si, ti]) == 0: targets[si].remove(ti) del numbers[si, ti] print("\n".join(" ".join(map(str, row)) for row in bbb)) print("\n".join(" ".join(map(str, row)) for row in ccc)) n, m = map(int, input().split()) aaa = [list(map(int, input().split())) for _ in range(n)] solve(n, m, aaa)
Statement We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}. You need to rearrange these numbers as follows: 1. First, for each of the N rows, rearrange the numbers written in it as you like. 2. Second, for each of the M columns, rearrange the numbers written in it as you like. 3. Finally, for each of the N rows, rearrange the numbers written in it as you like. After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.
[{"input": "3 2\n 2 6\n 4 3\n 1 5", "output": "2 6 \n 4 3 \n 5 1 \n 2 1 \n 4 3 \n 5 6 \n \n\n* * *"}, {"input": "3 4\n 1 4 7 10\n 2 5 8 11\n 3 6 9 12", "output": "1 4 7 10 \n 5 8 11 2 \n 9 12 3 6 \n 1 4 3 2 \n 5 8 7 6 \n 9 12 11 10"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s239737188
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
from collections import Counter def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() array_temp = [] if data != "": array_result.append(data.split(" ")) flg = 1 else: flg = 0 finally: return array_result arr_data = getinputdata() a = int(arr_data[0][0]) b = int(arr_data[0][1]) c = int(arr_data[0][2]) k = int(arr_data[0][3]) if k % 2 == 0: print("Unfair" if a - b >= 10**18 else a - b) else: print("Unfair" if b - a >= 10**18 else b - a)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s118270801
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
#!/usr/bin/env python3 import sys, math, copy # import fractions, itertools # import numpy as np # import scipy # sys.setrecursionlimit(1000000) HUGE = 2147483647 HUGEL = 9223372036854775807 ABC = "abcdefghijklmnopqrstuvwxyz" def main(): a, b, c, k = map(int, input().split()) su = a + b + c a += su * (k // 2) b += su * (k // 2) c += su * (k // 2) if k % 2 == 1: an = b + c bn = c + a cn = a + b a, b, c = an, bn, cn print(a - b if abs(a - b) <= 10**18 else "Unfair") main()
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s331277121
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] ## libs ## from itertools import accumulate as acc from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): a, b, c, k = MII() if k % 2 == 1: print(b - a) else: print(a - b) if __name__ == "__main__": main()
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s189147995
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a,b,c,k=map(int,input().split()) if abs(a-b)>10**18: print("unfair) else: if k%2==0: print(a-b) else: print(b-a)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s555103313
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a,b,c,k=map(int,input().split()) if k%2 == 0 and abs(a-b)<=10**8:print(a-b) elif k%2 != 0 abs(b-a)<=10**8:print(b-a) else:print("Unfair")
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s178209381
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
A, B, C, K = [int(i) for i in input().split()] # BC, AC, AB = B - A # AABC, ABBC, ABCC = A - B # AABBBCCC, AAABBCCC, AAABBBCC = B - A print(B - A if K & 1 else A - B)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s188688805
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
list = input().rstrip().split() A = int(list[0]) B = int(list[1]) C = int(list[2]) K = int(list[3]) print((A - B) * ((-1) ** K))
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s566320988
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
da = list(map(int,input().split())) m = 0 l = pow(10,18) if da[3] % 2 == 1: k = da[1] -da[0] else: k = da[0] -da[1] elif abs(da[0] - da[1]) < l: print(da[0] - da[1]) elif abs(da[0] - da[1]) >= l: print("Unfair")
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s405554994
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
a, b, c, k = list(map(int, input().split(" "))) print((b - a) * (2 * (k % 2) - 1))
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s789963479
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
a, b, c, k = [int(_) for _ in input().split()] print((-1) ** k * (a - b))
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s943979109
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
INF = 10**18 A,B,C,K = map(int,input().split()) print((B-A if K%2==1 else A-B)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s420103792
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a,b,c,k = int(input().split()) for i = range(k): na = b + c nb = a + c nc = a + b a = na b = nb c = nc sns = a - b if ans > 10**18: print('Unfair') else: print(ans)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s444063431
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from decimal import * from collections import deque sys.setrecursionlimit(10**7) MOD = 10**9 + 7 INF = float("inf") # 無限大 def gcd(a, b): return fractions.gcd(a, b) # 最大公約数 def lcm(a, b): return (a * b) // fractions.gcd(a, b) # 最小公倍数 def iin(): return int(sys.stdin.readline()) # 整数読み込み def ifn(): return float(sys.stdin.readline()) # 浮動小数点読み込み def isn(): return sys.stdin.readline().split() # 文字列読み込み def imn(): return map(int, sys.stdin.readline().split()) # 整数map取得 def imnn(): return map(lambda x: int(x) - 1, sys.stdin.readline().split()) # 整数-1map取得 def fmn(): return map(float, sys.stdin.readline().split()) # 浮動小数点map取得 def iln(): return list(map(int, sys.stdin.readline().split())) # 整数リスト取得 def iln_s(): return sorted(iln()) # 昇順の整数リスト取得 def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得 def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得 def join(l, s=""): return s.join(l) # リストを文字列に変換 def perm(l, n): return itertools.permutations(l, n) # 順列取得 def perm_count(n, r): return math.factorial(n) // math.factorial(n - r) # 順列の総数 def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得 def comb_count(n, r): return math.factorial(n) // ( math.factorial(n - r) * math.factorial(r) ) # 組み合わせの総数 def two_distance(a, b, c, d): return ((c - a) ** 2 + (d - b) ** 2) ** 0.5 # 2点間の距離 def m_add(a, b): return (a + b) % MOD def print_list(l): print(*l, sep="\n") def sieves_of_e(n): is_prime = [True] * (n + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, n + 1, i): is_prime[j] = False return is_prime A, B, C, K = imn() ans = A - B if K % 2 == 1: ans *= -1 print(ans)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s121977582
Accepted
p03345
Input is given from Standard Input in the following format: A B C K
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt from functools import lru_cache, reduce INF = 1 << 60 mod = 1000000007 sys.setrecursionlimit(10**7) input = sys.stdin.readline # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # 素因数分解 def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # ここから書き始める a, b, c, k = map(int, input().split()) if abs(a - b) > 10**18: print("Unfair") elif k % 2 == 0: print(a - b) else: print(b - a)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s343428587
Wrong Answer
p03345
Input is given from Standard Input in the following format: A B C K
a, b, c, k = list(map(int, input().split())) ta = tb = tc = 0 s = a + b + c a = s * (k // 4) + a b = s * (k // 4) + b c = s * (k // 4) + c for i in range(k % 4): ta = a tb = b tc = c a = tb + tc b = ta + tc c = ta + tb print(a - b if abs(a - b) < 10 * 18 else "Unfair")
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s935450557
Wrong Answer
p03345
Input is given from Standard Input in the following format: A B C K
a, b, c, k = map(int, input().split()) flag = 0 for i in range(k): if a > 10 ^ 18 or b > 10 ^ 18 or c > 10 ^ 18: print("Unfair") flag = 1 break e = b + c f = a + b g = a + c a = e c = f b = g if flag == 0: print(a - b)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s528104462
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a,b,c,k = list(map(int,input().split())) if result > 10 **18: print("Unfair") elif k % 2 == 0: print(result) elif l % 2 == 1: result = result * -1 print(result)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s812685342
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
def a():
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s426859249
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
A, B, C, K = list(map(int.input().split())) print(((-1) ** K) * (A - B))
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s721378078
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
def abs(k): if k >= 0: return k else: return -k def main(): a, b, c ,n = list(map(int,input().split())) i for i in range(n): a = b + c b = c + a c = a + b res = a - b if abs(res) > 10 ** 18: print('Unfair') else: print(res)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s603854607
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a, b, c, k = map(int, input().split()) for i in range(10**18): A = a B = b C = c a = B + C b = A + C c = A + B if i = k - 1: break if abs(a - b) <= 10**18: print(a - b) else: print('Unfair')
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s560619297
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
def abs(k): if k >= 0: return k else: return -k a, b, c ,n = list(map(int,input().split())) i for i in range(n): a = b + c b = c + a c = a + b res = a - b if abs(res) > 10 ** 18: print('Unfair') else: print(res)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s408899215
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a,b,c,k=map(int,input().split()) if a-b>10**8: print("Unfair") else: print(a-b if k%2=1 else b-a)
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. * * *
s993399206
Runtime Error
p03345
Input is given from Standard Input in the following format: A B C K
a,b,c,k = list(map(int,input().split())) unfair = 10^18 if k%2 ==0: if a-b <= unfair print(a-b) else: print('Unfair') else: if b-a <= unfair print(b-a) else: print('Unfair')
Statement Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead.
[{"input": "1 2 3 1", "output": "1\n \n\nAfter one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3,\nrespectively. We should print 5-4=1.\n\n* * *"}, {"input": "2 3 2 0", "output": "-1\n \n\n* * *"}, {"input": "1000000000 1000000000 1000000000 1000000000000000000", "output": "0"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s658591211
Accepted
p03715
Input is given from Standard Input in the following format: H W
h, w = map(int, input().split()) ch1 = h // 3 ch2 = ch1 + 1 cw1 = w // 3 cw2 = cw1 + 1 ans = float("inf") # ch1で切ってwの真ん中で切る。 s = [0, 0, 0] s[0] = ch1 * w yoko1 = w // 2 yoko2 = w - yoko1 s[1] = (h - ch1) * yoko1 s[2] = (h - ch1) * yoko2 temp = max(s) - min(s) ans = min(ans, temp) # ch2で切ってwの真ん中で切る。 s = [0, 0, 0] s[0] = ch2 * w yoko1 = w // 2 yoko2 = w - yoko1 s[1] = (h - ch2) * yoko1 s[2] = (h - ch2) * yoko2 temp = max(s) - min(s) ans = min(ans, temp) # 全部横 s = [0, 0, 0] s[0] = ch1 * w tate1 = (h - ch1) // 2 tate2 = h - ch1 - tate1 s[1] = tate1 * w s[2] = tate2 * w temp = max(s) - min(s) ans = min(ans, temp) # 全部縦 s = [0, 0, 0] s[0] = cw1 * h yoko1 = (w - cw1) // 2 yoko2 = w - cw1 - yoko1 s[1] = yoko1 * h s[2] = yoko2 * h temp = max(s) - min(s) ans = min(ans, temp) # cw1で切ってhの真ん中で切る。 s = [0, 0, 0] s[0] = cw1 * h tate1 = h // 2 tate2 = h - tate1 s[1] = (w - cw1) * tate1 s[2] = (w - cw1) * tate2 temp = max(s) - min(s) ans = min(ans, temp) # cw2で切ってhの真ん中で切る。 s = [0, 0, 0] s[0] = cw2 * h tate1 = h // 2 tate2 = h - tate1 s[1] = (w - cw2) * tate1 s[2] = (w - cw2) * tate2 temp = max(s) - min(s) ans = min(ans, temp) print(ans)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s916284355
Runtime Error
p03715
Input is given from Standard Input in the following format: H W
H,W=map(int,input().split()) if H%3==0 or W%3==0: print(0) elif H%2==0 or W%2==0: if W%2==0: H,W=W,H A1=(H//2 )* W A3=0 value=A1-A3 for i in range(1,W//2 +): A3+=H A1-=H//2 value=min(int(abs(A1-A3)),value) print(value) else: A1=(H//2 +1)* W A2=(H//2)* W A3=0 value=max(A1,A2,A3)-min(A1,A2,A3) for i in range(1,W//2): A3+=H A1-=H//2 + 1 A2-=H//2 value=min(max(A1,A2,A3)-min(A1,A2,A3),value) H,W=H,W A1=(H//2 +1)* W A2=(H//2) * W A3=0 value=min(max(A1,A2,A3)-min(A1,A2,A3),value) for i in range(1,W//2): A3+=H A1-=H//2 + 1 A2-=H//2 value=min(max(A1,A2,A3)-min(A1,A2,A3),value) print(value)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s112914809
Runtime Error
p03715
Input is given from Standard Input in the following format: H W
from heapq import * from collections import * n, *a = map(int, open(0).read().split()) ans = -float("inf") b = a[:n] c = deque(a[n:]) heapify(b) s = sum(b) s2 = sum(nsmallest(n, c)) red = [s - s2] for i in range(n, n * 2): s += a[i] - heappushpop(b, a[i]) c.popleft() s2 = sum(nsmallest(n, c)) red += [s - s2] print(max(red)) # あhjfkぁdshflkじゃgはlkjdjglk;あjdglk;あdsjgl;あjsdglk;あjsdgl;かs
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s954791384
Accepted
p03715
Input is given from Standard Input in the following format: H W
#!/usr/bin/env python3 # %% for atcoder uniittest use import sys input = lambda: sys.stdin.readline().rstrip() def pin(type=int): return map(type, input().split()) def tupin(t=int): return tuple(pin(t)) # %%code def resolve(): H, W = pin() if H % 3 == 0 or W % 3 == 0: print(0) return # ans = min(H, W) for i in range(1, H): yoko = W * i a = W // 2 * (H - i) b = W * H - yoko - a t = max(yoko, a, b) - min(yoko, a, b) ans = min(t, ans) for j in range(1, W): yoko = H * j a = (H // 2) * (W - j) b = W * H - yoko - a t = max(yoko, a, b) - min(yoko, a, b) ans = min(t, ans) print(ans) # %%submit! resolve()
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s087329710
Accepted
p03715
Input is given from Standard Input in the following format: H W
def calc(W, H): ans = float("inf") for w in range(1, W // 2 + 1): x = w * H w_ = W - w if w_ % 2 == 0 or H % 2 == 0: y = (w_ * H) // 2 li = sorted([x, y, y]) else: if w_ < H: a, b = w_, H else: a, b = H, w_ y = a * (b // 2) z = a * (b - b // 2) li = sorted([x, y, z]) ans = min(ans, li[2] - li[0]) return ans def main(): import sys input = sys.stdin.readline w, h = map(int, input().split()) ans = calc(w, h) ans = min(calc(h, w), ans) print(ans) if __name__ == "__main__": main()
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s121262221
Runtime Error
p03715
Input is given from Standard Input in the following format: H W
n = int(input()) A = list(map(int, input().split())) B = [] for i in range(n, 2 * n + 1): A1 = A[:i] A2 = A[i:] a1 = i - n a2 = 2 * n - i A1.sort() A1 = A1[a1:] A2.sort() if a2 != 0: A2 = A2[:-a2] # print(A1,A2) B.append(sum(A1) - sum(A2)) # print(B) print(max(B))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s755672237
Accepted
p03715
Input is given from Standard Input in the following format: H W
def main(): from math import floor, ceil h, w = map(int, input().split(" ")) result = [] if h % 3 == 0 or w % 3 == 0: print(0) elif h < 3 or w < 3: if h < 3 and w >= 3: for i in range(1, w - 1): x = i * h y = (w - i) * floor(h / 2) z = (w - i) * ceil(h / 2) result.append(max(x, y, z) - min(x, y, z)) y = floor((w - i) / 2) * h z = ceil((w - i) / 2) * h result.append(max(x, y, z) - min(x, y, z)) print(min(result)) elif h >= 3 and w < 3: for i in range(1, h - 1): x = i * w y = (h - i) * floor(w / 2) z = (h - i) * ceil(w / 2) result.append(max(x, y, z) - min(x, y, z)) y = floor((h - i) / 2) * w z = ceil((h - i) / 2) * w result.append(max(x, y, z) - min(x, y, z)) print(min(result)) else: print(1) else: for i in range(1, h - 1): x = i * w y = (h - i) * floor(w / 2) z = (h - i) * ceil(w / 2) result.append(max(x, y, z) - min(x, y, z)) y = floor((h - i) / 2) * w z = ceil((h - i) / 2) * w result.append(max(x, y, z) - min(x, y, z)) for i in range(1, w - 1): x = i * h y = (w - i) * floor(h / 2) z = (w - i) * ceil(h / 2) result.append(max(x, y, z) - min(x, y, z)) y = floor((w - i) / 2) * h z = ceil((w - i) / 2) * h result.append(max(x, y, z) - min(x, y, z)) print(min(result)) main()
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s325726383
Accepted
p03715
Input is given from Standard Input in the following format: H W
# -*- coding: utf-8 -*- import sys, math H, W = map(int, input().split(" ")) def calc(a, b, c): tmp = (a[0] * a[1], b[0] * b[1], c[0] * c[1]) return max(tmp) - min(tmp) result = H * W # H for i in range(H // 2 + 1): a = (i, W) hh = H - i rest = (hh, W) result = min( [ result, calc(a, (hh // 2, W), (hh - hh // 2, W)), calc(a, (hh, W // 2), (hh, W - W // 2)), ] ) # W for i in range(W // 2 + 1): a = (H, i) ww = W - i rest = (H, ww) result = min( [ result, calc(a, (H // 2, ww), (H - H // 2, ww)), calc(a, (H, ww // 2), (H, ww - ww // 2)), ] ) print(result)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s152422412
Accepted
p03715
Input is given from Standard Input in the following format: H W
h, w = map(int, input().split()) l = [] for i in range(1, h): s1 = w * i s2 = (h - i) * (w // 2) s3 = h * w - s1 - s2 l.append(max(s1, s2, s3) - min(s1, s2, s3)) for i in range(1, w): s1 = h * i s2 = (w - i) * (h // 2) s3 = h * w - s1 - s2 l.append(max(s1, s2, s3) - min(s1, s2, s3)) for i in range(1, h - 1): s1 = w * i s2 = w * ((h - i) // 2) s3 = w * h - s1 - s2 l.append(max(s1, s2, s3) - min(s1, s2, s3)) for i in range(1, w - 1): s1 = h * i s2 = h * ((w - i) // 2) s3 = w * h - s1 - s2 l.append(max(s1, s2, s3) - min(s1, s2, s3)) print(min(l))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s740157638
Accepted
p03715
Input is given from Standard Input in the following format: H W
h, w = map(int, input().split()) now = h * w y = 1 while y < h: a = y * w if w % 2 == 0: b = (h - y) * (w // 2) c = (h - y) * (w // 2) elif (h - y) % 2 == 0: b = ((h - y) // 2) * w c = ((h - y) // 2) * w else: if (h - y) >= w: b = (h - y) * (w // 2 + 1) c = (h - y) * (w // 2) else: b = w * ((h - y) // 2 + 1) c = w + ((h - y) // 2) lis = [a, b, c] if max(lis) - min(lis) < now: now = max(lis) - min(lis) y += 1 x = 1 while x < w: a = x * h if h % 2 == 0: b = (w - x) * (h // 2) c = (w - x) * (h // 2) elif (w - x) % 2 == 0: b = ((w - x) // 2) * h c = ((w - x) // 2) * h else: if (w - x) >= h: b = ((w - x) // 2) * h c = ((w - x) // 2 + 1) * h else: b = (h // 2 + 1) * (w - x) c = (h // 2) * (w - x) lis = [a, b, c] if max(lis) - min(lis) < now: now = max(lis) - min(lis) x += 1 print(now)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s606710028
Accepted
p03715
Input is given from Standard Input in the following format: H W
import bisect H, W = map(int, input().split()) ans = H * W for h in range(H): h1 = (H - h) // 2 if (H - h) % 2 == 0 else (H - h) // 2 + 1 Smax = max(h * W, h1 * W) Smin = min(h * W, ((H - h) // 2) * W) ans = min(ans, Smax - Smin) w1 = W // 2 if W % 2 == 0 else W // 2 + 1 Smax = max(h * W, (H - h) * w1) Smin = min(h * W, (H - h) * (W // 2)) ans = min(ans, Smax - Smin) for w in range(W): w1 = (W - w) // 2 if (W - w) % 2 == 0 else (W - w) // 2 + 1 Smax = max(H * w, H * w1) Smin = min(H * w, H * ((W - w) // 2)) ans = min(ans, Smax - Smin) h1 = H // 2 if H % 2 == 0 else H // 2 + 1 Smax = max(H * w, h1 * (W - w)) Smin = min(H * w, (H // 2) * (W - w)) ans = min(ans, Smax - Smin) print(ans)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s131595405
Accepted
p03715
Input is given from Standard Input in the following format: H W
h, w = [int(x) for x in input().split()] d1 = min( max(w1 * h, (w - w1) * (h // 2), (w - w1) * ((h + 1) // 2)) - min(w1 * h, (w - w1) * (h // 2), (w - w1) * ((h + 1) // 2)) for w1 in range(1, w) ) d2 = min( max(w1 * h, ((w - w1) // 2) * h, ((w - w1 + 1) // 2) * h) - min(w1 * h, ((w - w1) // 2) * h, ((w - w1 + 1) // 2) * h) for w1 in range(1, w) ) d3 = min( max(h1 * w, (h - h1) * (w // 2), (h - h1) * ((w + 1) // 2)) - min(h1 * w, (h - h1) * (w // 2), (h - h1) * ((w + 1) // 2)) for h1 in range(1, h) ) d4 = min( max(h1 * w, ((h - h1) // 2) * w, ((h - h1 + 1) // 2) * w) - min(h1 * w, ((h - h1) // 2) * w, ((h - h1 + 1) // 2) * w) for h1 in range(1, h) ) print(min(d1, d2, d3, d4))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s295471099
Wrong Answer
p03715
Input is given from Standard Input in the following format: H W
H, W = map(int, input().split()) if H % 3 == 0 or W % 3 == 0: sq = 0 else: sq = min((H // 3 + 1 - H // 3) * W, (W // 3 + 1 - W // 3) * H) for H, W in [[W, H], [W, H]]: for h in range(1, H + 1): sq21 = h * W sq22 = (H - h) * -(-W // 2) sq23 = (H - h) * (W // 2) sq = min(sq, max(sq21, sq22, sq23) - min(sq21, sq22, sq23)) print(sq)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s790349269
Accepted
p03715
Input is given from Standard Input in the following format: H W
import sys h, w = [int(i) for i in input().split()] h3 = int(h / 3) w3 = int(w / 3) ret = sys.maxsize # ||| Split if h % 3 == 0 or w % 3 == 0: ret = 0 a1 = h3 * w a2 = (h3 + 1) * w if ret > a2 - a1: ret = a2 - a1 a1 = w3 * h a2 = (w3 + 1) * h if ret > a2 - a1: ret = a2 - a1 # print("|||:", a2 - a1) # T Split a1 = h3 * w a2 = (h - h3) * int(w / 2) if w % 2 == 1: a2 += h - h3 a3 = (h - h3) * int(w / 2) amin = a1 if a1 > a3: amin = a3 amax = a2 if a1 > a2: amax = a1 if ret > (amax - amin): ret = amax - amin # print("T1: ", amax - amin) h31 = h3 + 1 a1 = (h31) * w # 10 a2 = (h - h31) * int(w / 2) # 6 if w % 2 == 1: a2 += h - h31 # 9 a3 = (h - h31) * int(w / 2) amin = a1 if a1 > a3: amin = a3 amax = a2 if a1 > a2: amax = a1 if ret > (amax - amin): ret = amax - amin # print("T2: ", amax - amin, amax, amin) h, w = w, h h3 = int(h / 3) w3 = int(w / 3) a1 = h3 * w a2 = (h - h3) * int(w / 2) if w % 2 == 1: a2 += h - h3 a3 = (h - h3) * int(w / 2) amin = a1 if a1 > a3: amin = a3 amax = a2 if a1 > a2: amax = a1 if ret > (amax - amin): ret = amax - amin # print("T3: ", amax - amin) h31 = h3 + 1 a1 = (h31) * w a2 = (h - h31) * int(w / 2) if w % 2 == 1: a2 += h - h31 a3 = (h - h31) * int(w / 2) amin = a1 if a1 > a3: amin = a3 amax = a2 if a1 > a2: amax = a1 if ret > (amax - amin): ret = amax - amin # print("T4: ", amax - amin) print(int(ret))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s236662539
Accepted
p03715
Input is given from Standard Input in the following format: H W
H, W = map(int, input().split()) alt = [] if H % 3 == 0 or W % 3 == 0: print(0) elif H == 2 or W == 2: print(1) else: S1 = (H // 3) * W S2 = (H - (H // 3)) * (W // 2) S3 = H * W - S1 - S2 alt.append([S1, S2, S3]) S1 = ((H // 3) + 1) * W S2 = (H - (H // 3) - 1) * (W // 2) S3 = H * W - S1 - S2 alt.append([S1, S2, S3]) S1 = (W // 3) * H S2 = (W - (W // 3)) * (H // 2) S3 = H * W - S1 - S2 alt.append([S1, S2, S3]) S1 = ((W // 3) + 1) * H S2 = (W - (W // 3) - 1) * (H // 2) S3 = H * W - S1 - S2 alt.append([S1, S2, S3]) if H % 3 == 1: S1 = W * (H // 3) S2 = W * (H // 3) S3 = W * ((H // 3) + 1) else: S1 = W * (H // 3) S2 = W * ((H // 3) + 1) S3 = W * ((H // 3) + 1) alt.append([S1, S2, S3]) if W % 3 == 1: S1 = H * (W // 3) S2 = H * (W // 3) S3 = H * ((W // 3) + 1) else: S1 = H * (W // 3) S2 = H * ((W // 3) + 1) S3 = H * ((W // 3) + 1) alt.append([S1, S2, S3]) print(min([max(i) - min(i) for i in alt]))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s350074699
Accepted
p03715
Input is given from Standard Input in the following format: H W
h, w = list(map(int, input().split())) def area(h, w, p): if p == 1: return h * w, h * w cmin = 10**10 + 1 hh = h // p if hh > 0: sh = hh * w smax, smin = area(h - hh, w, p - 1) tmax = max(sh, smax) tmin = min(sh, smin) if tmax - tmin < cmin: retmax = tmax retmin = tmin cmin = retmax - retmin hh += 1 if hh < h: sh = hh * w smax, smin = area(h - hh, w, p - 1) tmax = max(sh, smax) tmin = min(sh, smin) if tmax - tmin < cmin: retmax = tmax retmin = tmin cmin = retmax - retmin ww = w // p if ww > 0: sw = ww * h smax, smin = area(h, w - ww, p - 1) tmax = max(sw, smax) tmin = min(sw, smin) if tmax - tmin < cmin: retmax = tmax retmin = tmin cmin = retmax - retmin ww += 1 if ww < w: sw = ww * h smax, smin = area(h, w - ww, p - 1) tmax = max(sw, smax) tmin = min(sw, smin) if tmax - tmin < cmin: retmax = tmax retmin = tmin cmin = retmax - retmin return retmax, retmin smax, smin = area(h, w, 3) print(smax - smin)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s745978389
Runtime Error
p03715
Input is given from Standard Input in the following format: H W
import math H,W=map(int,input().split()) if H%3==0 or W%3==0: print(0) exit(0) S=[0]*3 s=H*import math H,W=map(int,input().split()) if H%3==0 or W%3==0: print(0) exit(0) S=[0]*3 s=H*W/3 w0=math.ceil(s/H) h0=math.ceil(s/W) S[0]=w0*H w1=W-W/3 w0=math.ceil(s/H) h0=math.ceil(s/W) S[0]=w0*H w1=W-w0 if w1%2==0 or H%2==0: S[1]=(H*w1)//2 S[2]=(H*w1)//2 else: s1=H*w1/2 w10=math.ceil(s1/H) h10=math.ceil(s1/w1) S[2]=max((w1-w10)*H,(H-h10)*w1) ans=abs(S[0]-S[2]) S[0]=W*h0 h1=H-h0 if h1%2==0 or W%2==0: S[1]=(W*h1)//2 S[2]=(W*h1)//2 else: s1=h1*W/2 w11=math.ceil(s1/h1) h11=math.ceil(s1/W) S[2]=max((W-w11)*h1,(h1-h11)*W) ans=min(ans,abs(S[0]-S[2])) S=[0]*3 s=H*W/3 w0=math.floor(s/H) h0=math.floor(s/W) S[0]=w0*H w1=W-w0 if w1%2==0 or H%2==0: S[1]=(H*w1)//2 S[2]=(H*w1)//2 else: s1=H*w1/2 w10=math.floor(s1/H) h10=math.floor(s1/w1) S[2]=max((w1-w10)*H,(H-h10)*w1) ans=min(ans,abs(S[0]-S[2])) S[0]=W*h0 h1=H-h0 if h1%2==0 or W%2==0: S[1]=(W*h1)//2 S[2]=(W*h1)//2 else: s1=h1*W/2 w11=math.floor(s1/h1) h11=math.floor(s1/W) S[2]=max((W-w11)*h1,(h1-h11)*W) ans=min(ans,abs(S[0]-S[2])) print(ans)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s064747013
Accepted
p03715
Input is given from Standard Input in the following format: H W
H, W = map(int, input().split()) a = [ [(H // 3) * W, ((H - 1) // 3 + 1) * W], [H * (W // 3), ((W - 1) // 3 + 1) * H], [(H // 3) * W, (H - H // 3) * (W // 2), (H - H // 3) * (W - W // 2)], [(W // 3) * H, (W - W // 3) * (H // 2), (W - W // 3) * (H - H // 2)], [ ((H - 1) // 3 + 1) * W, (H - ((H - 1) // 3 + 1)) * (W // 2), (H - ((H - 1) // 3 + 1)) * (W - W // 2), ], [ ((W - 1) // 3 + 1) * H, (W - ((W - 1) // 3 + 1)) * (H // 2), (W - ((W - 1) // 3 + 1)) * (H - H // 2), ], ] print(min([max(e) - min(e) for e in a]))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s745263130
Runtime Error
p03715
Input is given from Standard Input in the following format: H W
N = int(input()) A = list(map(int, input().split())) S = [] P = A[:N] Q = A[2 * N :] for i in range(N): Q[i] *= -1 R = A[N : 2 * N] p = [0] * (N + 1) q = [0] * (N + 1) import heapq heapq.heapify(P) heapq.heapify(Q) sp = sum(P) sq = sum(Q) p[0] = sp q[0] = sq for i in range(1, N + 1): heapq.heappush(P, R[i - 1]) x = heapq.heappop(P) heapq.heappush(Q, -R[-i]) y = heapq.heappop(Q) sp = sp + R[i - 1] - x sq = sq - R[-i] - y p[i] = sp q[i] = sq ans = -(10**100) for k in range(N + 1): ans = max(ans, p[k] + q[N - k]) print(ans)
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the minimum possible value of S_{max} - S_{min}. * * *
s057159441
Runtime Error
p03715
Input is given from Standard Input in the following format: H W
h, w = map(int, input().split()) if h%3 == 0 or w%3 ==0: print(0) else: def calculate_d(x, y): d = h*w + 1 i = x//2 s1, s2 = 0, d for i in range(x): s1 = (y//2)*i s2 = y*(x-i) s3 = (y-y//2)*i new_d = max(abs(s1-s2), abs(s1-s3)) if s1 < s2: i = if d > new_d: d = new_d continue else: break return d d1 = calculate_d(h, w) d2 = calculate_d(w, h) print(min(d1,d2))
Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
[{"input": "3 5", "output": "0\n \n\nIn the division below, S_{max} - S_{min} = 5 - 5 = 0.\n\n![2a9b2ef47b750c0b7ba3e865d4fb4203.png](https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png)\n\n* * *"}, {"input": "4 5", "output": "2\n \n\nIn the division below, S_{max} - S_{min} = 8 - 6 = 2.\n\n![a42aae7aaaadc4640ac5cdf88684d913.png](https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png)\n\n* * *"}, {"input": "5 5", "output": "4\n \n\nIn the division below, S_{max} - S_{min} = 10 - 6 = 4.\n\n![eb0ad0cb3185b7ae418e21c472ff7f26.png](https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png)\n\n* * *"}, {"input": "100000 2", "output": "1\n \n\n* * *"}, {"input": "100000 100000", "output": "50000"}]
Print the answer. * * *
s937446562
Accepted
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
N, *X = map(int, open(0).read().split()) M, g, q, r = 10**9 + 7, 1, [1, 1], 0 for i in range(1, N): r, g = (r + q[-1] * (X[-1] - X[i - 1])) % M, g * i % M q += [M // (-~i) * -q[M % (-~i)] % M] print(r * g % M)
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s189147773
Wrong Answer
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
N = int(input()) tmp = input().split() x = [i for i in tmp] print(x)
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s830140060
Wrong Answer
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
p = 10**9 + 7 N = int(input()) X = list(map(int, input().split())) prod = 1 for i in range(2, N): prod = (prod * i) % p prod2 = 1 for i in range(3, N): prod2 = (prod2 * i) % p tot = sum(X) a = ((N - 2) * prod2) % p a = (a * (tot - X[0])) % p a = a + (prod * X[-1]) % p b = ((tot - X[-1]) * prod) % p print((a - b) % p)
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s244728621
Runtime Error
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, groupby import sys import bisect import string import math import time import random def S_(): return input() def LS(): return [i for i in input().split()] def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i) - 1 for i in input().split()] def NI(n): return [int(input()) for i in range(n)] def NI_(n): return [int(input()) - 1 for i in range(n)] def StoI(): return [ord(i) - 97 for i in input()] def ItoS(nn): return chr(nn + 97) def LtoS(ls): return "".join([chr(i + 97) for i in ls]) def GI(V, E, Directed=False, index=0): org_inp = [] g = [[] for i in range(n)] for i in range(E): inp = LI() org_inp.append(inp) if index == 0: inp[0] -= 1 inp[1] -= 1 if len(inp) == 2: a, b = inp g[a].append(b) if not Directed: g[b].append(a) elif len(inp) == 3: a, b, c = inp aa = (inp[0], inp[2]) bb = (inp[1], inp[2]) g[a].append(bb) if not Directed: g[b].append(aa) return g, org_inp def bit_combination(k, n=2): rt = [] for tb in range(n**k): s = [tb // (n**bt) % n for bt in range(k)] rt += [s] return rt def show(*inp, end="\n"): if show_flg: print(*inp, end=end) YN = ["Yes", "No"] mo = 10**9 + 7 inf = float("inf") l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() # sys.setrecursionlimit(10**5) input = lambda: sys.stdin.readline().rstrip() def ran_input(): import random n = random.randint(4, 16) rmin, rmax = 1, 10 a = [random.randint(rmin, rmax) for _ in range(n)] return n, a class Comb: def __init__(self, n, mo=10**9 + 7): self.fac = [0] * (n + 1) self.inv = [1] * (n + 1) self.fac[0] = 1 self.fact(n) for i in range(1, n + 1): self.fac[i] = i * self.fac[i - 1] % mo self.inv[n] *= i self.inv[n] %= mo self.inv[n] = pow(self.inv[n], mo - 2, mo) for i in range(1, n): self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo return def fact(self, n): return self.fac[n] def invf(self, n): return self.inv[n] def comb(self, x, y): if y < 0 or y > x: return 0 return self.fac[x] * self.inv[x - y] * self.inv[y] % mo show_flg = False show_flg = True ans = 0 n = I() x = LI() p = permutations(range(n - 1)) cm = Comb(n + 20) StrN = [0] * (n + 10) StrN[1] = 1 StrN[0] = 0 def St(n): if n == 1: return 1 if StrN[n] != 0: return StrN[n] else: # a(n+1)=(n+1)*a(n)+n!. StrN[n] = (n) * St(n - 1) + cm.fac[n - 1] return StrN[n] St(n) Pat = [0] * (n + 1) for i in range(n): Pat[i] = StrN[i] * cm.fac[n - 1] * cm.inv[i] % mo # show('Pat',Pat) # show('St',StrN) for i in range(n - 1): ans += (x[i + 1] - x[i]) * Pat[i + 1] ans %= mo print(ans % mo) # show(SSS)
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s496708785
Runtime Error
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
a = input() b = input() N = int(a) x = b.split() d = [] EX = 0 L = 1 M = 1 O = 0 for i in range(N - 1): d.append(int(x[i + 1]) - int(x[i])) L = L * (i + 1) L = L / N for j in range(N - 1): EX += d[j] for k in range(N - 1): M = M * (k + 1) if k > 1: O += L / M EX += O * d[k] print(EX % 1000000007)
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s896751830
Runtime Error
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
N = int(input()) X = list(map(int, input().split())) # 一番移動量が大きくなるのはN-1番目->N-2番目(N-1番目)と選ばれるの # 一番移動量が小さくなるのは1番目->2番目(一番目)と選ばれるの # つまり右端の数字で移動量が決まる.例えば一番目のスライムの行き先は(N-1)通りあり(2~N)これらは等しい確率? # ではなくない? だってどう考えたって,右に2がある確率が高いし,N番目のがある確率は限りなく低くない? # 2番めより先に1番目が呼ばれれば右に2があるのか.つまり1/2か?右に3があるのは2->1->3の順番かつまり1/4か? # つまり1/2 + 1/4 + 1/8...1/2^(N-1?)か右にNがある確率は(1-(1/2+1/4+...1/2^(N-1?)))かな? # N=2の時は別に分けないといけないのか?これ.もうよくわからん.めんどくさいのでこれで終わり from collections import deque X = deque(X) kitai = 0 for i in range(N - 1): # N-1回の繰り返し if len(X) == 2: kitai += X[-1] - X[-2] break x = X.popleft() # xの行き先とそこに行ける確率で移動距離の期待値を計算する. left_num = len(X) left_dis = [X[k] - x for k in range(left_num)] kakuritsu = [1 / (2**l) for l in range(1, left_num)] last_kakuritsu = 1 - sum(kakuritsu) kakuritsu.append(last_kakuritsu) x_kitai = [dis * kaku for (dis, kaku) in zip(left_dis, kakuritsu)] kitai += sum(x_kitai) import math print(int(kitai * math.factorial(N - 1)) % (10**9 + 7))
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s402101601
Runtime Error
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
import sys import math input = sys.stdin.readline def main(): sc = Scan() N = sc.intarr()[0] X = sc.intarr() Y = X[:-1] last = X[-1] tmp = perm(Y) pp = [] for t in tmp: a = t a.append(last) pp.append(a) score = 0 for p in pp: for i in range(len(p) - 1): key = p[i] array = p[i + 1 :] near = array[-1] - key dist = array[-1] - key for j in range(len(array) - 1): dist = array[j] - key if dist > 0 and dist < near: near = dist score += near ans = (score * math.factorial(N - 1) / len(pp)) % 1000000007 print(int(ans)) def perm(p): if len(p) == 1: return [p] else: s = [] for i in range(len(p)): q = p[i] r = perm(p[:i] + p[i + 1 :]) for t in r: s.append([q] + t) return s class Scan: def intarr(self): num_array = list(map(int, input().split())) return num_array def intarr_ver(self, n): return [int(input()) for _ in range(n)] def strarr(self): line = input() array = line.split(" ") array[-1] = array[-1].strip("\n") return array def display(array): for a in range(len(array)): if len(array) - a != 1: print(array[a], end=" ") else: print(array[a]) def gcd(a, b): # 最大公約数 while b: a, b = b, a % b return a def lcm(a, b): # 最小公倍数 return a * b // gcd(a, b) main()
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s505990025
Runtime Error
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
import numpy as np N = int(input()) X = list(map(lambda x: int(x), input().split())) dic = {} class Node: def __init__(self, elm): self.elm = elm self.nexts = [] self.next_costs = [] self.prev = [] def __str__(self): return str(self.elm) root = Node(X) dic[str(root)] = root def reg(curr, co): if len(curr) == 1: return cn = dic[str(curr)] costs = [] for idx, x in enumerate(curr[:-1]): cost = curr[idx + 1] - x + co cn.next_costs.append(cost) n = curr[:idx] + curr[idx + 1 :] if str(n) in dic: dic[str(n)].prev.append(cn) continue nn = Node(n) nn.prev.append(cn) dic[str(n)] = nn costs.append(reg(n, cost)) reg(X, 0) cs = [] c = 0 for n in dic[str([max(X)])].prev: cs.append(n.next_costs[0]) c = np.mean(cs) for i in range(2, N): c = c * i print(int(c % ((10**9) + 7)))
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer. * * *
s344635029
Runtime Error
p02807
Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N
import itertools N = int(input()) x = list(map(int, input().split())) y = [] CONST = 10**9 + 7 def kaijo(n): if n == 1: return n return n * kaijo(n - 1) N_1 = kaijo(N - 1) ans = 0 for i in range(1, N): y.append(i) Y = list(itertools.permutations(y, len(y))) del_num = [] ok_num = [] # 操作のやつ # iは何回目の操作かを指す for i in range(1, N): prob = 1 / (N - i) # 順列Yの操作フェーズ for j in range(len(Y)): # 存在しうる順列を探す for k in range(N - i): # N-i番目の値がN-i以下ならばok、存在しうる # print(k) # print(Y[j]) if Y[j][k] <= (N - i): flag = 1 if k == (N - i - 1): ok_num.append(j) else: flag = 0 break if flag != 1: if j not in ok_num: del_num.append(j) # 存在しない順列を削除していく for num in range(len(del_num)): del Y[del_num[num]] ans_list = [] # ansを求めていく for i in range(len(Y)): Y_list = [] prob = 1 ans = 0 x_list = [] for m in range(len(x)): x_list.append(x[m]) for m in range(len(y)): Y_list.append(Y[i][m]) # ここから for j in range(len(y)): prob *= 1 / (N - (1 + j)) tmp = Y_list[j] - 1 ans += x_list[tmp + 1] - x_list[tmp] for k in range(len(y)): if tmp < (Y_list[k]): Y_list[k] = Y_list[k] - 1 del x_list[tmp] ans = ans * prob ans_list.append(ans) ans = 0 for i in range(len(ans_list)): ans += ans_list[i] ans = ans * N_1 ans = int(ans) ans = ans % CONST print(ans)
Statement There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equal probability. * Move the k-th slime from the left, to the position of the neighboring slime to the right. * Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7). If a slime is born by a fuse and that slime moves, we count it as just one slime.
[{"input": "3\n 1 2 3", "output": "5\n \n\n * With probability \\frac{1}{2}, the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2.\n * With probability \\frac{1}{2}, the middle slime is chosen in the first operation, in which case the total distance traveled is 3.\n * The answer is the expected total distance traveled, 2.5, multiplied by 2!, which is 5.\n\n* * *"}, {"input": "12\n 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932", "output": "750927044\n \n\n * Find the expected value multiplied by (N-1)!, modulo (10^9+7)."}]
Print the answer modulo 10^9 + 7. * * *
s107925320
Accepted
p02554
Input is given from Standard Input in the following format: N
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [ [[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a) ] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**19 MOD = 10**9 + 7 EPS = 10**-10 N = INT() dp = list2d(3, N + 1, 0) dp[0][0] = 1 for i in range(N): dp[0][i + 1] += dp[0][i] * 8 dp[1][i + 1] += dp[0][i] * 2 dp[1][i + 1] += dp[1][i] * 9 dp[2][i + 1] += dp[1][i] dp[2][i + 1] += dp[2][i] * 10 dp[0][i + 1] %= MOD dp[1][i + 1] %= MOD dp[2][i + 1] %= MOD ans = dp[2][N] print(ans)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s088700585
Accepted
p02554
Input is given from Standard Input in the following format: N
def calculate(n): mod = 1000000000 + 7 result = pow(10, n, mod) # has 0 exists 9 not exists # 0 - 8 s1 = pow(9, n, mod) - pow(8, n, mod) # has 9 exists 0 not exists # 1 - 9 s2 = pow(9, n, mod) - pow(8, n, mod) # 9 not exists and 8 not exists # 1-8 s3 = pow(8, n, mod) result = result - (s1 + s2 + s3) print(result % mod) calculate(int(input()))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s052078848
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
def bigmod(v, n10, m): """ >>> bigmod(1, 2, 9) 1 >>> bigmod(2343413, 10, 100005) 1 """ # print((v*10.**n10) % m) v %= m while n10>0: v *= 10 n10 -= 1 v %= m return v def main(): n = int(input()) m = int(10**9+7) a = bigmod(n*(n-1), n-2, m) print(a) main()
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s856096713
Accepted
p02554
Input is given from Standard Input in the following format: N
import sys from functools import reduce from operator import mul from typing import Callable, ClassVar, Sequence, Type, TypeVar T = TypeVar("T", bound="ModIntBase") class ModIntBase: value: int mod: ClassVar[int] fac: ClassVar[Sequence[int]] = () inv: ClassVar[Sequence[int]] = () finv: ClassVar[Sequence[int]] = () def __init__(self, value: int) -> None: self.value = value % self.mod def __hash__(self) -> int: return hash((self.value, self.mod)) def __eq__(self, other) -> bool: if isinstance(other, self.__class__): return self.value == other.value else: return NotImplemented def __ne__(self, other) -> bool: if isinstance(other, self.__class__): return self.value != other.value else: return NotImplemented # TODO: Add type hints def __add__(self, other): if isinstance(other, self.__class__): return self.__class__((self.value + other.value) % self.mod) else: return NotImplemented def __sub__(self, other): if isinstance(other, self.__class__): return self.__class__((self.value - other.value) % self.mod) else: return NotImplemented def __mul__(self, other): if isinstance(other, self.__class__): return self.__class__(self.value * other.value % self.mod) else: return NotImplemented def __truediv__(self, other): if isinstance(other, self.__class__): a = other.value b = self.mod u = 1 v = 0 while b: t = a // b a, b = b, a - t * b u, v = v, u - t * v return self.__class__(self.value * u % self.mod) else: return NotImplemented def __pow__(self, other): if isinstance(other, self.__class__): v = 1 a = self.value b = other.value mod = self.mod while b > 0: if b & 1: v = v * a % mod a = a * a % mod b >>= 1 return self.__class__(v) else: return NotImplemented @classmethod def comb(cls, n: int, k: int): if n < k: return cls(0) if n < 0 or k < 0: return cls(0) if n < len(cls.fac): return cls(cls.fac[n] * (cls.finv[k] * cls.finv[n - k] % cls.mod) % cls.mod) else: k = min(k, n - k) a = reduce(mul, map(cls, range(n - k + 1, n + 1)), cls(1)) b = reduce(mul, map(cls, range(1, k + 1)), cls(1)) return a / b def __repr__(self) -> str: return f"{self.__class__.__name__}({self.value!r})" def __str__(self) -> str: return str(self.value) def mod_comb_init(max_: int) -> Callable[[Type[T]], Type[T]]: def _mod_comb_init(cls: Type[T]) -> Type[T]: mod: int = cls.mod assert max_ < mod fac = cls.fac = [0] * max_ finv = cls.finv = [0] * max_ inv = cls.inv = [0] * max_ fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, max_): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod return cls return _mod_comb_init class ModInt(ModIntBase): mod = 1000000007 # 10 ** 9 + 7 def resolve(in_): N = int(next(in_)) a = ModInt(10) ** ModInt(N) b = ModInt(9) ** ModInt(N) c = ModInt(8) ** ModInt(N) ans = a - b * ModInt(2) + c return ans def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == "__main__": main()
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s927766398
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
n = int(input()) x = n * (n - 1) % 1000000007 y = 10 ** (n - 2) % 1000000007 print((x * y) % 1000000007)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s550714523
Accepted
p02554
Input is given from Standard Input in the following format: N
n = int(input()) a = [1] * 10000001 b = [1] * 10000001 c = [0] * (n + 1) answer = 0 for i in range(1000001): a[i + 1] = (a[i] * 9) % 1000000007 for j in range(1000001): b[j + 1] = (b[j] * 8) % 1000000007 if n == 1: print(0) else: for k in range(2, n + 1): c[k] = 2 * a[k - 1] - 2 * b[k - 1] + 10 * c[k - 1] c[k] = c[k] % 1000000007 print(c[n])
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s486039406
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
print(2 ** int(input()) - 2)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s047843792
Accepted
p02554
Input is given from Standard Input in the following format: N
# import itertools # import math # import sys # sys.setrecursionlimit(500*500) # import numpy as np # import heapq # from collections import deque N = int(input()) # S = input() # n, *a = map(int, open(0)) # N, M = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # tree = [[] for _ in range(N + 1)] # B_C = [list(map(int,input().split())) for _ in range(M)] # S = input() # B_C = sorted(B_C, reverse=True, key=lambda x:x[1]) # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # def dfs(tree, s): # for l in tree[s]: # if depth[l[0]] == -1: # depth[l[0]] = depth[s] + l[1] # dfs(tree, l[0]) # dfs(tree, 1) # def factorization(n): # arr = [] # temp = n # for i in range(2, int(-(-n**0.5//1))+1): # if temp%i==0: # cnt=0 # while temp%i==0: # cnt+=1 # temp //= i # arr.append([i, cnt]) # if temp!=1: # arr.append([temp, 1]) # if arr==[]: # arr.append([n, 1]) # return arr print((10**N - (9**N + 9**N - 8**N)) % (10**9 + 7))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s298142500
Accepted
p02554
Input is given from Standard Input in the following format: N
if __name__ == "__main__": a = input() a = int(a) # not(0and9) not_0and9 = 8**a # not0 not_0 = 9**a # not9 not_9 = 9**a # not not_n = not_0 + not_9 - not_0and9 n = 10**a - not_n print(n % (10**9 + 7))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s371086644
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
n = int(input()) num = 0 x = n # 0,9が置かれる場所 y = 0 # 0,9の選び方 z = 8 * (n - 1) # それ以外の選び方 for i in range(2, n + 1): # 0,9の個数 x = x * (n - i + 1) // i y = (y + 2) * 2 - 2 z = z // 8 num += (x * y * z) % (10**9 + 7) print(num % (10**9 + 7))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s924443981
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
N = int(input()) count = 0 for i in range(10**N): l = str(i) count += "0" in l and "9" in l print(count + (9 ** (N - 2)))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s262743230
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
p = 1000000007 def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p def factor(k, p): fact = 1 for i in range(1, k + 1): fact = fact * i # print (fact) return (fact) % p n = int(input()) sum = 0 for i in range(2, n + 1): m = ncr(n, i, p) # print(m) f = factor(i, p) # print(f) sum = sum + (m * f) # print (sum) print(sum)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s863316038
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
N = int(input()) % 1000000007 print((N ^ 2 - N) * (2 ** (N - 2)))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s777036745
Accepted
p02554
Input is given from Standard Input in the following format: N
n = int(input()) ans = 10**n - 2 * (9**n) + 8**n res = ans % (10**9 + 7) print(res)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s463656676
Accepted
p02554
Input is given from Standard Input in the following format: N
s = int(input()) num = 10**s - (9**s * 2 - 8**s) print(num % (10**9 + 7))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s748258848
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
n = int(input()) x = (10**n) % (10**9 + 7) y = (9**n) % (10**9 + 7) z = (8**n) % (10**9 + 7) print(x - 2 * y + z)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s375351113
Accepted
p02554
Input is given from Standard Input in the following format: N
n = int(input()) f10 = 1 f8 = 1 f9 = 2 for _ in range(n): f10 = (f10 * 10) % (1e9 + 7) f8 = (f8 * 8) % (1e9 + 7) f9 = (f9 * 9) % (1e9 + 7) print(int((f10 + f8 - f9) % (1e9 + 7)))
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s174729150
Accepted
p02554
Input is given from Standard Input in the following format: N
N=int(input()) ans=0 NUM=7+10**9 if N==1: ans=0 else: a=10**N%NUM b=9**N%NUM b*=2 c=8**N%NUM ans=a-b+c ans%=NUM print(ans)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s211269698
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
k = int(input()) if k < 2: print(0) else: num = 2*(k*2-3) num2 = num*10 - num # print(num2) waru = 10**9+7 # print(waru) print(num2 % waru)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s506814564
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
import sys input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**9) # from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int, input().split()) def MF(): return map(float, input().split()) def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def TI(): return tuple(map(int, input().split())) # rstrip().decode('utf-8') def main(): n = II() a = pow(10, n, 10**9 + 7) b = pow(9, n, 10**9 + 7) c = pow(8, n, 10**9 + 7) print(a - 2 * b + c) if __name__ == "__main__": main()
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
Print the answer modulo 10^9 + 7. * * *
s233091494
Wrong Answer
p02554
Input is given from Standard Input in the following format: N
print((2 ** int(input()) - 2) % 1000000007)
Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? * 0 \leq A_i \leq 9 * There exists some i such that A_i=0 holds. * There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7.
[{"input": "2", "output": "2\n \n\nTwo sequences \\\\{0,9\\\\} and \\\\{9,0\\\\} satisfy all conditions.\n\n* * *"}, {"input": "1", "output": "0\n \n\n* * *"}, {"input": "869121", "output": "2511445"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s148543977
Accepted
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
import sys, queue, math, copy, itertools, bisect, collections, heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda: [int(x) for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) SI = lambda: sys.stdin.readline().rstrip() n = NI() a = [0] * (n + 1) b = [0] * (n + 1) for i, p in enumerate(LI()): a[p - 1] += i b[0] += i b[p] -= i ans_a = [] ans_b = [] cnt_a = 0 cnt_b = 0 for i in range(n): cnt_a += a[i] cnt_b += b[i] ans_a.append(cnt_a + i + 1) ans_b.append(cnt_b + (n - i)) print(*ans_a, sep=" ") print(*ans_b, sep=" ") if __name__ == "__main__": main()
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s645123950
Accepted
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, P): M = 30000 a = [] b = [] for i in range(1, N + 1): a.append(i * M + 1) b.append((N - i + 1) * M + 1) for i, p in enumerate(P): a[p - 1] += i return "\n".join([" ".join(map(str, a)), " ".join(map(str, b))]) def main(): N = read_int() P = read_int_n() print(slv(N, P)) if __name__ == "__main__": main()
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s070173010
Accepted
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
def gen_ordinary_lists(n): up_lis = list(range(1, n * 20001, 20001)) return up_lis, up_lis[::-1] def argsort(lis): tpls = [(l, i) for i, l in enumerate(lis)] return sorted(tpls) def solve(N, lis): up_list, down_list = gen_ordinary_lists(N) arg_tpls = argsort(lis) for val, idx in arg_tpls: up_list[val - 1] += idx print(*up_list) print(*down_list) N = int(input()) lis = list(map(int, input().split())) solve(N, lis)
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s932005174
Accepted
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
n = int(input()) p = list(map(int, input().split())) a = [(i + 1) * n for i in range(n)] b = [(n - i) * n for i in range(n)] for i in range(n): a[p[i] - 1] -= n - i - 1 sa = "" sb = "" for i in range(n): sa = sa + str(a[i]) sb = sb + str(b[i]) if i != n - 1: sa = sa + " " sb = sb + " " print(sa) print(sb)
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s779742854
Wrong Answer
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
n = int(input()) prr = list(map(int, input().split())) arr = [] brr = [] cumsum = 0 for p in prr: cumsum += p arr.append(cumsum) cumsum = 0 print(" ".join(map(str, arr))) for p in reversed(prr): cumsum += p brr.append(cumsum) print(" ".join(map(str, reversed(brr))))
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s484205061
Runtime Error
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
a = int(input()) x = list(map(int,input().split())) t = [range(1,a+1)] A = [] B = [] for i in range(1,a+1): A.append(30000*i) B.append(30000*(a-i+1)+tpx[i-1]]) print(*A) print(*B)
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s868783225
Wrong Answer
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
print("1 4") print("5 4")
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. * * *
s348693989
Wrong Answer
p03938
The input is given from Standard Input in the following format: N p_1 p_2 ... p_N
a = int(input()) x = list(map(float, input().split())) m = max(x) M = m / 2 t = 0 s = float("INF") for i in x: # print(s,abs(M-i),i,M) if s >= abs(M - i): s = min(s, abs(M - i)) t = i print(str(int(m)) + " " + str(int(t)))
Statement You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions: * 1 \leq a_i, b_i \leq 10^9 for all i * a_1 < a_2 < ... < a_N * b_1 > b_2 > ... > b_N * a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}
[{"input": "2\n 1 2", "output": "1 4\n 5 4\n \n\na_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.\n\n* * *"}, {"input": "3\n 3 2 1", "output": "1 2 3\n 5 3 1\n \n\n* * *"}, {"input": "3\n 2 3 1", "output": "5 10 100\n 100 10 1"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s608042212
Accepted
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
[N, K] = [int(item) for item in input().split()] p = [int(item) for item in input().split()] su = sum(p[0:K]) maxsu = su ind = 0 for i in range(0, N - K): su = su - p[i] + p[i + K] if su > maxsu: ind = i + 1 maxsu = su # print("{},{}".format(su,maxsu)) # print(p[ind:ind+K]) # print([n*(n+1)/(2*n) for n in p[ind:ind+K]]) print(sum([n * (n + 1) / (2 * n) for n in p[ind : ind + K]]))
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s033441366
Accepted
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
n, k = map(int, input().strip().split()) arr = [int(i) for i in input().strip().split()] maxi = s = (sum(arr[0:k]) + k) / 2 for i in range(1, n - k + 1): s += (arr[i + k - 1] - arr[i - 1]) / 2 if s > maxi: maxi = s print(maxi)
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s742180000
Runtime Error
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
n = int(input()) a = list(x for x in input().split()) if len(a) == len(list(set(a))): print("YES") else: print("NO")
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s588715939
Wrong Answer
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
a, b = map(int, input().split()) l = list(map(int, input().split())) l.sort(reverse=True) c = l[: b - 1] f = (sum(c) + b) / 2 print(f)
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s636182918
Wrong Answer
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
c, d = map(int, input().split()) a = [int(x) for x in input().split()] b = a.index(max(a)) b1 = [] b2 = [] for i in range(d): b1.append(a[b + i]) if b + i == len(a) - 1: break for i in range(d): b2.append(a[b - i]) if b - i == 0: break c1 = max(b1, b2) tot = 0 for i in c1: for _ in range(1, i + 1): tot += _ * 1 / i print(tot)
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s868882917
Accepted
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
N, K = map(int, input().strip().split(" ")) LL = [] for x in input().strip().split(" "): k = int(x) LL.append((k * (k + 1)) / k / 2) LL2 = [] LL2.append(LL[0]) for x in range(1, len(LL)): LL2.append(LL2[-1] + LL[x]) v0 = 0 for x in range(K - 1, N): d = 0.0 if x - K < 0 else LL2[x - K] v = LL2[x] - d v0 = max(v, v0) print("{0:.8f}".format(v0))
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s721187473
Runtime Error
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
kitailist = [] NandK = input() pi = input() NandK = NandK.split(" ") pi = pi.split(" ") K = int(NandK[1]) for j in range(len(pi) - 3): p1 = int(pi[j]) p2 = int(pi[j + 1]) p3 = int(pi[j + 2]) kitaiti = (p1 + p2 + p3 + 3) / 2 kitailist.append(kitaiti) print(max(kitailist))
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s584708800
Wrong Answer
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
NK = [int(i) for i in input().split(" ")] list1 = [(int(i) + 1) / 2 for i in input().split(" ")] Max = 0 for j in range(NK[0] - NK[1] + 1): if Max < sum(list1[j : j + NK[1]]): Max = sum(list1[j : j + NK[1]])
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s625817568
Wrong Answer
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
N, M = map(int, input().split(" ")) data = list(map(int, input().split(" "))) data = [(i + 1) / 2 for i in data] s = [] print(data) for i in range(0, N - M + 1): # print(data[i:i+M]) s.append(sum(data[i : i + M])) print(max(s))
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
Print the maximum possible value of the expected value of the sum of the numbers shown. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}. * * *
s252166649
Accepted
p02780
Input is given from Standard Input in the following format: N K p_1 ... p_N
# import numpy as np # S,T = input().split() N, K = list(map(int, input().split())) # N = int(input()) ps = list(map(int, input().split())) Es = [] for p in ps: Es.append((1 + p) / 2) beg = 0 end = K ans = sum(Es[beg:end]) prev = ans while end < N: prev = prev - Es[beg] + Es[end] if prev > ans: ans = prev beg += 1 end += 1 print(ans)
Statement We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown. We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]