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):
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))

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

Solution (Python):
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
a=A[0][0]
b=A[0][1]
import fractions
for i in range(1,N):
  if a<=A[i][0] and b<=A[i][1]:
    a=A[i][0] 
    b=A[i][1]
  else:
    aa=1
    bb=1
    if a>A[i][0]:
      if a%A[i][0]==0:
        aa=a//A[i][0]
      else:
        aa=1+a//A[i][0]
    if b>A[i][1]:
      if b%A[i][1]==0:
        bb=b//A[i][1]
      else:
        bb=1+b//A[i][1]
    c=max(aa,bb)
    a=c*A[i][0]
    b=c*A[i][1]
print(a+b)

Solution (Python):
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
a,b=1,1
for i in range(n):
  l=-min(-a//ta[i][0],-b//ta[i][1])
  a=ta[i][0]*l
  b=ta[i][1]*l
print(a+b)

Solution (Python):
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)


def main():
    n = int(input())
    senkyo = [tuple(map(int,input().split())) for _ in range(n)]
    
    last_t,last_a = senkyo[-1]
    
    def ok(x):
        t = x * last_t
        a = x * last_a
        flag = True
        for i in range(n - 2, -1, -1):
            ti,ai = senkyo[i]
            y = min(t//ti,a//ai)
            t = y * ti
            a = y * ai
            if a == 0 :
                flag = False
                break
        return flag
    
    r = 10 ** 18
    l = 0
    while r - l > 1:
        mid = (r + l)//2
        if ok(mid):
            r = mid
        else:
            l = mid
    
    print(r * (last_a + last_t))

if __name__=='__main__':
    main()

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



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

def main():
	n = int(input())
	a, t = IN()
	for _ in range(n-1):
		ap, tp = IN()
		aa=ww(a,ap)
		ta=ww(t,tp)
		rr=max(aa,ta)
		a,t=ap*rr, tp*rr
	return a+t
	
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):









N = int(input())
ans = 1


def ret_nm(t, a, n, m):
    times_t = (n - 1) // t + 1
    times_a = (m - 1) // a + 1
    times = max(times_t, times_a)
    return times * t, times * a


n = m = 1
for _ in range(N):
    t, a = map(int, input().split())
    n, m = ret_nm(t, a, n, m)


print(n + m)

Solution (Python):









N = int(input())
ans = 1


def ret_nm(t, a, n, m):
    times_t = (n - 1) // t + 1
    times_a = (m - 1) // a + 1
    times = max(times_t, times_a)
    return times * t, times * a


n = m = 1
for _ in range(N):
    t, a = map(int, input().split())
    n, m = ret_nm(t, a, n, m)


print(n + m)

Solution (Python):
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]


T = 0
A = 0
for i in range(n):
    t, a = p[i]
    if t >= T and a >= A:
        T, A = t, a
    else:
        d1 = T // t
        d2 = A // a
        if T % t != 0: d1 += 1
        if A % a != 0: d2 += 1
        d = max(d1, d2)
        T, A = d * t, d * a
    

print(T+A)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
T = []
A = []
for i in range(N) :
    p, q = map(int,input().split())
    T.append(p)
    A.append(q)

Tak = T[0]
Aok = A[0]
for i in range(1, N) :
    Tb = (Tak + T[i] - 1) // T[i]
    Ab = (Aok + A[i] - 1) // A[i]
    Tak = T[i] * max(Tb, Ab)
    Aok = A[i] * max(Tb, Ab)

print(Tak + Aok)

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    NT=1
    NA=1
    for i in range(N):
        T,A=MI()
        xt=(NT+T-1)//T
        xa=(NA+A-1)//A
        x=max(xt,xa)
        NT=T*x
        NA=A*x
    print(NT+NA)
            

main()

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

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

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

Solution (Python):

