Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h = len(nagasa)

if h // 2 <= k:
    print(n)
    exit()
lef = 0
rig = 2*k+1
now = sum(nagasa[lef:rig])
ans = now
while True:
    if rig == h:
        break
    now = now - nagasa[lef] - nagasa[lef+1] + nagasa[rig] + nagasa[rig+1]
    ans = max(ans,now)
    lef += 2
    rig += 2
print(ans)

Fixed submission:
n,k = map(int,input().split())
s = input()
cou = 0
p = 1
nagasa = []
for i in range(n):
    if int(s[i]) == p:
        cou += 1
    elif int(s[i]) != p:
        if p == 1:
            p = 0
        elif p == 0:
            p = 1
        nagasa.append(cou)
        cou = 1
nagasa.append(cou)
if len(nagasa) % 2 == 0:
    nagasa.append(0)
h = len(nagasa)

if h // 2 <= k:
    print(n)
    exit()
lef = 0
rig = 2*k+1
now = sum(nagasa[lef:rig])
ans = now
while True:
    if rig == h:
        break
    now = now - nagasa[lef] - nagasa[lef+1] + nagasa[rig] + nagasa[rig+1]
    ans = max(ans,now)
    lef += 2
    rig += 2
print(ans)
Buggy python submission (verdict: Runtime Error):
b = input()
if b = "A":
    print("T")
if b = "T":
    print("A")
if b = "G":
    print("C")
if b = "C":
    print("G")

Fixed submission:
b = input()
if b == "A":
    print("T")
if b == "T":
    print("A")
if b == "G":
    print("C")
if b == "C":
    print("G")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1)
        elif s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
k = dp[n][m]
p = list(combinations(range(n),k))
if k == 0:
    print()
    exit()
for i in p:
    cou = 0
    for j in range(m):
        if t[j] == s[i[cou]]:
            cou += 1
        if cou == k:
            for l in i:
                print(s[l],end="")
            print()
            exit()

Fixed submission:
from itertools import combinations
s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1)
        elif s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

i = n
j = m
ans = ""

while i > 0 and j > 0:

    if s[i-1] == t[j-1]:
        ans = s[i-1] + ans 
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1)
        elif s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
k = dp[n][m]
p = list(combinations(range(n),k))
if k == 0:
    print()
    exit()
for i in p:
    cou = 0
    for j in range(m):
        if t[j] == s[i[cou]]:
            cou += 1
        if cou == k:
            for l in i:
                print(s[l],end="")
            print()
            exit()

Fixed submission:
from itertools import combinations
s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1)
        elif s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

i = n
j = m
ans = ""

while i > 0 and j > 0:

    if s[i-1] == t[j-1]:
        ans = s[i-1] + ans 
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n , p = map(int,input().split())
pf={}
for i in range(2,int(p**0.5)+1):
    while p%i==0:
        pf[i]=pf.get(i,0)+1
        p//=i
if p>1:pf[m]=1

ans = 1

