CodeEff/ECCO huggingface dataset:
# Original solution
input0 = int(eval(input()))
input1 = int(eval(input()))
input2 = int(eval(input()))
input3 = int(eval(input()))
input4 = int(eval(input()))
K = int(eval(input()))

list = (input0,input1,input2,input3,input4)
max = max(list)
min = min(list)
fig = max - min

if fig <= K :
    print ("Yay!")
else :
    print (":(")

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))

x =[a,b,c,d,e]

x.sort()
if x[4] - x[0] <= k:
    print("Yay!")
else:
    print(":(")
# Original solution
l = [int(eval(input())) for i in range(6)]

if l[4]-l[0]>l[5]:
    print(":(")
else:
    print("Yay!")

# Optimized solution
l = [int(eval(input())) for i in range(5)]
k = int(eval(input()))
if l[4] - l[0] > k:
    print(":(")
else:
    print("Yay!")
# Original solution
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = int(eval(input()))
k = int(eval(input()))

if e - a <= k:
    print('Yay!')
else:
    print(':(')


# Optimized solution
p = -1
q = 124

for _ in range(5):
    a = int(eval(input()))
    p = max(p, a)
    q = min(q, a)
    
k = int(eval(input()))

if p - q <= k:
    print('Yay!')
else:
    print(':(')
# Original solution
a = [int(eval(input()))for i in range(5)]
k = int(eval(input()))
cnt = 0
for i in a:
    for j in a:
        if abs(i-j) > k:
            print(':(')
            cnt += 1
            break
    else:
        continue
    break
if cnt == 0:
    print('Yay!')

# Optimized solution
a = [int(eval(input()))for i in range(5)]
k = int(eval(input()))
if a[-1] - a[0] > k:
    print(':(')
else:
    print('Yay!')
# Original solution
a=int(eval(input()))
b=int(eval(input()))
c=int(eval(input()))
d=int(eval(input()))
e=int(eval(input()))
k=int(eval(input()))
 
if k< b-a:
  print(":(")
elif k< c-a:
  print(":(")
elif k< d-a:
  print(":(")
elif k< e-a:
  print(":(")
elif k< c-b:
  print(":(")
elif k< d-b:
  print(":(")
elif k< e-b:
  print(":(")
elif k< d-c:
  print(":(")
elif k< e-c:
  print(":(")
elif k< e-d:
  print(":(")
else:
  print("Yay!")

# Optimized solution
a=[int(eval(input())) for _ in range(5)];k=int(eval(input()));print((':(' if max(a)-min(a)>k else 'Yay!'))
# Original solution
mod=10**9+7
def mul(a,b):
    x,y=a,b
    return (x*y)%mod

H,W,K=list(map(int,input().split()))
mod=10**9+7
ans=0
const=1
for i in range(H+W-1,H+W-K,-1):
    const=(const*i)%mod

inv=pow(H+W-1,mod-2,mod)
for i in range(K):
    #ans+=(K-i)*(((H+W)*const)%mod)+(((K-i)*i*const)%mod)*((inv*2*H*W)%mod)
    #ans%=mod
    temp1=mul(mul(H+W,const),K-i)
    ans=(ans+temp1)%mod
    temp2=mul(inv,mul(2*H*W,mul(K-i,mul(i,const))))
    ans=(ans+temp2)%mod
ans+=mul(K,mul(H+W,const))
ans%=mod
print(ans)


# Optimized solution
mod=10**9+7
def mul(a,b):
    x,y=a,b
    return (x*y)%mod

H,W,K=list(map(int,input().split()))
mod=10**9+7
ans=0
const=1
for i in range(H+W-1,H+W-K,-1):
    const=(const*i)%mod

