Problem:
 Score : 300 points    Problem Statement 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 1 3
2 3
1 1
3 2      Sample Output 1 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.       Sample Input 2 4
1 1
1 1
1 5
1 100      Sample Output 2 101  It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.       Sample Input 3 5
3 10
48 17
31 199
231 23
3 2      Sample Output 3 6930

Solution (Python):
def cin():
	return 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)

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

t = 1
a = 1

for i in range(N):
    T, A = TA[i]
    if t > T or a > A:
        tmul = (t+T-1) // T
        amul = (a+A-1) // A
        mul = max(tmul, amul)
        T *= mul
        A *= mul
    t = T
    a = A
print(t+a)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
n=int(input())
t_prev,a_prev=map(int,input().split())
for i in range(n-1):
  t,a=map(int,input().split())
  k=max(t_prev//t+min(1,t_prev%t),a_prev//a+min(1,a_prev%a))
  t_prev,a_prev=t*k,a*k
    
print(t_prev+a_prev)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
n = int(input())
t, a = map(int, input().split())
for i in range(n - 1):
    r1, r2 = map(int, input().split())
    if r1 >= t and r2 >= a:
        multiple = 1
    elif r1 < t and r2 >= a:
        multiple = (t-1) // r1 + 1
    elif r1 >= t and r2 < a:
        multiple = (a-1) // r2 + 1
    else:
        multiple = max((t-1) // r1, (a-1) // r2) + 1
    t, a = r1 * multiple, r2 * multiple
print(t+a)

Solution (Python):
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)

if __name__ == '__main__':
    main()

Solution (Python):
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)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline
from math import floor, ceil

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((scr_t//t)+(scr_t%t!=0), (scr_a//a)+(scr_a%a!=0))
        scr_t = n * t
        scr_a = n * a

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
x, y = 1, 1

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

    l = -(-x // t)
    r = -(-y // a)
    if l > r:
        x = t * l
        y = a * l
    else:
        x = t * r
        y = a * r

    

print(x + y)

Solution (Python):
n = int(input())
mt = 0
ma = 0
for i in range(n):
    t , a = 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)

Solution (Python):
import math
def resolve():
    N = int(input())
    TA = [list(map(int, input().split())) for i in range(N)]
    t, a = TA[0]
    for i in range(1, len(TA)):
        t_next, a_next = TA[i]
        div = max((t//t_next)+(t%t_next!=0), (a//a_next)+(a%a_next!=0))
        t = t_next*div
        a = a_next*div
    print(t+a)


if '__main__' == __name__:
    resolve()

Solution (Python):

def resolve():
	n = int(input())
	v = []
	for _ in range(n):
		v.append(list(map(int, input().split())))
	t, a = 1, 1
	for i in range(n):
		tv, av = v[i]
		c = max(t//tv + (t%tv!=0), a//av + (a%av!=0))
		t, a = c*tv, c*av
	print(t+a)
resolve()

Solution (Python):
n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
  if (ta[i-1][0]<=ta[i][0]) and (ta[i-1][1]<=ta[i][1]):
    pass
  else:
    l=ta[i-1][0]//ta[i][0]
    if ta[i-1][0]%ta[i][0]!=0:
      l+=1
    r=ta[i-1][1]//ta[i][1]
    if ta[i-1][1]%ta[i][1]!=0:
      r+=1
    ta[i][0]*=max(l,r)
    ta[i][1]*=max(l,r)
print(sum(ta[-1]))

Solution (Python):
n=int(input())
t,a=[0]*n,[0]*n
for i in range(n):
  t[i],a[i]=map(int,input().split())
tt,aa=t[0],a[0]
for i in range(1,n):
  tt=t[i]*max((tt+t[i]-1)//t[i],(aa+a[i]-1)//a[i])
  aa=a[i]*max((tt+t[i]-1)//t[i],(aa+a[i]-1)//a[i])
print(aa+tt)

Solution (Python):
ma = lambda : map(int,input().split())
ni = lambda :int(input())

n = ni()
pt,pa = ma()
for i in range(n-1):
    t,a = ma()
    l = max((pt+t-1)//t,(pa+a-1)//a)
    pt = t*l
    pa = a*l
print(pt+pa)

Solution (Python):
N = int(input())
A, B = map(int, input().split())

for _ in range(N-1):
  T, S = map(int, input().split())
  x = max((A+T-1)//T, (B+S-1)//S)
  A = x*T
  B = x*S

print(A+B)

Solution (Python):
N = int(input())
T =[0]*N
A =[0]*N
Cnt=[1]*N
Cnt_pre =1
for i in range(N):
	T[i],A[i] = map(int,input().split())

for i in range(1,N):
	Cnt_pre = Cnt[i-1]
	if T[i]<T[i-1]*Cnt_pre:
		if (T[i-1]*Cnt_pre)%T[i]==0:
			Cnt[i] = (T[i-1]*Cnt_pre)//T[i]
		else:Cnt[i]= (T[i-1]*Cnt_pre)//T[i] + 1
	if A[i]*Cnt[i]<A[i-1]*Cnt_pre:
		if (A[i-1]*Cnt_pre)%A[i]==0:
			Cnt[i]=(A[i-1]*Cnt_pre)//A[i]
		else:Cnt[i]=(A[i-1]*Cnt_pre)//A[i]+1
print(Cnt[N-1]*(T[N-1]+A[N-1]))

Solution (Python):

n = int(input())
t, a = [0] * n, [0] * n
for i in range(n):
    t[i], a[i] = 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(ans)

Solution (Python):
def main():
    N = int(input())
    TA = [[int(_) for _ in input().split()] for __ in range(N)]
    x, y = TA[0] 
    for i in range(1, N):
        T, A = TA[i]
        if x%T != 0:
            x += T - x%T
        if A * x // T < y:
            if y%A != 0:
                y += A - y%A
            x = T * y // A
        else:
            y = A * x // T
    print(x+y)
    return

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
t, a = map(int, input().split())
for i in range(1, n):
    x, y = map(int, input().split())
    i = max(t // x, a // y)
    c, d = x, y
    while c < t or d< a:
        c = x * i
        d = y * i
        i += 1
    t, a = c, d
print(t + a)

Solution (Python):
n = int(input())
t = []
a = []
for i in range(n):
    t_i, a_i = map(int, input().split())
    t.append(t_i)
    a.append(a_i)

vt = t[0]
va = a[0]

for i in range(n):
    if (vt * a[i] == va * t[i]):
        continue
    
    if(vt * a[i] < va * t[i]):
        x = (va + a[i] - 1)//a[i]
    elif (vt * a[i] > va * t[i]):
        x = (vt + t[i] - 1)//t[i]
    vt = x * t[i]
    va = x * a[i]

ans = vt + va
print(ans)

Solution (Python):
n=int(input())
tv=1
av=1
for i in range(n):
    ti,ai=map(int,input().split())
    m=max(int((tv-1)//ti)+1,int((av-1)//ai)+1)
    tv=m*ti
    av=m*ai
print(tv+av)

Solution (Python):
n = int(input())

t_vote = 1
a_vote = 1

for _ in range(n):
    t,a = map(int,input().split())
    if t_vote*a > a_vote*t:
        t_vote = (t_vote + t-1)//t*t
        a_vote = t_vote//t*a
    else:
        a_vote = (a_vote + a-1)//a*a
        t_vote = a_vote//a*t
print(t_vote+a_vote)

Solution (Python):
N = int(input())

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

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

Solution (Python):
N = int(input())

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

for i in range(N - 1):
    nt, na = 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)

Solution (Python):
n=int(input())
a=1
b=1
for i in range(n):
    ti,ai=map(int,input().split())

    m=max(int((a-1)//ti)+1,int((b-1)//ai)+1)
    a=m*ti
    b=m*ai
print(a+b)

Solution (Python):
n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
    a,b = map(int,input().split())
    aa = 0
    bb = 0
    if A % a == 0:
        aa = A // a
    else:
        aa = A // a + 1
    if B % b == 0:
        bb = B // b
    else:
        bb = B // b + 1
    m = max(aa, bb)
    A,B = a * m, b * m
print(A+B)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()

a,b = 1,1

for i in range(n):
    x,y = m()
    po = max(-(-a//x),-(-b//y))
    a = po*x
    b = po*y

print(a+b)

Solution (Python):




def main():
    N = int(input())
    T, A = 1, 1

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


if __name__ == "__main__":
    main()

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools


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

A, B = 1, 1
for x,y in L:
    n = max(0-(-A//x), 0-(-B//y))
    A, B = n*x, n*y

print(A+B)

Solution (Python):
n=int(input())
A=[1,1]
for i in range(n):
  t,a=map(int,input().split())
  tt=(A[0]+t-1)//t
  aa=(A[1]+a-1)//a
  A[0]=max(tt,aa)*t
  A[1]=max(tt,aa)*a
print(A[0]+A[1])

Solution (Python):
import io
import math

data = int(input())
nim,mike = 1,1
for _ in range(data):
  n,m = [int(_) for _ in input().split(" ")]
  l = max(-(-nim//n), -(-mike//m))
  nim,mike = l*n,l*m
print(nim+mike)

Solution (Python):
n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = 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))

Solution (Python):
N = int(input())
TA = [[int(i) for i in input().split()] for _ in range(N)]
ans = [i for i in TA[0]]
for ta in TA[1:]:
    t, a = ta
    if t == a == 1:
        m = max(ans)
        ans = [m, m]
        continue
    si = 0
    sn = t
    ln = a
    if t > a:
        si = 1
        sn = a
        ln = t
    if ans[si] % sn:
        ans[si] = ans[si] // sn * sn + sn
    n = ans[si] // sn * ln
    if ans[si ^ 1] <= n:
        ans[si ^ 1] = n
    else:
        if ans[si ^ 1] % ln:
            ans[si ^ 1] = ans[si ^ 1] // ln * ln + ln
        ans[si] = ans[si ^ 1] // ln * sn
print(sum(ans))

Solution (Python):
N=int(input())
table=[[int(i) for i in input().split()] for j in range(0,N)]

for i in range(0,N-1):
    a=table[i][0]//table[i+1][0]
    A=table[i][0]%table[i+1][0]
    b=table[i][1]//table[i+1][1]
    B=table[i][1]%table[i+1][1]
    if a>b and A==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a>b and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a<b and B==0:
        table[i+1][0]=b*table[i+1][0]
        table[i+1][1]=b*table[i+1][1]
    elif a<b and not B==0:
        table[i+1][0]=(b+1)*table[i+1][0]
        table[i+1][1]=(b+1)*table[i+1][1]
    elif a==b and A==0 and B==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a==b and not A==0 and B==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==b and not B==0 and A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==b and not B==0 and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]

print(table[N-1][0]+table[N-1][1])

Solution (Python):
n = int(input())

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

a = tlist[0][0]
b = tlist[0][1]

for t in tlist:
    multi = max((a//t[0]) + (a%t[0] > 0), (b//t[1]) + (b%t[1] > 0))
    
    
    a = t[0]*multi
    b = t[1]*multi

print(a + b)

Solution (Python):
import math

def solve(ratio_list):
  a = 0
  b = 0
  for p, q in ratio_list:
    if a == 0 and b == 0:
      a = p
      b = q
    else:
      fact1 = -(-a//p)
      fact2 = -(-b//q)
      factor = int(max(fact1, fact2))
      a = factor*p
      b = factor*q
  return a,b


if __name__ == "__main__":
  n = int(input())
  ratio = [tuple(map(int, input().split())) for _ in range(n)]
  a,b = solve(ratio)
  print(a+b)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    at = [list(map(int, input().split())) for _ in range(n)]
    x, y = at[0]
    for i in range(1, n):
        nx, ny = at[i]
        if nx >= x and ny >= y:
            x = nx
            y = ny
        else:
            a = max((x+nx-1)//nx, (y+ny-1)//ny)
            x = nx * a
            y = ny * a
    print(x+y)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
res = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(n, 2)

def main():
  for i in range(n - 1):
    res[i+1] *= ((res[i] + res[i+1] - 1) // res[i+1]).max()
  print(res[n-1].sum())
  
if __name__ ==  '__main__':
  main()

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


x, y = 0, 0
n = int(input())
for i in range(n):
    t, a = map(int, input().split())
    if i == 0:
        x = t
        y = a
        continue
    b = -(-x // t)
    c = -(-y // a)
    d = max(b, c)
    x = t * d
    y = a * d
print(x + y)

Solution (Python):
N = int(input())
li = []
for i in range(N):
  li.append(list(map(int, input().split())))

HYOU = li[0]

def f(a, b):
  syou = b // a
  amari = b % a
  if amari == 0:
    c = syou
  else:
    c = syou + 1
  return c

for i in range(N-1):
  if li[i][0] <= li[i+1][0] and li[i][1] <= li[i+1][1]:
    HYOU = li[i+1]

  elif li[i][0] <= li[i+1][0] and li[i][1] > li[i+1][1]:
    c = f(li[i+1][1], li[i][1])
    li[i+1] = [li[i+1][0]*c, li[i+1][1]*c]
    HYOU = li[i+1]


  elif li[i][0] > li[i+1][0] and li[i][1] <= li[i+1][1]:
    c = f(li[i+1][0], li[i][0])
    li[i+1] = [li[i+1][0]*c, li[i+1][1]*c]
    HYOU = li[i+1]

  else:
    c1 = f(li[i+1][1], li[i][1])

    hyou1 = [li[i+1][0]*c1, li[i+1][1]*c1]

    c2 = f(li[i+1][0], li[i][0])

    hyou2 = [li[i+1][0]*c2, li[i+1][1]*c2]

    if hyou1[0] <= hyou2[0] and hyou1[0] >= li[i][0] and hyou1[1] >= li[i][1]:
      li[i+1] = hyou1
      HYOU = li[i+1]

    elif hyou2[0] <= hyou1[0] and hyou2[0] >= li[i][0] and hyou2[1] >= li[i][1]: 
      li[i+1] = hyou2
      HYOU = li[i+1]

    elif hyou1[0] > hyou2[0] and hyou1[0] >= li[i][0] and hyou1[1] >= li[i][1]:
      li[i+1] = hyou1
      HYOU = li[i+1]

    elif hyou2[0] > hyou1[0] and hyou2[0] >= li[i][0] and hyou2[1] >= li[i][1]: 
      li[i+1] = hyou2
      HYOU = li[i+1]



print(sum(HYOU))

Solution (Python):
a=b=1
for _ in range(int(input())):
  c,d=map(int,input().split())
  m=max(0--a//c,0--b//d)
  a,b=c*m,d*m
print(a+b)

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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

def main():
  import math
  from fractions import Fraction
  n = int(input())
  x = [1,1]
  for i in range(n):
    au,bu = x
    a,b = [int(i) for i in input().split()]
    
    nya = math.ceil(max(Fraction(au,a),Fraction(bu,b)))
    x = [nya*a, nya*b]
  print(int(sum(x)))
if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
TA = []
 
for _ in range(N):
    TA.append([int(x) for x in input().split()])
 
x, y = TA[0]
 
for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x // X + (x % X != 0), y // Y + (y % Y != 0))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    
 
print(x + y)

Solution (Python):
icase=0
if icase==0:
    n=int(input())
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=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)

Solution (Python):

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

Solution (Python):
X=[]
n=int(input())
for i in range(n):
    t,a=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)

Solution (Python):

def func(n,x):
    if n%x!=0:
        return n+(x-n%x)
    else:
        return n
X=[]
n=int(input())
for i in range(n):
    t,a=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)

Solution (Python):
import math




n = int(input())

tall = 1
aall = 1
for idx1 in range(n):
    t, a = map(int, input().split())
    
    mul = max(-(-tall // t), -(-aall // a))
    tall, aall = t * mul, a * mul
    

print(tall + aall)

Solution (Python):
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(max(t[i-1]//t[i], a[i-1]//a[i]), 10**18):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
    print(t[n-1]+a[n-1])

Solution (Python):
N = int(input())

tak = 1
aok = 1

for _ in range(N):
    t, a = map(int, input().split())
    d = max(-(-aok // a), -(-tak // t))
    tak, aok = t * d, a * d

print(tak + aok)

Solution (Python):
N = int(input())
T, A = [0]*N, [0]*N

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

Solution (Python):
N=int(input())
T=[]
A=[]
for i in range(N):
  t,a=map(int,input().split())
  T.append(t)
  A.append(a)
a=1
b=1
for i in range(N):
  n=max((a+T[i]-1)//T[i], (b+A[i]-1)//A[i])
  a=n*T[i]
  b=n*A[i]
print(a+b)

Solution (Python):
N = int(input())

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

Solution (Python):
import math
n = int(input())
T = [0]*n
A = [0]*n
for i in range(n):
    T[i], A[i] = map(int,input().split())

a = 1
b = 1
for ti, ai in zip(T,A):
    
    n = max((a+ti-1)//ti,(b+ai-1)//ai)
    a = n*ti
    b = n*ai
    
print(a+b)

Solution (Python):
n = int(input())
t = 1
a = 1
for i in range(n):
    next_t, next_a = map(int, input().split())
    kake_t = (t + next_t - 1) // next_t
    kake_a = (a + next_a - 1) // next_a
    kake = max(kake_t, kake_a)
    t = next_t * kake
    a = next_a * kake
print(int(a + t))

Solution (Python):
a=b=1
for _ in range(int(input())):
  c,d=map(int,input().split())
  m=max(0--a//c,0--b//d)
  a,b=c*m,d*m
print(a+b)

Solution (Python):
n=int(input())
f=lambda: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)

Solution (Python):
N=int(input())
T=1
A=1
for i in range(N):
    x,y=map(int,input().split())
    d1=1
    d2=1
    if T>x:
        d1=(T-1)//x+1
    if A>y:
        d2=(A-1)//y+1
    T=max(d1,d2)*x
    A=max(d1,d2)*y

print(T+A)

Solution (Python):
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
pt, pa = 1, 1
for i in range(n):
    t, a = ta[i]
    v = max((pt + t - 1) // t, (pa + a - 1) // a)
    pt = v * t
    pa = v * a

print(pt + pa)

Solution (Python):
n=int(input())
t=[0]*n
a=[0]*n
for i in range(n):
    t[i],a[i]=map(int,input().split())
curt=t[0]
cura=a[0]
for i in range(1,n):
    if t[i]>=curt and a[i]>=cura:
        curt=t[i]
        cura=a[i]
    else:
        kt=curt//t[i]
        if curt%t[i]:
            kt+=1
        ka=cura//a[i]
        if cura%a[i]:
            ka+=1

        k=max(kt,ka)
        curt=t[i]*k
        cura=a[i]*k
print(curt+cura)

Solution (Python):
N = int(input())


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


T, A = 1, 1
for _ in range(N):
    Tt, At = map(int, input().split())
    x = max(ceil(T , Tt), ceil(A , At))
    T, A = Tt * x, At * x
print(T + A)

Solution (Python):
t = int(input())
par = [0, 0]
for i in range(t):
	p, t = map(int, input().split())
	if p >= par[0] and t >= par[1]:
		par = [p, t]
	else:
		n = max((par[0]-1)//p + 1, (par[1]-1)//t +1)
		par = [p*n, t*n]
print(sum(par))

Solution (Python):
from decimal import Decimal
from math import ceil

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

t_voted = a_voted = 1
for t, a in ratio:
    val = max(ceil(Decimal(t_voted) / Decimal(t)), ceil(Decimal(a_voted) / Decimal(a)))
    t_voted = t * val
    a_voted = a * val

print(t_voted + a_voted)

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

Solution (Python):
from sys import stdin
from operator import itemgetter


N = int(stdin.readline().rstrip())
hyo = [0,0]
ans = [0,0]

for i in range(N):
    hyo[0],hyo[1] = [int(x) for x in stdin.readline().rstrip().split()]

    if ans[0]<=hyo[0] and ans[1]<=hyo[1]:
        ans[0] = hyo[0]
        ans[1] = hyo[1]
    elif ans[0]>hyo[0] and ans[1]>hyo[1]:
        if ans[0]%hyo[0] == 0:
            which1 = ans[0]//hyo[0]
        else:
            which1 = ans[0]//hyo[0]+1
        if ans[1]%hyo[1] == 0:
            which2 = ans[1]//hyo[1]
        else:
            which2 = ans[1]//hyo[1]+1
        if which1 >= which2:
            which = which1
        else:
            which = which2
        ans[0] = hyo[0] * which
        ans[1] = hyo[1] * which
    elif ans[0]>hyo[0]:
        left = ans[0]//hyo[0]
        if ans[0]%hyo[0] == 0:
            ans[0] = hyo[0]*left
            ans[1] = hyo[1]*left
        else:
            ans[0] = hyo[0]*(left+1)
            ans[1] = hyo[1]*(left+1)
    elif ans[1]>hyo[1]:
        right = ans[1]//hyo[1]
        if ans[1]%hyo[1] == 0:
            ans[0] = hyo[0]*right
            ans[1] = hyo[1]*right
        else:
            ans[0] = hyo[0]*(right+1)
            ans[1] = hyo[1]*(right+1)
    

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

Solution (Python):
n = int(input())
before = [0, 0]
for i in range(n):
    t, a = map(int, input().split())
    if t >= before[0] and a >= before[1]:
        before = [t, a]
    else:
        mul = max((before[0]-1)//t+1, (before[1]-1)//a+1)
        before = [t*mul, a*mul]

print(sum(before))

Solution (Python):
import math

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

x = l[0]
for i in range(1,n):
    
    
    y = -(-x[0] // l[i][0])
    z = -(-x[1] // l[i][1])
    x = [max(y, z) * j for j in l[i]]

print(sum(x))