from math import ceil
n=int(input())
t,a=1,1
for i in range(n):
    tt,aa=map(int,input().split())
    min_num=max(-(-t//tt),-(-a//aa))
    
    t=min_num*tt
    a=min_num*aa
print(t+a)

Solution (Python):
import math
n = int(input())
T = [0]*n
A = [0]*n
Tvote = [0]*n
Avote = [0]*n

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

for k in range(n):
    if k == 0:
        Tvote[k] = T[k]
        Avote[k] = A[k]
    else:
        '''
        j = math.ceil(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        print(Tvote[k-1]/T[k])
        print(Avote[k-1]/A[k])
        print(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        print(j)
        print(Avote[k-1], A[k]*j)
        print(bool(Avote[k-1]<A[k]*j))
        print(bool(j>Avote[k-1]/A[k]))
        '''
        j = int(min(Tvote[k-1]//(-T[k]),Avote[k-1]//(-A[k])))*-1
        
        
        
        
        




        Tvote[k] = j*T[k]
        Avote[k] = j*A[k]







print(Tvote[n-1]+Avote[n-1])

Solution (Python):
from math import ceil
N = int(input())
T, A = 1, 1
for k in range(N):
    t, a = map(int,input().split())
    b = max(T//t,A//a)
    if t*b < T or a*b < A:
        b += 1
    T, A = t*b, a*b
print(T+A)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline

n = int(readline())
t,a = 0,0
for i in range(n):
    rt,ra = map(int,readline().split())
    x = max((t-1)//rt+1,(a-1)//ra+1)
    t = rt*x
    a = ra*x
    if a+t == 0:
        t += rt
        a += ra

print(t+a)

Solution (Python):
import sys
input = sys.stdin.readline

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):
from math import ceil
 
n = int(input())
a = 1
b = 1
 
for i in range(n):
    s,t = map(int,input().split())
    
    x = max((a+s-1)//s, (b+t-1)//t)

 
    a = x*s
    b = x*t

print(a+b)

Solution (Python):
N = int(input())
T,A = map(int,input().split())
for i in range(N-1):
    t,a = map(int,input().split())
    T1 = (T+t-1)//t*t
    A1 = (T+t-1)//t*a
    T2 = (A+a-1)//a*t
    A2 = (A+a-1)//a*a
    if A1 < A:
        T,A = T2,A2
    else:
        T,A = T1,A1
print(T+A)

Solution (Python):
import math
n = int(input())
ans = 0
t_1, a_1 = map(int, input().split())
pret = t_1
prea = a_1
for x in range(n - 1):
    t, a = map(int, input().split())
    m = -min(-pret//t,-prea//a)
    pret = m * t
    prea = m * a
print(pret + prea)

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

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

for _ in range(N - 1):
    t_i, a_i = map(int, input().split())

    
    
    n = max(-(-T // t_i), -(-A // a_i))

    
    T, A = n * t_i, n * a_i

print(T + A)

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

XY = [TA[0]]

for i in range(1, n):
    x0, y0 = XY[i-1]
    x1, y1 = TA[i]
    xq, xr = divmod(x0, x1)
    yq, yr = divmod(y0, y1)
    if xr != 0:
        xq += 1
    if yr != 0:
        yq += 1
    q = max(xq, yq)
    x1, y1 = x1*q, y1*q
    XY.append([x1, y1])
    
print(sum(XY[-1]))

Solution (Python):
n = int(input())
a,b = 1,1
for _ in range(n):
    x,y = map(int,input().split())
    k = -min(-a//x,-b//y)
    a,b = k*x,k*y
print(a+b)

Solution (Python):
n = int(input())
a,b = 1,1
for _ in range(n):
    x,y = map(int,input().split())
    k = -min(-a//x,-b//y)
    a = k*x
    b = k*y
print(a+b)

Solution (Python):
import math

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

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

ans = a + b
print(ans)

Solution (Python):
n=int(input())
nt,na=map(int,input().split())
for i in range(n-1):
    t,a=map(int,input().split())
    x=-min((-nt)//t,(-na)//a)
    nt,na=x*t,x*a
print(nt+na)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
tak, aok = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    if T == A:
        tak = aok = max(tak, aok)
    else:
        f = (tak + T - 1) // T
        t = f * T
        a = f * A
        if a >= aok:
            tak = t
            aok = a
        else:
            f = (aok + A - 1) // A
            tak = f * T
            aok = f * A
print(tak + aok)

Solution (Python):
N = int(input())
TT,AA= map(int,input().split())
for k in range(1,N):
    T,A = map(int,input().split())
    j = max((TT-1+T)//T,(AA-1+A)//A)
    TT = T*j 
    AA = A*j
        
print(TT + AA)

Solution (Python):
n = int(input())
a = 1
b = 1
for i in range(n):
    c,d = map(int,input().split())
    
    num = max((a+c-1)//c,(b+d-1)//d)

    a = num*c
    b = num*d
print(a+b)

Solution (Python):

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

Solution (Python):
n = int(input())
votelist = [list(map(int, input().split())) for _ in range(n)]

chlist = votelist[0]
for i in range(1, n):
    x = max(-(chlist[0]*-1 // votelist[i][0]), -(chlist[1]*-1 // votelist[i][1]))
    chlist[0] = votelist[i][0] * x
    chlist[1] = votelist[i][1] * x
    
print(sum(chlist))

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

nowt,nowa=TA[0]
for t,a in TA[1:]:
  c=max(-(-nowt//t),-(-nowa//a))
  nowt,nowa=c*t,c*a
print(nowt+nowa)

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

T, A = TA[0]
answer = T+A
p = 1
prev = p
pT, pA = T, A
for i in range(1,N):
    
    
    T, A = TA[i]
    s = T+A
    p = (answer+s-1)//s
    p1 = (pT+T-1)//T
    p2 = (pA+A-1)//A
    p = max([p,p1,p2])
    pT, pA = p*T, p*A
    answer =  pT+pA
    
print(answer)

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

T, A = TA[0]
answer = T+A
p = 1
prev = p
pT, pA = T, A
for i in range(1,N):
    
    
    T, A = TA[i]
    s = T+A
    p = (answer+s-1)//s
    p1 = (pT+T-1)//T
    p2 = (pA+A-1)//A
    p = max([p,p1,p2])
    pT, pA = p*T, p*A
    answer =  pT+pA
    
print(answer)

Solution (Python):
N = int(input())
ta = [list(map(int, input().split())) for _ in range(N)]
t = 1
a = 1
for i in range(N):
    if t % ta[i][0] != 0:
        ttmp = t // ta[i][0] + 1
    else:
        ttmp = t // ta[i][0]

    if a % ta[i][1] != 0:
        atmp = a // ta[i][1] + 1
    else:
        atmp = a // ta[i][1]
    n = max(ttmp, atmp)
    t = (n * ta[i][0])
    a = (n * ta[i][1])

print(t + a)

Solution (Python):
from fractions import gcd
N = int(input())
t, a = map(int, input().split())
x = gcd(t,a)
pT = t//x
pA = a//x
for i in range(1,N):
  t, a = map(int, input().split())
  mt = pT//t+1 if pT%t!=0 else pT//t
  ma = pA//a+1 if pA%a!=0 else pA//a
  m = max(mt,ma)
  pT = t*m
  pA = a*m

print(pT+pA)

Solution (Python):
n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)] 

ta_cur = list(ta[0])
for i in range(1, n):
  hi = max(-(ta_cur[0]*-1 // ta[i][0]), -(ta_cur[1]*-1 // ta[i][1]))
  ta_cur[0] = ta[i][0] * hi
  ta_cur[1] = ta[i][1] * hi

print(sum(ta_cur))

Solution (Python):
from math import ceil

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

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

    a = x*s
    b = x*t

print(a+b)

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

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

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

Solution (Python):


N=int(input())

pre_T=0
pre_A=0

def krag(n,m):
    return -(-n//m)


for _ in range(N):
    T,A=map(int,input().split())
    
    if T<pre_T or A<pre_A:
        k=max(krag(pre_T,T),krag(pre_A,A))
        T*=k
        A*=k
    
    pre_T,pre_A=T,A    
print(T+A)

Solution (Python):
N = int(input())
TA = [tuple(map(int, input().split()))for _ in range(N)]
ans = TA[0]
for ta in TA[1:]:
    x = max((ans[0] + ta[0] - 1) // ta[0], (ans[1] + ta[1] - 1) // ta[1])
    ans = (x * ta[0], x * ta[1])
print(sum(ans))

Solution (Python):

n = int(input())
now = [1,1]
data = []

for i in range(n):
    data.append(list(map(int, input().split())))
for i in range(n):
    t,a = data[i]
    mul = max((now[0] + t - 1)//t, (now[1] + a - 1) //a)
    now = list(map(lambda x:x*mul, data[i]))
print(sum(now))

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
x=0
y=0
for i in range(n):
    if x<=a[i][0] and y<=a[i][1]:
        x=a[i][0]
        y=a[i][1]
    else:
        v=-(x//-a[i][0])
        w=-(y//-a[i][1])
        u=max(v,w)
        x=u*a[i][0]
        y=u*a[i][1]

print(x+y)

Solution (Python):
import sys

input = sys.stdin.readline


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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
X,Y=1,1
for i in range(N):
  T,A=map(int,input().split())
  k=max((X+T-1)//T,(Y+A-1)//A)
  X,Y=k*T,k*A
print(X+Y)

Solution (Python):
n=int(input())
for i in range(n):
  if i==0:
    t,a=map(int,input().split())
  else:
    x,y=map(int,input().split())
    p=(t+x-1)//x
    q=(a+y-1)//y
    r=max(p,q)
    t,a=x*r,y*r
print(t+a)

Solution (Python):
n=int(input())
t_sum=1
a_sum=1
for i in range(n):
    T,A=map(int,input().split())
    t_sum = max(-(-t_sum//T),-(-a_sum//A))*T
    a_sum = max(-(-t_sum//T),-(-a_sum//A))*A
print(t_sum+a_sum)

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

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

Solution (Python):
n = int(input())
ratio_array = [tuple(map(int, input().split())) for _ in range(n)]

t, a = 1, 1

for x, y in ratio_array:
    m = max((t+x-1)//x, (a+y-1)//y)
    t, a = m*x, m*y

print(t + a)

Solution (Python):
n = int(input())
ratio_array = [tuple(map(int, input().split())) for _ in range(n)]

votes_numｓ = (1, 1)

for x, y in ratio_array:
    t, a = votes_numｓ
    m = max((t+x-1)//x, (a+y-1)//y)
    votes_numｓ = (m*x, m*y)

print(sum(votes_numｓ))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = 1, 1
    for i in range(N):
        newT, newA = LI()
        
        
        
        r1 = (curT-1)//newT + 1
        r2 = (curA-1)//newA + 1
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()

Solution (Python):
from math import ceil
N = int(input())
L = [list(map(int,input().split())) for k in range(N)]
A, T = 1, 1
for k in range(N):
    a, t = L[k][0], L[k][1]
    m = max(A//a,T//t)
    if a*m < A or t*m < T:
        m += 1
    A = a*m
    T = t*m
print(A+T)

Solution (Python):
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
N = int(input())
ca, cb = 0, 0
for _ in range(N):
    a, b = map(int, input().split())
    if ca == 0 and cb == 0:
        ca, cb = a, b
    else:
        r = int(math.ceil(max(Fraction(ca, a), Fraction(cb,b))))
        ca, cb = a*r, b*r

print (ca + cb)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
T=1
A=1

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

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

Solution (Python):
n=int(input())
x,y=map(int,input().split())

import math
for i in range(n-1):
  t,a=map(int,input().split())
  tbai=(x-1)//t+1
  abai=(y-1)//a+1
  bai=max(tbai,abai)
  x=t*bai
  y=a*bai
  
print(x+y)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            
            ok = mid
        else:
            
            ng = mid
    return ok

N = INT()
cura, curb = MAP()
for i in range(N-1):
    a, b = MAP()
    
    res = bisearch_min(0, INF, lambda m: a*m >= cura and b*m >= curb)
    cura, curb = a * res, b * res
ans = cura + curb
print(ans)

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

nums=TA[0]

def f(points, rate):
  if points[0]%rate[0]>0:
    a=1
  else:
    a=0
  if points[1]%rate[1]>0:
    b=1
  else:
    b=0
    
  tmp=max(points[0]//rate[0]+a, points[1]//rate[1]+b)
  return [rate[0]*tmp, rate[1]*tmp]

for i in range(1, N):
  nums=f(nums, TA[i])
  
print(sum(nums))

Solution (Python):
from decimal import *

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

Taka = 0
Aoki = 0

for i in range(n):

    if (T[i] >= Taka) and (A[i] >= Aoki):
        Taka = T[i]
        Aoki = A[i]
    elif T[i] == A[i]:
        Taka = max(Taka, Aoki)
        Aoki = Taka
    else:
        Taka_up = -(-Taka//T[i])
        Aoki_up = -(-Aoki//A[i])
        multi = max(Taka_up, Aoki_up)
        Taka = T[i] * multi
        Aoki = A[i] * multi   

ans = int(Taka + Aoki)
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  t,a=LI()
  l=[LI() for _ in range(n-1)]

  
  
  for _t,_a in l:
    _n=max(-(-t//_t),-(-a//_a))
    t=_n*_t
    a=_n*_a

  return t+a


print(main())

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N)]
    na,nb = X[0][0],X[0][1]
    for i in range(N-1):
        i += 1
        x,y = X[i][0],X[i][1]
        if (x >= na and y >= nb):
            na,nb = x,y
        elif (x < na and y >= nb):
            q = -(-na//x)
            na,nb = x*q,y*q
        elif (x >= na and y < nb):
            q = -(-nb//y)
            na,nb = x*q,y*q
        else:
            use = max(-(-na//x),-(-nb//y))
            na,nb = x*use,y*use
    
    print(na+nb)
    
if __name__ == "__main__":
    main()

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

Solution (Python):

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

now = da[0]
for i in range(1,n):
    co = max((now[0] - 1)// da[i][0], (now[1] - 1)// da[i][1])
    co += 1
    now[0] = da[i][0] * co
    now[1] = da[i][1] * co
print(now[0] + now[1])

Solution (Python):
N = int(input())
ansT = 1
ansA = 1
for i in range(N):
    T, A = map(int,input().split())
    if int(ansT / T) > int(ansA / A):
        ansT = T * int((ansT + T - 1) // T)
        ansA = A * int((ansT + T - 1) // T)
    else:
        ansT = T * int((ansA + A - 1) // A)
        ansA = A * int((ansA + A - 1) // A)

print(int(ansT + ansA))

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

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

Solution (Python):


import sys
input = sys.stdin.readline

N = int(input())

T = []
A = []

for i in range(N):
    temp = list(map(int,input().split()))
    T.append(temp[0])
    A.append(temp[1])

for i in range(1,N):
    if (T[i-1] <= T[i]) & (A[i-1] <= A[i]):
        
        continue
    else:
        rT = - ( - T[i-1] // T[i])
        rA = - ( - A[i-1] // A[i])
        temp = max(rT,rA)
        T[i] *= temp
        A[i] *= temp
        

res = T[N-1] + A[N-1]

print(res)

Solution (Python):
n = int(input())
ans = 0
max_t = 0
max_a = 0
for _ in range(n):
    t, a = map(int, input().split())
    x = max(max_t//t, max_a//a, 1)
    while 1:
        if max_t <= t*x and max_a <= a*x:
            max_t = t * x
            max_a = a * x
            break
        else:
            x += 1
print(max_t + max_a)

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

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

x, y = 1, 1


def ceil(a, b):
    return a // b + (a % b > 0)


for t, a in TA:
    tv = ceil(x, t)
    av = ceil(y, a)
    n = max(tv, av)
    x = n * t
    y = n * a
print(x + y)

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


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


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

def ceil(a, b):
  return a // b + (a % b > 0)

import math
ans = (1, 1)
for _ in range(n):
   t,a = map(int,input().split())
   b = max(ceil(ans[0],t), ceil(ans[1],a))
   ans = [b*t, b*a]
print(sum(ans))

Solution (Python):
N = int(input())
takahashi = 1
aoki = 1
for _ in range(N):
  t, a = map(int, input().split())
  X = -(-(takahashi + t-1))//t 
  Y = -(-(aoki + a-1))//a      
  n = max(X, Y)
  takahashi = t*n
  aoki = a*n
  
print(int(takahashi+aoki))

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

Solution (Python):
n = int(input())
from math import ceil

tkhs = 1
aoki = 1

for _ in range(n):
    t, a = map(int, input().split())
    k = max((tkhs+t-1)//t, (aoki+a-1)//a)
    tkhs = k*t
    aoki = k*a

print(tkhs+aoki)

Solution (Python):
n = int(input())
tpred = 1
apred = 1

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

print(tpred+apred)

Solution (Python):
n = int(input())
tpred = 1
apred = 1

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

print(tpred+apred)

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

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

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

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

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

Solution (Python):
def ceil(x,y):
    return x//y+(not( not x%y))
n=int(input())
a,b=1,1
for i in range(n):
    t,s = map(int,input().split())
    i = max( ceil(a,t), ceil(b,s) )
    a=t*i;b=s*i
print(a+b)

Solution (Python):

def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)

Solution (Python):
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)

Solution (Python):
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)

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

import math
dp = ta[0]
for i in range(1, n):
    t = ta[i][0]
    a = ta[i][1]

    k1 = dp[0] // t
    if k1 * t != dp[0]:
        k1 += 1
    k2 = dp[1] // a
    if k2 * a != dp[1]:
        k2 += 1
    k = max(k1, k2)

    dp = [k * t, k * a]
print(sum(dp))

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

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

t = 0
a = 0
for _ in range(N):
    rt,ra = map(int,input().split())
    c = max((t-1)//rt+1, (a-1)//ra+1)
    t = rt*c
    a = ra*c
    if a+t == 0:
        t += rt
        a += ra
    
answer = t+a
print(answer)

Solution (Python):
import sys

n = int(sys.stdin.readline().rstrip())
ab = map(int, sys.stdin.read().split())
ab = zip(ab, ab)

def main():
    c_a = c_b = 1
    for a, b in ab:
        t_a = (c_a + a - 1) // a
        t_b = (c_b + b - 1) // b
        t = max(t_a, t_b)
        c_a = a * t
        c_b = b * t
    
    ans = c_a + c_b
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
A,B = li[0][0],li[0][1]
for i in range(1,n):
    a,b = li[i][0],li[i][1]
    bai = max(-(-A//a),-(-B//b))
    A = bai*a
    B = bai*b
print(A+B)

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


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


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

    
    
    n = max(-(-T // t), -(-A // a))
    
    T = n*t
    A = n*a
    

print(T+A)

Solution (Python):
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
x,y = a[0][0],a[0][1]
for i in range(1,n):
  xr=(x+a[i][0]-1)//a[i][0]
  yr=(y+a[i][1]-1)//a[i][1]
  r=max(xr,yr)
  x=r*a[i][0]
  y=r*a[i][1]
print(x+y)

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

Solution (Python):
def ceil(a, b):
  return a // b + (a % b > 0)

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