for k,v in pf.items():
    if v//n >= 1:
        ans *= k*(v//n)
print(ans)

Fixed submission:
n , p = map(int,input().split())
pf={}
for i in range(2,int(p**0.5)+1):
    while p%i==0:
        pf[i]=pf.get(i,0)+1
        p//=i
if p>1:
    pf[p]=1

ans = 1

for k,v in pf.items():
    ans *= k**(v//n)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n , k = map(int,input().split())
a = list(map(int,input().split()))
b = []
for i in range(n):
    for j in range(i,n):
        b.append(sum(a[i:j+1]))
ans = 0
for i in reversed(range(41)):
    cou = 0
    now = ans + 2**i
    for j in b:
        if j & now >= now:
            cou += 1
    if cou >= k:
        ans += 2**i
print(ans)

Fixed submission:
n , k = map(int,input().split())
a = list(map(int,input().split()))
b = []
for i in range(n):
    for j in range(i,n):
        b.append(sum(a[i:j+1]))
ans = 0
for i in reversed(range(41)):
    cou = 0
    now = ans + 2**i
    for j in b:
        if j & now >= now:
            cou += 1
    if cou >= k:
        ans += 2**i
print(ans)
Buggy python submission (verdict: Runtime Error):
n , m = map(int,input().split())
s = input()
t = input()
l = n*m//fractions.gcd(n,m)
p = l//n
q = l//m

for i in range(10**9):
    if q*i >= n or p*i >= m:
        print(l)
        exit()
    if s[q*i] != t[p*i]:
        print(-1)
        exit()

Fixed submission:
import fractions
n , m = map(int,input().split())
s = input()
t = input()
l = n*m//fractions.gcd(n,m)
p = l//n
q = l//m

for i in range(10**9):
    if q*i >= n or p*i >= m:
        print(l)
        exit()
    if s[q*i] != t[p*i]:
        print(-1)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
n , m = map(int,input().split())
s = input()
t = input()
l = n*m//fractions.gcd(n,m)
x = ["#" for i in range(l)]
for i in range(n):
    x[i*(l//n)] = s[i]
for i in range(m):
    if x[i*(l//m)] != "#" and x[i*(l//m)] != t[i]:
        print(-1)
        exit()
print(l)

Fixed submission:
import fractions
n , m = map(int,input().split())
s = input()
t = input()
l = n*m//fractions.gcd(n,m)
p = l//n
q = l//m

for i in range(10**9):
    if q*i >= n or p*i >= m:
        print(l)
        exit()
    if s[q*i] != t[p*i]:
        print(-1)
        exit()
Buggy python submission (verdict: Runtime Error):
import math
n , x = map(int,input().split())
p = list(map(int,input().split()))
ans = abs(x - p[0])
for i in range(n):
    ans = math.gcd(ans,abs( x - p[i] ))
    
print(ans)

Fixed submission:
import fractions
n , x = map(int,input().split())
p = list(map(int,input().split()))
ans = abs(x - p[0])
for i in range(n):
    ans = fractions.gcd(ans,abs( x - p[i] ))
    
print(ans)
Buggy python submission (verdict: Runtime Error):
a , b , c = map(int,input().split())
print(min(abs(a-b)+abs(b-c),abs(b-a)+abs(a-c),abs(a-c)+abs(c-b))

Fixed submission:
a , b , c = map(int,input().split())
print(min(abs(a-b)+abs(b-c),abs(b-a)+abs(a-c),abs(a-c)+abs(c-b)))
Buggy python submission (verdict: Runtime Error):
n , m , d = map(int,input().split())
cou = 0
if d == 0:
    cou += n
elif d+1 <= n-d:
    cou += 2*n-2*d-2
else:
    cou += n
print(pow(cou,m-1)*(m-1)/pow(n,m))
    

Fixed submission:
n , m , d = map(int,input().split())
cou = 0
if d == 0:
    cou += n
else:
    cou += 2*(n-d)
print(cou*(m-1)/pow(n,2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
k = [[int(input()),1]]
cou = 1
for i in range(n-1):
    now = int(input())
    flag = False
    for i in range(cou):
        if now == k[i][0] + 1:
            k[i] = [now,k[i][1]+1]
            flag = True
    if not flag:
        k.append([now,1])
        cou += 1
p = 0
for i in range(cou):
    p = max(p,k[i][1])
print(n-p)

Fixed submission:
from bisect import bisect_left,bisect
 
n = int(input())
cou = [0 for i in range(n+1)]
for i in range(n):
    now = int(input())
    cou[now] = cou[now-1] + 1  

print(n-max(cou))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
k = [[int(input())]]
cou = 1
for i in range(n-1):
    now = int(input())
    flag = False
    for i in range(cou):
        if now == k[i][-1]+1:
            k[i].append(now)
            flag = True
    if not flag:
        k.append([now])
        cou += 1
p = 0
for i in range(cou):
    p = max(p,len(k[i]))
print(n-p)

Fixed submission:
from bisect import bisect_left,bisect
 
n = int(input())
cou = [0 for i in range(n+1)]
for i in range(n):
    now = int(input())
    cou[now] = cou[now-1] + 1  

print(n-max(cou))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
kouho = set()
n = len(s)
for i in range(n):
    for j in range(i,n):
        kouho.add(s[i:j+1])
kouho = list(kouho)
kouho.sort()
print(kouho[k-1])

Fixed submission:
s = input()
k = int(input())
kouho = set()
n = len(s)
for i in range(n):
    for j in range(i,min(n,i+5)):
        kouho.add(s[i:j+1])
kouho = list(kouho)
kouho.sort()
print(kouho[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
nag = int(input())
kaz = list(map(int,input().split(" ")))
cou = 0
for i in range(nag):
    kar = 0
    for j in range(nag - i):
       kar += kaz[i + j]
       if kar == 0:
           cou += 1

print(cou)

Fixed submission:
from itertools import accumulate
import collections
n = int(input())
A = [0]
A.extend(list(map(int,input().split())))
p = list(accumulate(A))
c = collections.Counter(p)
ans = 0
for k,v in c.items():
    ans += v*(v-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
nag = int(input())
kaz = list(map(int,input().split(" ")))
cou = 0
for i in range(nag):
    kar = 0
    for j in range(nag - i):
       kar += kaz[i + j]
       if kar == 0:
           cou += 1

print(cou)

Fixed submission:
from itertools import accumulate
import collections
n = int(input())
A = [0]
A.extend(list(map(int,input().split())))
p = list(accumulate(A))
c = collections.Counter(p)
ans = 0
for k,v in c.items():
    ans += v*(v-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
if s.count("a")*s.count("b")*s.count("c") == 1:
  print("Yes)
else:
        print("No")

Fixed submission:
s = input()
if s.count("a")*s.count("b")*s.count("c") == 1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(0)
sys.stdout.flush()
maes = input()
if maes == "Vacant":
    sys.exit()
print(n-1)
sys.stdout.flush()
maes = input()
if maes == "Vacant":
    sys.exit()
lef = 0
rig = n -1 
print((lef+rig)//2 - ((lef+rig)//2)%2)
sys.stdout.flush()
p = 0
while abs(rig-lef)<=2:
    s = input()
    if s == "Vacant":
        sys.exit()
    else:
        if maes == s:
            if p == 0:
                lef = (lef+rig)//2 - ((lef+rig)//2)%2
            elif p == 1:
                rig = (lef+rig)//2 + ((lef+rig)//2)%2
        elif maes != s:
            if p == 0:
                p = 1
                rig = (lef+rig)//2 + ((lef+rig)//2)%2
            elif p == 1:
                lef = (lef+rig)//2 - ((lef+rig)//2)%2
    maes = s
    print((lef+rig)//2 - ((lef+rig)//2)%2)
    sys.stdout.flush()

print((lef+rig)//2)
sys.stdout.flush()
if maes == "Vacant":
    sys.exit()

Fixed submission:
n = int(input())

print(0)
lf = input()
if lf == "Vacant":
    exit()

print(n-1)
rf = input()
if rf == "Vacant":
    exit()
l = 0
r = n-1

while True:
    k = (l+r)//2
    print(k)
    f = input()
    if f == "Vacant":
        exit()
    else:
        if (abs(r-k) % 2 == 1 and rf == f) or (abs(r-k) % 2 == 0 and rf != f):
            l = k
            lf = f
        elif (abs(l-k) % 2 == 1 and lf == f) or (abs(l-k) % 2 == 0 and lf != f):
            r = k
            rf = f

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(0)
sys.stdout.flush()
maes = input()
if maes == "Vacant":
    exit()
print(n-1)
sys.stdout.flush()
maes = input()
if maes == "Vacant":
    exit()
lef = 0
rig = n -1 
print((lef+rig)//2 - ((lef+rig)//2)%2)
sys.stdout.flush()
p = 0
while abs(rig-lef)<=2:
    s = input()
    if s == "Vacant":
        exit()
    else:
        if maes == s:
            if p == 0:
                lef = (lef+rig)//2 - ((lef+rig)//2)%2
            elif p == 1:
                rig = (lef+rig)//2 + ((lef+rig)//2)%2
        elif maes != s:
            if p == 0:
                p = 1
                rig = (lef+rig)//2 + ((lef+rig)//2)%2
            elif p == 1:
                lef = (lef+rig)//2 - ((lef+rig)//2)%2
    maes = s
    print((lef+rig)//2 - ((lef+rig)//2)%2)
    sys.stdout.flush()

print((lef+rig)//2)
sys.stdout.flush()
if maes == "Vacant":
    exit()

Fixed submission:
n = int(input())

print(0)
lf = input()
if lf == "Vacant":
    exit()

print(n-1)
rf = input()
if rf == "Vacant":
    exit()
l = 0
r = n-1

while True:
    k = (l+r)//2
    print(k)
    f = input()
    if f == "Vacant":
        exit()
    else:
        if (abs(r-k) % 2 == 1 and rf == f) or (abs(r-k) % 2 == 0 and rf != f):
            l = k
            lf = f
        elif (abs(l-k) % 2 == 1 and lf == f) or (abs(l-k) % 2 == 0 and lf != f):
            r = k
            rf = f
Buggy python submission (verdict: Runtime Error):
from collections import deque
n , m = map(int,input().split())
z = [[] for i in range(n)]
for i in range(m):
    l , r , d = map(int,input().split())
    z[l-1].append((r-1,d))
    z[r-1].append((l-1,-d))

visit = [False for i in range(n)]
x = [-1 for i in range(n)]
for i in range(n):
    if visit[i]:
        continue
    visit[i] = True
    d = deque()
    d.append(i)
    x[i] = 0
    while d:
        now = d.popleft()
        for t , d in z[now]:
            if not visit[t]:
                visit[t] = True
                x[t] = x[now] + d
                d.append(t)
            elif visit[t]:
                if x[t] - x[now] != d:
                    print("No")
                    exit()
print("Yes")

Fixed submission:
from collections import deque
n , m = map(int,input().split())
z = [[] for i in range(n)]
for i in range(m):
    l , r , d = map(int,input().split())
    z[l-1].append((r-1,d))
    z[r-1].append((l-1,-d))

visit = [False for i in range(n)]
x = [-1 for i in range(n)]
for i in range(n):
    if visit[i]:
        continue
    visit[i] = True
    q = deque()
    q.append(i)
    x[i] = 0
    while q:
        now = q.popleft()
        for t , d in z[now]:
            if not visit[t]:
                visit[t] = True
                x[t] = x[now] + d
                q.append(t)
            elif visit[t]:
                if x[t] - x[now] != d:
                    print("No")
                    exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
s=input()
print(s.count(“1”))

Fixed submission:
s=input()
print(s.count("1"))
Buggy python submission (verdict: Runtime Error):
p = [2,1]
n = int(input())

if n >= 3:
    for i in range(2,n+1):
        p.append(p[i-2]+p[i-1])

print(p[n])

Fixed submission:
p = [2,1]
n = int(input())

if n >= 2:
    for i in range(2,n+1):
        p.append(p[i-2]+p[i-1])

print(p[n])
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
t = input()
m = len(t)

if n < m:
    print("UNRESTORABLE")
    exit()
p = False
for i in reversed(range(n-m+1)):
    flag = True
    for j in range(m):
        if s[i+j] != "?" and s[i+j] != t[j]:
            flag = False
            break
    if flag:
        s = s[:i] + t
        p = True
        break

if not p:
    print("UNRESTORABLE")
    exit()
elif p:
    for i in range(n):
        if s[i] == "?":
            s = s[:i] + "a" + s[i+1:]
print(s)

Fixed submission:
s = input()
t = input()

a = len(s)
b = len(t)
ans = []
if a-b+1 < 0:
    print("UNRESTORABLE")
    exit()

for i in range(a-b+1):
    p = 0
    for j in range(b):
        if s[i+j] != t[j] and s[i+j] != "?":
            p = 1
            break
    if p == 0:
        kar = s[:i] + t + s[i+b:]
        kar = kar.replace("?","a")
        ans.append(kar)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])
Buggy python submission (verdict: Runtime Error):
from collections import deque
def f(x,q):
    for i in route[x]:
        if not visit[i]:
            visit[i] = True
            f(i,q+[i])
            visit[i] = False
            if i == n-1:
                p = q + [i-1]
                flag = True
                return p
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(lambda x:int(x)-1,input().split())
    route[a].append(b)
    route[b].append(a)
visit = [False for i in range(n)]
p = f(0,[0])
t = p[-(-len(p)//2)-1]

d = deque()
d.append(n-1)
visit = [False for i in range(n)]
siro = 1
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit[i] and i != t:
            visit[i] = True
            d.append(i)
            siro += 1
kuro = n - siro
if kuro <= siro:
    print("Snuke")
elif kuro > siro:
    print("Fennec")

Fixed submission:
from heapq import heappop, heappush
from collections import deque
n = int(input())
mp2 = []
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(lambda x:int(x)-1,input().split())
    mp2.append((a,b,1))
    mp2.append((b,a,1))
    route[a].append(b)
    route[b].append(a)
inf=float('inf')
d=[inf for i in range(n)]
d[0]=0
prev=[None]*n
p=dict()
for i,j,k in mp2: p[i]=p.get(i,[])+[(j,k)]

q=[]
heappush(q,(d[0],0))
while q:
    du, u = heappop(q)
    if d[u]<du: continue
    for v,weight in p.get(u,[]):
        alt=du+weight
        if d[v]>alt:
            d[v]=alt
            prev[v]=u
            heappush(q, (alt,v))

p=[n-1]
while prev[p[-1]]!=None: p.append(prev[p[-1]])

p = p[::-1]
t = p[-(-len(p)//2)-1]

d = deque()
d.append(n-1)
visit = [False for i in range(n)]
siro = 1
visit[n-1] = True
visit[t] = True
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit[i] and i != t:
            visit[i] = True
            d.append(i)
            siro += 1
kuro = n - siro
if kuro <= siro:
    print("Snuke")
elif kuro > siro:
    print("Fennec")
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()
    elif lef > rig:
        print(ans)
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1

Fixed submission:
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()
    elif lef > rig:
        print(ans)
        exit()
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1

Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()

Fixed submission:
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()
    elif lef > rig:
        print(ans)
        exit()
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
kai = int(input())
a = 0
b = 0
cou = 0
kaz = []

for i in range(kai):
    a,b = map(int,input().split(" "))
    kaz.append(a)
    kaz.append(b)

for j in range(kai):
    while True:
        if (kaz[(kai-j)*2 -2]+cou) % kaz [(kai-j)*2 -1] == 0:
            break
        else:
            cou += 1
print(cou)

Fixed submission:
n = int(input())
p = []
for i in range(n):
    a , b = map(int,input().split())
    p.append([a,b])
ans = 0
for i in reversed(range(n)):
    if (p[i][0] + ans) % p[i][1] != 0:
        ans += p[i][1] - ((p[i][0] + ans)%p[i][1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
kai = int(input())
a = 0
b = 0
cou = 0
kaz = []

for i in range(kai):
    a,b = map(int,input().split(" "))
    kaz.append(a)
    kaz.append(b)

for j in range(kai):
    while True:
        if kaz[(kai-j)*2 -2] % kaz [(kai-j)*2 -1] == 0:
            break
        else:
            cou += 1
            for k in range(kai):
                kaz[k*2] += 1
    
print(cou)

Fixed submission:
n = int(input())
p = []
for i in range(n):
    a , b = map(int,input().split())
    p.append([a,b])
ans = 0
for i in reversed(range(n)):
    if (p[i][0] + ans) % p[i][1] != 0:
        ans += p[i][1] - ((p[i][0] + ans)%p[i][1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
kai = int(input())
a = 0
b = 0
cou = 0
kaz = []

for i in range(kai):
    a,b = map(int,input().split(" "))
    kaz.append(a)
    kaz.append(b)

for j in range(kai):
    while True:
        if kaz[(kai-j)*2 -2] % kaz [(kai-j)*2 -1] == 0:
            break
        else:
            cou += 1
            for k in range(kai):
                kaz[k*2] += 1
    
print(cou)

Fixed submission:
n = int(input())
p = []
for i in range(n):
    a , b = map(int,input().split())
    p.append([a,b])
ans = 0
for i in reversed(range(n)):
    if (p[i][0] + ans) % p[i][1] != 0:
        ans += p[i][1] - ((p[i][0] + ans)%p[i][1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t,a = map(int,input().split())
nowt = t
nowa = a
for i in range(n-1):
    t , a = map(int,input().split())
    kou = 1
    while True:
        if t*kou >= nowt and a*kou >= nowa:
            break
        else:
            kou += 1
    nowt = t*kou
    nowa = a*kou
print(nowt+nowa)

Fixed submission:
n = int(input())
t,a = map(int,input().split())
nowt = t
nowa = a
for i in range(n-1):
    t , a = map(int,input().split())
    kou = max(nowt//t,nowa//a)
    while True:
        if t*kou >= nowt and a*kou >= nowa:
            break
        else:
            kou += 1
    nowt = t*kou
    nowa = a*kou
print(nowt+nowa)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t,a = map(int,input().split())
nowt = t
nowa = a
for i in range(n-1):
    t , a = map(int,input().split())
    kou = 1
    while True:
        if t*kou >= nowt and a*kou >= nowa:
            break
        else:
            kou += 1
    nowt = t*kou
    nowa = a*kou
print(nowt+nowa)

Fixed submission:
n = int(input())
t,a = map(int,input().split())
nowt = t
nowa = a
for i in range(n-1):
    t , a = map(int,input().split())
    kou = max(nowt//t,nowa//a)
    while True:
        if t*kou >= nowt and a*kou >= nowa:
            break
        else:
            kou += 1
    nowt = t*kou
    nowa = a*kou
print(nowt+nowa)