AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

-----Constraints-----
 - 1≦N≦1000
 - 1≦T_i,A_i≦1000 (1≦i≦N)
 - T_i and A_i (1≦i≦N) are coprime.
 - It is guaranteed that the correct answer is at most 10^{18}.

-----Input-----
The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N

-----Output-----
Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

-----Sample Input-----
3
2 3
1 1
3 2

-----Sample Output-----
10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Difficulty: introductory

Starter code:

Solutions:
import sys
readline = sys.stdin.readline
def ceil(a, b):
    return -(-a//b)

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 0, 0
    for t, a in inp:
        if t >= scr_t and a >= scr_a:
            scr_t = t
            scr_a = a
        elif t < scr_t and a >= scr_a:
            scr_t = t * ceil(scr_t, t)
            scr_a = scr_t * a // t
        elif a < scr_a and t >= scr_t:
            scr_a = a * ceil(scr_a, a)
            scr_t = scr_a * t // a
        else:
            if t / a >= scr_t / scr_a:
                scr_a = a * ceil(scr_a, a)
                scr_t = scr_a * t // a
            else:
                scr_t = t * ceil(scr_t, t)
                scr_a = scr_t * a // t

    print((scr_t + scr_a))

def __starting_point():
    main()

__starting_point()

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

print(vote_t + vote_a)

import sys

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

    n=int(readline())
    a,b=map(int, readline().rstrip().split())
    for _ in range(n-1):
        x,y=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()
    return

n = int(input())
A, B = 0, 0
for i in range(n):
    x, y = map(int,input().split())
    dx, dy = 1, 1
    if A > x:
        dx = A // x
        if A % x != 0:
            dx += 1
    
    if B > y:
        dy = B // y
        if B % y != 0:
            dy += 1

    a = max(dx, dy)
    A, B = a * x, a * y
print(A + B)

t = 1
a = 1

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

print(t+a)

N = int(input())
Ratio = [tuple(map(int, input().split())) for _ in range(N)]
from math import ceil
Vote = (1, 1)
for t,a in Ratio:
    p = max((t+Vote[0]-1)//t, (a+Vote[1]-1)//a)
    Vote = (p*t, p*a)
print(sum(Vote))

n = int(input())
t_all, a_all = 0, 0
for i in range(n):
    t, a = list(map(int, input().split()))
    if i == 0:
        t_all = t
        a_all = a
    else:
        if t >= t_all and a >= a_all:
            t_all, a_all = t, a
        else:
            diff1, diff2 = 0, 0
            diff1 = t_all // t if t_all % t == 0 else t_all // t + 1
            diff2 = a_all // a if a_all % a == 0 else a_all // a + 1
            max_diff = max(diff1, diff2)
            t_all = t * max_diff
            a_all = a * max_diff
print((t_all + a_all))
        


N = int(input())
TNow,ANow = (int(T) for T in input().split())
for TN in range(1,N):
    TNext,ANext = (int(T) for T in input().split())
    Magn = max(TNow//TNext+(TNow%TNext!=0),ANow//ANext+(ANow%ANext!=0))
    TNow,ANow = TNext*Magn,ANext*Magn
print(TNow+ANow)

import sys
def v():
    N=int(sys.stdin.readline())
    P=[]
    pt,pa=tuple(map(int,sys.stdin.readline().split()))
    res=pt+pa
    for _ in [0]*(N-1):
        xt,xa=tuple(map(int,sys.stdin.readline().split()))
        xs=xt+xa
        kt=pt//xt if pt%xt ==0 else pt//xt+1
        ka=pa//xa if pa%xa ==0 else pa//xa+1
        k=max([kt,ka])
        pt,pa=k*xt,k*xa
        res=pt+pa
    print(res)
def __starting_point():v()

__starting_point()

from decimal import Decimal, ROUND_CEILING

N = int(input())
pairs = (map(Decimal, input().split()) for _ in range(N))

t = Decimal('1')
a = Decimal('1')
ceil = lambda d: d.to_integral_exact(rounding=ROUND_CEILING)

for ti, ai in pairs:
    mul = max(ceil(t / ti), ceil(a / ai))
    t = ti * mul
    a = ai * mul

print(int(t + a))

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def gcd(a,b):
    while b:a,b=b,a%b
    return a

def lcm(a,b):return a*b//gcd(a,b)

def main():
    n=II()
    ta=LLI(n)
    x=y=-1
    for t,a in ta:
        if x==-1:
            x,y=t,a
            continue
        c=max((t+x-1)//t,(a+y-1)//a)
        x=c*t
        y=c*a
    print(x+y)

main()

import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

n = int(input())
tv = av = 1
t = [0]*n; a = [0]*n
for i in range(n):
    t[i], a[i] = imap()
for i in range(n):
    tmp = max(tv//t[i]+(tv%t[i]!=0), av//a[i]+(av%a[i]!=0))
    tv = t[i]*tmp; av=a[i]*tmp
print(tv+av)

T = 1
A = 1

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

print(T+A)

n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max((t+ti-1)//ti, (a+ai-1)//ai)
    t = n*ti
    a = n*ai
print(t+a)

from math import ceil 
N = int(input())
votes = [1,1]
rate = 1
for i in range(N):
    t,a = map(int,input().split())
    rate = max((votes[0] - 1) // t, (votes[1] - 1) // a) + 1
    # if t * rate >= votes[0] and a * rate >= votes[1]:
    votes = [t * rate, a * rate]

print(sum(votes))

n = int(input())
A,B = 0,0
for i in range(n):
    x,y = map(int,input().split())
    t,a = 1,1
    if A > x:
        t = A // x
        if A % x != 0:
            t += 1
    if B > y:
        a = B // y
        if B % y != 0:
            a += 1
    m = max(t,a)
    A = x*m
    B = y*m
print(A+B)

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    t_pev, a_prev = TA[0]
    for i in range(1, n):
        t_now, a_now = TA[i]
        if t_pev <= t_now and a_prev <= a_now:
            t_pev, a_prev = t_now, a_now
        else:
            d = max((t_pev + (t_now - 1)) // t_now, (a_prev + (a_now - 1)) // a_now)
            t_pev, a_prev = t_now * d, a_now * d
    print((t_pev + a_prev))


def __starting_point():
    resolve()

__starting_point()

import math
from fractions import Fraction
n = int(input())
# t0, a0 = map(int, input().split())
anst = 1
ansa = 1
for _ in range(n):
    ti, ai = list(map(int, input().split()))
    anst = ti * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))
    ansa = ai * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))
    # p
    # if math.ceil(anst/ti) < math.ceil(ansa/ai):
    #     # if math.ceil(anst/ti)*ai >= ansa:
    #     #     anst = ti * math.ceil(anst/ti)
    #     #     ansa = ai * math.ceil(anst/ti)
    #     # else:
    #     ansa = ai * math.ceil(ansa/ai)
    #     anst = ti * math.ceil(ansa/ai)
    # else:
    #     # if math.ceil(ansa/ai)*ti >= anst:
    #     #     ansa = ai * math.ceil(ansa/ai)
    #     #     anst = ti * math.ceil(ansa/ai)
    #     # else:
    #     ansa = ai * math.ceil(anst/ti)
    #     anst = ti * math.ceil(anst/ti)
    # # print("anst", anst,"ansa = ", ansa)
        
print((int(anst + ansa)))
    


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for x, y in TA:
	n = max((vote_T+x-1)//x, (vote_A+y-1)//y)
	vote_T = x * n
	vote_A = y * n
print((vote_A + vote_T))


### ----------------
### ここから
### ----------------

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

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


n = int(input())
pt, pa = 0, 0
for _ in range(n):
    t, a = tuple(map(int, input().split()))
    l = 0
    r = 10**18+1
    while (r-l) > 1:
        mid = (l+r)//2
        if (t*mid >= pt and a*mid >= pa):
            r = mid
        else:
            l = mid
    pt, pa = t*r, a*r

print((pt+pa))


import math
N = int(input())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))

T = 1
A = 1
for i in range(N):
    bai = max(-(-T//ls[i][0]),-(-A//ls[i][1]))
    T = bai * ls[i][0]
    A = bai * ls[i][1]
print(T+A)

def cin():
	return list(map(int,input().split()))

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

a = cino()
x,y = 1,1
for _ in range(a):
    p,q = cin()
    k = max((x+p-1)//p,(y+q-1)//q)
    x,y = k*p,k*q
print((x+y))
    


n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  t_rate = (ary[0] - 1) // tmp_ary[0] + 1
  a_rate = (ary[1] - 1) // tmp_ary[1] + 1
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))
print(int(ary[0] + ary[1]))

N=int(input())
takahashi=1
aoki=1
for i in range(N):
  T,A=list(map(int,input().split()))
  n=max((takahashi+T-1)//T,(aoki+A-1)//A)
  takahashi=n*T
  aoki=n*A
print((takahashi+aoki))


import sys
readline = sys.stdin.readline

def ceil(a, b):
    return -(-a//b)

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 1, 1
    for t, a in inp:
        n = max(ceil(scr_t, t), ceil(scr_a, a))
        scr_t = n * t
        scr_a = n * a

    print(scr_t + scr_a)

def __starting_point():
    main()
__starting_point()

N=int(input())

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

N = int(input())
Q = [tuple(map(int, input().split())) for _ in range(N)]
vote = Q[0]  # 初期値はそのまま得票(互いに素)

for p, q in Q[1:]:
    if p == q:
        g = max(vote)
        vote = (g, g)
    # p基準: 現在の得票以上の最小のpの倍数
    p_v0 = ((vote[0] + p - 1) // p) * p
    p_v1 = q * p_v0 // p
    # q基準
    q_v1 = ((vote[1] + q - 1) // q) * q
    q_v0 = p * q_v1 // q
    # 減っていたら除外
    if p_v1 < vote[1]:
        vote = (q_v0, q_v1)
    elif q_v0 < vote[0]:
        vote = (p_v0, p_v1)
    else:
        # どっちもありえるなら小さいほう
        if p_v0 + p_v1 <= q_v0 + q_v1:
            vote = (p_v0, p_v1)
        else:
            vote = (q_v0, q_v1)

ans = sum(vote)
print(ans)

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

n = int(input())
t,a = 1,1
import math
for _ in range(n):
    T,A = map(int,input().split())
    k=(T+t-1)//T
    m=(A+a-1)//A
    x=max(k,m)
    t,a = x*T,x*A
print(t+a)

def ceil(x, y):
    # ceil(x / y)
    return (x + y - 1) // y


def main():
    n = int(input())
    takahashi = 1
    aoki = 1
    for _ in range(n):
        t, a = list(map(int, input().split()))
        diff = max(ceil(takahashi, t), ceil(aoki, a))
        takahashi = t * diff
        aoki = a * diff
    print((takahashi + aoki))


def __starting_point():
    main()

__starting_point()

import math
from fractions import Fraction
from decimal import *
# ex) Fraction(2,6) > 1/3 > 0.33333

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

for _ in range(n - 1):
    tt, aa = list(map(int, input().split()))

    # c = 1
    '''
    if (t >= a):
        c = math.ceil(tt / t)

    else:
        c = math.ceil(aa / a)
    '''
    # c = math.ceil(max(t / tt, a / aa))
    # c = math.ceil(max(Fraction(t + tt - 1, tt), Fraction(a + aa - 1 / aa)))
    c = max(math.ceil(Fraction(t, tt)), math.ceil(Fraction(a, aa)))
    c = max(1, c)

    t = tt * c
    a = aa * c


ans = t + a
print(ans)


from decimal import Decimal,getcontext
from math import ceil

N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(takahashi/Decimal(a)),ceil(aoki/Decimal(b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

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

x, y = 1, 1
for t, a in query:
    if t >= x and a >= y:
        x = t
        y = a
    else:
        if t < x and a < y:
            x = t * max((x + t - 1) // t, (y + a - 1) // a)
            y = a * max((x + t - 1) // t, (y + a - 1) // a)
        elif t < x:
            x = t * ((x + t - 1) // t)
            y = a * ((x + t - 1) // t)
        else:
            x = t * ((y + a - 1) // a)
            y = a * ((y + a - 1) // a)
print(x + y)

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


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

def eceil(x, y):
    return (x+y-1)//y
prev = ballots[0]

for i in range(1,N):
    m,n = ballots[i]
    k = max(eceil(prev[0],m),eceil(prev[1],n))
    tot = k * (m+n)
    prev[0] = tot*m//(m+n)
    prev[1] = tot*n//(m+n)
    #print(m,n,k,tot,prev)
print((sum(prev)))


def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
def lcm(x,y):
    return x*y//gcd(x,y)
N=int(input())
x,y=0,0
for i in range(N):
  p=0
  T,A=map(int,input().split())
  if i==0:
    x,y=T,A
    continue
  if x<=T and y<=A:
    x,y=T,A
  elif x<=T and A<y:
    if y%A!=0:
      p=1
    x=T*(y//A+p)
    y=A*(y//A+p)
  elif T<x and y<=T:
    if x%T!=0:
      p=1
    y=A*(x//T+p)
    x=T*(x//T+p)
  else:
    if (x//T+1)<=(y//A+1):
      if y%A!=0:
        p=1
      x=T*(y//A+p)
      y=A*(y//A+p)
    else:
      if x%T!=0:
        p=1
      y=A*(x//T+p)
      x=T*(x//T+p)
print(x+y)

N = int(input())
T = 1
A = 1
for i in range(N):
    Tk = [0,0]
    Ak = [0,0]
    Tn,An = map(int,input().rstrip().split(" "))
    if T % Tn == 0:
        Tk[0] = T
    else:
        Tk[0] = (T // Tn + 1) * Tn
    Ak[0] = (Tk[0] // Tn) * An
    if Ak[0] < A:
        Ak[0] = 10 ** 18 + 1

    if A % An == 0:
        Ak[1] = A
    else:
        Ak[1] = (A // An + 1) * An
    Tk[1] = (Ak[1] // An) * Tn
    if Tk[1] < T:
        Tk[1] = 10 ** 18 + 1
    
    if Tk[0] + Ak[0] <= Tk[1] + Ak[1]:
        T = Tk[0]
        A = Ak[0]
    else:
        T = Tk[1]
        A = Ak[1]
print(A + T)

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

import math
from fractions import Fraction

N = int(input())
a, b = map(int, input().split())
ret_a = a
ret_b = b
for _ in range(1, N):
    a, b = map(int, input().split())
    x = math.ceil(max(Fraction(ret_a, a), Fraction(ret_b, b)))
    ret_a = a * x
    ret_b = b * x
print(ret_a + ret_b)

n = int(input())
ca, cb = 0, 0
for i in range(n):
    a, b = list(map(int,input().split()))
    x, y = 1, 1
    if ca > a:
        x = ca // a
        if ca % a:
            x += 1
    if cb > b:
        y = cb // b
        if cb % b:
            y += 1
    x = max(x, y)
    ca = a * x
    cb = b * x
print((ca + cb))


#
# abc046 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
2 3
1 1
3 2"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 1
1 1
1 5
1 100"""
        output = """101"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
3 10
48 17
31 199
231 23
3 2"""
        output = """6930"""
        self.assertIO(input, output)


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

    t = R[0][0]
    a = R[0][1]
    for i in range(1, N):
        n = max((t+R[i][0]-1)//R[i][0], (a+R[i][1]-1)//R[i][1])
        t = n*R[i][0]
        a = n*R[i][1]

    print((t+a))


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *TA = list(map(int, read().split()))

    x, y = 1, 1

    for t, a in zip(*[iter(TA)] * 2):
        m1 = (x + t - 1) // t
        m2 = (y + a - 1) // a
        m = max(m1, m2)
        x, y = t * m, a * m

    print((x + y))
    return


def __starting_point():
    main()

__starting_point()

import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

A, B = 1, 1

for i in range(N):
    XA, XB = map(int, input().split())

    if A * XB > XA * B:
        d = (A + XA - 1) // XA
        A, B = d * XA, d * XB
    else:
        d = (B + XB - 1) // XB
        A, B = d * XA, d * XB

print(A + B)

n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
tv,av=1,1
#print('-----')
for t,a in ta:
  i=(t+tv-1)//t
  j=(a+av-1)//a
  k=max(i,j)
  tv=t*k
  av=a*k
print(tv+av)

n = int(input())

p = 1
q = 1
for i in range(n):
  t, a = map(int, input().split())
  f = max((p + t - 1) // t, (q + a - 1) // a)
  p = t * f
  q = a * f
  
print(p+q)

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

N = int(input())

T, A = map(int, input().split())

for i in range(N-1):
  t, a = map(int, input().split())
  da = (a - A%a)%a
  dt = (A + da)*t//a - T
  if dt >= 0:
    A += da
    T += dt
  else:
    i = -(dt // t)
    da += i*a
    dt += i*t
    A += da
    T += dt

print(T + A)

n = int(input())
tvote = 1
avote = 1

for i in range(n):
	t, a = [int(n) for n in input().split()]
	k = (tvote-1)//t + 1
	tnow = t * k
	anow = a * k
	if avote > anow:
		k = (avote-1)//a + 1
		tnow = t * k
		anow = a * k
	tvote = tnow
	avote = anow
	
print(avote+tvote)

n=int(input())
p,q=1,1

for _ in range(n):
    t,a=map(int,input().split())
    #n=1
    #hile p>n*t or q>n*a:
    #    n+=1
    n=max((p+t-1)//t,(q+a-1)//a)
    p,q=n*t,n*a
    #print(n,p,q)

print(p+q)

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for x, y in TA:
	n = max(-(-vote_T // x), -(-vote_A // y))
	vote_T = x * n
	vote_A = y * n
print((vote_A + vote_T))


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

print((t + a))


from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return list(map(int,stdin.readline().split()))

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

    
def solve():
    n=inp()
    a,b=1,1
    for _ in range(n):
        x,y=mp()
        d=max((x+a-1)//x,(y+b-1)//y)
        a=d*x
        b=d*y
    pr(a+b)
for _ in range(1):
    solve()
    


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

print((t + a))


class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))


def __starting_point():
    n = int(input())
    ml = 1
    last = [0,0]
    for i in range(n):
        x = iparse()
        # print(len(x))
        l = (last[0] + x[0] - 1) // x[0]
        r = (last[1] + x[1] - 1) // x[1]
        m = max(l, r)
        if m == 0:
            m = 1
        x[0] *= m
        x[1] *= m
        
        last = x
    print((sum(last)))
    
        
    

__starting_point()

n = int(input())

t0, a0 = 1, 1

for i in range(n):
    t1, a1 = map(int, input().split())
    f0 = t0 // t1
    if t0 % t1 != 0:f0 += 1
    f1 = a0 // a1
    if a0 % a1 != 0:f1 += 1
    f = max(f0, f1)
    t0, a0 = t1*f, a1*f

print(t0 + a0)

N = int(input())
x = 1
y = 1
for i in range(N):
    T, A = list(map(int, input().split()))
    p = (T + x - 1) // T
    q = (A + y - 1) // A
    x = T * max(p, q)
    y = A * max(p, q)
    #print(f"[{x} {y}]")
print((x + y))


n = int(input())
T, A = map(int, input().split())

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

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

for i in range(n-1):
    c,d = map(int,input().split())
    x = -min((-a)//c,(-b)//d)
    a,b = c*x,d*x
print(a + b)

#!/usr/bin/env python3
import math

def main():
    N = int(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))

def __starting_point():
    main()

__starting_point()

n = int(input())
vt, va = 1, 1
for i in range(n):
  t, a = list(map(int, input().split()))
  d = max((t + vt - 1) // t, (a + va - 1) // a)
  vt = d * t
  va = d * a
print((vt + va))


n = int(input())
t = [0]*n
a = [0]*n
for i in range(n): t[i],a[i] = map(int,input().split())
tcnt = t[0]
acnt = a[0]
for i in range(1,n):
    x = max((tcnt+t[i]-1)//t[i],(acnt+a[i]-1)//a[i])
    tcnt = t[i]*x
    acnt = a[i]*x
print(tcnt+acnt)

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

for _ in range(N - 1):
    nt, na = list(map(int, input().split(' ')))
    if nt >= t and na >= a:
        t = nt
        a = na
    else:
        tr = (t + nt - 1) // nt
        ar = (a + na - 1) // na
        r = max(tr, ar)
        t = r * nt
        a = r * na

print((t + a))


n = int(input())
ca, cb = 0, 0
for i in range(n):
    a, b = list(map(int,input().split()))
    x, y = 1, 1
    if ca > a:
        x = ca // a
        if ca % a:
            x += 1
    if cb > b:
        y = cb // b
        if cb % b:
            y += 1
    x = max(x, y)
    ca = a * x
    cb = b * x
print((ca + cb))


def nextpt(ratio1, ratio2, pt):
  if ratio1[0]*ratio2[1]-ratio1[1]*ratio2[0]>0:
    pt[0]=pt[0]+((-1)*pt[0])%ratio2[0]
    pt[1]=pt[0]*ratio2[1]//ratio2[0]
  else:
    pt[1]=pt[1]+((-1)*pt[1])%ratio2[1]
    pt[0]=pt[1]*ratio2[0]//ratio2[1]
  return pt

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

pt=ratios[0]
for i in range(n-1):
  pt=nextpt(ratios[i], ratios[i+1], pt)

print(sum(pt))

from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = 1,1
 
for _ in range(N):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = max((t + T - 1) // T,(a + A - 1) // A)
    t = n*T
    a = n*A
    
print(t+a)

from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())
 
takahashi,aoki = 1,1
 
for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(str(takahashi))/Decimal(a)),ceil(Decimal(str(aoki))/Decimal(b)))
    takahashi = c*a
    aoki = c*b
 
print(takahashi+aoki)

n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  # 桁が大きいとceil, floorでは正しく判定ができない
  t_rate = (ary[0] - 1) // tmp_ary[0] + 1
  a_rate = (ary[1] - 1) // tmp_ary[1] + 1
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))
print(int(ary[0] + ary[1]))

import math

n=int(input())
ans=list(map(int,input().split()))
if n==1:
  print((sum(ans)))
  
else:
  ans1=[]
  ans1.append(ans)
  for i in range(n-1):
    x,y=list(map(int,input().split()))
    p,q=ans1[-1][0],ans1[-1][1]
    if p%x==0:
      p1=p//x
    else:
      p1=p//x+1
    if q%y==0:
      q1=q//y
    else:
      q1=q//y+1
    pq=max(p1,q1)
    r=[x*pq,y*pq]
    ans1.append(r)
    
  print((sum(ans1[-1])))
    


def main():
    N = int(input())
    TA = [list(map(int, input().split(' '))) for _ in range(N)]
    if N == 1:
        print(sum(TA[0]))
        return
    cur_t, cur_a = TA[0]
    for t, a in TA[1:]:
        ratio = max([(cur_t + t - 1) // t, (cur_a + a - 1) // a])
        cur_t, cur_a = ratio * t, ratio * a
    print(cur_t + cur_a)


def __starting_point():
    main()
__starting_point()

def main():
    N = int(input())
    T1, A1 = map(int, input().split())
    for _ in range(N-1):
        T2, A2 = map(int, input().split())
        n = max(-(-T1//T2),-(-A1//A2))
        T1,A1 = T2*n,A2*n
    print(T1 + A1)


def __starting_point():
    main()
__starting_point()

def main():
    from math import ceil
    n = int(input())
    a, b = 1, 1
    for _ in range(n):
        i, j = list(map(int, input().split()))
        x = max((a + i - 1) // i, (b + j - 1) // j)
        a, b = x * i, x * j
    print((a + b))


def __starting_point():
    main()

__starting_point()

from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = [int(x) for x in stdin.readline().rstrip().split()]
 
for _ in range(N-1):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = max((t + T - 1) // T,(a + A - 1) // A)
    t = n*T
    a = n*A
    
print(t+a)

n = int(input())

ra,rb = 1,1
for i in range(n):
  a,b = map(int,input().split())
  n = max((ra+a-1)//a,(rb+b-1)//b)
  ra = a*n
  rb = b*n
    
print(ra+rb)

#!/usr/bin/env python3

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return list(map(int, input().split()))
    def mi_0():  return [int(x)-1 for x in input().split()]
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list([int(x)-1 for x in input().split()])
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        # multiply_rate = max(math.ceil(a / s), math.ceil(b / t))
        multiply_rate = max((a + s - 1) // s, (b + t - 1) // t)
        return (s * multiply_rate, t * multiply_rate)
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 1, 1
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        # print(a, b)
    
    # print('')
    print((a + b))


def __starting_point():
    main()

__starting_point()

import fractions
N=int(input())

vt=va=0
for _ in range(N):
  T,A=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)

n = int(input())
A, B = 0, 0
for i in range(n):
    x, y = map(int,input().split())
    dx, dy = 1, 1
    if A > x:
        dx = A // x
        if A % x != 0:
            dx += 1
    
    if B > y:
        dy = B // y
        if B % y != 0:
            dy += 1
 
    a = max(dx, dy)
    A, B = a * x, a * y
print(A + B)

n = int(input())
t_i,a_i = map(int,input().split())
t = []
a = []
t.append(t_i)
a.append(a_i)
for i in range(1,n):
    t_i,a_i = map(int,input().split())
    t.append(t_i)
    a.append(a_i)
    if t[i-1]>t[i] or a[i-1]>a[i]:
        t_max = t[i-1]//t[i]
        if t[i-1]%t[i]!=0:
            t_max += 1
        a_max = a[i-1]//a[i]
        if a[i-1]%a[i]!=0:
            a_max += 1
        bai = max(t_max,a_max)
        t[i] *= bai
        a[i] *= bai
print(t[-1]+a[-1])

import math

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

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

print((x + y))


from math import gcd

n = int(input())
for i in range(n):
    a, b = list(map(int, input().split()))
    if i == 0:
        pre_a, pre_b = a, b
    if pre_a * b < pre_b * a:
        mul = (pre_b + b - 1) // b
        pre_b = mul * b
        pre_a = pre_b * a // b
    else:
        mul = (pre_a + a - 1) // a
        pre_a = mul * a
        pre_b = pre_a * b // a
    # print(i, pre_a, pre_b)
print((pre_a + pre_b))


N=int(input())
x,y=0,0
for i in range(N):
  p=0
  T,A=map(int,input().split())
  if i==0:
    x,y=T,A
    continue
  if x<=T and y<=A:
    x,y=T,A
  elif x<=T and A<y:
    if y%A!=0:
      p=1
    x=T*(y//A+p)
    y=A*(y//A+p)
  elif T<x and y<=T:
    if x%T!=0:
      p=1
    y=A*(x//T+p)
    x=T*(x//T+p)
  else:
    if (x//T+1)<=(y//A+1):
      if y%A!=0:
        p=1
      x=T*(y//A+p)
      y=A*(y//A+p)
    else:
      if x%T!=0:
        p=1
      y=A*(x//T+p)
      x=T*(x//T+p)
print(x+y)

n=int(input())
anst,ansa=map(int,input().split())
for _ in range(1,n):
    t,a=map(int,input().split())
    if anst>t or ansa>a:
        mul=max(-(-anst//t),-(-ansa//a))
        anst=mul*t
        ansa=mul*a
    else:
        anst=t
        ansa=a
print(anst+ansa)

N=int(input())
A,B=1,1
for i in range(N):
   tmpl=list(map(int,input().split()))
   tmp=max(-1*(-1*A//tmpl[0]),-1*(-1*B//tmpl[1]))
   A,B=tmpl[0]*tmp,tmpl[1]*tmp
print(A+B)

from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(takahashi)/Decimal(a)),ceil(Decimal(aoki)/Decimal(b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

n = int(input())

t1, a1 = list(map(int,input().split()))

for i in range(n-1):
    t,a = list(map(int,input().split()))
    if t1 * a == t * a1:
        pass
    elif t1 * a < t * a1:
        a1 = -(-a1 // a) * a
        t1 = a1 // a * t
    else:
        t1 = -(-t1 // t) * t
        a1 = t1 // t * a

print((a1+t1))


N=int(input())

vt=va=0
for _ in range(N):
  T,A=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)

N = int(input())
T, A = 1, 1
for _ in range(N):
    t, a = map(int,input().split())
    k = max((T - 1) // t + 1, (A - 1) // a + 1)
    T = t * k
    A = a * k
print(A + T)

n = int(input())
t_v = a_v = 1
for _ in range(n):
    t, a = [int(x) for x in input().split()]
    r = max((t_v + t - 1) // t, (a_v + a - 1) // a)
    t_v, a_v = r * t, r * a
print(t_v + a_v)

N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max((takahashi-1)//a+1,(aoki-1)//b+1)
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

n=int(input())
ans_t=1
ans_a=1
for i in range(n):
    t,a=map(int,input().split())
    if t==1:
        k1=ans_t
    else:
    	k1=(ans_t-1)//t+1
    if a==1:
        k2=ans_a
    else:
    	k2=(ans_a-1)//a+1
    k=max(k1,k2)
    ans_t=k*t
    ans_a=k*a
print(ans_t+ans_a)

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    for i in range(n):
        if i==0:
            t,a=map(int,readline().split())
        else:
            t_i,a_i=map(int,readline().split())
            tmp1=(t+t_i-1)//t_i
            tmp2=(a+a_i-1)//a_i
            x=max(tmp1,tmp2)
            t=t_i*x
            a=a_i*x
    
    print(a+t)

def __starting_point():
    main()
__starting_point()

N = int(input())
T, A = map(int, input().split())
for i in range(N-1):
  t, a = map(int, input().split())
  p = (T-1)//t + 1
  q = (A-1)//a + 1
  n = max(p, q)
  T = n*t
  A = n*a
print(T+A)

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

T, A = 0, 0
for t, a in TA:
    if T == 0 and A == 0:
        T = t
        A = a
        continue
    if t == a:
        M = max(T, A)
        T = M
        A = M
    elif t < a:
        n = max((T // t) * t, (A // a) * t)
        while n < T or a * (n // t) < A:
            n += t
        T = n
        A = a * (T // t)
    else:
        n = max((A // a) * a, (T // t) * a)
        while n < A or t * (n // a) < T:
            n += a
        A = n
        T = t * (A // a)
print(A + T)

import math
N = int(input())
ta = [tuple(map(int,input().split())) for _ in range(N)]
left = ta[0][0]
right = ta[0][1]
res = left+right
for t,a in ta[1:]:
    tmp1 = (left+t-1)//t
    tmp2 = (right+a-1)//a
    buff = max(tmp1,tmp2)
    right = buff*a
    left = buff*t
print((int(right+left)))




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