output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the minimum number of operations required to achieve the objective. * * *
s165173367
Runtime Error
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
def minCandies(boxes,limit): out = 0 for i in range(len(boxes) - 1): total = boxes[i] + boxes[i + 1] if total > limit: out += total - limit boxes[i + 1] = boxes[i + 1] - (total - limit) if boxes[i + 1] < 0: boxes[i + 1] = 0 return out num_of_boxes, limit = map(int,input().split()) boxes = list(map(int,input().split())) if limit == 0: return sum(boxes) elif max([a + b for (a,b) in zip(boxes[:-1],boxes[1:])) <= limit: return 0 else: return minCandies(boxes,limit)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s521626003
Runtime Error
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
def candy(): boxNum, x = [int(i) for i in input().split()] ain = input() alist = ain.split(' ') s = 0 for i in range(0, boxNum-1): c = alist[i] , d = alist[i + 1] if int( alist[i] + alist[i + 1] ) > x: if int( alist[i] ) >= x: alist[i] = x alist[i + 1] = 0 else : alist[i + 1] = x - a[i] s += c - alist[i] + d - alist[i + 1] /* if int(alist[i]) > x: s = s + int(alist[i+1]) alist[i+1] = 0 if int(alist[i+1]) + int(alist[i]) > x: s = s + (int(alist[i+1]) + int(alist[i]) - x) alist[i+1] = x - int(alist[i]) */ print(s) candy()
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s321701488
Runtime Error
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
n,x = map(int,input().split()) a = list(map(int,input().split())) cnt = 0 for i in range(1,n): if a[i-1]+a[i]<=x: pass else: if (a[i]+a[i-1])-x > a[i] a[i] = 0 cnt += (a[i]+a[i-1])-x else: cnt += (a[i]+a[i-1])-x a[i]-= (a[i]+a[i-1])-x print(cnt)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s779058739
Wrong Answer
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
print("he")
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s840668000
Wrong Answer
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] from collections import defaultdict, deque from sys import exit import heapq import math import copy from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) N, X = getNM() A = getList() between = [A[i] + A[i + 1] - X for i in range(N - 1)] ans = 0 flag = True while flag: flag = False for i in range(N - 2): if between[i] > 0 and between[i + 1] > 0: minuspoint = min(between[i], between[i + 1], A[i + 1]) A[i + 1] -= minuspoint ans += minuspoint flag = True between = [A[i] + A[i + 1] - X for i in range(N - 1)] for i in between: if i > 0: ans += i print(ans)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s544108330
Wrong Answer
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
# 003 N, x = input().split(" ") s = input().split(" ") list = [] for i in range(int(N)): list.append(int(s[i])) count = 0 for i in range(1, int(N)): temp = list[i] + list[i - 1] if temp > int(x): count += temp - int(x) list[i] -= temp - int(x) print(count)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s219113407
Wrong Answer
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
import copy """ def ct(x,y): if (x>y):print("+") elif (x<y): print("-") else: print("?") """ def ip(): return int(input()) def iprow(): return [int(i) for i in input().split()] def ips(): return (int(i) for i in input().split()) def printrow(a): for i in a: print(i) n, m = ips() a = iprow() s = 0 for i in range(1, n - 1): if m < (a[i] + a[i + 1]): if a[i] + a[i + 1] >= m: difference = a[i] + a[i + 1] - m if a[i] >= difference: s += difference a[i] -= difference else: s += a[i] a[i] = 0 else: s += a[i] a[i] = 0 if a[0] + a[1] > m: if a[0] + a[1] >= m: difference = a[0] + a[1] - m if a[0] >= difference: s += difference a[0] -= difference else: s += a[0] a[0] = 0 else: s += a[0] a[0] = 0 if a[n - 2] + a[n - 1] > m: if a[n - 2] + a[n - 1] >= m: difference = a[n - 2] + a[n - 1] - m if a[n - 1] >= difference: s += difference a[n - 1] -= difference else: s += a[n - 1] a[n - 1] = 0 else: s += a[n - 1] a[n - 1] = 0 print(s)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s457765364
Wrong Answer
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
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) # ここから書き始める n, x = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for i in range(1, n): if a[i] > x: ans += a[i] + a[i - 1] - x a[i] -= a[i] + a[i - 1] - x a[i] = max(a[i], 0) elif a[i] + a[i - 1] > x: ans += (a[i] + a[i - 1]) - x a[i] = 0 print(ans)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print the minimum number of operations required to achieve the objective. * * *
s551881838
Accepted
p03862
The input is given from Standard Input in the following format: N x a_1 a_2 ... a_N
N, x = map(int, input().split()) As = list(map(int, input().split())) # 隣り合う箱の和を取る # sum_As = [0 for i in range(N-1)] # for i in range(N-1): # sum_As[i] = As[i] + As[i+1] count = 0 # 両側があふれていたら減らせるだけ減らそう for i in range(1, N - 1): if As[i - 1] + As[i] > x and As[i] + As[i + 1] > x: minus = min(As[i], As[i - 1] + As[i] - x, As[i] + As[i + 1] - x) As[i] -= minus count += minus # 片側があふれていたら減らせるだけ減らそう if As[0] + As[1] > x: minus = min(As[0], As[0] + As[1] - x) As[0] -= minus count += minus for i in range(1, N - 1): if As[i - 1] + As[i] > x: minus = min(As[i], As[i - 1] + As[i] - x) As[i] -= minus count += minus if As[i] + As[i + 1] > x: minus = min(As[i], As[i] + As[i + 1] - x) As[i] -= minus count += minus if As[N - 2] + As[N - 1] > x: minus = min(As[N - 1], As[N - 2] + As[N - 1] - x) As[N - 1] -= minus count += minus print(count)
Statement There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
[{"input": "3 3\n 2 2 2", "output": "1\n \n\nEat one candy in the second box. Then, the number of candies in each box\nbecomes (2, 1, 2).\n\n* * *"}, {"input": "6 1\n 1 6 1 2 0 4", "output": "11\n \n\nFor example, eat six candies in the second box, two in the fourth box, and\nthree in the sixth box. Then, the number of candies in each box becomes (1, 0,\n1, 0, 0, 1).\n\n* * *"}, {"input": "5 9\n 3 1 4 1 5", "output": "0\n \n\nThe objective is already achieved without performing operations.\n\n* * *"}, {"input": "2 0\n 5 5", "output": "10\n \n\nAll the candies need to be eaten."}]
Print q lines. The i-th line should contain the response to the i-th query. * * *
s046100008
Accepted
p02770
Input is given from Standard Input in the following format: k q d_0 d_1 ... d_{k - 1} n_1 x_1 m_1 n_2 x_2 m_2 : n_q x_q m_q
def numba_compile(numba_config): import os, sys if sys.argv[-1] == "ONLINE_JUDGE": from numba import njit from numba.pycc import CC cc = CC("my_module") for func, signature in numba_config: vars()[func.__name__] = njit(signature)(func) cc.export(func.__name__, signature)(func) cc.compile() exit() elif os.name == "posix": exec( f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}" ) for func, _ in numba_config: globals()[func.__name__] = vars()[func.__name__] else: from numba import njit for func, signature in numba_config: globals()[func.__name__] = njit(signature, cache=True)(func) print("compiled!", file=sys.stderr) import sys import numpy as np def solve(K, Q, D, NXM): Ans = np.empty(Q, dtype=np.int64) for q in range(Q): n, x, m = NXM[q] D_mod = D % m cnt_D0 = (D_mod == 0).sum() sum_D = D_mod.sum() t, rem = divmod(n - 1, K) ans = n - 1 # print(ans) ans -= t * cnt_D0 # print(f"ans={ans},t={t},rem={rem}") progress = sum_D * t x1 = x % m + progress for i in range(rem): d = D_mod[i] if d == 0: ans -= 1 x1 += d # print(f"D={D_mod}") # print(f"progress={progress},x1={x1}") ans -= x1 // m Ans[q] = ans return Ans numba_compile([[solve, "i8[:](i8,i8,i8[:],i8[:,:])"]]) def main(): K, Q = map(int, input().split()) D = np.array(input().split(), dtype=np.int64) NXM = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(Q, 3) Ans = solve(K, Q, D, NXM) print("\n".join(map(str, Ans.tolist()))) main()
Statement We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: * The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray} Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i). Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).
[{"input": "3 1\n 3 1 4\n 5 3 2", "output": "1\n \n\nFor the first query, the sequence {a_j} will be 3,6,7,11,14.\n\n * (a_0~\\textrm{mod}~2) > (a_1~\\textrm{mod}~2)\n * (a_1~\\textrm{mod}~2) < (a_2~\\textrm{mod}~2)\n * (a_2~\\textrm{mod}~2) = (a_3~\\textrm{mod}~2)\n * (a_3~\\textrm{mod}~2) > (a_4~\\textrm{mod}~2)\n\nThus, the response to this query should be 1.\n\n* * *"}, {"input": "7 3\n 27 18 28 18 28 46 1000000000\n 1000000000 1 7\n 1000000000 2 10\n 1000000000 3 12", "output": "224489796\n 214285714\n 559523809"}]
Print q lines. The i-th line should contain the response to the i-th query. * * *
s540078267
Accepted
p02770
Input is given from Standard Input in the following format: k q d_0 d_1 ... d_{k - 1} n_1 x_1 m_1 n_2 x_2 m_2 : n_q x_q m_q
def f_modularness(): K, Q = [int(i) for i in input().split()] D = [int(i) for i in input().split()] Queries = [[int(i) for i in input().split()] for j in range(Q)] def divceil(a, b): return (a + b - 1) // b ans = [] for n, x, m in Queries: last, eq = x, 0 # 末項、D_i % m == 0 となる D_i の数 for i, d in enumerate(D): num = divceil(n - 1 - i, K) # D_i を足すことは何回起きるか? last += (d % m) * num if d % m == 0: eq += num ans.append((n - 1) - (last // m - x // m) - eq) return "\n".join(map(str, ans)) print(f_modularness())
Statement We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: * The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray} Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i). Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).
[{"input": "3 1\n 3 1 4\n 5 3 2", "output": "1\n \n\nFor the first query, the sequence {a_j} will be 3,6,7,11,14.\n\n * (a_0~\\textrm{mod}~2) > (a_1~\\textrm{mod}~2)\n * (a_1~\\textrm{mod}~2) < (a_2~\\textrm{mod}~2)\n * (a_2~\\textrm{mod}~2) = (a_3~\\textrm{mod}~2)\n * (a_3~\\textrm{mod}~2) > (a_4~\\textrm{mod}~2)\n\nThus, the response to this query should be 1.\n\n* * *"}, {"input": "7 3\n 27 18 28 18 28 46 1000000000\n 1000000000 1 7\n 1000000000 2 10\n 1000000000 3 12", "output": "224489796\n 214285714\n 559523809"}]
Print q lines. The i-th line should contain the response to the i-th query. * * *
s507432117
Wrong Answer
p02770
Input is given from Standard Input in the following format: k q d_0 d_1 ... d_{k - 1} n_1 x_1 m_1 n_2 x_2 m_2 : n_q x_q m_q
def main(): from collections import defaultdict k, q = map(int, input().split()) (*ds,) = map(int, input().split()) for _ in range(q): n, x, m = map(int, input().split()) u = v = x % m cnt = 0 d = defaultdict(bool) ctr = defaultdict(int) es = [d % m for d in ds] for i in range(n - 1): j = i % k u = (u + es[j]) % m if d[u, j]: cnt = cnt * (n - 1) // i + ctr[((n - 1) % i) - 1] break d[u, j] = True if u > v: cnt += 1 ctr[i] = cnt v = u print(cnt) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
Statement We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: * The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray} Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i). Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).
[{"input": "3 1\n 3 1 4\n 5 3 2", "output": "1\n \n\nFor the first query, the sequence {a_j} will be 3,6,7,11,14.\n\n * (a_0~\\textrm{mod}~2) > (a_1~\\textrm{mod}~2)\n * (a_1~\\textrm{mod}~2) < (a_2~\\textrm{mod}~2)\n * (a_2~\\textrm{mod}~2) = (a_3~\\textrm{mod}~2)\n * (a_3~\\textrm{mod}~2) > (a_4~\\textrm{mod}~2)\n\nThus, the response to this query should be 1.\n\n* * *"}, {"input": "7 3\n 27 18 28 18 28 46 1000000000\n 1000000000 1 7\n 1000000000 2 10\n 1000000000 3 12", "output": "224489796\n 214285714\n 559523809"}]
Print q lines. The i-th line should contain the response to the i-th query. * * *
s813712249
Wrong Answer
p02770
Input is given from Standard Input in the following format: k q d_0 d_1 ... d_{k - 1} n_1 x_1 m_1 n_2 x_2 m_2 : n_q x_q m_q
import math # import numpy as np # Pythonのみ! # from operator import xor # import re # from scipy.sparse.csgraph import connected_components # Pythonのみ! # ↑cf. https://note.nkmk.me/python-scipy-connected-components/ # from scipy.sparse import csr_matrix # import statistics # Pythonのみ # import string import sys sys.setrecursionlimit(10**5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): k, q = map(int, input().split()) d = list(map(int, input().split())) for qi in range(q): n, x, m = map(int, input().split()) last = x eq = 0 for i in range(k): num = math.ceil(n / k) if i + 1 >= n % k: num -= 1 # numはd_iが足される回数 last += (d[i] % m) * num if d[i] % m == 0: eq += num ans = (n - 1) - (last // m - x // m) - eq print(ans) resolve()
Statement We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: * The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray} Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i). Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).
[{"input": "3 1\n 3 1 4\n 5 3 2", "output": "1\n \n\nFor the first query, the sequence {a_j} will be 3,6,7,11,14.\n\n * (a_0~\\textrm{mod}~2) > (a_1~\\textrm{mod}~2)\n * (a_1~\\textrm{mod}~2) < (a_2~\\textrm{mod}~2)\n * (a_2~\\textrm{mod}~2) = (a_3~\\textrm{mod}~2)\n * (a_3~\\textrm{mod}~2) > (a_4~\\textrm{mod}~2)\n\nThus, the response to this query should be 1.\n\n* * *"}, {"input": "7 3\n 27 18 28 18 28 46 1000000000\n 1000000000 1 7\n 1000000000 2 10\n 1000000000 3 12", "output": "224489796\n 214285714\n 559523809"}]
Print q lines. The i-th line should contain the response to the i-th query. * * *
s956883072
Wrong Answer
p02770
Input is given from Standard Input in the following format: k q d_0 d_1 ... d_{k - 1} n_1 x_1 m_1 n_2 x_2 m_2 : n_q x_q m_q
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.readline # from heapq import heappop, heappush # from collections import defaultdict sys.setrecursionlimit(10**7) # import math # from itertools import combinations def run(): k, q = map(int, sysread().split()) d = list(map(int, sysread().split())) def check(n, x, m): _d = [d[0] % m] for val in d[1:]: _d.append(_d[-1] + val % m) # n_step n_d = (n - 1) // k n_rest = (n - 1) % k x %= m _d_rest = 0 if n_rest == 0 else _d[n_rest - 1] a_last = x + n_d * _d[k - 1] + _d_rest n_step = a_last // m - x // m # n_same d0 = [1] if val == 0 else [0] for val in d[1:]: plus = 1 if val % m == 0 else 0 d0.append(d0[-1] + plus) d0_rest = 0 if n_rest == 0 else d0[n_rest - 1] n_same = n_d * d0[k - 1] + d0_rest return n - 1 - n_same - n_step for _ in range(q): n, x, m = map(int, sysread().split()) print(check(n, x, m)) if __name__ == "__main__": run()
Statement We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: * The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray} Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i). Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).
[{"input": "3 1\n 3 1 4\n 5 3 2", "output": "1\n \n\nFor the first query, the sequence {a_j} will be 3,6,7,11,14.\n\n * (a_0~\\textrm{mod}~2) > (a_1~\\textrm{mod}~2)\n * (a_1~\\textrm{mod}~2) < (a_2~\\textrm{mod}~2)\n * (a_2~\\textrm{mod}~2) = (a_3~\\textrm{mod}~2)\n * (a_3~\\textrm{mod}~2) > (a_4~\\textrm{mod}~2)\n\nThus, the response to this query should be 1.\n\n* * *"}, {"input": "7 3\n 27 18 28 18 28 46 1000000000\n 1000000000 1 7\n 1000000000 2 10\n 1000000000 3 12", "output": "224489796\n 214285714\n 559523809"}]
Print q lines. The i-th line should contain the response to the i-th query. * * *
s030943722
Accepted
p02770
Input is given from Standard Input in the following format: k q d_0 d_1 ... d_{k - 1} n_1 x_1 m_1 n_2 x_2 m_2 : n_q x_q m_q
import sys input = sys.stdin.readline K, Q = map(int, input().split()) D = list(map(int, input().split())) Query = [list(map(int, input().split())) for _ in range(Q)] for n, x, mod in Query: Td = [] for d in D: Td.append(d % mod) Init = [0] zero_count = 0 zero_tmp = 0 for i, d in enumerate(Td): Init.append(Init[-1] + d) if d == 0: zero_count += 1 if i < (n - 1) % K: zero_tmp += 1 c = Init.pop() last = x + c * ((n - 1) // K) + Init[(n - 1) % K] over_count = last // mod - x // mod print((n - 1) - over_count - zero_count * ((n - 1) // K) - zero_tmp)
Statement We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: * The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray} Print the number of j~(0 \leq j < n_i - 1) such that (a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i). Here (y~\textrm{mod}~z) denotes the remainder of y divided by z, for two integers y and z~(z > 0).
[{"input": "3 1\n 3 1 4\n 5 3 2", "output": "1\n \n\nFor the first query, the sequence {a_j} will be 3,6,7,11,14.\n\n * (a_0~\\textrm{mod}~2) > (a_1~\\textrm{mod}~2)\n * (a_1~\\textrm{mod}~2) < (a_2~\\textrm{mod}~2)\n * (a_2~\\textrm{mod}~2) = (a_3~\\textrm{mod}~2)\n * (a_3~\\textrm{mod}~2) > (a_4~\\textrm{mod}~2)\n\nThus, the response to this query should be 1.\n\n* * *"}, {"input": "7 3\n 27 18 28 18 28 46 1000000000\n 1000000000 1 7\n 1000000000 2 10\n 1000000000 3 12", "output": "224489796\n 214285714\n 559523809"}]
Print the maximum total values of the items in a line.
s074765167
Wrong Answer
p02320
N W v1 w1 m1 v2 w2 m2 : vN wN mN The first line consists of the integers N and W. In the following N lines, the value, weight and limitation of the i-th item are given.
#! /usr/bin/python # -*- coding:utf-8 -*- N, W = map(int, input().split()) dp = [0] * (W + 1) max_w = 0 for i in range(N): v, w, m = map(int, input().split()) n = 1 while m > 0: m -= n _v, _w = v * n, w * n if max_w + _w > W: max_w = W else: max_w = max_w + _w for k in range(max_w, _w - 1, -1): if dp[k] < dp[k - w] + _v: dp[k] = dp[k - _w] + _v if n * 2 > m: n = m else: n = 2 * n print(max(dp))
Knapsack Problem with Limitations You have N items that you want to put them into a knapsack. Item i has value vi, weight wi and limitation mi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. * You can select at most mi items for _i_ th item. Find the maximum total value of items in the knapsack.
[{"input": "4 8\n 4 3 2\n 2 1 1\n 1 2 4\n 3 2 2", "output": "12"}, {"input": "2 100\n 1 1 100\n 2 1 50", "output": "150"}]
Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive). * * *
s574317455
Runtime Error
p02635
Input is given from Standard Input in the following format: S K
import sys readline = sys.stdin.readline # 非再帰 import sys def scc(Edge): N = len(Edge) Edgeinv = [[] for _ in range(N)] for vn in range(N): for vf in Edge[vn]: Edgeinv[vf].append(vn) used = [False] * N order = [] for st in range(N): if not used[st]: used[st] = True stack = [~st, st] while stack: vn = stack.pop() if vn >= 0: for vf in Edge[vn]: if not used[vf]: used[vf] = True stack.append(~vf) stack.append(vf) else: order.append(~vn) res = [None] * N used = [False] * N cnt = -1 for st in order[::-1]: if not used[st]: cnt += 1 stack = [st] res[st] = cnt used[st] = True while stack: vn = stack.pop() for vf in Edgeinv[vn]: if not used[vf]: used[vf] = True res[vf] = cnt stack.append(vf) M = cnt + 1 components = [[] for _ in range(M)] for i in range(N): components[res[i]].append(i) """ tEdge = [[] for _ in range(M)] teset = set() for vn in range(N): tn = res[vn] for vf in Edge[vn]: tf = res[vf] if tn != tf and tn*M + tf not in teset: teset.add(tn*M + tf) tEdge[tn].append(tf) """ return res, components N, M = map(int, readline().split()) Edge = [[] for _ in range(N)] for _ in range(M): a, b = map(int, readline().split()) Edge[a].append(b) R, comp = scc(Edge) Ans = [str(len(comp))] for c in comp: Ans.append(f"{len(c)} " + " ".join(map(str, c))) print("\n".join(Ans))
Statement Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
[{"input": "0101 1", "output": "4\n \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]
Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive). * * *
s050029557
Wrong Answer
p02635
Input is given from Standard Input in the following format: S K
P = 998244353 S, K = input().split() N = S.count("0") + 1 A = [len(a) for a in S.split("0")][::-1] K = int(K) X = [[0] * N for _ in range(N)] X[0][0] = 1 for a in A: nX = [[0] * N for _ in range(N)] Y = [x[:] for x in X] for i in range(N - 1)[::-1]: for j in range(N): Y[i][j] += Y[i + 1][j] if Y[i][j] >= P: Y[i][j] -= P Z = [[0] * (N + 1)] + [[0] + x[:] for x in X] for i in range(N): for j in range(N): Z[i + 1][j + 1] = Z[i][j] + X[i][j] if Z[i + 1][j + 1] >= P: Z[i + 1][j + 1] -= P for i in range(N): for j in range(N): nX[i][j] += Y[i][j] t = min(a, i, j) nX[i][j] += Z[i][j] - Z[i - t][j - t] nX[i][j] %= P X = nX print(sum(X[0][: K + 1]) % P)
Statement Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
[{"input": "0101 1", "output": "4\n \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]
Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive). * * *
s488850012
Wrong Answer
p02635
Input is given from Standard Input in the following format: S K
s, k = map(int, input().split())
Statement Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
[{"input": "0101 1", "output": "4\n \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]
Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive). * * *
s367618693
Accepted
p02635
Input is given from Standard Input in the following format: S K
# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline # a,b,c,d = map(int,readline().split()) s, k = readline().split() a = [len(i) for i in s.split("0")] while a and a[-1] == 0: a.pop() if not a: print(1) exit() MOD = 998244353 M = sum(a) + 1 k = min(int(k), M) dp = [[0] * M for _ in range(k + 1)] # j 使って(上限 k)、l 余ってる dp[0][0] = 1 # print(a) for ai in a[::-1]: ndp = [[0] * M for _ in range(k + 1)] # j 使って(上限 k)、l 余ってる for j in range(k + 1): for l in range(M): if dp[j][l]: for ll in range(l): ndp[j][ll] += dp[j][l] ndp[j][ll] %= MOD V = min(M - l, k - j + 1, ai + 1) for i in range(V): # if j+i > k: break ndp[j + i][l + i] += dp[j][l] ndp[j + i][l + i] %= MOD dp = ndp # print(dp) ans = 0 for jj in range(k + 1): ans += dp[jj][0] print(ans % MOD)
Statement Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
[{"input": "0101 1", "output": "4\n \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]
Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive). * * *
s131919283
Runtime Error
p02635
Input is given from Standard Input in the following format: S K
import sys n = int(input()) alpha = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] lst = [] Lst = [] def Base_10_to_n_(X, n): X_dumy = X while X_dumy > 0: Lst.append((X_dumy % n)) X_dumy = int(X_dumy / n) return Lst if sum(Base_10_to_n_(n, 26)) == 1: p = "" for i in range(len(Base_10_to_n_(n, 26)) - 3): p += "z" print(p) sys.exit() def Base_10_to_n(X, n): X_dumy = X ku = 0 while X_dumy > 0: if ku: lst.append(max(0, (X_dumy % n) - 1)) if X_dumy % n == 0: ku = 1 else: ku = 0 X_dumy = int(X_dumy / n) else: lst.append((X_dumy % n)) if X_dumy % n == 0: ku = 1 else: ku = 0 X_dumy = int(X_dumy / n) return lst lst = Base_10_to_n(n, 26) lst.reverse() t = "" for i in range(len(lst)): t += alpha[lst[i] - 1] print(t)
Statement Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
[{"input": "0101 1", "output": "4\n \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]
Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive). * * *
s732411268
Accepted
p02635
Input is given from Standard Input in the following format: S K
S, K = input().split() S = list(S) ori = [0] for i in range(len(S) - 1, -1, -1): if S[i] == "0": ori.append(0) else: ori[-1] += 1 # print (ori) N = len(ori) K = int(K) K = min(310, K) mod = 998244353 dp = [[[0] * (K + 1) for i in range(K + 1)] for j in range(N + 10)] dp[-1][0][0] = 1 for i in range(N): # なにもしない for k in range(K + 1): for x in range(k + 1): dp[i][k][x] += dp[i - 1][k][x] # 1を追加する for x in range(K + 1): nsum = 0 for k in range(K + 1): if x <= k: dp[i][k][x] += nsum dp[i][k][x] %= mod nsum += dp[i - 1][k][x] if k - ori[i] >= 0: nsum -= dp[i - 1][k - ori[i]][x] nsum %= mod # xを使用する for k in range(K + 1): nsum = 0 for x in range(k + 1): dp[i][k][x] += nsum dp[i][k][x] %= mod if x >= 0: nsum += dp[i - 1][k][x] nsum %= mod # print (dp[i]) ans = 0 for i in range(K + 1): ans += dp[N - 1][i][i] ans %= mod print(ans)
Statement Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are `0` and `1`, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.
[{"input": "0101 1", "output": "4\n \n\nFour strings, `0101`, `0110`, `1001`, and `1010`, can result.\n\n* * *"}, {"input": "01100110 2", "output": "14\n \n\n* * *"}, {"input": "1101010010101101110111100011011111011000111101110101010010101010101 20", "output": "113434815"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s582217079
Wrong Answer
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
print(1)
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s929263735
Wrong Answer
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
class DoubleEndedList: # クラス内クラスを作る(CellクラスはDoubleEndedListクラスからしか参照しないため) class Cell: def __init__(self, data, prv=None, nxt=None): self.data = data self.prv = prv self.nxt = nxt def __init__(self): head = DoubleEndedList.Cell(None) head.prv = head head.nxt = head self.head = head def insertFirst(self, data): x = DoubleEndedList.Cell(data, self.head, self.head.nxt) self.head.nxt = x x.nxt.prv = x def delete(self, index): x = self.head while x.data != index: x = x.nxt x.prv.nxt = x.nxt x.nxt.prv = x.prv deque = DoubleEndedList() for i in range(int(input())): cmd = input().split() if cmd[0] == "insert": deque.insertFirst(int(cmd[1])) elif cmd[0] == "delete": deque.delete(int(cmd[1])) elif cmd[0] == "deleteFirst": deque.delete(deque.head.nxt.data) elif cmd[0] == "deleteLast": x = deque.head while x.nxt is not deque.head: x = x.nxt deque.delete(x.data) else: print("Wrong Command") n = deque.head.nxt while n is not deque.head: print(n.data, end="") if n.nxt is not deque.head: print(" ", end="") else: print("") n = n.nxt
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s478973502
Runtime Error
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp sample_input = list(range(3)) sample_input[ 0 ] = """7 insert 5 insert 2 insert 3 insert 1 delete 3 insert 6 delete 5""" sample_input[ 1 ] = """9 insert 5 insert 2 insert 3 insert 1 delete 3 insert 6 delete 5 deleteFirst deleteLast""" sample_input[2] = """""" give_sample_input = None if give_sample_input is not None: sample_input_list = sample_input[give_sample_input].split("\n") def input(): return sample_input_list.pop(0) # main class DoublyLinkedList: def __init__(self, a_data=[]): self.data = a_data def insert(self, x): self.data.insert(0, x) def delete(self, x): self.data.remove(x) def delete_first(self): self.data.pop(0) def delete_last(self): self.data.pop() def to_str(self): output = "" for x in self.data: output += str(x) + " " output = output.rstrip() return output num_of_command = int(input()) doublely_list = DoublyLinkedList() for n in range(num_of_command): str_command = input() if str_command == "deleteFirst": doublely_list.delete_first() continue elif str_command == "deleteLast": doublely_list.delete_last() continue command_name = str_command.split()[0] command_obj = int(str_command.split()[1]) if command_name == "insert": doublely_list.insert(command_obj) elif command_name == "delete": doublely_list.delete(command_obj) print(doublely_list.to_str())
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s477189593
Runtime Error
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
from collections import deque def insert(linked, x): if x not in linked: linked.appendleft(x) return linked def delete(linked, x): if x in linked: linked.remove(x) return linked def deleteFirst(linked): del linked[0] return linked def deleteLast(linked): del linked[-1] return linked orders = deque([]) n = int(input()) for i in range(n): orders.append(list(input().split())) linked = deque([]) for o in orders: order = o[0] if order == "insert": insert(linked, o[1]) elif order == "delete": delete(linked, o[1]) elif order == "deleteFirst": deleteFirst(linked) elif order == "deleteLast": deleteLast(linked) print(" ".join(map(str, linked)))
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s159666428
Runtime Error
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
n = int(input()) dlist = [] for i in range(n): code = input().split() if code[0] == "insert": dlist.insert(0, code[1]) if code[0] == "delete": dlist.remove(code[1]) if code[0] == "deleteFirst": dlist.pop(0) if code[0] == "deleteLast": dlist.pop() print(*dlist, sep=" ")
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s912667426
Accepted
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
class Node: def __init__(self, num, next=None, prev=None): self.num = num self.next = next self.prev = prev class Doubly: def __init__(self): self.start = self.end = None def insert(self, x): it = Node(x) if self.end is None: self.end = self.start = it else: it.next = self.start self.start.prev = it self.start = it def delete(self, x): poin = self.start while poin is not None: if poin.num == x: if poin.prev is None and poin.next is None: self.start = self.end = None elif poin is self.start: # 先頭 self.start.next.prev = None self.start = poin.next elif poin is self.end: # 末尾 poin.prev.next = None self.end = poin.prev else: poin.prev.next = poin.next poin.next.prev = poin.prev break poin = poin.next # def deleteFirst(self): # self.start=self.start.next # def deleteLast(self): # self.end.prev.next =None # self.end=self.end.prev def deleteFirst(self): if self.start is self.end: self.start = self.end = None else: self.start.next.prev = None self.start = self.start.next def deleteLast(self): if self.start is self.end: self.start = self.end = None else: self.end.prev.next = None self.end = self.end.prev def print(self): var = self.start lis = [] while var is not None: lis.append(var.num) var = var.next return " ".join(lis) from sys import stdin N = int(input()) DB = Doubly() # code=[input().split() for k in range(N)] # for _ in range(N): # c=input().split() # if len(c)==1: # eval('DB.'+c[0]+'()') # else: # eval('DB.'+c[0]+'(c[1])') for _ in range(N): cmd = stdin.readline().strip().split() if cmd[0] == "insert": DB.insert(cmd[1]) elif cmd[0] == "delete": DB.delete(cmd[1]) elif cmd[0] == "deleteFirst": DB.deleteFirst() elif cmd[0] == "deleteLast": DB.deleteLast() print(DB.print())
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s991082553
Wrong Answer
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
import sys res = dict() dll = [None] * 2000000 left = 0 right = 0 n = int(input()) for inpt in sys.stdin.read().splitlines(): i = inpt.split() if i[0] == "insert": x = int(i[1]) dll[left] = x if x in res: res[x].append(left) else: res[x] = [left] left += 1 if i[0] == "delete": x = int(i[1]) if x in res: ind = max(res[x]) dll[ind] = None res[x].remove(ind) if len(res[x]) == 0: del res[x] if ind == (left - 1): left = ind if i[0] == "deleteFirst": left -= 1 dll[left] = None if i[0] == "deleteLast": right += 1 ret = [] for i in range(right, left): ind = left - 1 - i if dll[ind] is not None: ret.append(str(dll[ind])) print(" ".join(ret))
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s876049586
Accepted
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
import sys head = -1 tail = -1 dll = [] for i in range(int(sys.stdin.readline())): line = sys.stdin.readline() if line[6] == "F": if head == tail: dll = [] head = -1 tail = -1 else: nxt = dll[head][2] # if nxt >= 0: dll[nxt][1] = -1 if tail == head: tail = -1 head = nxt elif line[6] == "L": if head == tail: dll = [] head = -1 tail = -1 else: prv = dll[tail][1] if prv >= 0: dll[prv][2] = -1 if tail == head: head = -1 tail = prv elif line[0] == "i": # 'insert': x = int(line[7:]) dll.append([x, -1, head]) llen = len(dll) - 1 if head == -1: tail = llen else: dll[head][1] = llen head = llen elif line[0] == "d": # 'delete': x = int(line[7:]) cur = head while cur >= 0: if dll[cur][0] == x: nxt = dll[cur][2] prv = dll[cur][1] dll[nxt][1] = prv dll[prv][2] = nxt if nxt == -1: tail = prv if prv == -1: head = nxt break cur = dll[cur][2] print(dll[head][0], end="") cur = dll[head][2] while cur >= 0: print("", dll[cur][0], end="") cur = dll[cur][2] print()
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
s179202319
Accepted
p02265
The input is given in the following format: _n_ _command_ 1 _command_ 2 ... _command n_ In the first line, the number of operations _n_ is given. In the following _n_ lines, the above mentioned operations are given in the following format: * insert x * delete x * deleteFirst * deleteLast
import sys, collections input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = 10**10 def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): n = I() command = [LSS() for _ in range(n)] que = collections.deque() for i in command: if i[0] == "insert": que.appendleft(i[1]) elif i[0] == "delete": if i[1] in que: que.remove(i[1]) elif i[0] == "deleteFirst": que.popleft() elif i[0] == "deleteLast": que.pop() print(*que) if __name__ == "__main__": resolve()
Doubly Linked List Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
[{"input": "7\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5", "output": "6 1 2"}, {"input": "9\n insert 5\n insert 2\n insert 3\n insert 1\n delete 3\n insert 6\n delete 5\n deleteFirst\n deleteLast", "output": "1"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s986781973
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
S = list(input()) sum = 15 - len(S) S.sort() for i in S: if i == "o": sum += 1 if sum >= 8: print("YES") break if i == "x": print("NO") break
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s530580426
Accepted
p03024
Input is given from Standard Input in the following format: S
print("YES" if sum([c == "x" for c in input()]) < 8 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s958232270
Accepted
p03024
Input is given from Standard Input in the following format: S
print("YES" if 15 - input().count("x") >= 8 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s620115661
Accepted
p03024
Input is given from Standard Input in the following format: S
print(["NO", "YES"][input().count("x") < 8])
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s504544786
Accepted
p03024
Input is given from Standard Input in the following format: S
f = input() print("YNEOS"[f.count("o") + 7 < len(f) :: 2])
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s007435414
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("YES" if input().count("x") >= 8 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s915869659
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("YES" if input().count("o") > 7 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s927144616
Accepted
p03024
Input is given from Standard Input in the following format: S
print("YES" if list(input()).count("x") <= 7 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s920422276
Accepted
p03024
Input is given from Standard Input in the following format: S
print("YES" if input().count("x") <= 7 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s023978504
Accepted
p03024
Input is given from Standard Input in the following format: S
print("NO" if input().count("x") >= 8 else "YES")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s245261068
Accepted
p03024
Input is given from Standard Input in the following format: S
print("YES" if input().count("x") < 8 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s970835837
Accepted
p03024
Input is given from Standard Input in the following format: S
print("YNEOS"[input().count("x") >= 8 :: 2])
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s226349690
Accepted
p03024
Input is given from Standard Input in the following format: S
print(("NO", "YES")[input().count("x") <= 7])
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s971489859
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("NO" if input().count("x") > 6 else "YES")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s709506157
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("No" if input().count("x") >= 8 else "Yes")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s315285460
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("YES" if sum([x == "o" for x in input()]) > 6 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s218893704
Runtime Error
p03024
Input is given from Standard Input in the following format: S
print("YES")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s570788239
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("YES") if input().count("o") >= 7 else print("NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s388808915
Runtime Error
p03024
Input is given from Standard Input in the following format: S
c = str(int(input())).count("x") print("YES" if c <= 7 else "NO")
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` otherwise. * * *
s263369063
Wrong Answer
p03024
Input is given from Standard Input in the following format: S
print("YNeos"[input().count("x") >= 8 :: 2])
Statement Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
[{"input": "oxoxoxoxoxoxox", "output": "YES\n \n\nTakahashi has 7 wins and 7 losses before the last match. If he wins that\nmatch, he will have 8 wins.\n\n* * *"}, {"input": "xxxxxxxx", "output": "NO"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s625135328
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a, b = map(int, input().split()) s = input() for i in range(1, b + 1): if i != a + 1: if s[i] != "-": y = "yes" if s[a + 1] == "-" and y = "yes": print("Yes") else: print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s337908623
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a, b = map(int, input().split()) s = input() for i in range(1, b + 1): if i != a + 1: if s.split() != "-": y = "yes" if s[a + 1] == "-" and y = "yes": print("Yes") else: print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s668612780
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A, B = map(int, input().split()) S = list(map(str, input().split(-))) ans = "No" if A == len(S[0]): if B == len(S[1]): ans = "Yes" print(ans)
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s249485777
Wrong Answer
p03474
Input is given from Standard Input in the following format: A B S
print("Yes")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s035461048
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
import re a,b=map(int,input().split()) s=input() if re.fullmatch([0-9]{a}-[0-9]{b},s)==True: print('Yes') else: print('No')
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s849366285
Wrong Answer
p03474
Input is given from Standard Input in the following format: A B S
print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s593864163
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A, B = map(int, input().split()) S = input() C = "1234567890" for i in range(len(S)): if i == A: if S[i] == "-": continue else: print("No") exit() else: if S[i] in C: continue else: print("No") exit() print("Yes") exit() resolve()
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s806051088
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a,b=map(int,input().split()) s=str(input()) e=["0",'1','2','3','4','5','6','7','8','9'] for i in range(len(s)): if a=i: if s[i]!='-': print("No") exit() else: if s[i] not in e: print("No") exit() print("Yes")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s238241677
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A, B = map(int, input().split()) S = input() C = "1234567890" for i in range(len(S)): if i == A: if S[i] == "-": continue else: print("No") exit() else: if S[i] in C: continue else: print("No") exit() print("Yes") resolve()
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s499977963
Accepted
p03474
Input is given from Standard Input in the following format: A B S
a, b = map(int, input().split()) p = input() frag = True if len(p) != a + b + 1 or p.count("-") != 1: frag = False if p[a] != "-": frag = False print("Yes" if frag == True else "No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s376518888
Accepted
p03474
Input is given from Standard Input in the following format: A B S
a, _, s = open(0).read().split() print("YNeos"[s.count("-") > 1 or "-" != s[int(a)] :: 2])
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s488205842
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a, b = map(int, input().split()) s = input() if s[a] == '-' and s[:a].isdigit() and s[a+1:].isdigit(): print('Yes') else: print('No')
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s937432691
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A, B = map(int, input().split()) S = input() pos_hyphen = [i if S[i] == "-" for i in range(len(S))] if len(pos_hyphen) == 1 and pos_hyphen[0] == A: print("Yes") else: print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s719487570
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A,B=map(int, input().split()) s=input() ng = 0 if !(s[0:A].isdecimal()): ng = 1 if s[A] != "-": ng = 1 if !(s[A+1:A+B+1].isdecimal()): ng = 1 if ng == 1: print("No") else: print("Yes")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s068050688
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a, b = map(int, input().split()) s = input() import re r = "[0-9]{}-[0-9]{}".format(a, b) if re.match(r"%s" % r, s) <> None: print("Yes") else: print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s245533690
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
1 2 7444
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s912375454
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a,b=map(int,input().split());s=input();print(""[len(s)<11*s[a]=="-"::2]
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s418114970
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A,B=int(input().split()) S="input()" if length(S)==A+B+1 and S[A]==-: print("Yes") else: print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s577770177
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
3 4 269-6650
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s007093713
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
a,b = map(int,input().split()) s = input() L = [i for i in range(1,10)] ans = "Yes" for i in range(a): if not int(s[i]) in L: ans = "No" if s[a] != "-": ans = "No" for i in range(a+1,a+b+1): if not int(s[i]) in L: ans = "No" print(ans)
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s068337704
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A,B =map(int,input().split()) hih=0 num=1 JG=1 S=int(input()) S= list(str(S)) for s in S: if s=="-": hih=num num+=1 for s in S: if s=="0" or s=="1" or s=="2" or s=="3" or s=="4" or s=="5" or s=="6" or s=="7" or s == "8" or s=="9": else: JG=0 if hih==A & JG==1: print("Yes") else: print("No")
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s201791357
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A,B=map(int,input().split()) S=input() number=0 list=['0','1','2','3','4'.'5','6','7','8','9'] for a in range(A): if S[a] in list: number+=1 if S[A]=='-': number+=1 for a in range(B): if S[A+a+1] in list: number+=1 if number==A+B+1: print('Yes') else: print('No')
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s462006196
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
A,B = [int(x) for x in input().split()] S = input() flag = True for ind,i in enumerate(S): if(ind!=A): if(ord(i)<48 or 57<ord(i): flag = False break else: if(i!='-'): flag = False break if(flag): print('Yes') else: print('No')
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print `Yes` if S follows the postal code format in AtCoder Kingdom; print `No` otherwise. * * *
s530854807
Runtime Error
p03474
Input is given from Standard Input in the following format: A B S
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <iterator> #include <unordered_map> #include <unordered_set> #include <tuple> using namespace std; typedef long long ll; //input //------------------------------------------ #define re(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; } template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); } #define rv_row(type, n, ...)vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int i=0; i<n; ++i){MACRO_VEC_ROW_Scan(i, __VA_ARGS__);} template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); } template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { cin >> t[p]; } template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define rv(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i; #define rMAT(type, c, n, m) vector<vector<type>> c(n, vector<type>(m));for(auto& r:c)for(auto& i:r)cin>>i; void _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } // output //------------------------------------------ #define pr(x) cout<<x<<endl; #define prv(v){for(const auto& xxx : v){cout << xxx << " ";}cout << "\n";} #define sankou(x,a,b) cout<<(x?a:b)<<endl; #define hihumi(x,a,y,b,c) cout<<(x?a:y?b:c)<<endl; #define YESNO(x) cout<<(x?"YES":"NO")<<endl; #define yesno(x) cout<<(x?"Yes":"No")<<endl; #define ck(x) cerr << #x << " = " << (x) << endl; #define ckv(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} //conversion //------------------------------------------ inline ll toInt(std::string s) { ll v; std::istringstream sin(s);sin >> v;return v; } template<class T> inline string toString(T x) { ostringstream sout;sout << x;return sout.str(); } //math //------------------------------------------ template<class T> inline T sqr(T x) { return x*x; } template<typename A, typename B>inline void chmin(A &a, B b) { if (a>b)a = b; } template<typename A, typename B>inline void chmax(A &a, B b) { if (a<b)a = b; } ll qp(ll a, ll b) { ll ans = 1ll;do { if (b & 1)ans = 1ll * ans*a;a = 1ll * a*a; } while (b >>= 1);return ans; } ll qpmod(ll a, ll b, ll mo) { ll ans = 1ll;do { if (b & 1)ans = 1ll * ans*a%mo;a = 1ll * a*a%mo; } while (b >>= 1);return ans; } ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } inline bool valid(int x, int h) { return 0 <= x && x < h; } //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define EXISTST(s,c) (((s).find(c)) != std::string::npos) #define SORT(c) sort((c).begin(),(c).end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,val) (lower_bound(x.begin(),x.end(),val)-x.begin()) #define POSU(x,val) (upper_bound(x.begin(),x.end(),val)-x.begin()) #define FI first #define SE second #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MEMINF(a) memset(a,0x3f,sizeof(a))//1e9<1061109567<INTMAX/2 //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define FORll(i,a,b) for(long long i=(a);i<(b);++i) #define repll(i,n) FORll(i,0,n) #define rrep(i,a,b) for(int i=(int)(b)-1;i>=a;i--) #define rrepll(i,a,b) for(long long i=(b)-1ll;i>=a;i--) #define fo(x,c) for(auto &x : c) #define repeat(i,a,b) for(int i=(a);i<=(b);++i) //typedef //------------------------------------------ typedef vector<int> vi; typedef vector<vi> vii; typedef vector<long long> vll; typedef vector<string> vs; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<pair<int, int>> vpii; //constant //------------------------------------------ const double EPS = 1e-8; const double PI = acos(-1.0); const int INF = (int)(1e9) + 7; const ll MOD = (ll)(1e9) + 7; const ll MOD2 = (ll)(1e18) + 9; #define ADD(a, b) a = (a + ll(b)) % MOD #define MUL(a, b) a = (a * ll(b)) % MOD const ll INF2 = (ll)(1e18); const ll INTMAX = (0x7FFFFFFFL); const ll LLMAX = (0x7FFFFFFFFFFFFFFFL); const int N4 = (int)1e4 + 10; const int N5 = (int)1e5 + 10; int dx[8] = { 1, 0, -1, 0 , 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 }; //------------------------------------------ ll ans, cnt, ret, cur, f; void _main() { re(int, a, b); re(string, s); if (s[a] == '-') { s[a] = ' '; f = 1; FOR(i, 0, a)f &= (0 <= s[i]-'0' && s[i] - '0' <= 9); FOR(i, a + 1, b + 1)f &= (0 <= s[i] - '0' && s[i] - '0' <= 9); } yesno(f); }
Statement The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
[{"input": "3 4\n 269-6650", "output": "Yes\n \n\nThe (A+1)-th character of S is `-`, and the other characters are digits from\n`0` through `9`, so it follows the format.\n\n* * *"}, {"input": "1 1\n ---", "output": "No\n \n\nS contains unnecessary `-`s other than the (A+1)-th character, so it does not\nfollow the format.\n\n* * *"}, {"input": "1 2\n 7444", "output": "No"}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s509284750
Runtime Error
p02818
Input is given from Standard Input in the following format: A B K
a, b, k = list(map(int, input().split())) a_ans = a - min(a, k) if a_ans == 0: b_ans = b - min(b, k - a) print("{} {}".format(a_ans, b_ans))
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s618164217
Runtime Error
p02818
Input is given from Standard Input in the following format: A B K
n = [int(e) for e in input().split(" ")] for i in range(n[2]): if 0 < n[0]: n[0] -= 1 elif 0 < n[1]: n[1] -= 1 print(n[0] + " " + n[1])
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s539316441
Wrong Answer
p02818
Input is given from Standard Input in the following format: A B K
A, resB, K = map(int, input().strip().split()) resA = A - K if resA < 0: resB += resA resA = 0 print(resA, resB)
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s626840986
Wrong Answer
p02818
Input is given from Standard Input in the following format: A B K
# 入力が10**5とかになったときに100ms程度早い import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_matrix(H): """ H is number of rows """ return [list(map(int, read().split())) for _ in range(H)] def read_map(H): """ H is number of rows 文字列で与えられた盤面を読み取る用 """ return [read()[:-1] for _ in range(H)] def read_col(H, n_cols): """ H is number of rows n_cols is number of cols A列、B列が与えられるようなとき """ ret = [[] for _ in range(n_cols)] for _ in range(H): tmp = list(map(int, read().split())) for col in range(n_cols): ret[col].append(tmp[col]) return ret A, B, K = read_ints() ans1 = max(A - K, 0) ans2 = max(B - (K - A), 0) print(ans1, ans2)
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s514308432
Accepted
p02818
Input is given from Standard Input in the following format: A B K
a, b, k = input().split() aa = int(a) bb = int(b) kk = int(k) res = (aa + bb) - kk if res <= 0: print(0, "", 0) elif aa > kk: print(aa - kk, "", bb) elif aa <= kk: print(0, "", res)
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s127654328
Wrong Answer
p02818
Input is given from Standard Input in the following format: A B K
a, b, k = [int(i) for i in input().split()] t = a + b - k print(t if t >= 0 else 0)
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s552071833
Wrong Answer
p02818
Input is given from Standard Input in the following format: A B K
t, a, k = map(int, input().split()) T = max(t - k, 0) k -= T - t A = max(a - k, 0) print(T, A)
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the numbers of Takahashi's and Aoki's cookies after K actions. * * *
s597113697
Accepted
p02818
Input is given from Standard Input in the following format: A B K
if __name__ == "__main__": a, b, k = map(int, input().split()) ans_a = max(a - k, 0) ans_b = b if ans_a == 0: k = k - a ans_b = max(b - k, 0) print(ans_a, ans_b)
Statement Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: * If Takahashi has one or more cookies, eat one of his cookies. * Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies. * If they both have no cookies, do nothing. In the end, how many cookies will Takahashi and Aoki have, respectively?
[{"input": "2 3 3", "output": "0 2\n \n\nTakahashi will do the following:\n\n * He has two cookies, so he eats one of them.\n * Now he has one cookie left, and he eats it.\n * Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.\n\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.\n\n* * *"}, {"input": "500000000000 500000000000 1000000000000", "output": "0 0\n \n\nWatch out for overflows."}]
Print the maximum number of pairs that Snuke can create. * * *
s338581100
Accepted
p04020
The input is given from Standard Input in the following format: N A_1 : A_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AtoZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() A = ILs(N) for i in range(N - 1): if A[i] % 2 == 1: if A[i + 1]: A[i] += 1 A[i + 1] -= 1 print(sum(a // 2 for a in A))
Statement Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1. Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
[{"input": "4\n 4\n 0\n 3\n 2", "output": "4\n \n\nFor example, Snuke can create the following four pairs:\n(1,1),(1,1),(3,4),(3,4).\n\n* * *"}, {"input": "8\n 2\n 0\n 1\n 6\n 0\n 8\n 2\n 1", "output": "9"}]
Print the maximum number of pairs that Snuke can create. * * *
s441032697
Runtime Error
p04020
The input is given from Standard Input in the following format: N A_1 : A_N
n=int(input()) l=[int(input()) for i in range(n)] ans=0 for i in range(n): ans+=(l[i]-l[i]%2)//2 l[i]%=2 if l[i]==1 ans+=1 l[i]=0;l[i+1]-=1 print(ans)
Statement Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1. Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
[{"input": "4\n 4\n 0\n 3\n 2", "output": "4\n \n\nFor example, Snuke can create the following four pairs:\n(1,1),(1,1),(3,4),(3,4).\n\n* * *"}, {"input": "8\n 2\n 0\n 1\n 6\n 0\n 8\n 2\n 1", "output": "9"}]
Print the maximum number of pairs that Snuke can create. * * *
s771033906
Runtime Error
p04020
The input is given from Standard Input in the following format: N A_1 : A_N
n=int(input()) tmp, ans=0,0 for i in range(n): a=int(input()) if a=0: ans+=tmp//2 tmp=0 else: tmp+=a print(ans)
Statement Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1. Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
[{"input": "4\n 4\n 0\n 3\n 2", "output": "4\n \n\nFor example, Snuke can create the following four pairs:\n(1,1),(1,1),(3,4),(3,4).\n\n* * *"}, {"input": "8\n 2\n 0\n 1\n 6\n 0\n 8\n 2\n 1", "output": "9"}]
Print the maximum number of pairs that Snuke can create. * * *
s163227962
Wrong Answer
p04020
The input is given from Standard Input in the following format: N A_1 : A_N
N, *A = open(0).read().split() print(sum([sum(map(int, t)) // 2 for t in "".join(A).split("0")]))
Statement Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1. Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.
[{"input": "4\n 4\n 0\n 3\n 2", "output": "4\n \n\nFor example, Snuke can create the following four pairs:\n(1,1),(1,1),(3,4),(3,4).\n\n* * *"}, {"input": "8\n 2\n 0\n 1\n 6\n 0\n 8\n 2\n 1", "output": "9"}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s463056493
Accepted
p03835
The input is given from Standard Input in the following format: K S
K, S = (int(T) for T in input().split()) Count = 0 for TX in range(0, K + 1): for TY in range(0, K + 1): if 0 <= (S - TX - TY) <= K: Count += 1 print(Count)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s570375621
Accepted
p03835
The input is given from Standard Input in the following format: K S
# from fractions import gcd # mod = 10 ** 9 + 7 # N = int(input()) # a = list(map(int,input().split())) # a,b,c = map(int,input().split()) # ans = [0] * N # math.ceilで切り上げ # dp = [[0] * 4 for i in range(3)] #2次元配列初期化 # dp = [[[0] * 2 for i in range(3)] for j in range(5)] # (ord('A'))でASCII出力 Aは65 import math import numpy as np import statistics import string import sys from array import array from collections import deque from functools import wraps import time def intinput(): return int(input()) def listintinput(): return list(map(int, input().split())) def splitintinput(): return map(int, input().split()) def factorialsurplus(x, y, z): # xからyまでの階乗をzで割ったあまりを求める ret = 1 for i in range(x, y + 1): ret = (ret * i) % z return ret def isprime(x): if x == 1: return False if x == 2: return True sq = int(math.sqrt(x)) for i in range(2, sq + 1): if x % i == 0: return False return True def hcfnaive( a, b ): # 最大公約数 math.gcdが使えない時の手段として入れとく。pythonが更新されたらいらなくなるはず if b == 0: return a else: return hcfnaive(b, a % b) K, S = splitintinput() time_sta = time.perf_counter() ans = 0 for i in range(K + 1): for j in range(min(S - i + 1, K + 1)): if S - i - j <= K: ans += 1 print(ans) time_end = time.perf_counter() # print(time_end - time_sta)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s305595426
Wrong Answer
p03835
The input is given from Standard Input in the following format: K S
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math import bisect from collections import deque from fractions import gcd from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def inputI(): return int(input().strip()) def inputS(): return input().strip() def inputIL(): return list(map(int, input().split())) def inputSL(): return list(map(str, input().split())) def inputILs(n): return list(int(input()) for _ in range(n)) def inputSLs(n): return list(input().strip() for _ in range(n)) def inputILL(n): return [list(map(int, input().split())) for _ in range(n)] def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)] #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count ############# # Main Code # ############# K, S = inputIL() ans = 0 for i in range(K + 1): for j in range(K + 1): k = S - i - j ans += 0 <= k <= S print(ans)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s611284170
Accepted
p03835
The input is given from Standard Input in the following format: K S
import sys """テンプレ""" # 高速 input = sys.stdin.readline # 1行を空白でリストにする(int) def intline(): return list(map(int, input().split())) # 上のstrヴァージョン def strline(): return list(map(str, input().split())) # 1列に並んだ数 def intlines(n): return [int(input() for _ in range(n))] # 上の文字列ヴァージョン def lines(n): return [input() for _ in range(n)] # Union-Find木 http://at274.hatenablog.com/entry/2018/02/02/173000 class UnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) # 検索 def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same_check(self, x, y): return self.find(x) == self.find(y) # 重み付きのUnion-Find木 http://at274.hatenablog.com/entry/2018/02/03/140504 class WeightedUnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) # 根への距離を管理 self.weight = [0] * (n + 1) # 検索 def find(self, x): if self.par[x] == x: return x else: y = self.find(self.par[x]) # 親への重みを追加しながら根まで走査 self.weight[x] += self.weight[self.par[x]] self.par[x] = y return y # 併合 def union(self, x, y, w): rx = self.find(x) ry = self.find(y) # xの木の高さ < yの木の高さ if self.rank[rx] < self.rank[ry]: self.par[rx] = ry self.weight[rx] = w - self.weight[x] + self.weight[y] # xの木の高さ ≧ yの木の高さ else: self.par[ry] = rx self.weight[ry] = -w - self.weight[y] + self.weight[x] # 木の高さが同じだった場合の処理 if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 # 同じ集合に属するか def same(self, x, y): return self.find(x) == self.find(y) # xからyへのコスト def diff(self, x, y): return self.weight[x] - self.weight[y] """ここからメインコード""" k, s = intline() r = range ans = 0 for x in r(k + 1): for y in r(k + 1): if x + y <= s and s - x - y <= k: ans += 1 print(ans)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s117865250
Wrong Answer
p03835
The input is given from Standard Input in the following format: K S
sk = input() count = 0 s, k = [int(x) for x in sk.split(" ")] count = 0 for i in range(min(k + 1, s + 2)): for j in range(i + 1, s + 2): x = i y = j - i - 1 z = s - y - x if x <= k and y <= k and z <= k: count += 1 print(count)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s158529503
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
k,s=map(int,input().split()) c=0 m=min(s,k) for x in range(m+1): for y in range(m+1-x) for z in range(m+1-x-y) if x+y+z==s: c+=1 print(c)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s011706579
Wrong Answer
p03835
The input is given from Standard Input in the following format: K S
import math import time from collections import defaultdict, deque from sys import stdin, stdout from bisect import bisect_left, bisect_right k, s = map(int, stdin.readline().split()) print(((k + 2) * (k + 1)) // 2)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s310027657
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
k, s = map(int, input().split()) #k, s = 5,15 ans = 0 for i in range(k+1): for j in range(k+1): l = s-i-j if i + j + l == s and l>0 ans += 1 print(ans)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s331149122
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
# -*- coding: utf-8 -*- # problem B k, s = map(int, input().split()) ans = 0 for i in range(k+1): forj in range(k+1): z = s-i-j if 0 <= z and z <=k: ans = ans+1 print(ans)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s914518708
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
K,S = map(int,input().split()) count = 0 for i in range(K+1): for j in range(K+1): for k in range(K+1): if i+j+k = S: count += 1 print(count)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s232395883
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
k = int(input()) s = int(input()) x = 0 y = 0 z = 0 i = 0 for x in range(k) for y in range(k) for z in range(k) if x+y+z == s: i +=1 print(i)
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s239099237
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
k, s = map(int, input().split()) from math import factorial def c(n, k): return factorial(n) // factorial(n - k) // factorial(k) if s < k: print(c(s + 2, 2)) elif 3 * k < s: print(0) else: # k<=s<=3k の場合 くっそ~わかんねぇ~
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
Print the number of the triples of X, Y and Z that satisfy the condition. * * *
s560566422
Runtime Error
p03835
The input is given from Standard Input in the following format: K S
# coding: utf-8 # Your code here! import itertools import pandas as pd
Statement You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
[{"input": "2 2", "output": "6\n \n\nThere are six triples of X, Y and Z that satisfy the condition:\n\n * X = 0, Y = 0, Z = 2\n * X = 0, Y = 2, Z = 0\n * X = 2, Y = 0, Z = 0\n * X = 0, Y = 1, Z = 1\n * X = 1, Y = 0, Z = 1\n * X = 1, Y = 1, Z = 0\n\n* * *"}, {"input": "5 15", "output": "1\n \n\nThe maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]