CodeEff/ECCO huggingface dataset:
# Original solution
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    #print(x,y,a,b)
    for i in range(max(1,min(floor(x/a),floor(y/b))),max(ceil(x/a),ceil(y/b))+1):
        p,q=a*i,b*i
        if p>=x and q>=y:
            break
    return [p,q]
    #return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
    #for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=pairs[0]
for i in range(n-1):
    u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print((u+v))
    
    
        





# Optimized solution
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def LI2(): return [int(eval(input())) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print(('\n'.join(x)))
def printni(x): print(('\n'.join(list(map(str,x)))))
inf = 10**17
mod = 10**9 + 7

def ceil(x,y):
    return (-1)*((-x)//y)
    
n=I()
pairs=[LI() for i in range(n)]
x,y=1,1
for i in range(n):
    a=pairs[i][0]
    b=pairs[i][1]
    k=max(ceil(x,a),ceil(y,b))
    x,y=a*k,b*k
print((x+y))





'''def pair_revise(x,y,a,b):
    global p
    global q
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return p,q
u,v=1,1
for i in range(n):
    u,v=pair_revise(u,v,pairs[i][0],pairs[i][1])
    print(u,v)
print(u+v)'''
# Original solution
n = int(eval(input()))
ta = []
for i in range(n):
    ta.append([int(i) for i in input().split()])

for i in range(1, n):
    tmp = ta[i][:]
    while ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]:
        ta[i][0] += tmp[0]
        ta[i][1] += tmp[1]

print((ta[-1][0] + ta[-1][1]))


# Optimized solution
def round_up(x, y):
    res = x // y
    if x % y != 0:
        res += 1
    return res

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

for i in range(1, n):
    if ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]:
        multi = max(
            round_up(ta[i-1][0], ta[i][0]),
            round_up(ta[i-1][1], ta[i][1])
        )
        ta[i][0] *= multi
        ta[i][1] *= multi

print((ta[-1][0] + ta[-1][1]))
# 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)

#比に対する掛け率
kake = 1
sum_tmp = 0
t_tmp = 0
a_tmp = 0

for i in range(n):
    kake = 1
    #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する
    while kake*(T[i]+A[i]) < sum_tmp or kake*T[i] < t_tmp or kake*A[i] < a_tmp:
        kake += 1
    
    sum_tmp = kake*(T[i]+A[i])
    t_tmp = kake*T[i]
    a_tmp = kake*A[i]

ans = kake * (T[n-1]+A[n-1])
print(ans)

