qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())

l = [0, 0]
for _ in range(N):
    t, a = map(int, input().split())
    if t >= l[0] and a >= l[1]:
        l = [t, a]
    else:
        print(t, a)
        temp = max((l[0] - 1) // t + 1, (l[1] - 1) // a + 1)
        l = [t * temp, a * temp]
    
print(sum(l))

Fixed code:
N = int(input())

l = [0, 0]
for _ in range(N):
    t, a = map(int, input().split())
    if t >= l[0] and a >= l[1]:
        l = [t, a]
    else:
        temp = max((l[0] - 1) // t + 1, (l[1] - 1) // a + 1)
        l = [t * temp, a * temp]
    
print(sum(l))
Buggy code:
import fractions
N=int(input())
T,A=map(int,input().split())
for i in range(1,N):
    nT,nA=map(int,input().split())
    m,p=nT,nA
    if(nT>=T and nA>=A):
        T,A=nT,nA
        continue
    pT,pA=T//nT,A//nA
    if(T%nT!=0):
        pT+=1
    if(A%nT!=0):
        pA+=1
    T,A=nT*max(pT,pA),nA*max(pT,pA)
print(T+A)

Fixed code:
import fractions
N=int(input())
T,A=map(int,input().split())
for i in range(1,N):
    nT,nA=map(int,input().split())
    if(nT>=T and nA>=A):
        T,A=nT,nA
        continue
    pT,pA=T//nT,A//nA
    if(T%nT!=0):
        pT+=1
    if(A%nA!=0):
        pA+=1
    T,A=nT*max(pT,pA),nA*max(pT,pA)
print(T+A)
Buggy code:
import sys
input = sys.stdin.readline

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x // X + x % X != 0, y // Y + y % Y)
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    # print(x, y)

print(x + y)




Fixed code:
import sys
input = sys.stdin.readline

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x // X + (x % X != 0), y // Y + (y % Y != 0))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    # print(x, y)

print(x + y)
Buggy code:
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]

XY = [TA[0]]

for i in range(1, n):
    x0, y0 = XY[i-1]
    x1, y1 = TA[i]
    xq, xr = divmod(x0, x1)
    yq, yr = divmod(y0, y1)
    if xr != 0:
        xq += 1
    elif yr != 0:
        yq += 1
    q = max(xq, yq)
    x1, y1 = x1*q, y1*q
    XY.append([x1, y1])
    
print(sum(XY[-1]))

Fixed code:
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]

XY = [TA[0]]

for i in range(1, n):
    x0, y0 = XY[i-1]
    x1, y1 = TA[i]
    xq, xr = divmod(x0, x1)
    yq, yr = divmod(y0, y1)
    if xr != 0:
        xq += 1
    if yr != 0:
        yq += 1
    q = max(xq, yq)
    x1, y1 = x1*q, y1*q
    XY.append([x1, y1])
    
print(sum(XY[-1]))
Buggy code:
import math

n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)]

a, b = ta[0]
for i in range(n):
    x, y = ta[i]
    z = max(-(-a/x), -(-b/y))
    a = x * z
    b = y * z

ans = a + b
print(ans)

Fixed code:
import math

n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)]

