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):
a = int(input())
b = [list(map(int, input().split()))for _ in range(a)]
c = []
for i in range(len(b)):
    c.append(b[i].copy())
    if len(c) != 1:
        while True:
            if c[i][0] < c[i-1][0] or c[i][1] < c[i-1][1]:
                c[i][0] = b[i][0] * max((c[i-1][0] + b[i][0] - 1) // b[i][0], (c[i-1][1] + b[i][1] - 1) // b[i][1])
                c[i][1] = b[i][1] * max((c[i-1][0] + b[i][0] - 1) // b[i][0], (c[i-1][1] + b[i][1] - 1) // b[i][1])
            else:
                break
print(c[len(c)-1][0] + c[len(c)-1][1])

Solution (Python):
def solve(v_t, v_a, t, a):
    tmpt = 0
    tmpa = 0
    if v_t % t == 0:
        tmpt = v_t // t
    else:
        tmpt = v_t // t + 1
    if v_a % a == 0:
        tmpa = v_a // a
    else:
        tmpa = v_a // a + 1
    return max(tmpt, tmpa)

N = int(input())
vote_t = 0
vote_a = 0
for i in range(N):
    t, a = map(int,input().split())
    if i == 0:
        vote_t = t
        vote_a = a
    else:
        
        n = solve(vote_t, vote_a, t, a)
        vote_t = t*n
        vote_a = a*n
print(str(vote_t + vote_a))

Solution (Python):
from fractions import gcd
n=int(input())
ab=[list(map(int,input().split())) for _ in [0]*n]
l,r=1,1
for i in range(n):
    a,b=ab[i]
    c=max((l-1)//a+1,(r-1)//b+1)
    l=a*c
    r=b*c
print(l+r)

Solution (Python):
A, B = 1, 1
for _ in range(int(input())):
    x, y = map(int, input().split())
    n = max(-(-A // x), -(-B // y))
    A, B = n * x, n * y

print(A + B)

Solution (Python):
import math
n=int(input())
T,A=map(int,input().split())
for i in range(n-1):
    t,a=map(int,input().split())
    x=T//t if T%t==0 else T//t+1
    y=A//a if A%a==0 else A//a+1
    c=max(x,y)
    T=t*c
    A=a*c

print(A+T)

Solution (Python):
N=int(input())
 
X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
 
 
a=X[0][0]
b=X[0][1]
 
for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
 

  x= (a + (c - 1)) // c
  y= (b + (d -1)) // d
  
  a1=1000000000000000000
  b1=1000000000000000000
  a2=1000000000000000000
  b2=1000000000000000000
  if d*x-b>=0:
    a1=c*x
    b1=d*x
 
  
  if c*y-a>=0:
    a2=c*y
    b2=d*y
  if (a1+b1)<(a2+b2):
    a=a1
    b=b1
  else:
    a=a2
    b=b2
 
  
  
 
 
 
 
  
print(a+b)

Solution (Python):
N = 1000
def ee(a, b, c):
	arr = [[1,0,a],[0,1,-b]]

	while arr[1][2]!=0:
		for j in range(3):
			arr[0][j] -= arr[1][j]*(arr[0][2]//arr[1][2])
			arr[0][j], arr[1][j] = arr[1][j], arr[0][j]
	
	x0 = c*arr[0][0]
	y0 = c*arr[0][1]
	
	if arr[0][2]==-1:
		x0 *= -1
		y0 *= -1

	t = max(-(x0//b), -(y0//a))

	x0 = x0+b*t
	y0 = y0+a*t

	return x0, y0

def main():
	n = int(input())
	t0, a0 = [int(i) for i in input().split()]

	for ctr in range(1,n):
		t, a = [int(i) for i in input().split()]
		d =  ee(a,t,t*a0-a*t0)
		t0 += d[0]
		a0 += d[1]

	print(t0+a0)

main()

Solution (Python):

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    t, a = 1, 1
    for i, j in arr:
        r = max((t - 1) // i + 1, (a - 1) // j + 1)
        t, a = i * r, j * r
    print(t + a)


if __name__ == "__main__":
    main()

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

Solution (Python):
import math

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

A, B = 1, 1

for t in TA:
    a = A // t[0]
    b = B // t[1]
    if A % t[0] != 0:
        a += 1
    if B % t[1] != 0:
        b += 1
    n = max(a, b)
    
    A, B = t[0] * n, t[1] * n

print(A + B)

Solution (Python):
N = int(input())
T = [0 for i in range(N)]
A = [0 for i in range(N)]
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
vote_num = A[0] + T[0]
a_num = A[0]
t_num = T[0]
for i in range(1, N):
    
    mult_a = a_num // A[i] if a_num % A[i] == 0 else a_num // A[i] + 1
    mult_t = t_num // T[i] if t_num % T[i] == 0 else t_num // T[i] + 1
    mult_vote = vote_num // (A[i] + T[i]) if vote_num % (A[i] + T[i]) == 0 else vote_num // (A[i] + T[i]) + 1
    
    mult = max(mult_a, mult_t, mult_vote)
    a_num = A[i] * mult
    t_num = T[i] * mult
    vote_num = mult * (A[i] + T[i])

print(vote_num)

Solution (Python):
N = int(input())
TA = [[int(_) for _ in input().split()] for _ in range(N)]
tak = TA[0][0]
aok = TA[0][1]

if N == 1:
    print(tak+aok)
else:
    for i in range(1, N):
        nowTrate = TA[i][0]
        nowArate = TA[i][1]
        T = tak//nowTrate if tak % nowTrate == 0 else tak//nowTrate+1
        A = aok//nowArate if aok % nowArate == 0 else aok//nowArate+1
        y = max(T, A)
        tak = nowTrate * y
        aok = nowArate * y
    print(tak+aok)

Solution (Python):
N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = x//a if x%a==0 else x//a+1
    yt = y//t if y%t==0 else y//t+1
    c = max(xa,yt)
    x,y = a*c,t*c
print(x+y)

Solution (Python):
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
total_t = 1; total_a = 1;
for t, a in ratio:
    q = max((total_t + t - 1) // t, (total_a + a - 1) // a)
    total_t = t*q
    total_a = a*q
ans = total_t + total_a
print(ans)

Solution (Python):
N = int(input())
x = 1
y = 1
for _ in range(N):
    T, A = map(int, input().split())
    r = max((x + T - 1) // T, (y + A - 1) // A)
    x = T * r
    y = A * r
print(x + y)

Solution (Python):
N = int(input())
T_current, A_current = 1,1

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

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

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


ans = [vote_ratio[0][0], vote_ratio[0][1]]

for i in range(1,n):
	
	
	bairitsu = max( 
		(ans[0] + vote_ratio[i][0] - 1)// vote_ratio[i][0],
		(ans[1] + vote_ratio[i][1] - 1)// vote_ratio[i][1])
	ans = [vote_ratio[i][0] * bairitsu, vote_ratio[i][1] * bairitsu]

print(sum(ans))

Solution (Python):






import math

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



ans = [vote_ratio[0][0], vote_ratio[0][1]]

for i in range(1,n):
	bairitsu = max(ans[0] // vote_ratio[i][0], ans[1] // vote_ratio[i][1])
	if vote_ratio[i][0] * bairitsu < ans[0] \
	or vote_ratio[i][1] * bairitsu < ans[1]:
		bairitsu += 1
	ans = [vote_ratio[i][0] * bairitsu, vote_ratio[i][1] * bairitsu]

print(sum(ans))

Solution (Python):
N = int(input())
T = []
A = []
for i in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
    
v1 = 1
v2 = 1

for i in range(N):
    n = max((v1+T[i]-1)//T[i],(v2+A[i]-1)//A[i])
    v1 = T[i]*n
    v2 = A[i]*n

print(v1+v2)

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

Solution (Python):
N = int(input())
TA = [[int(x) for x in input().split()]for _ in range(N)]
t = 1
a = 1

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

print(t+a)

Solution (Python):
N = int(input())
t = 1
a = 1
TA = [0]*N
for i in range(N):
    TA[i] = map(int,input().split(" "))

for T,A in TA:
    n = max(t//T+(t%T and 1),a//A+(a%A and 1))
    t = n * T
    a = n * A

print(t+a)

Solution (Python):
from decimal import *

def calc_vote(T, A, TN_prev, AN_prev):
    '''
    input:
        T, A: rate of vote
        TN_prev, AN_prev: previous minimum number of vote
    output:
        TN, AN: minimum number of vote 
    '''
    k = max((TN_prev/T).quantize(Decimal('0'), rounding=ROUND_CEILING), (AN_prev/A).quantize(Decimal('0'), rounding=ROUND_CEILING))
    TN = k * T
    AN = k * A
    
    return TN, AN
  

N = int(input())

TN, AN = map(Decimal, input().split())
for _ in range(2, N + 1):
    T, A = map(Decimal, input().split())
    TN, AN = calc_vote(T, A, TN, AN)

print(TN + AN)

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

c,d = 0,0
for i in range(n):
    a,b = map(int,input().split())
    if c<=a and d<=b:
        c,d=a,b
        continue
    else:
        f = max(c//a + (c%a>0),d//b+(d%b>0))
        c,d = a*f,b*f
print(c+d)

Solution (Python):
N = int(input())
T,A = [],[]
for i in range(N):
    t,a = map(int,input().split())
    T.append(t); A.append(a)
x,y = T[0],A[0]
for i in range(1,N):
    p = x//T[i] if x%T[i]==0 else x//T[i]+1
    q = y//A[i] if y%A[i]==0 else y//A[i]+1
    p = max(p,q)
    x = p*T[i]
    y = p*A[i]
print(x+y)

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

print(a+b)

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):
  k = max((t+ta[i][0]-1)//ta[i][0], (a+ta[i][1]-1)//ta[i][1])
  t = ta[i][0]*k
  a = ta[i][1]*k
  
print(t+a)

Solution (Python):
N = int(input())
a = list(int(i) for i in input().split())
x =a[0]
y =a[1]
for j in range(N-1):
    a = list(int(i) for i in input().split())
    if a[0]>x:
        if a[1]>y:
            x =a[0]
            y =a[1]
        else:
            q=(y-1)//a[1]+1
            x =a[0]*q
            y =a[1]*q
    else:
        if a[1]>y:
            p=(x-1)//a[0]+1
            x = a[0]*p
            y = a[1]*p
        else:
            q=(y-1)//a[1]+1
            p=(x-1)//a[0]+1
            if p > q:
                x =a[0]*p
                y =a[1]*p
            else:
                x = a[0]*q
                y = a[1]*q
print(x+y)

Solution (Python):
n = int(input())
t,a = map(int,input().split())
for i in range(n-1):
    ti,ai = map(int,input().split())
    if t*ai == a*ti:
        continue
    else:
            b = max(-(-t//ti),-(-a//ai))
            t = ti*b
            a = ai*b
print(t+a)

Solution (Python):
n = int(input())
sa,sb=[int(it) for it in input().split()]
for i in range(n-1):
  a,b=[int(it) for it in input().split()]
  r =  max( sa//a + (1 if sa%a!=0 else 0),sb//b+(1 if sb%b!=0 else 0) )
  sa = r*a
  sb = r*b
print (sa+sb)

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

t, a = T[0], A[0]

for i in range(1, N):
  if (t < T[i] and a < A[i]):
    t, a = T[i], A[i]
  else:
    n = max((t - 1) // T[i] + 1, (a - 1) // A[i] + 1)
    t, a = n * T[i], n * A[i]

print(t + a)

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

t = T[0]
a = A[0]

for i in range(1, N):
  if t < T[i] and a < A[i]:
    t = T[i]
    a = A[i]
  else:
    x = (t + T[i] - 1) // T[i]
    y = (a + A[i] - 1) // A[i]
    t = T[i] * max(x, y)
    a = A[i] * max(x, y)

print(t + a)

Solution (Python):
n=int(input())
t1,a1=map(int,input().split())
for i in range(1,n):
  t,a=map(int,input().split())
  if t1%t==0:
    kt=t1//t
  else:
    kt=t1//t+1
  if a1%a==0:
    ka=a1//a
  else:
    ka=a1//a+1
  k=max(kt,ka)
  t1=k*t
  a1=k*a
print(t1+a1)

Solution (Python):
n = int(input())
t = [list(map(int,input().split())) for _ in range(n)]
ans = [1,1]
for t_ in t:
    k = max(ans[0]//t_[0]+min(ans[0]%t_[0],1),ans[1]//t_[1]+min(ans[1]%t_[1],1))
    ans[0] = t_[0]*k
    ans[1] = t_[1]*k
print(sum(ans))

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

Solution (Python):
n=int(input())
a0,b0=1,1
for _ in range(n):
  a,b=map(int,input().split())
  k=max(a0//a+(a0%a>0),b0//b+(b0%b>0))
  a0,b0=a*k,b*k
print(a0+b0)

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

for i in range(N-1):
    D = ((TA[i]-1)//TA[i+1])+1
    E = ((AO[i]-1)//AO[i+1])+1
    F = max(D, E)
    TA[i+1] *= F
    AO[i+1] *= F
ans = int(TA[N-1] + AO[N-1])
print(ans)

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

for i in range(N):
 A,T = map(int,input().split())
 if(i == 0):
  now_A,now_T = A,T
 else:
  if((now_A<=A)and(now_T<=T)):
    now_A,now_T = A,T
  else: 
    if(now_A%A == 0): tmp1 = now_A//A
    else: tmp1 = now_A//A + 1
    if(now_T%T == 0): tmp2 = now_T//T
    else: tmp2 = now_T//T + 1
    tmp = max(tmp1,tmp2)
    now_A,now_T = tmp*A,tmp*T
ans = now_A + now_T
print(ans)

Solution (Python):
import math

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

T, A = 1, 1
for i in range(N):
  if T >= A:
    if TA[i][0] / TA[i][1] >= T / A:
      a = -1 * ((-1 * A) // TA[i][1])
    else:
      a = -1 * ((-1 * T) // TA[i][0])
  else:
    if TA[i][1] / TA[i][0] >= A / T:
      a = -1 * ((-1 * T) // TA[i][0])
    else:
      a = -1 * ((-1 * A) // TA[i][1])
  T = TA[i][0] * a
  A = TA[i][1] * a
  

print(T + A)

Solution (Python):
import sys
import math
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
m = 0
t0, a0 = 1, 1
for i in range(n):
    t, a = nm()
    m = max((a0 + a - 1) // a, (t0 + t - 1) // t)
    a0 = a * m
    t0 = t * m
print(a0 + t0)

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

Solution (Python):
N = int(input())
T, A = 1, 1

for _ in range(N):
    ti, ai = map(int, input().split())
    ratio = max(-(-T // ti), -(-A // ai))
    T = ratio * ti
    A = ratio * ai
print(T + A)

Solution (Python):
import math
from decimal import *

n=int(input())

t_prev,a_prev=1,1
for i in range(n):
  t,a=map(int,input().split())
  n_koho1=math.ceil(Decimal(t_prev)/Decimal(t))
  n_koho2=math.ceil(Decimal(a_prev)/Decimal(a))

  
  
  

  
  
  
  
  
  
  
        
  n=max(n_koho1,n_koho2)
  t=n*t
  a=n*a
    
  t_prev=t
  a_prev=a

print(t_prev+a_prev)

"""
t=10**15
print(t)
print(t+1)
print((t+1)/t)
print(math.ceil((t+1)/t))

t=10**16
print(t)
print(t+1)
print((t+1)/t)
print(math.ceil((t+1)/t))

print(Decimal((t+1)/t))
print(Decimal(t+1)/Decimal(t))
print(math.ceil(Decimal(t+1)/Decimal(t)))
"""

Solution (Python):
import math
from decimal import *

n=int(input())

t_prev,a_prev=1,1
for i in range(n):
  t,a=map(int,input().split())
  n_koho1=math.ceil(Decimal(t_prev)/Decimal(t))
  n_koho2=math.ceil(Decimal(a_prev)/Decimal(a))

  
  
  

  
  
  
  
  
  
  
        
  n=max(n_koho1,n_koho2)
  t=n*t
  a=n*a
    
  t_prev=t
  a_prev=a

print(t_prev+a_prev)

Solution (Python):
import math

n=int(input())

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

  n_koho1 = t_prev // t
  n_koho2 = a_prev // a
  if t_prev % t != 0:
      n_koho1 += 1
  if a_prev % a != 0:
      n_koho2 += 1
        
  n=max(n_koho1,n_koho2)
  t=n*t
  a=n*a
    
  t_prev=t
  a_prev=a

print(t_prev+a_prev)

Solution (Python):
N=int(input())
P=[list(map(int,input().split(' '))) for i in range(N)]
T=[P[i][0] for i in range(N)]
A=[P[i][1] for i in range(N)]
t=T[0]
a=A[0]
k=1
for i in range(1,N):
	k1 = int((T[i-1]*k-1)//T[i]+1)
	k2 = int((A[i-1]*k-1)//A[i]+1)
	k = max(k1,k2)
print(k*(T[-1]+A[-1]))

Solution (Python):
import math

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

    t_ratio = pt // t
    a_ratio = pa // a
    if pt % t != 0:
        t_ratio += 1
    if pa % a != 0:
        a_ratio += 1
    min_ratio = max(t_ratio, a_ratio)
    pt = t * min_ratio
    pa = a * min_ratio

print(pt+pa)

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

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

Solution (Python):
import math
from decimal import *

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

total_T = 1
total_A = 1

for t,a in _input:
    
    n = max(-(-total_T//t), -(-total_A//a))
    total_T = int(t*n)
    total_A = int(a*n)

print(total_A+total_T)

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

Solution (Python):
n = int(input())
ans_t, ans_a = map(int,input().split())
for i in range(n-1):
    t, a = map(int,input().split())

    if ans_t % t == 0:
        p = ans_t//t
    else:
        p = ans_t//t + 1
    if ans_a % a == 0:
        q = ans_a // a
    else:
        q = ans_a// a + 1

    r = max(p, q)
    ans_a = a * r
    ans_t = t * r


print(ans_a + ans_t)

Solution (Python):
n = int(input())
t2, a2 = map(int, input().split())
for _ in range(n-1):
  t, a = map(int, input().split())
  m = max((t2-1)//t, (a2-1)//a)+1
  t2 = m*t
  a2 = m*a
print(t2+a2)

Solution (Python):
N = int(input())
TA = []
for _ in range(N):
    t, a = map(int, input().split())
    TA.append([t, a])

t0, a0 = 1, 1
for t, a in TA:
    t0 = -(-t0 // t) * t
    a0 = -(-a0 // a) * a
    if t0 / a0 < t / a:
        t0 = t * a0 // a
    else:
        a0 = a * t0 // t

ans = t0 + a0
print(ans)

Solution (Python):
def inpl():
    return list(map(int, input().split()))


N = int(input())
TA = [inpl() for i in range(N)]

a, b = TA[0][0], TA[0][1]
for ta, ao in TA[1:]:
    if ta >= a and ao >= b:
        a = ta
        b = ao
    else:
        
        tmp_a = -(-1 * a // ta)
        tmp_b = -(-1 * b // ao)
        tmp = max(tmp_a, tmp_b)
        a = ta * tmp
        b = ao * tmp
    

print(a + b)

Solution (Python):
n = int(input())
mt, ma = 1, 1
for t, a in (map(int, input().split()) for _ in range(n)):
    l = max((mt-1)//t, (ma-1)//a)  + 1
    mt, ma = l*t, l*a
print(mt+ma)

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

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

Solution (Python):
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    e,f=map(int,input().split())
    if (a//e+(1 if a%e!=0 else 0))*f>=b:
        b=f*(a//e+(1 if a%e!=0 else 0))
        a=e*(a//e+(1 if a%e!=0 else 0))
    else:
        a=e*(b//f+(1 if b%f!=0 else 0))
        b=f*(b//f+(1 if b%f!=0 else 0))
print(a+b)

Solution (Python):
N = int(input())
v_T = 1
v_A = 1
for _ in range(N):
    t, a = list(map(int, input().split()))
    d = max(((-v_T)//t)*(-1), ((-v_A)//a)*(-1))
    v_T = d*t
    v_A = d*a


print(v_T+v_A)

Solution (Python):
def floor(a, b):
    return ((-a)//b)*-1


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

v_T = ratio[0][0]
v_A = ratio[0][1]

for t, a in ratio[1:]:
    diff_t = t - v_T
    diff_a = a - v_A

    d = max(floor(v_T, t), floor(v_A, a))
    v_T = d*t
    v_A = d*a


print(v_T+v_A)

Solution (Python):
def floor(a, b):
    return ((-a)//b)*-1


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

v_T = ratio[0][0]
v_A = ratio[0][1]

for t, a in ratio[1:]:
    diff_t = t - v_T
    diff_a = a - v_A

    if diff_t < 0 or diff_a < 0:
        d = max(floor(v_T, t), floor(v_A, a))
        v_T = d*t
        v_A = d*a

    elif diff_t >= 0 and diff_a >= 0:
        m = max(diff_t, diff_a)
        v_T = t
        v_A = a

print(v_T+v_A)

Solution (Python):
def floor(a, b):
    return ((-a)//b)*-1


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

v_T = ratio[0][0]
v_A = ratio[0][1]

for t, a in ratio[1:]:
    diff_t = t - v_T
    diff_a = a - v_A

    if diff_t < 0 or diff_a < 0:
        d = max(floor(v_T, t), floor(v_A, a))
        v_T = d*t
        v_A = d*a

    elif diff_t < 0:
        d = floor(v_T, t)
        v_T = d*t
        v_A = d*a

    elif diff_a < 0:
        d = floor(v_A, a)
        v_T = d*t
        v_A = d*a

    elif diff_t >= 0 and diff_a >= 0:
        m = max(diff_t, diff_a)
        v_T = t
        v_A = a

print(v_T+v_A)

Solution (Python):
def floor(a, b):
    return ((-a)//b)*-1


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

v_T = ratio[0][0]
v_A = ratio[0][1]

for t, a in ratio[1:]:
    diff_t = t - v_T
    diff_a = a - v_A

    if diff_t < 0 and diff_a < 0:
        d = max(floor(v_T, t), floor(v_A, a))
        v_T = d*t
        v_A = d*a

    elif diff_t < 0:
        d = floor(v_T, t)
        v_T = d*t
        v_A = d*a

    elif diff_a < 0:
        d = floor(v_A, a)
        v_T = d*t
        v_A = d*a

    elif diff_t >= 0 and diff_a >= 0:
        m = max(diff_t, diff_a)
        v_T = t
        v_A = a

print(v_T+v_A)

Solution (Python):

def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
TA = zeros(N)
for i in range(N):
    TA[i] = getIntList()
db(TA)
real = TA[0]
for i in range(1,N):

    if real[0]/TA[i][0] > real[1]/TA[i][1]:
        lc = (real[0]+TA[i][0]-1)//TA[i][0]*TA[i][0]
        real[0] = lc 
        real[1] = lc * TA[i][1] // TA[i][0]  
    else:
        lc = (real[1]+TA[i][1]-1)//TA[i][1]*TA[i][1]
        real[1] = lc 
        real[0] = lc * TA[i][0] // TA[i][1]  
    db((lc,real))
print(sum(real))

Solution (Python):

def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def gcd(x, y): 
    m = max(x,y)
    n = min(x,y)
    while m%n != 0:
        w = m%n
        m = n
        n = w
    return n

def lcm(x, y): return x*y//gcd(x,y) 
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
TA = zeros(N)
for i in range(N):
    TA[i] = getIntList()
db(TA)
real = TA[0]
for i in range(1,N):

    if real[0]/TA[i][0] > real[1]/TA[i][1]:
        lc = (real[0]+TA[i][0]-1)//TA[i][0]*TA[i][0]
        real[0] = lc 
        real[1] = lc * TA[i][1] // TA[i][0]  
    else:
        lc = (real[1]+TA[i][1]-1)//TA[i][1]*TA[i][1]
        real[1] = lc 
        real[0] = lc * TA[i][0] // TA[i][1]  
    db((lc,real))
print(sum(real))

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

Solution (Python):

from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007


"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""


"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""


"""
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
"""


"""
n = II()
d = LIR(n)
q = II()
p = IIR(q)
d.insert(0,[0 for i in range(n+1)])
for i in range(n):
    d[i+1].insert(0,0)
for i in range(n):
    for j in range(n):
        d[i+1][j+1] += d[i+1][j]+d[i][j+1]-d[i][j]
ans = [0 for i in range(n**2+1)]

for a in range(n+1):
    for b in range(n+1):
        for c in range(a):
            for e in range(b):
                ans[(a-c)*(b-e)] = max(ans[(a-c)*(b-e)],d[a][b]-d[c][b]-d[a][e]+d[c][e])

for i in p:
    an = 0
    for a in range(i+1):
        an = max(an, ans[a])
    print(an)
"""


"""
s = list(S())
ans = -1
s.insert(0,0)
d = 0
for i in range(1,len(s)):
    if s[i] != d:
        d = s[i]
        ans += 1
print(ans)
"""


n = II()
x,y = LI()
for _ in range(n-1):
    a,b = LI()
    if a == b:
        x = max(x,y)
        y = x
    else:
        i = max(x//a,y//b)
        while 1:
            if a*i >= x and b*i >= y:break
            i += 1
        x = a*i
        y = b*i
print(x+y)

Solution (Python):

"""
import math
a, b = map(str, input().split())
j = int(a + b)
if math.sqrt(j).is_integer():
    print("Yes")
else:
    print("No")
"""


"""
ans = ["Positive","Negative"]
a, b = map(int, input().split())
if 0 < a:
    print("Positive")
elif b >= 0:
    print("Zero")
else:
    print(ans[(b-a)%2-1])
"""


"""
import itertools
n = int(input())
MARCH = ["M", "A", "R", "C", "H"]
march = [0 for _ in range(5)]
for i in range(n):
    s = input()
    if s[0] in MARCH:
        march[MARCH.index(s[0])] += 1
num = list(range(5))
a = list(itertools.combinations(num, 3))
ans = 0
for i in a:
    bf = 1
    for k in i:
        bf *= march[k]
    ans += bf
print(ans)
"""


"""
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]
q = int(input())
p = [int(input()) for _ in range(q)]
for i in range(n):
    D[i].insert(0, 0)
    D[i].insert(n+1, 0)
D.insert(0,[0 for _ in range(n + 2)])
D.insert(n + 2, [0 for _ in range(n + 2)])
print(D)
"""


"""
s = input()
bf = s[0]
ans = 0
for i in range(1,len(s)):
    if bf != s[i]:
        ans += 1
        bf = s[i]
print(ans)
"""


n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
bf = ta[0]
ans = ta[0]
for i in ta:
    if ans == i:
        continue
    elif ans[0] <= i[0] and ans[1] <= i[1]:
        ans = i
    else:
        a = ((ans[0] - 1) // i[0]) + 1
        b = ((ans[1] - 1) // i[1]) + 1
        ab = max(a,b)
        ans = [i[0] * ab, i[1] * ab]

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

Solution (Python):
n = int(input())
t,a = [],[]
for i in range(n):
    tmp = [int(i) for i in input().split()]
    t.append(tmp[0])
    a.append(tmp[1])

p,q = 1,1
for i in range(n):
    tmp = max(-(-p//t[i]),-(-q//a[i]))
    p = t[i]*tmp 
    q = a[i]*tmp
print(p+q)

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

print(T + A)

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

ratio = [list(map(int, input().split(' '))) for i in range(N)]
ans_T = ratio[0][0]
ans_A = ratio[0][1]
for i in range(1, N):
    now_T = ratio[i][0]
    now_A = ratio[i][1]

    count = max((ans_T+now_T-1)//now_T, (ans_A+now_A-1)//now_A)

    ans_T = ratio[i][0] * count
    ans_A = ratio[i][1] * count
print(ans_A + ans_T)

Solution (Python):










import math

N = int(input())
for i in range(0, N):
    t, a = map(int, input().split())
    if i == 0:
        tt = t
        aa = a
        ratio = 1
    else:
        if tt % t == 0:
            rt = tt // t
        else:
            rt = tt // t + 1
        if aa % a == 0:
            ra = aa // a
        else:
            ra = aa // a + 1

        ratio = max(rt, ra)

        tt = t * ratio
        aa = a * ratio
    

print("{}".format(tt + aa))

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

for i in range(n-1):
    t,a = map(int,input().split())
    if x%t == 0:
        x1 = x
        y1 = (x//t)*a
    else:
        x1 = (x//t+1)*t
        y1 = (x//t+1)*a
    
    if y % a == 0:
        x2 = (y//a)*t
        y2 = y
    else:
        x2 = (y//a+1)*t
        y2 = (y//a+1)*a
    
    if y1 < y:
        x1 = y1 = float("inf")
    if x2 < x:
        x2 = y2 = float("inf")
    
    if x1 + y1 >= x2 + y2:
        x = x2
        y = y2
    else:
        x = x1
        y = y1

print(x+y)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N = int(input())
t, a = 1, 1
for _ in range(N):
    Ti, Ai = inpl()
    n = max(-(-t//Ti), -(-a//Ai))
    t, a = n*Ti, n*Ai
print(t+a)

Solution (Python):
n = int(input())
l ,r = 1, 1
for i in range(n):
    t, a = list(map(int, input().split()))

    k = max(l//t + 1 if l%t else l//t, r//a + 1 if r%a else r//a)
    l = t*k
    r = a*k
print(l+r)

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

Solution (Python):

N=int(input())
table=[]
for i in range(N):
    t,x=map(int,input().split())
    table.append((t,x))
A,B=1,1
def f(A,x):
    t=A//x
    if A%x!=0:
        t+=1
    return t
    
for x,y in table:
    t=max(f(A,x),f(B,y))
    A=t*x
    B=t*y
print(A+B)

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

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

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

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

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