Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(len(A)-1,len(A)//2,-1):
  bunshi=A[i]
  target=A[i]//2
  tarp=bisect.bisect_left(A,target)
  for j in (-1,0):
    if tarp+j>=0 and tarp+j<len(A):
      c=cmb(bunshi,A[tarp+j])
      if c>maxval:
        maxval=c
        maxpair=[bunshi,A[tarp+j]]

print(*maxpair)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])
Buggy python submission (verdict: Runtime Error):
n=input()
a=input().split()
print(("Three","Four")[len(set(a))==4]

Fixed submission:
n=input()
a=input().split()
print(("Three","Four")[len(set(a))==4])
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input())
if y==0:
  print(x)
elif x%y==0:
  print(-1)
else:
  print(x)


Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  print(x)

Buggy python submission (verdict: Runtime Error):
x,y=map(int,input())
if x%y==0:
  print(-1)
else:
  print(x)

Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  print(x)
Buggy python submission (verdict: Runtime Error):
print(("Even","Odd")[int(input())&1])

Fixed submission:
a,b=map(int,input().split())
print(("Even","Odd")[a*b&1])
Buggy python submission (verdict: Time Limit Exceeded):
f=[True]*(10**5+1)
like=[False]*(10**5+1)
f[0]=False
f[1]=False
import math
for i in range(2,len(f)):
  fact=True
  for j in range(2,int(math.sqrt(i))+1):
    if i%j==0:
      fact=False
      break
  
  if fact:
    f[i]=True
    if i*2-1<len(like):
      like[i*2-1]=True
    for p in range(i*2,len(f),i):
      f[p]=False

Q=int(input())
for i in range(Q):
  l,r=map(int,input().split())
  cnt=0
  for p in range(l,r+1,2):
    if f[p] and like[p]:
      cnt+=1
  print(cnt)

Fixed submission:
f=[True]*(10**5+1)
like=[False]*(10**5+1)
f[0]=False
f[1]=False
import math
for i in range(2,len(f)):
  fact=True
  for j in range(2,int(math.sqrt(i))+1):
    if i%j==0:
      fact=False
      break
  
  if fact:
    f[i]=True
    if i*2-1<len(like):
      like[i*2-1]=True
    for p in range(i*2,len(f),i):
      f[p]=False

sums=[0]*(10**5+1)
cur=0
for i in range(len(sums)):
  if f[i] and like[i]:
    sums[i]=cur+1
    cur+=1
  else:
    sums[i]=cur

Q=int(input())
for i in range(Q):
  l,r=map(int,input().split())
  if l>0:
    print(sums[r]-sums[l-1])
  else:
    print(sums[r])
Buggy python submission (verdict: Runtime Error):
K,A,B=map(int,input().split())
if A>=K:
  print(1)
elif A<B:
  print(-1)