inv=pow(H+W-1,mod-2,mod)
temp1=mul(H+W,mul((K*(K+1)//2)%mod,const))
const=mul(const,inv)
u=(K*(K**2-1))//6
u%=mod
temp2=mul(2*H*W,mul(u,const))
ans=(temp1+temp2)%mod
const=mul(const,H+W-1)
ans+=mul(K,mul(H+W,const))
ans%=mod
print(ans)
# Original solution
mod=10**9+7
def mul(a,b):
    x,y=a,b
    return (x*y)%mod

H,W,K=list(map(int,input().split()))
mod=10**9+7
ans=0
const=1
for i in range(H+W-1,H+W-K,-1):
    const=(const*i)%mod

inv=pow(H+W-1,mod-2,mod)
temp1=mul(H+W,mul((K*(K+1)//2)%mod,const))
const=mul(const,inv)
u=(K*(K**2-1))//6
u%=mod
temp2=mul(2*H*W,mul(u,const))
ans=(temp1+temp2)%mod
const=mul(const,H+W-1)
ans+=mul(K,mul(H+W,const))
ans%=mod
print(ans)


# Optimized solution
H,W,K=list(map(int,input().split()));m=10**9+7;a,c=0,1;H+=W;mul=lambda x,y:(x*y)%m
for i in range(H-1,H-K,-1): c=c*i %m;
v=pow(H-1,m-2,m);temp1=mul(H,mul((K*(K+1)//2)%m,c));c=mul(c,v);u=((K*(K**2-1))//6)%m;temp2=mul(2*(H-W)*W,mul(u,c));c=mul(c,H-1);ans=mul(K,mul(H,c));ans=(ans+temp1+temp2)%m;print(ans)
# Original solution
R, G = (int(eval(input())) for i in range(2))

R += (G - R) * 2

print(R)

# Optimized solution
print((-int(eval(input())) + int(eval(input())) * 2))
# Original solution
import sys

r, g = (int(x) for x in sys.stdin.read().split())
ans = g * 2 - r
print(ans)

# Optimized solution
import sys

r, g = list(map(int, sys.stdin.read().split()))

def main():
    return g * 2 - r

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
r = int(eval(input()))
g = int(eval(input()))
print((2*g - r))

# Optimized solution
def main():
    R = int(eval(input()))
    G = int(eval(input()))
    print((2*G - R))


if __name__ == '__main__':
    main()
# Original solution
print((-int(eval(input())) + int(eval(input())) * 2))


# Optimized solution
current_rating = int(eval(input()))
final_rating = int(eval(input()))
performance = final_rating * 2 - current_rating
print(performance)
# Original solution
print((-int(eval(input()))+2*int(eval(input()))))

# Optimized solution
r=int(eval(input()))
g=int(eval(input()))
print((2*g-r))
# Original solution
r = int(eval(input()))
g = int(eval(input()))
print((g*2 - r))

# Optimized solution
r, g = list(map(int, [eval(input()) for _ in range(2)]))
print((g*2 - r))
# Original solution
r = int(eval(input()))
g = int(eval(input()))
print((g * 2 - r))

# Optimized solution
r = int(eval(input()))
g = int(eval(input()))
print((2 * g - r))
# Original solution
#A:

R =  int(eval(input()))
G = int(eval(input()))

print((2*G-R))


# Optimized solution
R = int(eval(input()))
G = int(eval(input()))
print((G*2 - R))
# Original solution
import sys
for s in sys.stdin:
    n,w,h=list(map(float, s.split(",")))
    bmi=w/h/h
    if bmi>=25: print(int(n))

# Optimized solution
import sys
for s in sys.stdin:
    n,w,h=s.split(",")
    n,w,h=int(n),float(w),float(h)
    bmi=w/h/h
    if bmi>=25: print(n)
# Original solution
import sys
import math

N = int(sys.stdin.readline().strip())

ratios = []
for _ in range(N):
    t, a = list(map(int, sys.stdin.readline().strip().split()))
    ratios.append((t, a))

ans = 0
for i in range(N-1):
    t1, a1 = ratios[i]
    t2, a2 = ratios[i+1]

    # math.ceilが直球だが、精度が悪い？
    # rate = max(math.ceil(t1 / t2), math.ceil(a1 / a2))
    rate = max((t1 - 1) // t2, (a1 - 1) // a2) + 1
    ratios[i+1] = (t2 * rate, a2 * rate)

print((sum(ratios[N-1])))

# Optimized solution
import sys

input = sys.stdin.readline
N = int(eval(input()))

rates = []
for _ in range(N):
    t, a = list(map(int, input().split()))
    rates.append((t, a))

ans = 0
for i in range(N-1):
    t1, a1 = rates[i]
    t2, a2 = rates[i+1]

    rate = max((t1 - 1) // t2, (a1 - 1) // a2) + 1
    rates[i+1] = (t2 * rate, a2 * rate)

print((sum(rates[N-1])))
# Original solution
from fractions import Fraction
import math

N = int(eval(input()))
TA = [tuple(map(int, input().split())) for _ in range(N)]


"""

・Ti, Ai を i回目の二人の得票数の比
・Pti, Pai をi回目の二人の得票数とすると、

Pti : Pai = Ti : Ai なので、　Pti = M * Ti, Pai = M * Ai (M=1,2,3,...)と表せる。

とあらわせる。ここで、
Pti-1 <= Pti
Pai-1 <= Pai
なので、Mは
M >= Pti-1 / Ti
M >= Pai-1 / Ai
の両方を満たすものになり、得票数を最小に保つにはMもなるべく小さくとる
"""
t,a = 0,0
for i in range(N):
    if i == 0:
        t,a = TA[i][0], TA[i][1]

    else:
        M = math.ceil(max(Fraction(t , TA[i][0]), Fraction(a , TA[i][1])))
        t = M * TA[i][0]
        a = M * TA[i][1]


print((t+a))

# Optimized solution


from fractions import Fraction
import math

N = int(eval(input()))
TA = [tuple(map(int, input().split())) for _ in range(N)]

"""
Ti : Ai = t : a の時、整数xを使って、i回目のそれぞれの得票数を、t * x, a * x と表せる。
なので、一回前のそれぞれの得票数がわかっている場合、xの範囲がわかるので、xが最小になるように更新していく
"""


T = 0
A = 0
for i,(t,a) in enumerate(TA):
    if i == 0:
        T = t
        A = a
    else:
        x = math.ceil(max(Fraction(T, t), Fraction(A, a)))
        T = t * x
        A = a * x


print((T+A))
# Original solution
N = int(eval(input()))
A = 1
B = 1
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b:
        A = max(A, B)
        B = max(A, B)
    elif a < b:
        if A%a == 0:
            pass
        else:
            A = (A//a+1)*a
        while (A//a)*b < B:
            A += a
        B = (A//a)*b
    else:
        if B%b == 0:
            pass
        else:
            B = (B//b+1)*b
        while (B//b)*a < A:
            B += b
        A = (B//b)*a
print((A+B))

    

# Optimized solution
N = int(eval(input()))
A = 1
B = 1
for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b:
        A = max(A, B)
        B = max(A, B)
    else:
        if A%a == 0:
            aa = A//a
        else:
            aa = A//a + 1
        if B%b == 0:
            bb = B//b
        else:
            bb = B//b + 1
        tmp = max(aa, bb)
        A = tmp*a
        B = tmp*b

print((A+B))
# Original solution
# -*- coding: utf-8 -*-
import math

N=int(input())

a_num = 1
b_num = 1

for i in range(N):
        ratio_a, ratio_b = list(map(int,input().split()))

        base_n = min(math.floor(a_num / ratio_a), math.floor(b_num / ratio_b))

        while a_num > ratio_a * base_n or b_num > ratio_b * base_n:
                base_n += 1

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print(int(a_num + b_num))

# Optimized solution
# -*- coding: utf-8 -*-

N=int(input())

a_num = 1
b_num = 1

for i in range(N):
        ratio_a, ratio_b = list(map(int,input().split()))

        base_n = max( (a_num - 1) // ratio_a + 1 , (b_num - 1 ) // ratio_b + 1)

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print(int(a_num + b_num))
# Original solution
N = int(eval(input()))
T = []
A = []
for i in range(N):
    t, a = list(map(int, input().split()))
    T.append(t)
    A.append(a)
    
v1 = T[0]
v2 = A[0]

for i in range(1, N):
    n = 1
    if v1<=T[i] and v2<=A[i]:
        v1 = T[i]
        v2 = A[i]
    else:
        while v1>n*T[i] or v2>n*A[i]:
            n += 1
        v1 = T[i]*n
        v2 = A[i]*n

print((v1+v2)) 

# Optimized solution
N = int(eval(input()))
T = []
A = []
for i in range(N):
    t, a = list(map(int, input().split()))
    T.append(t)
    A.append(a)
    
v1 = 1
v2 = 1

for i in range(N):
    n = max((v1+T[i]-1)//T[i],(v2+A[i]-1)//A[i])
    v1 = T[i]*n
    v2 = A[i]*n

print((v1+v2))
# Original solution
n = int(eval(input()))
t,a = list(map(int,input().split()))
nowt = t
nowa = a
for i in range(n-1):
    t , a = list(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))

# Optimized solution
n = int(eval(input()))
t,a = list(map(int,input().split()))
nowt = t
nowa = a
for i in range(n-1):
    t , a = list(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))
# Original solution
N = int(eval(input()))
T = [0]*N
A = [0]*N
for i in range(N):
    T[i],A[i] = list(map(int,input().split()))

def aa(a,t,na,nt):
    c = 1
    while not(a<=na*c and t<=nt*c):
        c += 1
    return (na*c,nt*c)
t = T[0]
a = A[0]
for i in range(N):
    a,t = aa(a,t,A[i],T[i])
print((t+a))


# Optimized solution
N = int(eval(input()))
T = [0]*N
A = [0]*N
for i in range(N):
    T[i],A[i] = list(map(int,input().split()))

def aa(a,t,na,nt):
    c = max( (1+(a-1)//na,1+(t-1)//nt) )
    return (na*c,nt*c)
t = T[0]
a = A[0]
for i in range(N):
    a,t = aa(a,t,A[i],T[i])
print((t+a))
# Original solution
n=int(eval(input()))
ta=[]
t=0
a=0
ans=[[0,0]]
for i in range(n):
    p=[int(j) for j in input().split()]
    t=max(t,p[0])
    a=max(a,p[1])
    i,j=1,1
    while True:
        if p[0]*i>=t and p[1]*j>=a and p[0]*i>=ans[-1][0] and p[1]*j>=ans[-1][1]:
            ans.append([p[0]*i,p[1]*j])
            break
        i+=1
        j+=1

print((sum(ans[-1])))

# Optimized solution
n=int(eval(input()))
ta=[]
t=0
a=0
ans=[[1,1]]
for i in range(n):
    p=[int(j) for j in input().split()]
    i=max(ans[-1][0]//p[0],ans[-1][1]//p[1])
    while True:
        if p[0]*i>=ans[-1][0] and p[1]*i>=ans[-1][1]:
            ans.append([p[0]*i,p[1]*i])
            break
        i+=1

print((sum(ans[-1])))
# Original solution
#!/usr/bin/env python3

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(eval(input()))
    ta = [list(map(int, input().split())) for _ in range(n)]
    ans = sum(ta[0])
    for i in range(1, n):
        si1 = sum(ta[i - 1])
        si = sum(ta[i])
        tmp = si
        while tmp * ta[i][0] // si < ans * ta[i - 1][0] // si1 or tmp * ta[i][1] // si < ans * ta[i - 1][1] // si1:
            tmp += si
        ans = tmp
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


# Optimized solution
#!/usr/bin/env python3

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(eval(input()))
    ta = [list(map(int, input().split())) for _ in range(n)]
    ans = sum(ta[0])
    for i in range(1, n):
        si1 = sum(ta[i - 1])
        si = sum(ta[i])
        cand1 = (ans * ta[i - 1][0] // si1) // ta[i][0] if (ans * ta[i - 1][0] // si1) % ta[i][0] == 0 else (ans * ta[i - 1][0] // si1) // ta[i][0] + 1
        cand2 = (ans * ta[i - 1][1] // si1) // ta[i][1] if (ans * ta[i - 1][1] // si1) % ta[i][1] == 0 else (ans * ta[i - 1][1] // si1) // ta[i][1] + 1
        ans = si * max([cand1, cand2])
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
# Original solution
N = int(eval(input()))

tNow = 1
aNow = 1

for i in range(N) :
    t, a = list(map(int, input().split()))
    n = 1
    while n * t < tNow or n * a < aNow :
        n += 1
    tNow = n * t
    aNow = n * a

print((tNow + aNow))

# Optimized solution
N = int(eval(input()))

tNow = 1
aNow = 1

for i in range(N) :
    t, a = list(map(int, input().split()))

    n = max(-(-tNow // t), -(-aNow // a))

    tNow = n * t
    aNow = n * a

print((tNow + aNow))
# Original solution
N = int(eval(input()))
T = []
A = []
for _ in range(N):
    t, a = list(map(int,input().split()))
    T.append(t)
    A.append(a)

ct = T[0]
ca = A[0]
for i in range(1, N):
    t = T[i]
    a = A[i]
    m = 1
    while (t + a) * m < (ct + ca) or m * t < ct or m * a < ca:
        m += 1
    ct = m * t
    ca = m * a

print((ct+ca))




# Optimized solution
N = int(eval(input()))
T = []
A = []
for _ in range(N):
    t, a = list(map(int,input().split()))
    T.append(t)
    A.append(a)

ans = 1
ct = 1
ca = 1
for t, a in zip(T, A):
    n = max((ct + t - 1) // t, (ca + a - 1) // a)
    ct = n * t
    ca = n * a

print((ct+ca))
# Original solution
n = int(eval(input()))

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

x = ab[0][0]
y = ab[0][1]
j = 1
flg = True
for i in range(1,n):
    xx = ab[i][0]
    yy = ab[i][1]
    while flg:
        if x> j*xx or y > j*yy:
            j +=1
        else:
            x = xx *j
            y = yy *j
            break
    j = 1

print((x+y))

# Optimized solution
n = int(eval(input()))

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

x = ab[0][0]
y = ab[0][1]
j = 1
flg = True
for i in range(1,n):
    xx = ab[i][0]
    yy = ab[i][1]
    j = max(x//xx,y//yy)
    while flg:
        if x> j*xx or y > j*yy:
            j +=1
        else:
            x = xx *j
            y = yy *j
            break

print((x+y))
# Original solution
a = int(eval(input()))
b = [list(map(int, input().split()))for _ in range(a)]
c = []
for i in range(len(b)):
    c.append(b[i].copy())
    if len(c) != 1:
        while True:
            if c[i][0] < c[i-1][0] or c[i][1] < c[i-1][1]:
                c[i][0] = c[i][0] + b[i][0]
                c[i][1] = c[i][1] + b[i][1]
            else:
                break
print((c[len(c)-1][0] + c[len(c)-1][1]))


# Optimized solution
a = int(eval(input()))
b = [list(map(int, input().split()))for _ in range(a)]
c = []
for i in range(len(b)):
    c.append(b[i].copy())
    if len(c) != 1:
        while True:
            if c[i][0] < c[i-1][0] or c[i][1] < c[i-1][1]:
                c[i][0] = b[i][0] * max((c[i-1][0] + b[i][0] - 1) // b[i][0], (c[i-1][1] + b[i][1] - 1) // b[i][1])
                c[i][1] = b[i][1] * max((c[i-1][0] + b[i][0] - 1) // b[i][0], (c[i-1][1] + b[i][1] - 1) // b[i][1])
            else:
                break
print((c[len(c)-1][0] + c[len(c)-1][1]))
# Original solution
a = int(eval(input()))
d = e = 0
for i in range(a):
    b, c = list(map(int, input().split()))
    if i == 0:
        d = b
        e = c
    else:
        f = b
        g = c
        while True:
            if d <= f and e <= g:
                d = f
                e = g
                break
            else:
                f += b
                g += c
print((d + e))


# Optimized solution
a = int(eval(input()))
d = e = 0
for i in range(a):
    b, c = list(map(int, input().split()))
    if i == 0:
        d = b
        e = c
    else:
        if d <= b and e <= c:
            d = b
            e = c
        else:
            h = max((b + d - 1) // b, (c + e - 1) // c)
            d = b * h
            e = c * h
print((d + e))
# Original solution
n=int(eval(input()))
l =1
r=1
for _ in range(n):
    t,a=list(map(int,input().split()))
    l = (l+t-1)//t*t
    r = (r+a-1)//a*a
    l = max(l,r//a*t)
    r = max(r,l//t*a)
print((r+l))

# Optimized solution
l,r=1,1
for _ in range(int(eval(input()))):
    k,t=list(map(int,input().split()))
    gen = max((l+k-1)//k,(r+t-1)//t)
    l,r=gen*k,gen*t
print((l+r))
# Original solution
taka, aoki = 1, 1
for _ in range(int(eval(input()))):
    a, b = list(map(int, input().split()))
    ratio = max(taka//a + [0, 1][taka%a != 0], aoki//b + [0, 1][aoki%b != 0])
    taka = a * ratio
    aoki = b * ratio
print((taka + aoki))

# Optimized solution
taka, aoki = 1, 1
for _ in range(int(eval(input()))):
    a, b = list(map(int, input().split()))
    ratio = max(-(-taka//a), -(-aoki//b))
    taka = ratio * a
    aoki = ratio * b
print((taka + aoki))
# Original solution
T,A=1,1
for _ in range(int(eval(input()))):
    a,b=list(map(int,input().split()))
    r=max(-(-T//a),-(-A//b))
    T,A=r*a,r*b
print((T+A))

# Optimized solution
T,A=1,1
for _ in range(int(eval(input()))):
    a,b=list(map(int,input().split()))
    r=max(-(-T//a),-(-A//b))
    T=r*a
    A=r*b
print((T+A))
# Original solution
import math

N = int(eval(input()))

T,A = list(map(int, input().split()))
rlt = T+A
for _ in range(N-1):
  t,a = list(map(int, input().split()))
  i = math.ceil(rlt/(t+a))
  while i*t < T or i*a < A:
    i += 1
  T = i*t
  A = i*a
  
print((T+A)) 

# Optimized solution
import math

N = int(eval(input()))

T,A = list(map(int, input().split()))
for _ in range(N-1):
  t,a = list(map(int, input().split()))
  if T % t == 0:
    i = T // t
  else:
    i = T // t + 1
  if A % a == 0:
    j = A // a
  else:
    j = A // a + 1
  k = max(i,j)
  T = k*t
  A = k*a
  
print((T+A))
# Original solution
import math
N = int(eval(input()))
T,A = 1,1
for _ in range(N):
    t,a = list(map(int,input().split()))
    k1 = T//t
    if T%t>0:
        k1 += 1
    k2 = A//a
    if A%a>0:
        k2 += 1
    k = max(k1,k2)
    T = k*t
    A = k*a
print((T+A))

# Optimized solution
N = int(eval(input()))
T,A = 1,1
for _ in range(N):
    t,a = list(map(int,input().split()))
    k1 = (T+t-1)//t
    k2 = (A+a-1)//a
    k = max(k1,k2)
    T = k*t
    A = k*a
print((T+A))
# Original solution
n=int(eval(input()))
x,y=1,1
for _ in range(n):
  t,a=list(map(int,input().split()))
  if t>a:
    for i in range(x-x%t,x*1000+1,t):
      if i>=x and i//t*a>=y:break
    x,y=i,i//t*a
  else:
    for i in range(y-y%a,y*1000+1,a):
      if i>=y and i//a*t>=x:break
    x,y=i//a*t,i
print((x+y))

# Optimized solution
n=int(eval(input()))
x,y=1,1
for _ in range(n):
  t,a=list(map(int,input().split()))
  m=max((x+t-1)//t,(y+a-1)//a)
  x,y=m*t,m*a
print((x+y))
# Original solution
import sys


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


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


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


if __name__ == '__main__':
    solve()
# Original solution
n = int(eval(input()))

T = A = 1
for _ in range(n):
    t, a = list(map(int, input().split()))
    total = T+A
    x = -(-total//(a+t))
    x = max(x, -(-T//t))
    x = max(x, -(-A//a))
    T = t*x
    A = a*x

print((T+A))

# Optimized solution
n = int(eval(input()))

T = A = 1
for _ in range(n):
    t, a = list(map(int, input().split()))
    x = max(-(-T//t), -(-A//a))
    T = t*x
    A = a*x

print((T+A))
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N=int(eval(input()))

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

def func1(x, xi):
    if x % xi == 0:
        return x
    else:
        return xi * (x // xi) + xi

for i in range(N):
    ti,ai = list(map(int,input().split()))
    if i == 0:
        t,a = ti,ai
    else:
        t,a = func1(t, ti),func1(a, ai)

        # a is short
        if ti / ai < t / a:
            a = t // ti * ai
        else:
            t = a // ai * ti

    # print("t,a=",t,a)
print((a+t))



# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 解説に従い実装

N=int(eval(input()))

for i in range(N):
    ti,ai = list(map(int,input().split()))
    if i == 0:
        t,a = ti,ai
    else:
        # t <= n * ti and a <= n * ai を満たす最小のnを求める
        n = max((t + ti - 1) // ti, (a + ai - 1) // ai)
        t = n * ti
        a = n * ai

print((a+t))
# Original solution
n = int(eval(input()))
ta = [list(map(int, input().split())) for x in range(n)]


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = 1
    while True:
        ac = a * cnt
        bc = b * cnt
        if limit[0] <= ac and limit[1] <= bc:
            return ac, bc
        cnt += 1


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print((sum(now)))


# Optimized solution
n = int(eval(input()))
ta = [list(map(int, input().split())) for x in range(n)]


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = (limit[0] + a - 1) // a
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc

    cnt = (limit[1] + b - 1) // b
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print((sum(now)))
# Original solution
N = int(eval(input()))
t = a = 0
for i in range(N):
    T,A = list(map(int, input().split()))
    for n in range(1,10**18):
        if t <= T*n and a <= A*n:
            t = T*n
            a = A*n
            break
print((t+a))

# Optimized solution
N = int(eval(input()))
t = a = 1
for i in range(N):
    T, A = list(map(int, input().split()))
    tb = (t + T - 1) // T
    ab = (a + A - 1) // A
    b = max(tb, ab)
    t = T * b
    a = A * b
print((t+a))
# Original solution
n=int(eval(input()))
th,ah=1,1
for i in range(n):
    t,a=list(map(int,input().split()))
    while 1:
        if th*a>ah*t:ah+=1
        elif th*a<ah*t:th+=1
        elif th*a==ah*t:break
print((th+ah))

# Optimized solution
n=int(eval(input()))
th,ah=1,1
for i in range(n):
    t,a=list(map(int,input().split()))
    n=max((th+t-1)//t,(ah+a-1)//a)
    th,ah=n*t,n*a
print((th+ah))