s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s576353698 | p03821 | u277429554 | 1593408716 | Python | Python (3.8.2) | py | Runtime Error | 27 | 8996 | 239 | n = int(input())
a = []
b = []
for j in range(n):
l = list(map(int, input().split()))
a.append(l[0])
b.append(l[1])
c = 0
for i in range(n-1, -1, -1):
if (a[i]+c) % b[i] != 0:
c += (b[i] - (a[i]+c) % b[i])
print(c) |
s353943603 | p03821 | u228232845 | 1592162957 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 641 | import math
import sys
from typing import Reversible
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): r... |
s724599032 | p03821 | u075304271 | 1592000391 | Python | PyPy3 (2.4.0) | py | Runtime Error | 190 | 39856 | 571 | import numpy as np
import math
import collections
import fractions
import itertools
def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))
def solve():
n = int(input())
cost = 0
a, b = [0]*n, [0]*n
for i in range(n):
a[i]... |
s877917127 | p03821 | u060736237 | 1590528636 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 261 | n = int(input())
A, B = [], []
for _ in range(n):
a, b = map(int, input().split())
A.append(a)
B.append(b)
result = 0
for a, b in zip(A[::-1], B[::-1]):
piyo = (a+result) % b
if piyo == 0:
continue
result += b - piyo
print(result |
s727104646 | p03821 | u056358163 | 1589936642 | Python | Python (3.4.3) | py | Runtime Error | 37 | 5048 | 407 | import fractions
def lcm(a, b):
return a * b / fractions.gcd(a, b)
N, M = map(int, input().split())
S = input()
T = input()
d_N = {}
for n in range(N):
d = fractions.gcd(n, N)
d_N[(n // d, N // d)] = n
for m in range(M):
d = fractions.gcd(m, M)
k = (m // d, M // d)
if k in d_N:
if S... |
s363839959 | p03821 | u276204978 | 1589679122 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 371 | import numpy as np
N = int(input())
A = np.zeros(N).astype(int)
B = np.zeros(N).astype(int)
for i in range(N):
A[i], B[i] = map(int, input().split())
ans = 0
for i in reversed(range(N)):
A[i] = A[i] + ans
if A[i] % B[i] == 0:
continue
elif B[i] - A[i] > 0:
ans += B[i] - A[i]
else:
... |
s250815795 | p03821 | u479638406 | 1589645373 | Python | Python (3.4.3) | py | Runtime Error | 340 | 11048 | 516 | def solve():
n = int(input())
a = []
b = []
for _ in range(n):
A, B = map(int, input().split())
if B != 1:
a.append(A)
b.append(B)
ans = b[-1] - a[-1]%b[-1]
if a[-1]%b[-1] == 0: ans = 0
for i in range(1, len(a)):
c = a[-(i+1)]+ans
... |
s701141632 | p03821 | u479638406 | 1589644827 | Python | Python (3.4.3) | py | Runtime Error | 341 | 11036 | 478 | def solve():
n = int(input())
a = []
b = []
for _ in range(n):
A, B = map(int, input().split())
if B != 1:
a.append(A)
b.append(B)
ans = b[-1] - a[-1]%b[-1]
for i in range(1, len(a)):
c = a[-(i+1)]+ans
if c > b[-(i+1)]:
dis = b... |
s403129434 | p03821 | u479638406 | 1589644436 | Python | Python (3.4.3) | py | Runtime Error | 359 | 15860 | 565 | def solve():
n = int(input())
a = []
b = []
for _ in range(n):
A, B = map(int, input().split())
if B != 1:
a.append(A)
b.append(B)
dis = b[-1] - a[-1]%b[-1]
ans = [dis]
for i in range(1, len(a)):
c = a[-(i+1)]+ans[i-1]
if c > b[-(i+1)]... |
s494186186 | p03821 | u479638406 | 1589643786 | Python | Python (3.4.3) | py | Runtime Error | 353 | 15860 | 565 | def solve():
n = int(input())
a = []
b = []
for _ in range(n):
A, B = map(int, input().split())
if B != 1:
a.append(A)
b.append(B)
dis = b[-1] - a[-1]%b[-1]
ans = [dis]
for i in range(1, len(a)):
c = a[-(i+1)]+ans[i-1]
if c > b[-(i+1)]... |
s863984076 | p03821 | u479638406 | 1589643475 | Python | Python (3.4.3) | py | Runtime Error | 356 | 15860 | 511 | def solve():
n = int(input())
a = []
b = []
for _ in range(n):
A, B = map(int, input().split())
if B != 1:
a.append(A)
b.append(B)
dis = b[-1] - a[-1]%b[-1]
ans = [dis]
for i in range(1, len(a)):
c = a[-(i+1)]+ans[i-1]
if c >= b[-(i+1)... |
s764086221 | p03821 | u479638406 | 1589643388 | Python | Python (3.4.3) | py | Runtime Error | 355 | 15860 | 503 | def solve():
n = int(input())
a = []
b = []
for _ in range(n):
A, B = map(int, input().split())
if B != 1:
a.append(A)
b.append(B)
dis = b[-1] - a[-1]%b[-1]
ans = [dis]
for i in range(1, len(a)):
c = a[-(i+1)]+ans[i-1]
if c >= b[-(i+1)... |
s098881454 | p03821 | u077003677 | 1589592837 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 648 | import sys
import os
def file_input():
f = open('AGC009/input.txt', 'r')
sys.stdin = f
def main():
#file_input()
N=int(input())
A=[]
B=[]
for i in range(N):
tmp=list(map(int, input().split()))
A.append(tmp[0])
B.append(tmp[1])
cnt=0
for j in range(N):
... |
s692813138 | p03821 | u077003677 | 1589589641 | Python | Python (3.4.3) | py | Runtime Error | 388 | 11108 | 764 | import sys
import os
def file_input():
f = open('AGC009/input.txt', 'r')
sys.stdin = f
def main():
#file_input()
N=int(input())
A=[]
B=[]
for i in range(N):
tmp=list(map(int, input().split()))
A.append(tmp[0])
B.append(tmp[1])
cnt=0
for j in range(N):
... |
s903634817 | p03821 | u408375121 | 1589383198 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 422 | n = int(input())
l = []
r = []
for _ in range(n):
a, b = map(int, input())
l.append(a)
r.append(b)
before_sa = 0
for i in range(1, n+1):
j = 0
a, b = l[-i], r[-i]
while True:
if j == 0 and a % b == 0:
sa = 0
elif j == 0 and a % b != 0:
sa = (a//b + 1) * b - a
elif j > 0:
sa = (... |
s667807867 | p03821 | u807772568 | 1586227758 | Python | Python (3.4.3) | py | Runtime Error | 273 | 31732 | 1445 | import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if l... |
s659578275 | p03821 | u088552457 | 1583112704 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2109 | 95604 | 837 | def count_baisuu(a, b):
return b - (a % b)
def main():
n = int(input())
alist = []
blist = []
ab = []
for i in range(n):
a, b = input_list()
ab.append((a, b))
alist.append(a)
blist.append(b)
dp = [0]*n
i = n - 1
for a, b in reversed(ab):
if i != n-1:
a += sum(dp)
... |
s159773311 | p03821 | u348868667 | 1582733717 | Python | PyPy3 (2.4.0) | py | Runtime Error | 162 | 38384 | 386 | import numpy as np
def main():
N = int(input())
A = np.array([None]*N)
B = np.array([None]*N)
for i in range(N):
A[i],B[i] = map(int,input().split())
ans = 0
for i in range(N-1,-1,-1):
if A[i]%B[i] == 0:
continue
ans += (B[i] - A[i]%B[i])
A += (B[i] -... |
s997140817 | p03821 | u857428111 | 1582517974 | Python | PyPy3 (2.4.0) | py | Runtime Error | 321 | 69356 | 1194 | # coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe
# my functions here!
#標準エラー出力
def printargs2err(*args):
names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
pri... |
s690790834 | p03821 | u417014669 | 1577674441 | Python | PyPy3 (2.4.0) | py | Runtime Error | 180 | 38384 | 403 | N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
A=[]
for x in T:
if x == 's':
A.append('r')
if x == 'p':
A.append('s')
if x == 'r':
A.append('p')
for i in range(K,N):
if A[i-K] == A[i]:
A[i] = 'x'
ans = 0
for x in A:
if x == 's':
ans ... |
s205884359 | p03821 | u905582793 | 1577347832 | Python | PyPy3 (2.4.0) | py | Runtime Error | 164 | 38384 | 169 | n=int(input())
ab=[list(map(int,input())) for i in range(n)]
ans = 0
for i in range(n-1,-1,-1):
k = (ab[i][0]+ans)%ab[i][1]
if k!=0:
ans += ab[i][1]-k
print(ans) |
s328237061 | p03821 | u644907318 | 1577018942 | Python | Python (3.4.3) | py | Runtime Error | 310 | 3060 | 112 | N = int(input())
cnt = 0
for _ in range(N):
a,b = map(int,input().split())
cnt += (a-b)%a
print(cnt) |
s430620686 | p03821 | u724742135 | 1576982402 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 227 | from sys import stdin
N = int(stdin.readline().rstrip())
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
ans = 0
for i in range(N-1, -1, -1):
a, b = AB[i]
ans += (b - (a + ans) % b) % b
print(ans) |
s693240883 | p03821 | u252828980 | 1576099440 | Python | Python (3.4.3) | py | Runtime Error | 354 | 14896 | 587 | n = int(input())
L1,L2 = [],[]
for i in range(n):
a,b = map(int,input().split())
L1.append(b)
L2.append(a)
L1 = L1[::-1]
L2 = L2[::-1]
#print(L1)
#print(L2)
cnt = 0
for i in range(n):
L1[i] += cnt
#print(L1[i])
if L1[i] >= L2[i]:
cnt += L1[i]%L2[i]
elif L1[i] < L2[... |
s893546509 | p03821 | u936985471 | 1575133693 | Python | Python (3.4.3) | py | Runtime Error | 383 | 14864 | 283 | N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
a,b=map(int,input().split())
A[i]=a
B[i]=b
ans=0
for i in range(N-1,-1,-1):
plus=0
A[i]+=ans
if B[i]==1:
plus=0
elif A[i]<B[i]:
plus=B[i]%A[i]
elif A[i]>B[i]:
plus=B[i]-A[i]%B[i]
ans+=plus
print(ans) |
s976208302 | p03821 | u911575040 | 1574132336 | Python | PyPy3 (2.4.0) | py | Runtime Error | 178 | 38544 | 55 | a,b,c=map(int,input().split())
print(min(b+c,a+2*b+1))
|
s854794830 | p03821 | u573272932 | 1573184383 | Python | Python (3.4.3) | py | Runtime Error | 403 | 27380 | 161 | N = int(input())
cnt = 0
L = []
for i in range(N):
L.append(list(map(int, input().split())))
for i in range(N):
A, B = L[-i+1]
cnt += -(A + cnt)%B
print(cnt) |
s151814206 | p03821 | u573272932 | 1573184357 | Python | Python (3.4.3) | py | Runtime Error | 483 | 28916 | 162 | N = int(input())
cnt = 0
L = []
for i in range(N):
L.append(list(map(int, input().split())))
for i in range(N):
A, B = L[-i+1]
cnt += -(A + cnt)%B
print(cnt) |
s430143825 | p03821 | u777283665 | 1569434084 | Python | PyPy3 (2.4.0) | py | Runtime Error | 163 | 38256 | 317 | import numpy as np
n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
a, b = map(int, input().split())
A[i] = a
B[i] = b
ans = 0
for i in range(n-1, -1, -1):
if not A[i] % B[i] == 0:
temp = B[i]*((A[i]//B[i])+1) - A[i]
ans += temp
A += temp
print(int(ans))
|
s864853598 | p03821 | u777283665 | 1569432941 | Python | PyPy3 (2.4.0) | py | Runtime Error | 165 | 38384 | 335 | import numpy as np
n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
a, b = map(int, input().split())
A[i] = a
B[i] = b
ans = 0
for i in range(n-1, -1, -1):
if A[i] % B[i] == 0:
pass
else:
temp = B[i]*((A[i]//B[i])+1) - A[i]
ans += temp
A += temp
... |
s022148258 | p03821 | u777283665 | 1569432398 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 130 | n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
a, b = map(int, input().split())
A[i] = a
B[i] = b |
s238690297 | p03821 | u777283665 | 1569432321 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 55 | ans = 0
for i in range(10**9):
ans += 1
print(ans |
s854869476 | p03821 | u077291787 | 1569149039 | Python | Python (3.4.3) | py | Runtime Error | 65 | 25124 | 261 | # AGC009A - Multiple Array
def main():
N, *AB = map(int, open(0).read().split())
ans = 0
for i, j in zip(*[iter(A[::-1])] * 2): # decide from the last one greedily
ans += -(i + ans) % j
print(ans)
if __name__ == "__main__":
main() |
s446523836 | p03821 | u993622994 | 1567811120 | Python | Python (3.4.3) | py | Runtime Error | 423 | 31348 | 414 | N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.reverse()
count = 0
for i in range(N):
ab[i][0] += count
if ab[i][1] == 1:
continue
else:
if ab[i][0] > ab[i][1]:
num = ab[i][1] - ab[i][0] % ab[i][1]
elif ab[i][0] < ab[i][1]:
num =... |
s288003993 | p03821 | u498620941 | 1566525492 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 294 | A = []
B = []
for i in range(N):
a,b = map(int,input().split())
A.append(a)
B.append(b)
k = 0
for i in range(N-1,-1,-1):
if A[i] % B[i] == 0 :
continue
else :
c = (B[i] - A[i] % B[i])
k += c
for j in range(i):
A[j] += c
print(k) |
s864384772 | p03821 | u388415336 | 1559891851 | Python | Python (3.4.3) | py | Runtime Error | 326 | 11052 | 297 | seq_a = []
seq_b = []
seq_n = int(input())
for i in range(seq_n):
num_a,num_b=map(int,input().split())
seq_a.append(num_a)
seq_b.append(num_b)
x = 0
for i in range(seq_n - 1, -1 ,-1):
seq_n , elem_b = seq_a[i],seq_b[i]
y = (seq_n + x)% elem_b
if y != 0: x += (m-y)
print(x) |
s672444704 | p03821 | u388415336 | 1559891769 | Python | Python (3.4.3) | py | Runtime Error | 330 | 11052 | 299 | seq_a = []
seq_b = []
seq_n = int(input())
for i in range(seq_n):
num_a,num_b=map(int,input().split())
seq_a.append(num_a)
seq_b.append(num_b)
x = 0
for i in range(seq_n - 1, -1 ,-1):
elem_a , elem_b = seq_a[i],seq_b[i]
y = (elem_a + x)% elem_b
if y != 0: x += (m-y)
print(x) |
s336075198 | p03821 | u388415336 | 1559891706 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 291 | seq_a = []
seq_b = []
seq_n = int(input())
for i in range(seq_n):
num_a,num_b=map(int,input().split())
a.append(num_a)
b.append(num_b)
x = 0
for i in range(seq_n - 1, -1 ,-1):
elem_a , elem_b = seq_a[i],seq_b[i]
y = (elem_a + x)% elem_b
if y != 0: x += (m-y)
print(x) |
s352014053 | p03821 | u905715926 | 1552528791 | Python | Python (3.4.3) | py | Runtime Error | 316 | 26712 | 190 | n = int(input())
ans = 0
li = []
for i in range(n):
a,b = map(int,input().split())
li.append(map(int,input().split()))
for (a,b) in li[::-1]:
ans += (b-((a+ans)%b))%b
print(ans)
|
s885009770 | p03821 | u270681687 | 1550845640 | Python | PyPy3 (2.4.0) | py | Runtime Error | 182 | 45168 | 409 | import sys
sys.setrecursionlimit(10**7)
n = int(input())
rev_g = [[] for _ in range(n+1)]
for i in range(n-1):
a = int(input())
rev_g[a].append(i+2)
def f(v):
m = len(rev_g[v])
if m == 0:
return 0
q = []
for nv in rev_g[v]:
q.append(f(nv))
q.sort()
dp = [0] * (m+1)
... |
s069351557 | p03821 | u595893956 | 1550821664 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 155 | n=int(input())
a=[]
b=[]
ret = 0
for i in range(n):
a[i],b[i]=map(int,input().split())
for i in range(n):
ret+=b[-1-i]-(ret+a[-1-i])%b[-1-i]
print(ret) |
s671260720 | p03821 | u434208140 | 1547076446 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3828 | 136 | n=int(input())
c=[list(map(int,unput().split())) for _ in [0]*n].reverse()
t=0
for i in c:
a=c[0]
b=c[2]
t+=b-1-(a+t-1)%b
print(t) |
s929416302 | p03821 | u459233539 | 1546493174 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 203 | n = int(input())
push = 0
for i in range(n):
a, b = map(int, input().split())
if a < b:
push += b - a
else a > b:
for j in range(b):
if (a + i * j)%b==0:
push += j
print(push) |
s101284367 | p03821 | u427344224 | 1540564459 | Python | Python (3.4.3) | py | Runtime Error | 373 | 11048 | 381 | N = int(input())
a_list = []
b_list = []
for i in range(N):
a, b = map(int, input().split())
a_list.append(a)
b_list.append(b)
count = 0
for i in range(N-1, -1, -1):
a = a_list[i]
b = b_list[i]
if b == 1:
continue
if b % a == 0:
continue
if count > 0:
a += cou... |
s498882651 | p03821 | u451017206 | 1535676987 | Python | Python (3.4.3) | py | Runtime Error | 363 | 11816 | 255 | N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A = A[::-1]
B = B[::-1]
ans = 0
for a, b in zip(A, B):
a += ans
if a % b!= 0:
m = b - (a % b)
ans += m
print(ans) |
s439268851 | p03821 | u451017206 | 1535676218 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 269 | N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A = A[::-1]
B = B[::-1]
ans = 0
for a, b in zip(A, B):
a += ans
m = b - (a % b) if b != 1 else 0
m = b if a == 0
ans += m
print(ans) |
s824105834 | p03821 | u391475811 | 1528491258 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 260 | N=int(input())
A=[]
B=[]
for i in range(N):
a,b=map(int,input().split())
A.append(a)
B.append(b)
ans=0
for i in range(N-1,-1,-1):
a=A[i]+ans
b=B[i]
if a < b:
ans+=(b-a)
elif a % b==0
continue
else:
ans+=(a+b)//b*b-a
print(ans) |
s651071625 | p03821 | u952708174 | 1527790819 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 514 | def a_multiple_array_(N, A, B):
ans = 0 # ボタンを押した回数
for k in range(N - 1, -1, -1): # 末尾から貪欲に決めていく
remainder = (A[k] + ans) % B[k] # A[k]+ansが現在のA[k]の値
if remainder != 0: # 定義の仕方より、reminderは非負整数
ans += B[k] - remainder
return ans
N = int(Input())
A, B = [], []
for _ in range(... |
s925049031 | p03821 | u362700058 | 1522003091 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2568 | 478 | N = int(raw_input())
A,B = [],[]
for _ in range(N):
a, b = raw_input().split()
a,b = int(a), int(b)
A.append(a)
B.append(b)
press = [0 for _ in range(N)]
for i in range(N)[::-1]:
a = A[i]
b = B[i]
# see if there's Amari
c = a % b
# if Amari exists, how many presses are needed to ... |
s066454226 | p03821 | u730606460 | 1516928709 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 261 | a = []
b = []
n = int(input())
ind = -1
count = 0
for i in range(n):
c,d = int(input().split())
a.append(c)
b.append(d)
for i in range((n-1),0,-1):
if a[i]+count % b[i] != 0:
count+= b[i] - (a[i] + count) % b[i]
print(count)
|
s545238072 | p03821 | u048472001 | 1487630283 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 283 |
N = int(input())
total = 0
A = [None] * N
B = [None] * N
for i in range(N):
A[i], B[i] = map(int, input().split())
for t in range(N):
i = N + 1 - t
a = A[i] % B[i]
if a == 0:
pass
else:
total = B[i]-a:
for j in range (i):
A[i] = A[i] + B[i] - a
print (total)
|
s032767995 | p03821 | u851455395 | 1485621184 | Python | Python (2.7.6) | py | Runtime Error | 140 | 4344 | 288 | from sys import stdin
n = stdin.readline()
a = []
b = []
#read input
for line in stdin:
a.append(int(line[0]))
b.append(int(line[2]))
counter = 0
i = int(n)-1
while i >= 0:
if( (a[i]+counter)%b[i]):
counter += b[i] - ((a[i]+counter)%b[i])
i-=1
print counter
|
s405245376 | p03821 | u631914718 | 1485541087 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 215 | n = int(input())
a, b = [], []
for i in range(n):
a[i], b[i] = map(int, input().split())
ans = 0
for i in range(n)[::-1]:
a_, b_ = a[i] + ans, b[i]
if a_%b_ != 0:
ans += ((a_ // b_ + 1) * b_ - a_)
print(ans)
|
s545214903 | p03821 | u631914718 | 1485541080 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 213 | n = int(input())
a, b = [], []
for i in range(n):
a[i], b[i] = map(int, input().split())
ans = 0
for i in range(n)[::-1]:
a_, b_ = a[i] + ans, b[i]
if a_%b_ != 0:
ans += ((a_ // b_ + 1) * b_ - a_)
print(p)
|
s698031805 | p03821 | u631914718 | 1485540710 | Python | Python (3.4.3) | py | Runtime Error | 369 | 10996 | 215 | n = int(input())
a, b = [0]*n, [0]*n
for i in range(n):
a[i], b[i] = map(int, input().split())
ans = 0
for i in range(n)[::-1]:
a_, b_ = a[i] + p, b[i]
if a_%b_ != 0:
ans += (a_ // b_ + 1) * b_ - a_
print(p)
|
s239157077 | p03821 | u631914718 | 1485540659 | Python | Python (3.4.3) | py | Runtime Error | 377 | 10996 | 212 | n = int(input())
a, b = [0]*n, [0]*n
for i in range(n):
a[i], b[i] = map(int, input().split())
ans = 0
for i in range(n)[::-1]:
a_, b_ = a[i] + p, b[i]
if a%b != 0:
ans += (a_ // b_ + 1) * b_ - a_
print(p) |
s425593334 | p03821 | u966695411 | 1485372942 | Python | Python (3.4.3) | py | Runtime Error | 29 | 3064 | 264 | N = int(input())
cnt = 0
L = [list(map(int, input().split())) for x in range(N)]
for a, b in L[::-1]:
a += cnt
if a < b && a != 0 : cnt += b - a
if a > b:
if a % b:
cnt += b - a % b
else:
cnt += a % b
print(cnt) |
s055007266 | p03821 | u090994275 | 1485305639 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 249 | N = input()
A = []
B = []
for i in range(N):
a, b = input().split()
A.append(a)
B.append(b)
ans = 0
for i in reversed(range(N)):
diff = B[i] - A[i] % B[i]
for j in range(i):
A[j] += diff
ans += diff
print(ans)
|
s538033103 | p03821 | u090994275 | 1485305530 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3192 | 248 | N = input()
A = []
B = []
for i in range(N):
a, b = input().split()
A.append(a)
B.append(b)
ans = 0
for i in reversed(range(N)):
diff = B[i] - A[i] % B[i]
for j in range(i):
A[j] += diff
ans += diff
return ans |
s488582758 | p03821 | u107077660 | 1485144212 | Python | Python (3.4.3) | py | Runtime Error | 59 | 14260 | 502 | N = int(input())
B = [[] for _ in range(N)]
unchecked = [i for i in range(N)]
for i in range(1,N):
t = int(input()) - 1
B[t].append(i)
ans = [0]*N
for i in range(N):
if not B[i]:
unchecked.remove(i)
while 0 in unchecked:
for i in unchecked:
f = 0
C = []
for a in B[i]:
if a in unchecked:
f = 1
... |
s475748727 | p03821 | u481333386 | 1485143603 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 555 | def calc(a, b):
push_count = 0
while True:
if a % b == 0:
break
a += 1
push_count += 1
return push_count
def add_a(answer, a):
return answer + a
def main(nums):
answer = 0
for a, b in reversed(nums):
if answer != 0:
a = add_a(answer, ... |
s729384588 | p03821 | u481333386 | 1485142983 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3192 | 564 | def calc(a, b):
push_count = 0
while True:
if a % b == 0:
break
a += 1
push_count += 1
return push_count
def add_a(answer, a):
return answer + a
def main(nums):
answer = 0
nums.reverse()
for a, b in nums:
if answer != 0:
a = add_a... |
s195568729 | p03821 | u481333386 | 1485140158 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3192 | 618 | def calc(a, b):
push_count = 0
while True:
if a % b == 0:
break
a += 1
push_count += 1
return push_count
def add_a(answer, a):
return answer + a
def main(nums):
answer = 0
nums.reverse()
for a, b in nums:
if answer != 0:
a = add_... |
s990238408 | p03821 | u093843560 | 1485139745 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 431 | mport numpy as np
N = int(raw_input())
a=np.array([])
b=np.array([])
for i in range(N-1):
A, B = map(int, raw_input().split())
a = np.append(a,A)
b = np.append(b,B)
A,B = map(int, raw_input().split())
a = np.append(a,A)
b = np.append(b,B)
s=0
for i in range(N):
if a[N-i-1] % b[N-i-1] ==0:
t... |
s677940065 | p03821 | u425351967 | 1485137952 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 332 | N = int(input())
A=[]
B=[]
for i in range(N):
a,b=[int(n) for n in input().split()]
A.append(a)
B.append(b)
cnt=0
# print(list(reversed(range(N))))
for i in reversed(range(N)):
if A[i]%B[i]==0:
r=0
else
r=B[i]-A[i]%B[i]
cnt+=r
A=[A[n]+r if n<=i else A[n] for n in range(N)]
... |
s117466177 | p03822 | u457901067 | 1600361200 | Python | PyPy3 (7.3.0) | py | Runtime Error | 531 | 220376 | 751 | import sys
input = sys.stdin.readline
import heapq
from collections import deque
N = int(input())
X = [[] for _ in range(N)]
for i in range(N-1):
a = int(input())
X[a-1].append(i+1)
# dfsをして、Depthを計算しつつ、depth大きい順に取り出せるようにheapqを使う
h = []
seen = [False] * N
def dfs(a,depth):
seen[a] = True
heapq.heappush(h, ... |
s429326804 | p03822 | u536034761 | 1600094446 | Python | Python (3.8.2) | py | Runtime Error | 271 | 23320 | 289 | n = int(input())
graph = [[] for _ in range(n)]
for i in range(1, n):
graph[int(input()) - 1].append(i)
def dfs(x):
arr = [dfs(y) for y in graph[x]]
if not (arr):
return 0
arr.sort(reverse=True)
return max(i + a for i, a in enumerate(arr, 1))
print(dfs(0))
|
s832765667 | p03822 | u368796742 | 1599083875 | Python | Python (3.8.2) | py | Runtime Error | 263 | 23132 | 289 | n = int(input())
e = [[] for i in range(n)]
for i in range(1,n):
x = int(input())
e[x-1].append(i)
def dfs(x):
count = len(e[x])
if count == 0:
return 0
now = 0
for nex in e[x]:
now = max(now,dfs(nex))
return max(count,now+1)
print(dfs(0)) |
s771251925 | p03822 | u654470292 | 1597789260 | Python | PyPy3 (7.3.0) | py | Runtime Error | 103 | 74656 | 1001 | import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
def celi(a,b):
return -(-a//b)
sys.setrecursi... |
s404495915 | p03822 | u550061714 | 1592398175 | Python | Python (3.4.3) | py | Runtime Error | 619 | 123036 | 312 | import sys
sys.setrecursionlimit(10 ** 5)
N = int(input())
T = [[] for _ in range(N)]
for i in range(1, N):
x = int(input()) - 1
T[x].append(i)
def f(x):
candidates = sorted([f(y) for y in T[x]], reverse=True)
return max((c + i for i, c in enumerate(candidates, 1)), default=0)
print(f(0))
|
s156707832 | p03822 | u287132915 | 1591887794 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 538 | import sys
sys.setrecursionlimit(10**10)
n = int(input())
dic = {}
for i in range(n+1):
if i <= 1: continue
ai = int(input())
if ai in dic:
dic[ai].append(i)
else:
dic[ai] = [i]
def dfs(nxt):
lst = []
if nxt in dic:
while dic[nxt] != []:
child = dic[nxt].pop... |
s905833495 | p03822 | u287132915 | 1591887683 | Python | Python (3.4.3) | py | Runtime Error | 428 | 26016 | 496 | n = int(input())
dic = {}
for i in range(n+1):
if i <= 1: continue
ai = int(input())
if ai in dic:
dic[ai].append(i)
else:
dic[ai] = [i]
def dfs(nxt):
lst = []
if nxt in dic:
while dic[nxt] != []:
child = dic[nxt].pop()
tempmax = dfs(child)
... |
s204073054 | p03822 | u227082700 | 1591790002 | Python | Python (3.4.3) | py | Runtime Error | 467 | 19196 | 217 | n=int(input())
edge=[[]for _ in range(n)]
for i in range(n-1):edge[int(input())-1].append(i+1)
def dfs(v):
d=[-1]+sorted([dfs(i)for i in edge[v]])
l=len(d)
return max(l-i+j for i,j in enumerate(d))
print(dfs(0)) |
s265527616 | p03822 | u102445737 | 1591709867 | Python | PyPy3 (2.4.0) | py | Runtime Error | 936 | 178380 | 615 | #from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x... |
s413800862 | p03822 | u424768586 | 1591480654 | Python | PyPy3 (2.4.0) | py | Runtime Error | 266 | 56668 | 2413 | import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), ... |
s380595815 | p03822 | u169350228 | 1590365582 | Python | Python (3.4.3) | py | Runtime Error | 371 | 20740 | 479 | import queue
n = int(input())
wl = [[] for i in range(n+1)]
for i in range(2,n+1):
ai = int(input())
wl[ai].append(i)
dp = [-1 for i in range(n+1)]
def calc_dp(a):
if len(wl[a]) == 0:
return 0
else:
dps = []
for i in wl[a]:
dps.append(calc_dp(i))
dps.sort(... |
s708988017 | p03822 | u488401358 | 1588040902 | Python | PyPy3 (2.4.0) | py | Runtime Error | 782 | 111460 | 582 | N=int(input())
edge={i:[] for i in range(1,N+1)}
parent={i:0 for i in range(1,N+1)}
for i in range(0,N-1):
a=int(input())
edge[a].append(i+2)
edge[i+2].append(a)
parent[i+2]=a
memo={i:-1 for i in range(1,N+1)}
def dp(num):
if memo[num]!=-1:
return memo[num]
if edge[num]==[parent[num]]:... |
s817809152 | p03822 | u145600939 | 1587319284 | Python | Python (3.4.3) | py | Runtime Error | 461 | 38884 | 511 | n = int(input())
win = {}
# key:勝者 value:keyに負けた人(set)
for i in range(n - 1):
a = int(input())
a -= 1
if a not in win.keys():win[a] = set()
win[a].add(i+1)
def dfs(winner):
if winner not in win.keys():return 0
losers = win[winner]
storong = len(losers)
deeps = []
for loser in losers... |
s530506363 | p03822 | u693716675 | 1585691064 | Python | Python (3.4.3) | py | Runtime Error | 351 | 19000 | 451 | #b
n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
b = int(input())
edges[b-1].append(i+1)
def dfs(u):
e = edges[u]
if e==[]:
return 0
#else
#return maximum
length = []
for v in e:
length.append(dfs(v))
l = len(length)
length.sort()
m... |
s560975678 | p03822 | u065446124 | 1584324327 | Python | Python (3.4.3) | py | Runtime Error | 373 | 28856 | 368 | import sys
input=sys.stdin.readline
n=int(input())
l=[int(input()) for i in range(n-1)]
import collections
d=collections.defaultdict(list)
for i,j in enumerate(l,2):
d[j].append(i)
def f(a):
if len(d[a])==0:
return 0
else:
l=[f(i) for i in d[a]]
l.sort(reverse=True)
return ma... |
s464292420 | p03822 | u476604182 | 1583544952 | Python | Python (3.4.3) | py | Runtime Error | 498 | 31824 | 349 | from functools import lru_cache
N, *A = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for i in range(N-1):
dic[A[i]] += [i+2]
@lru_cache(None)
def solve(n):
if len(dic[n])==0:
return 0
ls = []
for e in dic[n]:
ls += [solve(e)]
ls.sort(reverse=True)
return max(ls[i]+i+1 for i in ran... |
s863980969 | p03822 | u547167033 | 1582682894 | Python | PyPy3 (2.4.0) | py | Runtime Error | 848 | 141360 | 302 | import sys
input=sys.stdin.readline
n=int(input())
t=[[] for i in range(n)]
for i in range(1,n):
a=int(input())
t[a-1].append(i)
def dfs(v):
if not t[v]:
return 0
l=[dfs(i)+1 for i in t[v]]
l.sort()
for i in range(len(t[v])-1):
l[i+1]=max(l[i+1],l[i]+1)
return l[-1]
print(dfs(0)) |
s300355491 | p03822 | u712993629 | 1582675278 | Python | PyPy3 (2.4.0) | py | Runtime Error | 837 | 142796 | 351 | n = int(input())
g = [[] * 1 for i in range(n)]
for i in range(n-1):
a = int(input())
g[a-1].append(i+1)
def dfs(v):
max = 0
max_i = 0
for u in g[v]:
next = dfs(u)
if next == max:
max_i += 1
elif next > max:
max = next
max_i = 1
retu... |
s420077118 | p03822 | u712993629 | 1582675192 | Python | Python (3.4.3) | py | Runtime Error | 325 | 18912 | 351 | n = int(input())
g = [[] * 1 for i in range(n)]
for i in range(n-1):
a = int(input())
g[a-1].append(i+1)
def dfs(v):
max = 0
max_i = 0
for u in g[v]:
next = dfs(u)
if next == max:
max_i += 1
elif next > max:
max = next
max_i = 1
retu... |
s475568412 | p03822 | u754022296 | 1581814254 | Python | Python (3.4.3) | py | Runtime Error | 1431 | 594968 | 476 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import heapq
def main():
n = int(input())
T = [[] for _ in range(n+1)]
for i in range(1, n):
T[int(input())].append(i)
def dfs(v):
if not T[v]:
return 0
L = []
for i in T[v]:
heapq.heappush(L, dfs(i)+1)
temp = ... |
s467743144 | p03822 | u141610915 | 1580955738 | Python | PyPy3 (2.4.0) | py | Runtime Error | 702 | 182528 | 488 | import sys
input = sys.stdin.readline
N = int(input())
a = [0]
reva = [[] for _ in range(N + 1)]
for _ in range(N - 1): a.append(int(input()))
for i in range(N):
if a[i] == 0: continue
reva[a[i]].append(i + 1)
dp = [-1] * (N + 1)
def dfs(x):
global dp
if len(reva[x]) == 0:
dp[x] = 1
return 1
t = []
... |
s439285460 | p03822 | u141610915 | 1580955449 | Python | PyPy3 (2.4.0) | py | Runtime Error | 533 | 137136 | 494 | import sys
input = sys.stdin.readline
N = int(input())
a = [0]
reva = [[] for _ in range(N + 1)]
for _ in range(N - 1): a.append(int(input()))
for i in range(N):
if a[i] == 0: continue
reva[a[i]].append(i + 1)
dp = [-1] * (N + 1)
def dfs(x):
global dp
if len(reva[x]) == 0:
dp[x] = 1
return 1
t = []
... |
s011461622 | p03822 | u141610915 | 1580955388 | Python | PyPy3 (2.4.0) | py | Runtime Error | 688 | 182784 | 479 | import sys
input = sys.stdin.readline
N = int(input())
a = [0]
reva = [[] for _ in range(N + 1)]
for _ in range(N - 1): a.append(int(input()))
for i in range(N):
if a[i] == 0: continue
reva[a[i]].append(i + 1)
dp = [-1] * (N + 1)
def dfs(x):
global dp
if len(reva[x]) == 0:
dp[x] = 1
return 1
t = []
... |
s906832780 | p03822 | u141610915 | 1580955134 | Python | PyPy3 (2.4.0) | py | Runtime Error | 720 | 185216 | 510 | import sys
input = sys.stdin.readline
N = int(input())
a = [0]
reva = [[] for _ in range(N + 1)]
for _ in range(N - 1): a.append(int(input()))
for i in range(N):
if a[i] == 0: continue
reva[a[i]].append(i + 1)
dp = [-1] * (N + 1)
def dfs(x):
global dp
if len(reva[x]) == 0:
dp[x] = 1
return 1
t = []
... |
s118270517 | p03822 | u141610915 | 1580954172 | Python | PyPy3 (2.4.0) | py | Runtime Error | 723 | 185344 | 515 | import sys
input = sys.stdin.readline
N = int(input())
a = [0]
reva = [[] for _ in range(N + 1)]
for _ in range(N - 1): a.append(int(input()))
for i in range(N):
if a[i] == 0: continue
reva[a[i]].append(i + 1)
dp = [-1] * (N + 1)
def dfs(x):
global dp
if len(reva[x]) == 0:
dp[x] = 1
return 1
t = []
... |
s921198196 | p03822 | u334712262 | 1577354140 | Python | Python (3.4.3) | py | Runtime Error | 590 | 122872 | 1648 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permut... |
s806306472 | p03822 | u606045429 | 1576188402 | Python | Python (3.4.3) | py | Runtime Error | 313 | 23112 | 253 | N, *A = map(int, open(0).read().split())
E = [[] for _ in range(N + 1)]
for i, v in enumerate(A, 1):
E[v - 1].append(i)
def dfs(v):
D = sorted(dfs(u) for u in E[v])
return max([0] + [len(D) - i + d for i, d in enumerate(D)])
print(dfs(0)) |
s362420161 | p03822 | u532966492 | 1574919304 | Python | Python (3.4.3) | py | Runtime Error | 358 | 35696 | 440 | def main():
n=int(input())
a=[int(input()) for _ in [0]*(n-1)]
a=[[i+2,a[i]] for i in range(n-1)]
l=[[] for _ in [0]*n]
for i,j in a:
l[j-1].append(i-1)
def dps(i):
if l[i]==[]:
return 1
_max=0
_min=10**6
for j in l[i]:
temp=dps(j)
... |
s286965951 | p03822 | u844789719 | 1573180713 | Python | Python (3.4.3) | py | Runtime Error | 671 | 159972 | 514 | import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
win_lose[win].add(lose)
memo = [-1] * (N + 1)
def rec(x):
if memo[x] == -1:
if win_lose[x] == set():
... |
s759457794 | p03822 | u844789719 | 1573180647 | Python | Python (3.4.3) | py | Runtime Error | 651 | 159976 | 526 | import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
win_lose[win].add(lose)
memo = [-1] * (N + 1)
def rec(x):
if memo[x] == -1:
if win_lose[x] == set():
... |
s171694968 | p03822 | u844789719 | 1573179305 | Python | Python (3.4.3) | py | Runtime Error | 557 | 143736 | 556 | import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
win_lose[win].add(lose)
memo = [-1] * (N + 1)
def rec(x):
if memo[x] == -1:
if win_lose[x] == set():
... |
s931165288 | p03822 | u844789719 | 1573179085 | Python | Python (3.4.3) | py | Runtime Error | 308 | 52028 | 468 | import collections
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
win_lose[win].add(lose)
memo = [-1] * (N + 1)
def rec(x):
if memo[x] == -1:
if win_lose[x] == set():
memo[x] = 0
else:
... |
s343292117 | p03822 | u543954314 | 1571418794 | Python | Python (3.4.3) | py | Runtime Error | 435 | 20004 | 379 | n = int(input())
tree = [list() for _ in range(n+1)]
for i in range(2,n+1):
a = int(input())
tree[a].append(i)
win = [0]*(n+1)
def dfs(v,win):
if tree[v] == []:
win[v] = 0
return win[v]
l = list()
for x in tree[v]:
dfs(x,win)
l.append(win[x])
l.sort(reverse=True)
win[v] = max(i+1+l[i]... |
s222932462 | p03822 | u729133443 | 1570597812 | Python | Python (3.4.3) | py | Runtime Error | 302 | 22804 | 187 | def dfs(v):
d=sorted(map(dfs,t[v]))
l=len(d)
return max([0]+[l-i+d for i,d in e(d)])
e=enumerate
n,*a=map(int,open(0))
t=[[]for _ in[0]+a]
for i,v in e(a,1):t[v-1]+=i,
print(dfs(0)) |
s690158283 | p03822 | u509368316 | 1570064516 | Python | Python (3.4.3) | py | Runtime Error | 524 | 135828 | 374 | import sys
def input(): return sys.stdin.readline().strip()
N=int(input())
A=[int(input()) for i in range(N-1)]
c=[[] for i in range(N)]
for i,a in enumerate(A):
c[a-1].append(i+1)
import sys
sys.setrecursionlimit(10**5+9)
def f(i):
if len(c[i])==0:
return 0
return max([e+i+1 for i,e in enumerate(so... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.