else:
  bef=((K-A)//(A-B))+((K-A)%(A-B)!=0)
  print(2*bef+1)


Fixed submission:
K,A,B=map(int,input().split())
if A>=K:
  print(1)
elif A<=B:
  print(-1)
else:
  bef=((K-A)//(A-B))+((K-A)%(A-B)!=0)
  print(2*bef+1)
Buggy python submission (verdict: Time Limit Exceeded):
# 7,12,18
# ありうるのは、(7,17),(12,12),(8,16)
# ......AC...B...CA.......
# 7,12,16を選んだとき
# ......A_...B...C_.......
# BとCの差が4時間になる
# 17,12,8でもよい
# ......_C...B..._A.......
# 50人存在するが、時刻は0-23の24通り (ただし高橋くんは0固定なので、それ以外の人は23通り)
# N = 24人になったら鳩ノ巣理論により必ず誰かが同じ時刻になるため、答えは0
# 23人以下の場合は、全組み合わせ（2^23 = (10 ** 6) * 8）を試せば良い

N = int(input())
D = list(map(int,input().split()))
D = sorted(D,key = lambda x:min(x,24-x)) # ソートにより同時刻が固まるとループを抜けやすくなる？

if N >= 24:
  print(0)
  exit(0)
# 23桁のbit文字列で0の場合はそのまま、1の場合はひっくり返す（24-D[i]）
# []24桁のリスト(0は高橋くんがいるため初めから1人)に、人数を加算していく
# あるindexですでに人がいたらその時点で答えは0になる
# 最小値を更新していく
ans = 0

for i in range(2 ** N):
  data = [0] * 25
  data[0] = 1 # 高橋くん
  data[24] = 1 # 高橋くん
  for j in range(N):
    if (i >> j)&1:
      if data[24-D[j]] == 1:# 同時刻に既に誰かいた時点で最小値は0確定
        break
      data[24-D[j]] += 1
    else:
      if data[D[j]] == 1: # この時点で最小値は0確定
        break
      data[D[j]] += 1
  else:
    # 最小値が0でない場合
    minval = 24
    lastexist = 0
    for j in range(1,len(data)):
      if data[j]:
        if j - lastexist < minval:
          minval = j - lastexist
        lastexist = j
    if minval > ans:
      ans = minval
print(ans)


Fixed submission:
# 7,12,18
# ありうるのは、(7,17),(12,12),(8,16)
# ......AC...B...CA.......
# 7,12,16を選んだとき
# ......A_...B...C_.......
# BとCの差が4時間になる
# 17,12,8でもよい
# ......_C...B..._A.......
# 50人存在するが、時刻は0-23の24通り (ただし高橋くんは0固定なので、それ以外の人は23通り)
# N = 24人になったら鳩ノ巣理論により必ず誰かが同じ時刻になるため、答えは0
# 23人以下の場合は、全組み合わせ（2^23 = (10 ** 6) * 8）を試せば良い

N = int(input())
D = list(map(int,input().split()))
D = sorted(D,key = lambda x:min(x,24-x)) # ソートにより同時刻が固まるとループを抜けやすくなる？

if N >= 24:
  print(0)
  exit(0)
# 23桁のbit文字列で0の場合はそのまま、1の場合はひっくり返す（24-D[i]）
# []24桁のリスト(0は高橋くんがいるため初めから1人)に、人数を加算していく
# あるindexですでに人がいたらその時点で答えは0になる
# 最小値を更新していく
ans = 0

for i in range(2 ** N):
  data = [0] * 25
  data[0] = 1 # 高橋くん
  data[24] = 1 # 高橋くん
  for j in range(N):
    if (i >> j)&1:
      if data[24-D[j]] == 1:# 同時刻に既に誰かいた時点で最小値は0確定
        break
      data[24-D[j]] += 1
    else:
      if data[D[j]] == 1: # この時点で最小値は0確定
        break
      data[D[j]] += 1
  else:
    # 最小値が0でない場合
    minval = 24
    lastexist = 0
    for j in range(1,len(data)):
      if data[j]:
        if j - lastexist < minval:
          minval = j - lastexist
        lastexist = j
    if minval > ans:
      ans = minval
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(2**3):
  f=s[0]
  for j in range(3):
    if i>>j&1:
      f+="+"
    f+=s[j+1]
  if eval(f)==7:
    print(f+"=7")
    break


Fixed submission:
ss=input()
s=[0]*4
for i in range(len(ss)):
  s[i]=int(ss[i])
dif=7-s[0]
ans=str(s[0])
found=False
for b in [s[1],-s[1]]:
  for c in [s[2],-s[2]]:
    for d in [s[3],-s[3]]:
      if b+c+d==dif:
        if b==s[1]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[1])
        if c==s[2]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[2])
        if d==s[3]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[3])
        found=True
        break
    if found:
      break
  if found:
    break
print(ans+"=7")
Buggy python submission (verdict: Runtime Error):
n=inr(input())
a=list(map(int,input().split()))

odd=True
for p in a:
  if p%2==0:
    odd=False
    
print(3**n-1-(1 if not odd else 0))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

odd=0
even=0
for i in range(n):
  if a[i]%2==1:
    odd+=1
  else:
    even+=1

all=3**n
oddgr=2**even
print(all-oddgr)
Buggy python submission (verdict: Runtime Error):
N,Mmap(int,input())
e=[[] for i in range(N)]
tester=[None]*M
for i in range(M):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  e[a].append(b)
  e[b].append(a)
  tester[i]=set(a,b)
  