a, b = ta[0]
for i in range(n):
    x, y = ta[i]
    z = max(-(-a//x), -(-b//y))
    a = x * z
    b = y * z

ans = a + b
print(ans)
Buggy code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = -1, -1
    for i in range(N):
        newT, newA = LI()
        n = fractions.gcd(newT, newA)
        newT, newA = newT // n, newA // n
        if curT == -1 and curA == -1:
            curT, curA = newT, newA
            continue
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        # pattern1
        r1 = math.ceil(curT/newT) # <= 1
        r2 = math.ceil(curA/newA) # <= 1
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()



Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = 1, 1
    for i in range(N):
        newT, newA = LI()
        # if newT >= curT and newA >= curA:
        #     curT, curA = newT, newA
        #     continue
        r1 = (curT-1)//newT + 1
        r2 = (curA-1)//newA + 1
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()
Buggy code:
n=int(input())
x,y=map(int,input().split())

import math
for i in range(n-1):
  t,a=map(int,input().split())
  tbai=(x-1/t+1)
  abai=y-1/a+1
  bai=max(tbai,abai)
  x=t*bai
  y=a*bai
  #print(x,y)
print(x+y)

Fixed code:
n=int(input())
x,y=map(int,input().split())

import math
for i in range(n-1):
  t,a=map(int,input().split())
  tbai=(x-1)//t+1
  abai=(y-1)//a+1
  bai=max(tbai,abai)
  x=t*bai
  y=a*bai
  #print(x,y)
print(x+y)
Buggy code:
https://atcoder.jp/contests/abc046/tasks/arc062_a
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  t,a=LI()
  l=[LI() for _ in range(n-1)]

  # t<=nt' and a<=na'
  # t/t'<=n and a/a'<=n
  for _t,_a in l:
    _n=max(-(-t//_t),-(-a//_a))
    t=_n*_t
    a=_n*_a

  return t+a

# main()
print(main())


Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  t,a=LI()
  l=[LI() for _ in range(n-1)]

  # t<=nt' and a<=na'
  # t/t'<=n and a/a'<=n
  for _t,_a in l:
    _n=max(-(-t//_t),-(-a//_a))
    t=_n*_t
    a=_n*_a

  return t+a

# main()
print(main())
Buggy code:
n = int(input())
from math import ceil
from fractions import gcd

tkhs = 1
aoki = 1

for _ in range(n):
    t, a = map(int, input().split())
    t, a = t // gcd(t,a), a // gcd(t,a)
    k = max(ceil(tkhs/t), ceil(aoki/a))
    tkhs = k*t
    aoki = k*a

print(tkhs+aoki)



Fixed code:
n = int(input())
from math import ceil

tkhs = 1
aoki = 1

for _ in range(n):
    t, a = map(int, input().split())
    k = max((tkhs+t-1)//t, (aoki+a-1)//a)
    tkhs = k*t
    aoki = k*a

print(tkhs+aoki)
Buggy code:
def ceil(x,y):
    return x//y+(not( not x%y))
n=int(input())
a,b=1,1
for i in range(n):
    t,s = map(int,input().split())
    i = max( ceil(a/t), ceil(b/s) )
    a=t*i;b=s*i
print(a+b)

Fixed code:
def ceil(x,y):
    return x//y+(not( not x%y))
n=int(input())
a,b=1,1
for i in range(n):
    t,s = map(int,input().split())
    i = max( ceil(a,t), ceil(b,s) )
    a=t*i;b=s*i
print(a+b)
Buggy code:
from math import ceil
# def ceil(x,y):
#   return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)    
    


Fixed code:
# from math import ceil
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)
Buggy code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
x,y = a[0][0],a[0][1]
for i in range(1,n):
  xr=(a[i-1][0]+a[i][0]-1)//a[i][0]
  yr=(a[i-1][1]+a[i][1]-1)//a[i][1]
  r=max(xr,yr)
  x*=r
  y*=r
print(x+y)

Fixed code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
x,y = a[0][0],a[0][1]
for i in range(1,n):
  xr=(x+a[i][0]-1)//a[i][0]
  yr=(y+a[i][1]-1)//a[i][1]
  r=max(xr,yr)
  x=r*a[i][0]
  y=r*a[i][1]
print(x+y)
Buggy code:
N = int(input())
t, a = map(int, input().split())

ans = t + a

for _ in range(N - 1):
    T, A = map(int, input().split())

    n = max(t // T + (1 if t % T else 0), a // A + (1 if a % A else 0))

    if ((T + A) * n == ans):n += 1
    ans = (T + A) * n

    t, a = T * n, A * n

print(ans)


Fixed code:
N = int(input())
t, a = map(int, input().split())

ans = t + a

for _ in range(N - 1):
    T, A = map(int, input().split())

    n = max(t // T + (1 if t % T else 0), a // A + (1 if a % A else 0))

    ans = (T + A) * n

    t, a = T * n, A * n

print(ans)
Buggy code:
N=int(input())
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1

def UP(V1,V2,R1,R2):
    n=max(-(-V1//R1),-(-V2//R2))
    return(n*R1,n*R2)

for i in range(N):
    up=UP(Taka,Aoki,TA[i][0],TA[i][1])
    print(up)
    Taka=up[0]
    Aoki=up[1]

print(Taka+Aoki)

Fixed code:
N=int(input())
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1

def UP(V1,V2,R1,R2):
    n=max(-(-V1//R1),-(-V2//R2))
    return(n*R1,n*R2)

for i in range(N):
    up=UP(Taka,Aoki,TA[i][0],TA[i][1])
#    print(up)
    Taka=up[0]
    Aoki=up[1]

print(Taka+Aoki)
Buggy code:
N = int(input())
import math
t = 1
a = 1
for i in range(N):
    T, A = map(int,input().split())
    g = max(math.ceil(t/T),math.ceil(a/A))
    t = g*T
    a = g*A
    print(t+a)
ans = t + a
print(ans)

Fixed code:
N = int(input())
import math
t, a = map(int,input().split())
for i in range(N-1):
    T, A = map(int,input().split())
    g = math.ceil(max(-(-t//T),-(-a//A)))
    t = g*T
    a = g*A
    
ans = t + a
print(ans)
Buggy code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from math import ceil
from decimal import *
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]

t = TA[0][0]
a = TA[0][1]

for i in range(1,N):
    n = Decimal(max(ceil(t/TA[i][0]), ceil(a/TA[i][1])))
    t = n*TA[i][0]
    a = n*TA[i][1]
    print(i,t,a)

print(t+a)

Fixed code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from math import ceil
from decimal import *
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]


t,a = 1,1
for i in range(N):
    n = Decimal(max(ceil(t/TA[i][0]), ceil(a/TA[i][1])))
    t = n*TA[i][0]
    a = n*TA[i][1]

print(t+a)
Buggy code:
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    na = 1
    nb = 1
    for i in range(n):
        t, a = list(map(int, input().rstrip('\n').split()))
        r = max((na + t - 1) // t, (nb + a - 1) // a)
        na = r * t
        nb = r * a
        print(na, nb, r)


if __name__ == '__main__':
    slove()


Fixed code:
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    na = 1
    nb = 1
    for i in range(n):
        t, a = list(map(int, input().rstrip('\n').split()))
        r = max((na + t - 1) // t, (nb + a - 1) // a)
        na = r * t
        nb = r * a
    print(na + nb)


if __name__ == '__main__':
    slove()
Buggy code:
n=int(input())
suji=[]
for i in range (n):
	suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
	if i%2==0:
		tlist.append(suji[i])
	else:
		alist.append(suji[i])

for i in range(n-1):
	k=max(alist[i]//alist[i+1],tlist[i]//tlist[i+1])+1
	tlist[i+1]=tlist[i+1]*k
	alist[i+1]=alist[i+1]*k

print(int(tlist[n-1]+alist[n-1]))

Fixed code:
n=int(input())
suji=[]
for i in range (n):
	suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
	if i%2==0:
		tlist.append(suji[i])
	else:
		alist.append(suji[i])

for i in range(n-1):
	aaa=alist[i]//alist[i+1]
	ttt=tlist[i]//tlist[i+1]
	if alist[i]%alist[i+1]!=0:
		aaa+=1
	if tlist[i]%tlist[i+1]!=0:
		ttt+=1
	k=max(aaa,ttt)
	tlist[i+1]=tlist[i+1]*k
	alist[i+1]=alist[i+1]*k

print(int(tlist[n-1]+alist[n-1]))
Buggy code:
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi / t), -(-aoki / a))
        # k = max(math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()


Fixed code:
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi // t), -(-aoki // a))
        # k = max(math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()
Buggy code:
import math

n = int(input())

s0 = 2
t0 = a0 = 1
for i in range(n):
    t, a = map(int, input().split())

    m = max((t0 + t - 1) // t,
            (a0 + a - 1) // a)
    # m = max(math.ceil(t0 / t),
    #         math.ceil(a0 / a))

    t0, a0 = t * m, a * m
    s0 = t0 + a0
    print(s0, t0, a0, m)

print(s0)


Fixed code:
import math

n = int(input())

s0 = 2
t0 = a0 = 1
for i in range(n):
    t, a = map(int, input().split())

    m = max((t0 + t - 1) // t,
            (a0 + a - 1) // a)
    # m = max(math.ceil(t0 / t),
    #         math.ceil(a0 / a))

    t0, a0 = t * m, a * m
    s0 = t0 + a0
    # print(s0, t0, a0, m)

print(s0)
Buggy code:
N = int(input())
a, b = map(int,input().split())
for i in range(1,N):
  x, y = map(int,input().split())
  n = max(a-1//x, b-1//y)
  a = n*x
  b = n*y
print(a+b)
    


Fixed code:
N = int(input())

a, b = 1, 1

for _ in range(N):
    x, y = map(int, input().split())
    n = max((a + x - 1) // x, (b + y - 1) // y)
    a, b = n * x, n * y

print(a + b)
Buggy code:
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t/ls[i][0]+1 ,~-now_a/ls[i][1]+1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Fixed code:
if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([~-now_t//ls[i][0] +1 ,~-now_a//ls[i][1] +1])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)
Buggy code:
import fractions

N=int(input())
t,a=1,1
for i in range(N):
    T,A=map(int,input().split())
    n=max(fractions.ceil(a/A),fractions.ceil(t/T))
    t,a=n*T,n*A

print(t+a)


Fixed code:
import fractions

N=int(input())
t,a=1,1
for i in range(N):
    T,A=map(int,input().split())
    n=max(-(-a//A),-(-t//T))
    # n=max(fractions.ceil(a/A),fractions.ceil(t/T))
    t,a=n*T,n*A

print(t+a)
Buggy code:
import math
n = int(input())
a,b = 1,1
for i in range(n):
    x,y = map(int, input().split(' '))
    tmp = max((a/x, b/y))
    tmp = math.floor(tmp) + 1
    a,b = x*tmp,y*tmp
print(a+b)

Fixed code:
import math
n = int(input())
a,b = 1,1
for i in range(n):
    x,y = map(int, input().split(' '))
    tmp = max(-(-a//x), -(-b//y))
    a = x * tmp
    b = y * tmp
print(a+b)
Buggy code:
# -*- coding: utf-8 -*-
n = int(input())
ta = [list(map(int,input().split())) for i in range(n)]

cur_t = 1
cur_a = 1


def ceil(a, b):
    return a // b + int(a % b != 0)

for t,a in ta:
    if cur_t > t or cur_a > a:
        rate = ceil(max([cur_t/t,cur_a/a]))
        cur_t = t*rate
        cur_a = a*rate
    else:
        cur_t=t
        cur_a=a
print(cur_t+cur_a)


Fixed code:
# -*- coding: utf-8 -*-
n = int(input())
ta = [list(map(int,input().split())) for i in range(n)]

cur_t = 1
cur_a = 1


def ceil(a, b):
    return a // b + int(a % b != 0)

for t,a in ta:
    if cur_t > t or cur_a > a:
        rate = max([ceil(cur_t,t),ceil(cur_a,a)])
        cur_t = t*rate
        cur_a = a*rate
    else:
        cur_t=t
        cur_a=a
print(cur_t+cur_a)
Buggy code:
N = int(input())
t = 0
a = 0

for _ in range(N):
  rt,ra = map(int,input().split())
  c = max((t-1)//rt+1 (a-1)//ra+1)
  t = rt*c
  a = ra*c
  if a+t == 0:
    t += rt
    a += ra

print(a+t)

Fixed code:
N = int(input())

t = 0
a = 0
for _ in range(N):
  rt,ra = map(int,input().split())
  c = max((t-1)//rt+1, (a-1)//ra+1)
  t = rt*c
  a = ra*c
  if a+t == 0:
    t += rt
    a += ra

    
answer = t+a
print(answer)
Buggy code:
N = int(input())
tans = 1
aans = 1
for i in range(N):
    t, a = map(int, input().split())
    n = max(-(-tans // t), -(-aans / a))
    tans = n * t
    aans = n * a
print(aans + tans)

Fixed code:
N = int(input())
tans = 1
aans = 1
for i in range(N):
    t, a = map(int, input().split())
    n = max(-(-tans // t), -(-aans // a))
    tans = n * t
    aans = n * a
print(aans + tans)
Buggy code:
n  =int(input())
ta=[]
for i in range(n):
    ta.append(list(map(int,input().split())))

for i in range(n-1):
    bai = max(int(ta[i][0]/ta[i+1][0]), int(ta[i][1]/ta[i+1][1]))
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])



Fixed code:
n  =int(input())
ta=[]
for i in range(n):
    ta.append(list(map(int,input().split())))

import math
for i in range(n-1):
    bai = max(math.ceil((ta[i][0]-1)//ta[i+1][0]+1),math.ceil((ta[i][1]-1)//ta[i+1][1]+1))
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])
Buggy code:
n = int(input())
ta = [[int(i) for i in input().split()] for i in range(n)]

ct = ta[0][0]
ca = ta[0][1]

for i in range(1, n):
    t, a = ta[i]

    if ct / t > ca / a:
        if ct%t == 0:
            rate = ct//t
        else:
            rate = ct//t+1
    else:
        if ca%a == 0:
            rate = ca//a
        else:
            rate = ca//a+1
    ct = rate * t
    ca = rate * a
    print(ct+ca)

Fixed code:
n = int(input())
ta = [[int(i) for i in input().split()] for i in range(n)]

ct = ta[0][0]
ca = ta[0][1]

for i in range(1, n):
    t, a = ta[i]

    if ct / t > ca / a:
        if ct%t == 0:
            rate = ct//t
        else:
            rate = ct//t+1
    else:
        if ca%a == 0:
            rate = ca//a
        else:
            rate = ca//a+1
    ct = rate * t
    ca = rate * a
print(ct+ca)
Buggy code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(math.ceil(a/x), math.ceil(b/y))
  a,b = l*x,l*y
print(x+y)


Fixed code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(-(-a//x), -(-b//y))
  a,b = l*x,l*y
print(a+b)
Buggy code:
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max(-(-t//nt), -(-a//na)
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)


Fixed code:
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max((t-1)//nt+1, (a-1)//na+1)
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)
Buggy code:
import math


def main():
    N = int(input())
    TA = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        # n = max(math.ceil(A / x), math.ceil(B / y))
        n = max(A // x + A % x != 0,
                B // x + B % x != 0)
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()


Fixed code:
import math


def main():
    N = int(input())
    TA = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        # n = max(math.ceil(A / x), math.ceil(B / y))
        n = max(A // x + (A % x != 0),
                B // y + (B % y != 0))
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()
Buggy code:
# -*- coding: utf-8 -*-
import sys

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max((takahashi // t), (aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)
	
if __name__ == "__main__":
	main()


Fixed code:
# -*- coding: utf-8 -*-
import sys

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max(-(-takahashi // t), -(-aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)

if __name__ == "__main__":
	main()
Buggy code:
N=int(input())
t=a=1
for i in range(N):
    T,A=map(int,input().split())
    num=max(-t//T,a//A)
    t,a=num*T,num*A
print(t+a)


Fixed code:
N=int(input())
t=a=1
for i in range(N):
    T,A=map(int,input().split())
    num=max(-(-t//T),-(-a//A))
    t,a=num*T,num*A
print(t+a)
Buggy code:
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
ans = sum(ta[0])
for i in range(1,N):
    c = max(math.ceil(ta[i-1][0]/ta[i][0]),math.ceil(ta[i-1][1]/ta[i][1]))
    ans = sum(ta[i])*(c)
    ta[i][0] = ans//ta[i][0]
    ta[i][1] = ans//ta[i][1]
print(ans)

Fixed code:
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
for i in range(1,N):
    c = max(-(-ta[i-1][0]//ta[i][0]),-(-ta[i-1][1]//ta[i][1]))
    ta[i][0] = ta[i][0]*c
    ta[i][1] = ta[i][1]*c
print(sum(ta[N-1]))
Buggy code:
from math import ceil

N = int(input())
T,A = [],[]
for i in range(N):
    t,a = map(int,input().split())
    T.append(t)
    A.append(a)

t,a = 1,1
for i in range(N):
    r = max(ceil(t/T[i]),ceil(a/A[i]))
    t = r*T[i]
    a = r*A[i]
    print(r,t,a)

print(t+a)

Fixed code:
from math import ceil
from decimal import Decimal

N = int(input())
T,A = [],[]
for i in range(N):
    t,a = map(int,input().split())
    T.append(t)
    A.append(a)

t,a = 1,1
for i in range(N):
    r = Decimal(max(ceil(t/T[i]),ceil(a/A[i])))
    t = r*T[i]
    a = r*A[i]

print(t+a)
Buggy code:
n = int(input())
Ratio = [list(map(int,input().split())) for _ in range(n)]
t,a = Ratio[0][0],Ratio[0][1]

for i in range(1,n):
    x = max((t+Ratio[i][0]-1//Ratio[i][0]),(a+Ratio[i][1]-1)//Ratio[i][1])
    t,a = Ratio[i][0]*x,Ratio[i][1]*x
print(int(t+a))

Fixed code:
n = int(input())
Ratio = [list(map(int,input().split())) for _ in range(n)]
t,a = 1,1

for i in range(n):
    x = max((t+Ratio[i][0]-1)//Ratio[i][0],(a+Ratio[i][1]-1)//Ratio[i][1])
    t,a = Ratio[i][0]*x,Ratio[i][1]*x
print(int(t+a))