# Optimized solution
def main():
    n = int(eval(input()))

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

    #比に対する掛け率
    kake = 1
    sum_tmp = 0
    t_tmp = 0
    a_tmp = 0
    for i in range(n):
        if i == 0:
            kake = 1
        else:
            #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する
            if sum_tmp % (T[i]+A[i]) == 0:
                kake_sum = sum_tmp // (T[i]+A[i])
            else:
                kake_sum = sum_tmp // (T[i]+A[i]) + 1
            
            if t_tmp % T[i] == 0:
                kake_t = t_tmp // T[i]
            else:
                kake_t = t_tmp // T[i] + 1
            
            if a_tmp % A[i] == 0:
                kake_a = a_tmp // A[i]
            else:
                kake_a = a_tmp // A[i] + 1
            
            kake = max(kake_sum, kake_t, kake_a)

        sum_tmp = kake*(T[i]+A[i])
        t_tmp = kake*T[i]
        a_tmp = kake*A[i]

    ans = kake * (T[n-1]+A[n-1])
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
t,a=list(map(int,input().split()))
for i in range(1,n):
  c,d=list(map(int,input().split()))
  times=min(t//c,a//d)
  e,f=c*times,d*times
  while(e<t or f<a):
    #print(e,f)
    times+=1
    e,f=c*times,d*times
    #print(e,f)
  t,a=e,f
print((t+a))


# Optimized solution
n=int(eval(input()))
t,a=list(map(int,input().split()))
for i in range(1,n):
  c,d=list(map(int,input().split()))
  if(t/c>a/d):
    if(t%c==0):times=t//c
    else:times=t//c+1
  else:
    if(a%d==0):times=a//d
    else:times=a//d+1
  #print(times)
  t,a=c*times,d*times
  #print(t,a)
print((t+a))
# Original solution
import sys
sys.setrecursionlimit(500000)

def f(a,c,b,d):
    if a >= A and b >=B :
        return a,b
    return f(a+c,c,b+d,d)

n = int(eval(input()))
a = [list(map(int,input().split()))for _ in range(n)]
A,B = a[0][0],a[0][1]
for i in range(1,n):
    A,B = f(a[i][0],a[i][0],a[i][1],a[i][1])
print((A+B))

# Optimized solution
n = int(eval(input()))
a = [list(map(int,input().split()))for _ in range(n)]
A,B = a[0][0],a[0][1]
for i in range(1,n):
    C = max([1,-(-A//a[i][0]),-(-B//a[i][1])])
    A = a[i][0]*C
    B = a[i][1]*C
print((A+B))
# Original solution
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(eval(input()))
x, y = list(map(int, input().split()))
s = x + y
for i in range(N - 1):
    t, a = list(map(int, input().split()))
    if s % (t + a) == 0:
        x2 = t * (s // (t + a))
        y2 = a * (s // (t + a))
        while x2 < x or y2 < y:
            x2 += t
            y2 += a
        x, y = x2, y2
    else:
        s += (t + a) - s % (t + a)
        x2 = t * (s // (t + a))
        y2 = a * (s // (t + a))
        while x2 < x or y2 < y:
            x2 += t
            y2 += a
        x, y = x2, y2
    s = x + y
print(s)


# Optimized solution
N = int(eval(input()))
a, b = 1, 1
for i in range(N):
    x, y = list(map(int, input().split()))
    n = max((a + x - 1) // x, (b + y - 1) // y)
    a = n * x
    b = n * y
print((a + b))
# Original solution
import math
from fractions import Fraction
n = int(eval(input()))

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = list(map(int, input().split()))
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(Fraction(pt[i-1], t), Fraction(pa[i-1], a)))
    pt[i]=tmp*t
    pa[i]=tmp*a

print((int(pt[-1] + pa[-1])))      

# Optimized solution
import math
from fractions import Fraction
N = int(eval(input()))

pt = [0] * N
pa = [0] * N

for i in range(N):
    t, a = list(map(int, input().split()))
    if i == 0:
        pt[i] = t
        pa[i] = a
    else:
        #最小単位というかなんというか
        n = max(math.ceil(Fraction(pt[i-1],t)), math.ceil(Fraction(pa[i-1],a)))
        pt[i] = n*t
        pa[i] = n*a

print((pt[-1]+pa[-1]))
# Original solution
n = int(eval(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):
    count = 1
    while True:
        if Ratio[i][0]*count >= t and Ratio[i][1]*count >= a:
            t,a = Ratio[i][0]*count,Ratio[i][1]*count
            break
        else:
            count += 1

print((t+a))

# Optimized solution
n = int(eval(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)))
# Original solution
n = int(eval(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)))

# Optimized solution
n = int(eval(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)))
# Original solution
from math import ceil

n = int(eval(input()))
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

def calcn(r, x):
    n = 1
    while n * r < x:
        n += 1
    return n

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(calcn(ra, a))
    nt = int(calcn(rt, t))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print((t + a))


# Optimized solution
from math import ceil

n = int(eval(input()))
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

def calcn(r, x):
    n = int(x / r)
    while n * r > x:
        n -= 1
    while n * r < x:
        n += 1
    return n

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(calcn(ra, a))
    nt = int(calcn(rt, t))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print((t + a))
# Original solution
num = int(eval(input()))
arr = [list(map(int, input().split())) for i in range(num)]

ans = [[arr[0][0], arr[0][1]]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    while ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
        ans[i+1][0] += arr[i+1][0]
        ans[i+1][1] += arr[i+1][1]
print((ans[num-1][0] + ans[num-1][1]))

# Optimized solution
def divceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

num = int(eval(input()))
arr = [list(map(int, input().split())) for i in range(num)]
 
t = 1
a = 1
r = 0
for i in range(num):
    r = max(divceil(t, arr[i][0]), divceil(a, arr[i][1]))
    t = arr[i][0] * max(r, 1)
    a = arr[i][1] * max(r, 1)
print((t + a))
# Original solution
#!/usr/bin/env python3
import math

def main():
    N = int(eval(input()))
    T, A = list(map(int, input().split()))
    for _ in range(N-1):
        t, a = list(map(int, input().split()))
        tmpT, tmpA = t,a
        while 1:
            if T <= tmpT and A <= tmpA:
                T,A = tmpT, tmpA
                break
            else:
                tmpT += t
                tmpA += a
    print((T+A))

if __name__ == "__main__":
    main()


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

def main():
    N = int(eval(input()))
    T, A = list(map(int, input().split()))
    for _ in range(N-1):
        t, a = list(map(int, input().split()))
        # 桁が大きいとfloatの誤差が生じて正しく判定できない
        # 負の数にして切り捨てにすればceilと同じ挙動になる
        x = max(-(-T//t), -(-A//a))
        T = t*x
        A = a*x
    print((T+A))

if __name__ == "__main__":
    main()
# Original solution
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    TA = [[int(x) for x in input().split()] for _ in range(N)]

    now = TA[0]
    for t, a in TA[1:]:
        i = 1
        while now[0] > t * i or now[1] > a * i:
            i += 1
        now[0] = t * i
        now[1] = a * i

    print((now[0] + now[1]))


if __name__ == '__main__':
    main()


# Optimized solution
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    TA = [[int(x) for x in input().split()] for _ in range(N)]

    now = TA[0]
    for t, a in TA[1:]:
        i = max(now[0] //t , now[1] // a)
        while now[0] > t * i or now[1] > a * i:
            i += 1
        now[0] = t * i
        now[1] = a * i

    print((now[0] + now[1]))


if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3

n=int(eval(input()))

x,y=list(map(int, input().split()))
for i in range(n-1):
    t,a=list(map(int, input().split()))
    if (x<=t and y<=a):
        x=t
        y=a
    else:
        tmp=1
        while 1:
            if x<=t*tmp and y<=a*tmp:
                x=t*tmp
                y=a*tmp
                break
            tmp+=1
print((x+y))

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

n=int(eval(input()))

x,y=list(map(int, input().split()))
for i in range(n-1):
    t,a=list(map(int, input().split()))
    if (x<=t and y<=a):
        x=t
        y=a
    else:
        tmp=0
        k=max(x//t,y//a)
        tk=t*k
        ak=a*k
        while 1:
#            print(tk+(tmp*t),ak+(tmp*a))
            if x<=tk+(tmp*t) and y<=ak+(tmp*a):
                x=tk+(tmp*t)
                y=ak+(tmp*a)
                break
            tmp+=1
print((x+y))
# Original solution
# -*- coding: utf-8 -*-

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

now = nex = 1
for i in range(0, N - 1):
    nex = 1
    while True:
        if now * rates[i][0] <= nex * rates[i + 1][0] and now * rates[i][1] <= nex * rates[i + 1][1]:
            break
        nex += 1
    now = nex
print(((rates[-1][0] + rates[-1][1]) * nex))

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

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

a, b = 1, 1
n = 1
for i in range(N):
    n = max(-((-a) // rates[i][0]), -((-b) // rates[i][1]))
    a = rates[i][0] * n
    b = rates[i][1] * n
print((a + b))
# Original solution
n=int(eval(input()))
f=lambda:list(map(int,input().split()))
a,b=f()
for _ in range(1,n):
  s,t=f(); x=y=0
  while x<a or y<b: x+=s; y+=t
  a,b=x,y
print((a+b))

# Optimized solution
n=int(eval(input()))
f=lambda:list(map(int,input().split()))
a,b=f()
for _ in range(1,n):
  c,d=f()
  t=max(1,0--a//c,0--b//d)
  a,b=c*t,d*t
print((a+b))
# Original solution
n = int(eval(input()))
a = [tuple(map(int, input().split())) for _ in range(n)]

s, t = a[0][0], a[0][1]

for i in range(1, n):
    if a[i][0] < a[i][1]:
        j = 1
        while True:
            if a[i][0]*j < s or a[i][1]*j < t:
                pass
            else:
                s = a[i][0]*j
                break
            j += 1

        t = j*a[i][1]

    elif a[i][0] > a[i][1]:
        j = 1
        while True:
            if a[i][1]*j < t or a[i][0]*j < s:
                pass
            else:
                t = a[i][1]*j
                break
            j += 1

        s = j*a[i][0]

    else:
        s, t = max(s, t), max(s,t)

print((s+t))



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

s, t = 1, 1
for i in range(0, n):

    j = max((s+a[i][0]-1)//a[i][0], (t+a[i][1]-1)//a[i][1])
    s, t = a[i][0]*j, a[i][1]*j

print((s+t))
# Original solution
import fractions

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 2

for i in range(0, N):
    T_tmp = TA[i][0]
    A_tmp = TA[i][1]
    while T_tmp < T or A_tmp < A:
        T_tmp += TA[i][0]
        A_tmp += TA[i][1]
    T = T_tmp
    A = A_tmp
    ans = T + A

print(ans)


# Optimized solution
import math

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 2

for i in range(0, N):
    #m = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
    m = max(-(-T // TA[i][0]), -(-A // TA[i][1]))
    T = TA[i][0] * m
    A = TA[i][1] * m
    ans = T + A

print(ans)
# Original solution
n = int(eval(input()))

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

for i in range(n-1):
    s,t = list(map(int,input().split()))
    while float(a/b) != float(s/t):
        if float(a/b) > float(s/t):
            b += 1
        elif float(a/b) < float(s/t):
            a += 1

print((a+b))

# Optimized solution
from math import ceil

n = int(eval(input()))
a = 1
b = 1

for i in range(n):
    s,t = list(map(int,input().split()))
    #x = max([ceil(a/s), ceil(b/t)])
    x = max((a+s-1)//s, (b+t-1)//t)

    a = x*s
    b = x*t

print((a+b))
# Original solution
n = int(eval(input()))
mt = 0
ma = 0
for i in range(n):
    t , a = list(map(int, input().split()))
    if t>=mt and a>=ma:
        mt = t
        ma = a
    elif t<mt or a<ma:
        k=1
        while t*k<mt or a*k<ma:
            k+=1
        mt=t*k
        ma=a*k
print((mt+ma))


# Optimized solution
n = int(eval(input()))
mt = 0
ma = 0
for i in range(n):
    t , a = list(map(int, input().split()))
    if t>=mt and a>=ma:
        mt = t
        ma = a
    elif t<mt or a<ma:
        k1 = mt//t
        k2 = ma//a
        k=max(k1,k2)
        while t*k < mt or a*k <ma:
            k+=1
        mt=t*k
        ma=a*k
print((mt+ma))
# Original solution
n = int(eval(input()))
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = min(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print((curr_a + curr_b))


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

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = max(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print((curr_a + curr_b))
# Original solution
n = int(eval(input()))
x = y = 1
for i in range(n):
    t, a = list(map(int, input().split()))
    k = 1
    while True:
        if t*k >= x and a*k >= y:
            x, y = t*k, a*k
            break
        k += 1
print((x+y))

# Optimized solution
n = int(eval(input()))
x = y = 1
for i in range(n):
    t, a = list(map(int, input().split()))
    bx = 1 if x % t else 0
    by = 1 if y % a else 0
    k = max(x//t + bx, y//a + by)
    x, y = t*k, a*k
print((x+y))
# Original solution
n = int(eval(input()))
re_t = 0
re_a = 0
for i in range(n):
    t, a = list(map(int, input().split(' ')))
    n = 1
    while n*t < re_t or n*a < re_a:
        n += 1
    re_t = n * t
    re_a = n * a
print((re_t + re_a))

# Optimized solution
import math
n = int(eval(input()))
a,b = 1,1
for i in range(n):
    x,y = list(map(int, input().split(' ')))
    tmp = max(-(-a//x), -(-b//y))
    a = x * tmp
    b = y * tmp
print((a+b))
# Original solution
N = int(eval(input()))
T = A = 1
for _ in range(N):
    t, a = list(map(int, input().split()))
    k = max([1, T // t + (T % t != 0), A // a + (A % a != 0)])
    T, A = k * t, k * a
print((T + A))

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

# Optimized solution
n = int(eval(input()))
t = 1
a = 1
for i in range(n):
    T, A = list(map(int, input().split()))
    k = max(~-t//T + 1, ~-a//A + 1)
    t = k * T
    a = k * A
print((t + a))
# Original solution
# -*- coding: utf-8 -*-
N = int(eval(input()))
TA = []
for _ in range(N):
    TA.append(list(map(int, input().split())))

t0,a0 = 0,0
hyo = 0
for i in range(N):
    t,a = TA[i]
    if t0 == t and a0 == a:
        pass
    else:
        tmpt,tmpa = t,a
        if t0 > t or a0 > a:
            while t0 > tmpt or a0 > tmpa:
                tmpt += t
                tmpa += a
    t0,a0 = tmpt,tmpa
    # print(tmpt, tmpa)

print((t0+a0))



# Optimized solution
# -*- coding: utf-8 -*-
N = int(eval(input()))
TA = []
for _ in range(N):
    TA.append(list(map(int, input().split())))

t0,a0 = 0,0
for i in range(N):
    t,a = TA[i]
    if t0 == t and a0 == a:
        pass
    else:
        if t0 > t or a0 > a:
            tmp = max([t0//t + min([1, t0 % t]), a0//a + min([1, a0 % a])])
            t0 = t*tmp
            a0 = a*tmp
        else:
            t0 = t
            a0 = a

print((t0+a0))
# Original solution
import fractions
N=int(eval(input()))

vt=va=0
for _ in range(N):
  T,A=list(map(int,input().split()))
  kt=-(-vt//T)
  ka=-(-va//A)
  if kt==0 and ka==0:
    vt=T
    va=A
  else:
    k=max(kt,ka)
    vt=k*T
    va=k*A
  
  #print(vt,va)
  
print((vt+va))

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

vt=va=0
for _ in range(N):
  T,A=list(map(int,input().split()))
  kt=-(-vt//T)
  ka=-(-va//A)
  
  k=max(kt,ka,1)
  vt=k*T
  va=k*A  
  #print(vt,va)
  
print((vt+va))
# Original solution

def func(n,x):
    if n%x!=0:
        return n+(x-n%x)
    else:
        return n
X=[]
n=int(eval(input()))
for i in range(n):
    t,a=list(map(int,input().split()))
    X.append([t,a])

T=X[0][0]
A=X[0][1]

for i in range(1,n):
    if T<=X[i][0] and A<=X[i][1]:
        T=X[i][0]
        A=X[i][1]
    elif T>X[i][0] and A<=X[i][1]:
        T=func(T,X[i][0])
        A=T*X[i][1]//X[i][0]
    elif T<=X[i][0] and A>X[i][0]:
        A=func(A,X[i][1])
        T=A*X[i][0]//X[i][1]
    else:
        T=func(T,X[i][0])
        A=func(A,X[i][1])
        if T>A*X[i][0]//X[i][1]:
            A=T*X[i][1]//X[i][0]
        else:
            T=A*X[i][0]//X[i][1]
print((T+A))

# Optimized solution
X=[]
n=int(eval(input()))
for i in range(n):
    t,a=list(map(int,input().split()))
    X.append([t,a])

T=X[0][0]
A=X[0][1]

for i in range(1,n):
    N=max(-(-T//X[i][0]),-(-A//X[i][1]))
    T=X[i][0]*N
    A=X[i][1]*N
print((T+A))
# Original solution
import math
import fractions

N=int(eval(input()))
t,a=1,1
for i in range(N):
    T,A=list(map(int,input().split()))
    Te,Ae=T,A
    if t>T or a>A:
        T,A=T*math.ceil((t+a)/(T+A)),A*math.ceil((t+a)/(T+A))
        while t>T or a>A:
            T+=Te
            A+=Ae
    t,a=T,A

print((t+a))


# Optimized solution
import fractions

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

T = A = 0
for t, a in TA:
  _t, _a = t, a
  while t<T or a<A:
    t += _t; a += _a
  T = t; A = a
print((T+A))

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

T = A = 1
for t, a in TA:
  r = max(A//a, T//t)
  if r*a >= A and r*t >= T:
    A = r*a; T = r*t
  else:
    A = (r+1)*a; T = (r+1)*t

print((T+A))
# Original solution
import math
from decimal import Decimal
n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m0 = math.ceil(Decimal(a[k-1][0])/Decimal(a[k][0]))
        m1 = math.ceil(Decimal(a[k-1][1])/Decimal(a[k][1]))
        m = max(m0, m1)
        a[k] = [m*a[k][0], m*a[k][1]]
print((sum(a[n-1])))


# Optimized solution
from math import ceil
from decimal import Decimal as Deci
n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m0 = ceil(Deci(a[k-1][0])/Deci(a[k][0]))
        m1 = ceil(Deci(a[k-1][1])/Deci(a[k][1]))
        m = max(m0, m1)
        a[k] = [m*a[k][0], m*a[k][1]]
print((sum(a[n-1])))