ans=0
seen=[0 for i in range(N)]
for test in tester:
  stack=[]
  stack.append([0,-1])
  while stack:
    node=stack.pop()
    v=node[0]
    parent=node[1]
    if seen[v]==1:
      continue
    seen[v]=1
    childs=e[v]
    for child in childs:
      if child==parent:
        continue
      if len(test&set([v,child]))==2:
        continue
      stack.append([child,v])
      
  if sum(seen)!=N:
    ans+=1
print(ans)
    
    
      




Fixed submission:
N,M=map(int,input().split())
e=[[] for i in range(N)]
tester=[None]*M
for i in range(M):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  e[a].append(b)
  e[b].append(a)
  tester[i]=set([a,b])
  
ans=0
for test in tester:
  stack=[]
  stack.append([0,-1])
  seen=[0 for i in range(N)]
  while stack:
    node=stack.pop()
    v=node[0]
    parent=node[1]
    if seen[v]==1:
      continue
    seen[v]=1
    childs=e[v]
    for child in childs:
      if child==parent:
        continue
      if test==set([v,child]):
        continue
      stack.append([child,v])
      
  if sum(seen)!=N:
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 全探索する

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())

P = [None] * N
for i in range(N):
  P[i] = list(map(int,readline().split()))

ans = 10 ** 18 * 4 + 1
for ix in range(N-1):
  for jx in range(ix,N):
    # X軸が決まる
    left = P[ix][0]
    right = P[jx][0]
    if left > right:
      left,right = right,left
    for iy in range(N-1):
      for jy in range(iy,N):
        up = P[iy][1]
        down = P[jy][1]
        if up < down:
          up,down = down,up
        d = abs(up - down) * abs(right - left)
        if d > ans:
          continue
        cnt = 0
        for i in range(N):
          if left <= P[i][0] <= right and down <= P[i][1] <= up:
            cnt += 1
        if cnt >= K:
          ans = d
print(ans)

Fixed submission:
# 全探索する

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())

P = [None] * N
for i in range(N):
  P[i] = list(map(int,readline().split()))

ans = 10 ** 18 * 4 + 1
for ix in range(N-1):
  for jx in range(ix,N):
    # X軸が決まる
    left = P[ix][0]
    right = P[jx][0]
    if left > right:
      left,right = right,left
    for iy in range(N-1):
      for jy in range(iy,N):
        up = P[iy][1]
        down = P[jy][1]
        if up < down:
          up,down = down,up
        d = abs(up - down) * abs(right - left)
        if d > ans:
          continue
        cnt = 0
        for i in range(N):
          if left <= P[i][0] <= right and down <= P[i][1] <= up:
            cnt += 1
        if cnt >= K:
          ans = d
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=sorted(list(map(int,input().split())))
m=int(input())
t=sorted(list(map(int,input().split())))

j=0
for i in range(len(t)):
  if j==len(s):
    print("NO")
    break
  t[i]==s[j]:
    j+=1
else:
  print("YES")
   

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
M=int(input())
t=list(map(int,input().split()))
import collections
ac=collections.Counter(a)
tc=collections.Counter(t)

for task in tc.items():
  if task[0] not in ac:
    print("NO")
    exit(0)
  elif ac[task[0]]<task[1]:
    print("NO")
    exit(0)
print("YES")
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

# A + Bの組み合わせはせいぜい1～30のうち作れる数字のみなので全探索

A,B,C,D,E,F = map(int,readline().split())

if E == 0:
  print(min(A,B) * 100, 0)
  exit(0)

ans = [0,0]
maxrate = 0.0
for a in range(0,F,100 * A):
  for b in range(0,F,100 * B):
    if a == 0 and b == 0:
      continue
    if a + b > F:
      break
    water = a + b
    # waterに対して溶ける最大量は (a + b) * E
    limit = min(((a + b) / 100) * E, F - water)
    maxsugar = 0
    for c in range(0,limit + 1,C):
      for d in range(0,limit + 1,D):
        if c + d > limit:
          break
        if c + d > maxsugar:
          maxsugar = c + d
          rate = maxsugar / (water + maxsugar)
          if rate > maxrate:
            maxrate = rate
            ans = [water + maxsugar, maxsugar]
          
print(*ans)        

Fixed submission:
A,B,C,D,E,F=map(int,input().split())
# 作れる水の量をDPで求める (MAXはF)
# 作れる砂糖の量をDPで求める　（MAXは、F*(E/(E+100)）
# 作れる水の量に対して二分探索で、最も多く入れられる砂糖の量を求める。

