CodeEff/ECCO huggingface dataset:
# Original solution

n = int(eval(input()))
t, a = [0] * n, [0] * n
for i in range(n):
    t[i], a[i] = list(map(int, input().split()))
ans = a[0] + t[0]
j_pre = 1
for i in range(1, n):
    j = 1
    vote = t[i] + a[i]
    while vote * j < ans or (t[i] * j < t[i - 1] * j_pre or a[i] * j < a[i - 1] * j_pre):
        j += 1
    ans = vote * j
    j_pre = j
    #print(t[i] * j, a[i] * j)
    #print(ans)

print(ans)

# Optimized solution

n = int(eval(input()))
t, a = [0] * n, [0] * n
for i in range(n):
    t[i], a[i] = list(map(int, input().split()))
ans = a[0] + t[0]
j_pre = 1
for i in range(1, n):
    j = max(-(-(t[i - 1] * j_pre) // t[i]), -(-(a[i - 1] * j_pre) // a[i]) )
    ans = (t[i] + a[i]) * j
    j_pre = j
    #print(t[i] * j, a[i] * j)
    #print(ans)

print(ans)
# Original solution
n = int(eval(input()))
x = 1
y = 1
for i in range(n):
    t, a = [int(_) for _ in input().split()]
    tt = t
    aa = a
    while tt < x or aa < y:
        tt += t
        aa += a
    x = tt
    y = aa
print((x+y))

# Optimized solution
# import math
n = int(eval(input()))
x = 1
y = 1
for i in range(n):
    t, a = [int(_) for _ in input().split()]
    if x%t == 0:
        kt = x//t
    else:
        kt = x//t + 1
    if y % a == 0:
        ka = y // a
    else:
        ka = y // a + 1

    k = max(kt, ka)
    x = t*k
    y = a*k

print((x+y))
# Original solution
N = int(eval(input()))
T = 0
A = 0
for _ in range(N):
    t, a = list(map(int, input().split()))
    i = 1
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print((T+A))

# Optimized solution
N = int(eval(input()))
T = 0
A = 0
for _ in range(N):
    t, a = list(map(int, input().split()))
    i = max(T//t, A//a, 1)
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print((T+A))
# Original solution
n=int(eval(input()))
for i in range(n):
    if i==0:
        x,y=list(map(int,input().split()))
    else:
        t,a=list(map(int,input().split()))
        v=t
        w=a
        while v<x or w<y:
            v+=t
            w+=a
        x=v
        y=w
print((x+y))
        



# Optimized solution
n=int(eval(input()))
x=1
y=1
for i in range(n):
    t,a=list(map(int,input().split()))
    c=max(-(-x//t),-(-y//a))
    x=t*c
    y=a*c      
print((int(x+y)))
# Original solution
n = int(eval(input()))
t = []
a = []

for i in range(0, n):
    ti, ai = [int(_) for _ in input().split()]
    t.append(ti)
    a.append(ai)

newest_t = t[0]
newest_a = a[0]

for i in range(0, n):
    div_t = newest_t // t[i]
    div_a = newest_a // a[i]

    for j in range(min(div_t, div_a)-1, max(div_t, div_a)+2):
        if j * t[i] >= newest_t and j * a[i] >= newest_a:
            newest_t = j * t[i]
            newest_a = j * a[i]
            break

print((newest_t + newest_a))


# Optimized solution
n = int(eval(input()))
t = []
a = []

for i in range(0, n):
    ti, ai = [int(_) for _ in input().split()]
    t.append(ti)
    a.append(ai)

newest_t = t[0]
newest_a = a[0]

for i in range(0, n):
    div_t = newest_t // t[i]
    div_a = newest_a // a[i]

    for j in range(max(div_t, div_a)-1, max(div_t, div_a)+2):
        if j * t[i] >= newest_t and j * a[i] >= newest_a:
            newest_t = j * t[i]
            newest_a = j * a[i]
            break

print((newest_t + newest_a))
# Original solution
import math
n = int(eval(input()))
ans = 0
pret = 0
prea = 0
for x in range(n):
    t, a = list(map(int, input().split()))
    if ans == 0 : 
        ans = t + a 
        pret = t
        prea = a
    else:
        sum = t + a
        ans = math.ceil(ans / sum) * sum
        while (pret > (ans * t // sum) or prea > (ans * a // sum)):
            ans += sum
        pret = ans * t // sum
        prea = ans * a // sum
print(ans)

# Optimized solution
import math
n = int(eval(input()))
ans = 0
t_1, a_1 = list(map(int, input().split()))
pret = t_1
prea = a_1
for x in range(n - 1):
    t, a = list(map(int, input().split()))
    m = -min(-pret//t,-prea//a)
    pret = m * t
    prea = m * a
print((pret + prea))
# Original solution
n=int(eval(input()))
t=[]
a=[]

for i in range(n):
    ti,ai=list(map(int,input().split()))
    t.append(ti)
    a.append(ai)
    
ti=t[0]
ai=a[0]

for i in range(n-1):
    ta=a[i+1]*t[i+1]
    for ii in range(1,10000000):
        if ta*ii//a[i+1]>=ti and ta*ii//t[i+1]>=ai:
            ti=ta*ii//a[i+1]
            ai=ta*ii//t[i+1]
            break
            
print((ai+ti))

# Optimized solution
icase=0
if icase==0:
    n=int(eval(input()))
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=list(map(int,input().split()))
elif icase==1:
    n=5
    t=[3,48,31,231,3]
    a=[10,17,199,23,2]
    ans=6930

ti=t[0]
ai=a[0]
dt=1
for i in range(n-1):
    if ti/t[i+1]>ai/a[i+1]:
        ii=max((ti-dt)//t[i+1]+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max((ai-dt)//a[i+1]+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print((ai+ti))
# Original solution
n=int(eval(input()))
a=1
b=1
for i in range(n):
    ti,ai=list(map(int,input().split()))
    m=1
    while a>m*ti or b>m*ai:
        m=m+1
#        print(m,a,m*ti,b,m*ai)
#    print(m,a,m*ti,b,m*ai)
    a=m*ti
    b=m*ai
#    print(a,b,m)
print((a+b))    

# Optimized solution
n=int(eval(input()))
a=1
b=1
for i in range(n):
    ti,ai=list(map(int,input().split()))
#    m=max(int((a-1)/ti)+1,int((b-1)/ai)+1)
    m=max(int((a-1)//ti)+1,int((b-1)//ai)+1)
    a=m*ti
    b=m*ai
print((a+b))
# Original solution
N = int(eval(input()))
ratios = [[i for i in map(int,input().split())] for j in range(N)]

ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]

for ratio in ratios:
  
  i = min(ans_a // ratio[0], ans_t // ratio[1])
  
  while True:
    temp_a = ratio[0]*i
    temp_t = ratio[1]*i
    if temp_a >= ans_a and temp_t >= ans_t:
      ans_a = temp_a
      ans_t = temp_t
      break
    i += 1
    
print((ans_a + ans_t))

# Optimized solution
N = int(eval(input()))
ratios = [[i for i in map(int,input().split())] for j in range(N)]

ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]

for ratio in ratios:
  i = max(ans_a // ratio[0], ans_t // ratio[1])
  while True:
    temp_a = ratio[0]*i
    temp_t = ratio[1]*i
    if temp_a >= ans_a and temp_t >= ans_t:
      ans_a = temp_a
      ans_t = temp_t
      break
    i += 1
    
print((ans_a + ans_t))
# Original solution
N = int(eval(input()))
TA = [list(map(int, input().split(" "))) for _ in range(N)]

n_t, n_a = 1, 1
for t, a in TA:
    s, b = 0, 0
    while not (n_t <= s and n_a <= b):
        s += t
        b += a
    n_t, n_a = s, b

print((n_t+n_a))

# Optimized solution
N = int(eval(input()))
TA = [list(map(int, input().split(" "))) for _ in range(N)]

n_t, n_a = 1, 1
for t, a in TA:
    # print(n_t/t, n_a/a)
    v = max(-(-n_t//t), -(-n_a//a))
    n_t, n_a = t*v, a*v

print((n_t+n_a))
# Original solution
N=int(eval(input()))
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1

def UP(V1,V2,R1,R2):
    r1,r2=R1,R2
    while V1>R1 or V2>R2:
        R1+=r1
        R2+=r2
    return [R1,R2]

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

print((Taka+Aoki))

# Optimized solution
N=int(eval(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))
# Original solution
N = int(eval(input()))
TT=0
AA=0
for k in range(N):
    T,A = list(map(int,input().split()))
    k=min(TT//T,AA//A)
    for k in range(100000000000000000):
        k+=1
        if T*k>=TT and A*k>=AA:
            TT=T*k 
            AA=A*k
            break
print((TT+AA))

# Optimized solution
N = int(eval(input()))
TT,AA= list(map(int,input().split()))
for k in range(1,N):
    T,A = list(map(int,input().split()))
    j = max((TT-1+T)//T,(AA-1+A)//A)
    TT = T*j 
    AA = A*j
        
print((TT + AA))
# Original solution
N = int(eval(input()))
a,b = list(map(int,input().split()))
for i in range(N-1):
    aa,bb = list(map(int,input().split()))
    taa,tbb = aa,bb
    while True:
        if aa >= a and bb >=b:
            break
        aa += taa
        bb += tbb
    a,b = aa,bb
print((a+b))


# Optimized solution
N = int(eval(input()))
a,b = 1,1
for i in range(N):
    aa,bb = list(map(int,input().split()))
    k = max((a+aa-1)//aa,(b+bb-1)//bb)
    aa *= k
    bb *= k
    a,b = aa,bb

print((a+b))
# Original solution
from math import ceil
def solve():
    N = int(eval(input()))
    T = []
    A = []
    for _ in range(N):
        t, a = list(map(int,input().split()))
        T.append(t)
        A.append(a)
    
    now_t = T[0]
    now_a = A[0]

    for i in range(1,N):
        j = ceil(now_t / T[i])
        mul_t = T[i] * j
        mul_a = A[i] * j
        while now_t > mul_t or now_a > mul_a:
            j += 1
            mul_t = T[i] * j
            mul_a = A[i] * j
        else:
            now_t = mul_t
            now_a = mul_a
    
    print((now_t + now_a))

if __name__ == '__main__':
    solve()

# Optimized solution
from math import ceil
def solve():
    N = int(eval(input()))
    T = []
    A = []
    for _ in range(N):
        t, a = list(map(int,input().split()))
        T.append(t)
        A.append(a)
    
    now_t = T[0]
    now_a = A[0]

    for i in range(1,N):
        mul = f(now_t,now_a,T[i],A[i])
        now_t = T[i] * mul
        now_a = A[i] * mul
    
    print((now_t + now_a))

def f(now_t, now_a, t, a):
    left = 0
    right = 10 ** 18
    while right - left > 1:
        mid = (right + left) // 2
        if now_t > t * mid or now_a > a * mid:
            left = mid
        else:
            right = mid
    
    return right

if __name__ == '__main__':
    solve()
# Original solution
from math import ceil
def solve():
    N = int(eval(input()))
    T = []
    A = []
    for _ in range(N):
        t, a = list(map(int,input().split()))
        T.append(t)
        A.append(a)
    
    now_t = T[0]
    now_a = A[0]

    for i in range(1,N):
        mul = f(now_t,now_a,T[i],A[i])
        now_t = T[i] * mul
        now_a = A[i] * mul
    
    print((now_t + now_a))

def f(now_t, now_a, t, a):
    left = 0
    right = 10 ** 18
    while right - left > 1:
        mid = (right + left) // 2
        if now_t > t * mid or now_a > a * mid:
            left = mid
        else:
            right = mid
    
    return right

if __name__ == '__main__':
    solve()

# Optimized solution
def solve():
    N = int(eval(input()))

    now_t, now_a = 1,1
    for _ in range(N):
        t, a = list(map(int,input().split()))
        n = max(-(-now_t//t), -(-now_a//a))
        now_t = t * n
        now_a = a * n
    
    print((now_t + now_a))
    
if __name__ == '__main__':
    solve()
# Original solution

import math

def read_input():
    n = int(eval(input()))

    ratios = []
    for i in range(n):
        t, a = list(map(int, input().split()))
        ratios.append((t, a))

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    # cand1
    cand1 = list(ex_votes)
    a = ex_votes[0] % ratio[0]
    if a != 0:
        cand1[0] += ratio[0] - a
    cand1 = (cand1[0], int(cand1[0] / ratio[0] * ratio[1]))

    while not check_votes(ex_votes, cand1):
        cand1 = (cand1[0] + ratio[0], cand1[1] + ratio[1])


    cand2 = list(ex_votes)
    b = ex_votes[1] % ratio[1]
    if b != 0:
        cand2[1] += ratio[1] - b
    cand2 = (int(cand2[1] / ratio[1] * ratio[0]), cand2[1])

    while not check_votes(ex_votes, cand2):
        cand2 = (cand2[0] + ratio[0], cand2[1] + ratio[1])

    if sum(cand1) < sum(cand2):
        return cand1
    else:
        return cand2


def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print((sum(votes)))


if __name__ == '__main__':
    submit()

# Optimized solution
import math


def read_input():
    n = int(eval(input()))

    ratios = []
    for i in range(n):
        t, a = list(map(int, input().split()))
        ratios.append((t, a))

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    def div_ceil(a, b):
        if a % b == 0:
            return a //b
        else:
            return a // b + 1

    base = div_ceil(sum(ex_votes), (ratio[0] + ratio[1]))
    base = int(base)
    while True:
        test_votes = (ratio[0] * base, ratio[1] * base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0]/ratio[0] < diff_votes[1]/ratio[1]:
                base += div_ceil(-diff_votes[0], ratio[0])
            else:
                base += div_ceil(-diff_votes[1], ratio[1])
            base = int(base)


def submit():
    n, ratios = read_input()

    votes = ratios[0]
    for ratio in ratios[1:]:
        votes = get_votes(votes, ratio)

    print((sum(votes)))


if __name__ == '__main__':
    submit()
# Original solution
N=int(eval(input()))
B=[]


for i in range(N):
    a,b, = list(map(int, input().split()))
    B.append([a,b])

a=B[0][0]
b=B[0][1]

for i in range(1,N):
    a1=B[i][0]
    b1=B[i][1]
    if a>B[i][0] or b>B[i][1]:
        while a>a1 or b>b1:
            a1+=B[i][0]
            b1+=B[i][1]
        a=a1
        b=b1
    else:
        a=B[i][0]
        b=B[i][1]
print((a+b))


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

A = 1
B = 1
for _ in range(N):
    x, y = list(map(int, input().split()))
    na = A // x if A % x == 0 else A // x + 1
    nb = B // y if B % y == 0 else B // y + 1
    n = max(na, nb)
    A = n * x
    B = n * y

print((A + B))
# Original solution
n = int(eval(input()))
t = 0
r = 0
for i in range(n):
    a,b = list(map(int,input().split()))
    g = a
    h = b
    while a < t or b < r:
        a += g
        b += h
    t = a
    r = b
print((a + b))

# Optimized solution
n = int(eval(input()))
t = 1; a = 1;
for _ in range(n):
    ti,ai = list(map(int,input().split()))
    if t%ti != 0 : t = (t//ti+1)*ti
    if a%ai != 0 : a = (a//ai+1)*ai
    r = max(t//ti,a//ai)
    t = ti*r
    a = ai*r

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

x = 1
y = 1
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    for j in range(2, 10**18):
        if x <= a and y <= b:
            x = a
            y = b
            break
        else:
            a = ab[i][0] * j
            b = ab[i][1] * j
print((x + y))

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

x = 1
y = 1
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    m = max(-(-x // a), -(-y // b))
    x = m * a
    y = m * b
print((x + y))
# Original solution
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print(("Yes" if b==1 else "No"))
    return

def resolve():
    readline=sys.stdin.readline

    #a,b,c=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    for i in range(n):
        x,y=list(map(int, readline().rstrip().split()))
        if i==0:
            a,b=x,y
            continue
        start=max(a//x,b//y)
        zz=start-1
        for z in range(start,start+1000):
            if x*z>=a and y*z>=b:
                zz=z
                break
        a,b=x*z,y*z
    print((a+b))
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------


# Optimized solution
import sys

def resolve():
    readline=sys.stdin.readline

    n=int(readline())
    a,b=list(map(int, readline().rstrip().split()))
    for _ in range(n-1):
        x,y=list(map(int, readline().rstrip().split()))
        start=max(a//x,b//y)
        for z in range(start,start+1000):
            if x*z>=a and y*z>=b:
                a,b=x*z,y*z
                break
    print((a+b))

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()
# Original solution

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

lcms = TA[0]

for t,a in TA[1:]:
    tmp = [t,a]
    
    while tmp[0] < lcms[0]:
        tmp[0] += t
        tmp[1] += a
    while tmp[1] < lcms[1]:
        tmp[0] += t
        tmp[1] += a
    lcms = tmp

print((sum(lcms)))


# Optimized solution

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

lcms = TA[0]

for t,a in TA[1:]:
    tmp = [t,a]

    
    m1 = (lcms[0]+tmp[0]-1)//tmp[0]
    m2 = (lcms[1]+tmp[1]-1)//tmp[1]
    
    m = max(m1,m2)
    if m != 0:
        tmp[0] *= m
        tmp[1] *= m
    lcms = tmp

print((sum(lcms)))
# Original solution
def ceil(a, b):
  return a // b + (a % b > 0)

N = int(eval(input()))
T = A = 1
for i in range(N):
  t, a = list(map(int, input().split()))
  m = max(ceil(T, t), ceil(A, a))
  T = t * m
  A = a * m
print((T + A))

# Optimized solution
N = int(eval(input()))
T = A = 1
for i in range(N):
  t, a = list(map(int, input().split()))
  m = max(-(-T // t), -(-A // a))
  T = t * m
  A = a * m
print((T + A))
# Original solution
n = int(eval(input()))
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    tt, aa = ti, ai
    while tt < t or aa < a:
        tt += ti
        aa += ai

    t = tt
    a = aa

print((t + a))

# Optimized solution
n = int(eval(input()))
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    mt = t // ti if t % ti == 0 else t // ti + 1
    ma = a // ai if a % ai == 0 else a // ai + 1
    m = max(mt, ma)

    t = m * ti
    a = m * ai

print((t + a))
# Original solution
def ceil(a0,b0):
  if a0%b0 == 0:
    return a0//b0
  else:
    return a0//b0 +1

t_num,a_num = 1,1

n = int(eval(input()))

for i in range(n):
    t,a = list(map(int,input().split()))
    k = max(ceil(t_num,t),ceil(a_num,a))
    #その比に票を合わせる
    t_num = k*t
    a_num = k*a
    #print([t_num,a_num])    

print((t_num + a_num))


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

t = [0 for i in range(n)]
a = [0 for i in range(n)]

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

t_num = t[0]
a_num = a[0]

for i in range(1,n):
    k = max(-(-t_num//t[i]),-(-a_num//a[i]))
    #その比に票を合わせる
    t_num,a_num = k*t[i],k*a[i]

print((t_num + a_num))
# Original solution
N = int(eval(input()))

t, a = list(map(int, input().split()))

for i in range(N - 1):
    nt, na = list(map(int, input().split()))
    pt, pa = nt, na
    while pt < t or pa < a:
        pt += nt
        pa += na
    t = pt
    a = pa
print((t + a))


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

t, a = list(map(int, input().split()))

for i in range(N - 1):
    nt, na = list(map(int, input().split()))
    p = max(t // nt, a // na)
    pt = nt * p
    pa = na * p
    while pt < t or pa < a:
        pt += nt
        pa += na
    t = pt
    a = pa
print((t + a))
# 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()))

x = 1
y = 1
for i in range(N):
    n = 1
    while not (x <= n * T[i] and y <= n * A[i]):
        n += 1
    else:
        x = n * T[i]
        y = n * A[i]
else:
    print((x + y))

# 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()))

x = 1
y = 1
for i in range(N):
    k = max(-(-x // T[i]), -(-y // A[i]))
    x = k * T[i]
    y = k * A[i]
else:
    print((x + y))
# Original solution
n,t,a,*u=list(map(int,open(0).read().split()))
for u,b in zip(u[::2],u[1::2]):
    v,c=u,b
    while v<t or c<a:
        v+=u
        c+=b
    t,a=v,c
print((t+a))

# Optimized solution
n,t,a,*u=list(map(int,open(0).read().split()))
for u,b in zip(u[::2],u[1::2]):
    x=0-min(-t//u,-a//b)
    t,a=u*x,b*x
print((t+a))
# Original solution
import math
from decimal import Decimal
n = int(eval(input()))
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1
ah = 1
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x),math.ceil(ah/y))
     th = Decimal(m*x)
     ah = Decimal(m*y)
     h += 1
print((th+ah))

# Optimized solution
import math
from decimal import Decimal
n = int(eval(input()))
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1
ah = 1
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max((th+x-1)//x, (ah+y-1)//y)
     th = m*x
     ah = m*y
     h += 1
print((th+ah))
# Original solution
n = int(eval(input()))
a,b = list(map(int,input().split()))
for _ in range(n-1):
    c,d = list(map(int,input().split()))
    deltaA = 0
    deltaB = d/c * (a + deltaA) - b 
    #print(deltaA,deltaB)
    while deltaB < 0 or int(deltaB) != deltaB:
        deltaA += 1
        deltaB = d/c * (a + deltaA) - b 
        #print(deltaA,deltaB)
    a += int(deltaA)
    b += int(deltaB)
#print(a,b)
print((a+b))

# Optimized solution
n = int(eval(input()))
a,b = 1,1
for _ in range(n):
    x,y = list(map(int,input().split()))
    k = -min(-a//x,-b//y)
    a = k*x
    b = k*y
print((a+b))
# Original solution
n = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(n)]

PQ = [TA[0]]

for i in range(1, n):
    p0, q0 = PQ[i-1]
    p1, q1 = TA[i]
    t, a = TA[i]
    while p1 < p0 or q1 < q0:
        p1 += t
        q1 += a
    PQ.append([p1, q1])
    
print((sum(PQ[-1])))

# Optimized solution
n = int(eval(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])))
# Original solution
N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N)]

t,a = src[0]
for ti,ai in src[1:]:
    tn = t + (ti - t%ti)%ti
    an = tn // ti * ai
    while an < a:
        tn += ti
        an += ai
    t,a = tn,an
print((t + a))


# Optimized solution
N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N)]

ans_t, ans_a = src[0]
for t,a in src[1:]:
    t1 = ans_t + (t - ans_t%t)%t
    a1 = t1 // t * a
    a2 = ans_a + (a - ans_a%a)%a
    t2 = a2 // a * t
    if a1 < ans_a:
        ans_t, ans_a = t2,a2
    else:
        ans_t, ans_a = t1,a1
print((ans_t + ans_a))
# Original solution
def ceil(x, y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

n = int(eval(input()))
t = a = 1
for i in range(n):
    T, A = list(map(int, input().split()))
    n = max(ceil(t, T), ceil(a, A))
    t = n * T
    a = n * A
print((t + a))

# Optimized solution
n = int(eval(input()))
t = a = 1
for i in range(n):
    T, A = list(map(int, input().split()))
    n = max(-(-t // T), -(-a // A))
    t = n * T
    a = n * A
print((t + a))
# Original solution
from math import ceil


n = int(eval(input()))

votes = [0, 0]

for i in range(n):
    a, b = list(map(int, input().split()))
    if i == 0:
        votes = [a, b]
    else:
        if a == b:
            x = max(votes)
            votes = [x, x]
        else:
            num = min(ceil(votes[0]/a), ceil(votes[1]/b))
            for i in range(num, 10000000):
                x = a * i
                y = b * i
                if x >= votes[0] and y >= votes[1]:
                    votes = [x, y]
                    break

print((sum(votes)))


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

votes = [0, 0]

for i in range(n):
    a, b = list(map(int, input().split()))
    if i == 0:
        votes = [a, b]
    else:
        num = max(-(-votes[0]//a), -(-votes[1]//b))
        x = a * num
        y = b * num
        votes = [x, y]
print((sum(votes)))