dpW=[False]*(F+1)
dpW[0]=True
for w in (A*100,B*100):
  for j in range(len(dpW)):
    if dpW[j] and j+w<len(dpW):
      dpW[j+w]=True
      
water=[]
for i in range(len(dpW)):
  if dpW[i] and i!=0:
    water.append(i)

maxsugar=int(F*(E/(E+100)))+1
dpS=[False]*(maxsugar+1)
dpS[0]=True
for s in (C,D):
  for j in range(len(dpS)):
    if dpS[j] and j+s<len(dpS):
      dpS[j+s]=True
sugar=[]
for i in range(len(dpS)):
  if dpS[i]:
    sugar.append(i)
    
ans=[0,0]
maxrate=0
for w in water:
  maxS=int(w*(E/100))
  if w+maxS>F:
    maxS=F-w
  # maxSを越えない最大の砂糖をsugarから探す
  ok=0
  ng=len(sugar)
  while abs(ok-ng)>1:
    mid=abs(ok+ng)//2
    if sugar[mid]<=maxS:
      ok=mid
    else:
      ng=mid
  if sugar[ok]/w>=maxrate:
    maxrate=sugar[ok]/w
    ans=[w+sugar[ok],sugar[ok]]
print(*ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
import numpy as np
a=np.array(input().split(),dtype=int)
np.append(a,[0])
i=0
ans=0
while i<a.size:
  if a[i]==i+1:
    ans+=1
    if a[i+1]==i+2:
      i+=2
      continue
  i+=1
print(ans)

Fixed submission:
n=int(input())
import numpy as np
a=np.array(input().split(),dtype=int)
i=0
ans=0
while i<a.size:
  if a[i]==i+1:
    ans+=1
    if i+1 < a.size and a[i+1]==i+2:
      i+=2
      continue
  i+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

grid=[[0 for i in range(W)] for j in range(H)]
cur=0
curcnt=0
for i in range(H):
  for j in range(W):
    p=j
    if i%2==1:
      p=W-1-j
    grid[i][p]=cur+1
    curcnt+=1
    if curcnt=a[cur]:
      cur+=1
      curcnt=0
      
for i in range(H):
  print(*grid[i])
    
    
       

Fixed submission:
H,W=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

grid=[[0 for i in range(W)] for j in range(H)]
cur=0
curcnt=0
for i in range(H):
  for j in range(W):
    p=j
    if i%2==1:
      p=W-1-j
    grid[i][p]=cur+1
    curcnt+=1
    if curcnt==a[cur]:
      cur+=1
      curcnt=0
      
for i in range(H):
  print(*grid[i])
Buggy python submission (verdict: Runtime Error):
K=int(input())
N=int(K**0.5)+2
print(N)
print(*([N*K]+[0]*(N-1)))

Fixed submission:
# K回の操作
# N = 50とする
# 0,1,2,3,4...N - 1の数列に対して左からi番目にNを足し、それ以外から1を引く操作
# K // N回の操作をすると、1回あたり全項目に1が足される。

import sys
readline = sys.stdin.readline

K = int(readline())
N = 50

A = [i for i in range(N)]
A = list(map(lambda x:x + (K // N),A))
rest = K % N
for i in range(rest):
  A[i] += N
  for j in range(N):
    if i != j:
      A[j] -= 1

print(N)
print(*A)

Buggy python submission (verdict: Runtime Error):
K=int(input())
N=K+1
print(N)
print(str(N*K)+" "+"0 "*(N-2)+"0")

Fixed submission:
# K回の操作
# N = 50とする
# 0,1,2,3,4...N - 1の数列に対して左からi番目にNを足し、それ以外から1を引く操作
# K // N回の操作をすると、1回あたり全項目に1が足される。

import sys
readline = sys.stdin.readline

K = int(readline())
N = 50

A = [i for i in range(N)]
A = list(map(lambda x:x + (K // N),A))
rest = K % N
for i in range(rest):
  A[i] += N
  for j in range(N):
    if i != j:
      A[j] -= 1

print(N)
print(*A)

Buggy python submission (verdict: Runtime Error):
K=int(input())
N=K+1
print(N)
print(*([N*K]+[0]*(N-1)))

Fixed submission:
# K回の操作
# N = 50とする
# 0,1,2,3,4...N - 1の数列に対して左からi番目にNを足し、それ以外から1を引く操作
# K // N回の操作をすると、1回あたり全項目に1が足される。

import sys
readline = sys.stdin.readline

K = int(readline())
N = 50

A = [i for i in range(N)]
A = list(map(lambda x:x + (K // N),A))
rest = K % N
for i in range(rest):
  A[i] += N
  for j in range(N):
    if i != j:
      A[j] -= 1

print(N)
print(*A)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,imput().split())
a=list(map(int,input().split()))
a=sorted(a)
sum=0
for i in range(len(a)-1,len(a)-k,-1):
  sum=sum+a[i]
print(sum)

Fixed submission:
n,k=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(k):
  ans+=L.pop()
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=a[1::2][::-1]+a[0::2]
print((*b,*(b[::-1]))[n%2>0])


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
bbottom=[]
btop=[]
for i in range(n):
  if i%2==0:
    bbottom.append(a[i])
  else:
    btop.append(a[i])
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(*ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
bbottom=""
btop=""
for i in range(n):
  if i%2==0:
    bbottom.append(a[i])
  else:
    btop.append(a[i])
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(ans)
       


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
bbottom=[]
btop=[]
for i in range(n):
  if i%2==0:
    bbottom.append(a[i])
  else:
    btop.append(a[i])
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(*ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
bbottom=""
btop=""
for i in range(n):
  if i%2==0:
    bbottom+=a[i]
  else:
    btop+=a[i]
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(ans)
       


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
bbottom=[]
btop=[]
for i in range(n):
  if i%2==0:
    bbottom.append(a[i])
  else:
    btop.append(a[i])
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(*ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
bbottom=""
btop=""
for i in range(n):
  if i%2==0:
    bbottom+=a[i]
  else:
    btop+=a[i]
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
prin(ans)
       

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
bbottom=[]
btop=[]
for i in range(n):
  if i%2==0:
    bbottom.append(a[i])
  else:
    btop.append(a[i])
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(*ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[None]*n
minv=100
for in range(n):
  s[i]=int(input())
  if minv>s[i]:
    if s[i]%10!=0:
      minv=s[i]
if minv==100:
  print(0)
elif sum(s)%10==0:
  print(sum(s)-minv)
else:
  print(sum(s))



Fixed submission:
n=int(input())
s=[None]*n
minv=100
for i in range(n):
  s[i]=int(input())
  if minv>s[i]:
    if s[i]%10!=0:
      minv=s[i]
if minv==100:
  print(0)
elif sum(s)%10==0:
  print(sum(s)-minv)
else:
  print(sum(s))
Buggy python submission (verdict: Time Limit Exceeded):
DIV=10**9+7
N=int(input())

ans=1
while N>0:
  ans*=N
  N-=1
  
print(ans%DIV)


Fixed submission:
N=int(input())
ans=1
DIV=10**9+7
while N>1:
  ans=(ans*(N%DIV))%DIV
  N-=1
print(ans)
Buggy python submission (verdict: Runtime Error):
print(("ARC","ABC")[int(input()<1200])

Fixed submission:
print(("ARC","ABC")[int(input())<1200])
Buggy python submission (verdict: Runtime Error):
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)

Fixed submission:
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  x,y=map(int,input().split())
  a[i]=x
  b[i]=y

cur=0
for j in range(n-1,-1,-1):
  if (a[j]+cur)%b[j]!=0:
    cur+=b[j]-(a[j]+cur)%b[j]

print(cur)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
import numpy as np
A=np.zeros(N,dtype=int)
B=np.zeros(N,dtype=int)
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
  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
  A[:i+1]=A[:i+1]+plus
  
print(ans)

Fixed submission:
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  x,y=map(int,input().split())
  a[i]=x
  b[i]=y

cur=0
for j in range(n-1,-1,-1):
  if (a[j]+cur)%b[j]!=0:
    cur+=b[j]-(a[j]+cur)%b[j]

print(cur)
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
print(a,b,c)

Fixed submission:
print(input().replace(","," "))
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for x in range(max(0,s-2*k),k+1):
  if x>s:
    break
  for y in range(max(0,s-2*k),k+1):
    if x+y>s:
      break
    if s-(x+y)>=0 and s-(x+y)<=k:
      cnt+=1
print(cnt)


Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
  if s-x<0:
    break
  elif s-x<=k:
    cnt+=(s-x)+1
  elif s-x>2*k:
    cnt+=0
  elif s-x>k:
    cnt+=2*k-(s-x)+1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
  if x>s:
    break
  for y in range(k+1):
    if x+y>s:
      break
    if s-(x+y)>=0 and s-(x+y)<=k:
      cnt+=1
print(cnt)


Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
  if s-x<0:
    break
  elif s-x<=k:
    cnt+=(s-x)+1
  elif s-x>2*k:
    cnt+=0
  elif s-x>k:
    cnt+=2*k-(s-x)+1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

N = int(readline())
T, A = map(int,readline().split())

import math
for i in range(N - 1):
  t,a = map(int,readline().split())
  i = 1
  while True:
    if t * i >= T and a * i >= A:
      T,A = t * i,a * i
      break
    i += 1

print(T + A)

Fixed submission:
import sys
readline = sys.stdin.readline

N = int(readline())
T, A = map(int,readline().split())

for i in range(N - 1):
  t,a = map(int,readline().split())
  # newT % t == 0 , newA % a == 0である
  # newT >= T , newA >= Aである
  
  # T以上の、tの倍数の最小値 = T / tの切り上げ
  minT = ((T + t - 1) // t) * t
  minA = minT * a // t
  if minA >= A:
    T,A = minT,minA
    continue
  minA = ((A + a - 1) // a) * a
  minT = minA * t // a
  T,A = minT,minA
  
print(T + A)
Buggy python submission (verdict: Runtime Error):
n=input()
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[a[i]-1]-1==i:
    ans+=1
print(ans//2)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[a[i]-1]-1==i:
    ans+=1
print(ans//2)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
b=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
  x,y=map(int,input().split())
  if not b[x]:
    continue
  x,y=x-1,y-1
  b[y]+=1
  red[y]=red[x]
  
  b[x]-=1
  if b[x]==0:
    red[x]=False
    
print(red.count(True))


Fixed submission:
n,m=map(int,input().split())
b=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
  x,y=map(int,input().split())
  x,y=x-1,y-1
  if not b[x]:
    continue
  b[y]+=1
  if red[x]:
    red[y]=True
  
  b[x]-=1
  if b[x]==0:
    red[x]=False
    
print(red.count(True))
Buggy python submission (verdict: Runtime Error):
k=int(input())
print(k**"ACL")

Fixed submission:
k=int(input())
s="ACL"
for i in range(k):
  print(s,end="")
Buggy python submission (verdict: Runtime Error):
test1 = input()
test2 = input()

ans = test2 + test1

print(ans)

Fixed submission:
test1, test2 = input().split()

ans = test2 + test1

print(ans)
Buggy python submission (verdict: Runtime Error):
nx = [int(e) for e in input().split()]
ll = [int(e) for e in input().split()]

n = nx[0]   # バウンド回数
x = nx[1]   # 終点
point = 0   # バウンド位置
count = 0   # バウンド回数

if point <= x:
    count += 1

while point <= x:

    if count == n:
        break
    point += ll[count - 1]
    count += 1
    if point > x:
        count -= 1
        break

if count == n:
    count = n
print(count)

Fixed submission:
abc = [int(e) for e in input().split()]

x = abc[0]
a = abc[1]

if x < a:
    ans = 0
else:
    ans = 10

print(ans)

Buggy python submission (verdict: Runtime Error):
nx = [int(e) for e in input().split()]
ll = [int(e) for e in input().split()]

n = nx[0]   # バウンド回数
x = nx[1]   # 終点
point = 0   # バウンド位置
count = 0   # バウンド回数

if point <= x:
    count += 1

while point <= x:

    if count == n:
        break
    point += ll[count - 1]
    count += 1
    if point > x:
        count -= 1
        break

if count == n:
    count = n
print(count)

Fixed submission:
abc = [int(e) for e in input().split()]

x = abc[0]
a = abc[1]

if x < a:
    ans = 0
else:
    ans = 10

print(ans)