CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))

def check(t, a):
    T, A = list(map(int, input().split()))
    if T >= t and A >= a:
        t = T
        a = A
        return t, a
    if T >= t and A < a:
        t = T * ((a + (A-1))//A)
        a = A * ((a + (A-1))//A)
        return t, a
    if T < t and A >= a:
        t = T * ((t + (T-1))//T)
        a = A * ((t + (T-1))//T)
        return t, a
    if T < t and A < a:
        t = T * max((t + (T-1))//T, (a + (A-1))//A)
        a = A * max((t + (T-1))//T, (a + (A-1))//A)
        return t, a
t = 0
a = 0
for _ in range(N):
    t, a = check(t, a)

print((t + a))

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

def check(t, a):
    T, A = list(map(int, input().split()))
    t = T * max((t + (T-1))//T, (a + (A-1))//A)
    a = A * max((t + (T-1))//T, (a + (A-1))//A)
    return t, a

t = 1
a = 1
for _ in range(N):
    t, a = check(t, a)

print((t + a))
# Original solution
n = int(eval(input()))
x, y = [int(i) for i in input().split()]

for i in range(n-1):
  t, a = [int(i) for i in input().split()]
  
  if t >= x and a >= y:
    x = t
    y = a

  else:
    c = 2
    while True:
      x_ = t * c
      y_ = a * c
      if x_ >= x and y_ >= y:
        break
      c += 1
      
    x, y = x_, y_
    
print((x+y))

# Optimized solution
n = int(eval(input()))
x, y = [int(i) for i in input().split()]

for i in range(n-1):
  t, a = [int(i) for i in input().split()]
  
  if t >= x and a >= y:
    x = t
    y = a



  else:
    c = max(-(-x//t), -(-y//a))

    x = t * c
    y = a * c
    
print((x+y))
# Original solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = TA[0][0]
vote_A = TA[0][1]
if len(TA)>1:
	for Ti, Ai in TA[1:]:
		n = 1
		tmp_Ti = Ti * n
		tmp_Ai = Ai * n
		while tmp_Ti < vote_T or tmp_Ai < vote_A:
			n += 1
			tmp_Ti = Ti * n
			tmp_Ai = Ai * n
		vote_T = tmp_Ti
		vote_A = tmp_Ai
print((vote_A + vote_T))

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

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

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for x, y in TA:
	# n = max(ceil(vote_T/x),ceil(vote_A/y))
	# n = max(-(-vote_T // x), -(-vote_A // y))
	n = max((vote_T//x + (vote_T%x!=0)),vote_A//y + (vote_A%y!=0))
	vote_T = x * n
	vote_A = y * n
print((vote_A + vote_T))
# Original solution
from math import ceil
from decimal import Decimal

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

t,a = 1,1
for i in range(N):
    r = Decimal(max(ceil(t/T[i]),ceil(a/A[i])))
    t = r*T[i]
    a = r*A[i]

print((t+a))

# Optimized solution
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from math import ceil
from decimal import *
N = int(eval(input()))
TA = [list(map(int,input().split())) for _ in range(N)]


t,a = 1,1
for i in range(N):
    n = Decimal(max(ceil(t/TA[i][0]), ceil(a/TA[i][1])))
    t = n*TA[i][0]
    a = n*TA[i][1]

print((t+a))
# Original solution
N = int(eval(input()))
def func(T_pre, A_pre, T, A):
  for i in range(1, 10**10):
    if T_pre <= T and A_pre <= A:
      return T, A
    else:
      T = T*(i+1)/i
      A = A*(i+1)/i
for i in range(N):
  T, A = list(map(int, input().split()))
  if i == 0:
    T_pre = T
    A_pre = A
  else:
    T_pre, A_pre = func(T_pre, A_pre, T, A)
print((int(T_pre+A_pre)))

# Optimized solution
N = int(eval(input()))
def func(T_pre, A_pre, T, A):
  if T_pre <= T and A_pre <= A:
    return T, A
  else:
    t = -(-T_pre//T)
    a = -(-A_pre//A)
    x = max(t, a)
    return T*x, A*x
for i in range(N):
  T, A = list(map(int, input().split()))
  if i == 0:
    T_pre = T
    A_pre = A
  else:
    T_pre, A_pre = func(T_pre, A_pre, T, A)
print((int(T_pre+A_pre)))
# Original solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
TA = [LIST() for _ in range(N)]

T = TA[0][0]
A = TA[0][1]

for t, a in TA[1:]:
	p = max((T+t-1)//t, (A+a-1)//a)
	T = t*p
	A = a*p
	
print((T+A))



# Optimized solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
TA = [LIST() for _ in range(N)]

T = TA[0][0]
A = TA[0][1]

for t, a in TA[1:]:
	p = max(-(-T//t), -(-A//a))
	T = t*p
	A = a*p
	
print((T+A))
# Original solution
N = int(eval(input()))
vote = [1,1]
for i in range(N):
    ratio = list(map(int, input().split()))
    for j in range(2):
        while(vote[j] % ratio[j] != 0):
            vote[j] += 1
    if vote[0] * ratio[1] < vote[1] * ratio[0]:
        while (vote[0] * ratio[1] != vote[1] * ratio[0]):
            vote[0] += 1;
    if vote[0] * ratio[1] > vote[1] * ratio[0]:
        while (vote[0] * ratio[1] != vote[1] * ratio[0]):
            vote[1] += 1;
print((vote[0] + vote[1]))

# Optimized solution
N = int(eval(input()))
vote = [1,1]
for i in range(N):
    ratio = list(map(int, input().split()))
    for j in range(2):
        while(vote[j] % ratio[j] != 0):
            vote[j] += 1
    if vote[0] * ratio[1] < vote[1] * ratio[0]:
        vote[0] = vote[1] // ratio[1] * ratio[0];
    if vote[0] * ratio[1] > vote[1] * ratio[0]:
        vote[1] = vote[0] // ratio[0] * ratio[1];
print((vote[0] + vote[1]))
# Original solution
n = int(eval(input()))
A = [list(map(int,input().split())) for i in range(n)]

# def gcd(x, y):
#     #print(x, y)
#     while x != 0 and y != 0:
#         x, y = max(x, y), min(x, y)
#         x %= y
#     return y

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

# for i in range(1, n):
#     lcms = [0] * 2
#     for j in range(2):
#         lcms[j] = lcm(A[i][j], A[i-1][j])
#     print("lcms", lcms)
#     st = 0
#     op = 1
#     if lcms[0] > lcms[1]:
#         st = 1
#         op = 0
#     new_1 = (lcms[st] // A[i][st]) * A[i][op]
#     print(new_1)
#     if new_1 >= A[i-1][op]:
#         A[i][op] = new_1
#         A[i][st] = lcms[0]
#     else:
#         new_0 = lcms[op] // A[i][op] * A[i][st]
#         A[i][st] = new_0
#         A[i][op] = lcms[op]
#     print(A[i])

# print(sum(A[-1]))

for i in range(1, n):
    s = A[i][0]
    t = A[i][1]
    while not (A[i][0] >= A[i-1][0] and A[i][1] >= A[i-1][1]):
        A[i][0] += s
        A[i][1] += t
        # print(A[i-1], A[i])

print((sum(A[-1])))

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

# def gcd(x, y):
#     #print(x, y)
#     while x != 0 and y != 0:
#         x, y = max(x, y), min(x, y)
#         x %= y
#     return y

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

# for i in range(1, n):
#     lcms = [0] * 2
#     for j in range(2):
#         lcms[j] = lcm(A[i][j], A[i-1][j])
#     print("lcms", lcms)
#     st = 0
#     op = 1
#     if lcms[0] > lcms[1]:
#         st = 1
#         op = 0
#     new_1 = (lcms[st] // A[i][st]) * A[i][op]
#     print(new_1)
#     if new_1 >= A[i-1][op]:
#         A[i][op] = new_1
#         A[i][st] = lcms[0]
#     else:
#         new_0 = lcms[op] // A[i][op] * A[i][st]
#         A[i][st] = new_0
#         A[i][op] = lcms[op]
#     print(A[i])

# print(sum(A[-1]))

for i in range(1, n):
    s = -(-A[i-1][0] // A[i][0])
    t = -(-A[i-1][1] // A[i][1])
    # print(i,s,t)
    for j in range(2):
        A[i][j] *= max(s, t)
    # print(A)
    
print((sum(A[-1])))
# Original solution
n = int(eval(input()))
ta = [[int(i) for i in input().split()] for j in range(n)]

a = ta[0][0]
b = ta[0][1]
for i in range(1, n):
    tempa = ta[i][0]
    tempb = ta[i][1]
    j = 2
    while(tempa < a or tempb < b):
        tempa = ta[i][0] * j
        tempb = ta[i][1] * j
        j += 1

    a = tempa
    b = tempb

print((a+b))


# Optimized solution
import math

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

a = 1
b = 1
for i in range(n):
    #n = max(math.floor(a/ta[i][0]), math.floor(b/ta[i][1]))
    n = max(~-a//ta[i][0] + 1, ~-b//ta[i][1] + 1)
    a = n * ta[i][0]
    b = n * ta[i][1]

print((a+b))
# Original solution
n = int(eval(input()))
x,y = list(map(int,input().split()))
for i in range(n-1):
    t,a = list(map(int,input().split()))
    o = t
    p = a
    while x > o or y > p:
        o += t
        p += a
    x = o
    y = p
print((x+y))

# Optimized solution
n = int(eval(input()))
A,B = 0,0
for i in range(n):
    x,y = list(map(int,input().split()))
    t,a = 1,1
    if A > x:
        t = A // x
        if A % x != 0:
            t += 1
    if B > y:
        a = B // y
        if B % y != 0:
            a += 1
    m = max(t,a)
    A = x*m
    B = y*m
print((A+B))
# Original solution
def find_current_score(current_big_score, current_small_score, big_ratio, small_ratio):
    candidate_big_score = current_big_score
    candidate_small_score = 0
    while(True):
        candidate_small_score = candidate_big_score / big_ratio * small_ratio
        flag1 = candidate_small_score % 1 == 0.0
        flag2 = candidate_small_score >= current_small_score
        if(flag1 and flag2):
            break
        candidate_big_score += 1
    return int(candidate_big_score), int(candidate_small_score)

t_list = []
a_list = []

N = int(eval(input()))
for  n in range(N):
    t, a = list(map(int, input().strip().split()))
    t_list.append(t)
    a_list.append(a)
    
t_score = t_list[0]
a_score = a_list[0]

for n in range(1, N):
    t_ratio = t_list[n]
    a_ratio = a_list[n]
    t_score, a_score = find_current_score(t_score, a_score, t_ratio, a_ratio)
    
print((t_score + a_score))

# Optimized solution
def compute_current_score(previous_t_score, previous_a_score, current_t_ratio, current_a_ratio):
    initial_divisor = max(previous_t_score // current_t_ratio, previous_a_score // current_a_ratio)
    current_t_score = 0
    current_a_score = 0
    while(True):
        current_t_score = initial_divisor * current_t_ratio
        current_a_score = initial_divisor * current_a_ratio
        if((current_t_score >= previous_t_score) and (current_a_score >= previous_a_score)):
            break
        initial_divisor += 1
    return current_t_score, current_a_score

N = int(eval(input()))
t_score, a_score = list(map(int, input().strip().split()))

for  n in range(N-1):
    t_ratio, a_ratio = list(map(int, input().strip().split()))
    t_score, a_score = compute_current_score(t_score, a_score, t_ratio, a_ratio)
    
print((t_score + a_score))
# Original solution
# C問題
N = int(eval(input()))
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1,  N+1):
    tmp_t = 0
    tmp_a = 0
    if i == N:
        flag = False        
    while flag:
        tmp_t += TA[i][0]
        tmp_a += TA[i][1]
        if tmp_t >= t and tmp_a >= a:
            t = tmp_t
            a = tmp_a
            break
    
print((t+a))        

# Optimized solution
# C問題
N = int(eval(input()))
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1,  N+1):
    tmp_t = 0
    tmp_a = 0
    if i == N:
        flag = False
        break
    k = max(t // TA[i][0], a // TA[i][1])   # 整数k
    while flag:   # 整数倍(足していく)していって両方がが超えた時の値が得票数になる
        tmp_t = k * TA[i][0]
        tmp_a = k * TA[i][1]
        if tmp_t >= t and tmp_a >= a:
            t = tmp_t
            a = tmp_a
            break
        k += 1
    
print((t+a))
# Original solution
n=int(eval(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:
    r=ta[i][0]
    l=ta[i][1]
    while (ta[i-1][0]>ta[i][0]) or (ta[i-1][1]>ta[i][1]):
      ta[i][0]+=r
      ta[i][1]+=l
print((sum(ta[-1])))

# Optimized solution
n=int(eval(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])))
# Original solution
N=int(eval(input()))
import copy
inp=[]
for i in range(N):
    inp.append(list(map(int,input().split(" "))))

def compare(A,B):
    if A[0]>=B[0] and A[1]>=B[1]:
        return A
    else:
        A0=copy.copy(A[0])
        A1=copy.copy(A[1])
        while A0<B[0] or A1<B[1]:
            A0+=A[0]
            A1+=A[1]
        return [A0,A1]
st=inp[0]
for i in range(1,N):
    st=compare(inp[i],st)
print((sum(st)))

# Optimized solution
N=int(eval(input()))
import copy
inp=[]
for i in range(N):
    inp.append(list(map(int,input().split(" "))))

def compare(A,B):
    if A[0]>=B[0] and A[1]>=B[1]:
        return A
    else:
        if B[0]%A[0]!=0:
            i=B[0]//A[0]+1
        else:
            i=B[0]//A[0]
        if B[1]%A[1]!=0:
            j=B[1]//A[1]+1 
        else:
            j=B[1]//A[1]
        m=max(i,j)
        return [A[0]*m,A[1]*m]
st=inp[0]
for i in range(1,N):
    st=compare(inp[i],st)
print((sum(st)))
# Original solution
N = int(eval(input()))
t = []
a = []
for i in range(0,N):
	tokuhyousuu = list(map(int,input().split()))
	t.append(tokuhyousuu[0])
	a.append(tokuhyousuu[1])

T = t[0]
A = a[0]
r = 1
r_2 = 1

for j in range(0,N):
	if(T<=t[j] and A<=a[j]):
		T = t[j]
		A = a[j]

	elif(T>t[j] and A>a[j]):
		for k in range(1000000000000000000000000):
			if(T<=(k*t[j])):
				r = k
				break

		for l in range(1000000000000000000000000):
			if(A<=(l*a[j])):
				r_2 = l
				break

		T = t[j]*(max(r,r_2))
		A = a[j]*(max(r,r_2))


	elif(T>t[j]):
		for p in range(1000):
			if(T<=(p*t[j])):
				T = p*t[j]
				A = p*a[j]
				break

	elif(A>a[j]):
		for q in range(1000):
			if(A<=(q*a[j])):
				T = q*t[j]
				A = q*a[j]
				break
print((T+A))

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

T = 1
A = 1

for j in range(0,N):
	if(T<=t[j] and A<=a[j]):
		T = t[j]
		A = a[j]

	elif(T>t[j] and A>a[j]):
		if(T%t[j] == 0):
			r_1 = T//t[j]
		else:
			r_1 = T//t[j] + 1

		if(A%a[j] == 0):
			r_2 = A//a[j]
		else:
			r_2 = A//a[j] + 1

		r = max(r_1,r_2)

		T = t[j]*r
		A = a[j]*r


	elif(T>t[j]):
		if(T%t[j]==0):
			r = T//t[j]
		else:
			r = T//t[j]+1
		
		T = t[j]*r
		A = a[j]*r

	elif(A>a[j]):
		if(A%a[j] == 0):
			r = A//a[j]
		else:
			r = A//a[j]+1			
		T = t[j]*r
		A = a[j]*r

print((T+A))
# Original solution
n = int(eval(input()))
x, y = 1, 1
for _ in range(n):
    t, a = list(map(int, input().split()))
    if x <= t and y <= a:
        x = t
        y = a
    elif x <= t and y > a:
        i = 1
        while y > a:
            a //= i
            i += 1
            a *= i
        x = i*t
        y = a

    elif x > t and y <= a:
        i = 1
        while x > t:
            t //= i
            i +=1
            t *= i
        y = i*a
        x = t

    elif x > t and y > a:
        i = 1
        while x > t or y > a:
            t //= i
            a //= i
            i += 1
            t *= i
            a *= i
        x = t
        y = a

print((x+y))

# Optimized solution
n = int(eval(input()))
x, y = 1, 1
for _ in range(n):
    t, a = list(map(int, input().split()))
    if x <= t and y <= a:
        x = t
        y = a
    elif x <= t and y > a:
        if y % a == 0:
            i = y // a
        else:
            i = y // a + 1
        y = i*a
        x = i*t
    elif x > t and y <= a:
        if x % t == 0:
            i = x // t
        else:
            i = x // t + 1
        x = i*t
        y = i*a
    elif x > t and y > a:
        if x % t == 0:
            i_x = x // t
        else:
            i_x = x // t + 1

        if y % a == 0:
            i_y = y // a
        else:
            i_y = y // a + 1
        bigger = max(i_x, i_y)
        x = bigger*t
        y = bigger*a
print((x+y))
# Original solution
n=int(eval(input()))
suji=[]
for i in range (n):
	suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
	if i%2==0:
		tlist.append(suji[i])
	else:
		alist.append(suji[i])

for i in range(n-1):
	k=1
	while tlist[i]>tlist[i+1]*k or alist[i]>alist[i+1]*k:
		k+=1
	tlist[i+1]=tlist[i+1]*k
	alist[i+1]=alist[i+1]*k

print((int(tlist[n-1]+alist[n-1])))

# Optimized solution
n=int(eval(input()))
suji=[]
for i in range (n):
	suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
	if i%2==0:
		tlist.append(suji[i])
	else:
		alist.append(suji[i])

for i in range(n-1):
	aaa=alist[i]//alist[i+1]
	ttt=tlist[i]//tlist[i+1]
	if alist[i]%alist[i+1]!=0:
		aaa+=1
	if tlist[i]%tlist[i+1]!=0:
		ttt+=1
	k=max(aaa,ttt)
	tlist[i+1]=tlist[i+1]*k
	alist[i+1]=alist[i+1]*k

print((int(tlist[n-1]+alist[n-1])))
# Original solution
n=int(eval(input()))
p,q=1,1

for _ in range(n):
    t,a=list(map(int,input().split()))
    n=1
    while p>n*t or q>n*a:
        n+=1
    p,q=n*t,n*a

print((p+q))

# Optimized solution
n=int(eval(input()))
p,q=1,1

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

print((p+q))
# Original solution
N=int(eval(input()))
TA=[list(map(int, input().split())) for _ in range(N)]
ls=[[TA[0][0],TA[0][1]]]
for i in range(1,N):
    tmp=[TA[i][0],TA[i][1]]
    j=2
    while 1:
        if tmp[0]>=ls[-1][0] and tmp[1]>=ls[-1][1]:
            break
        tmp[0]=TA[i][0]*j
        tmp[1]=TA[i][1]*j
        j+=1
    ls.append([tmp[0],tmp[1]])
print((ls[-1][0]+ls[-1][1]))


# Optimized solution
N=int(eval(input()))
TA=[list(map(int, input().split())) for _ in range(N)]
ls=[[TA[0][0],TA[0][1]]]
for i in range(1,N):
    tmp=[TA[i][0],TA[i][1]]
    a=max(-(ls[-1][0]//(-tmp[0])),-(ls[-1][1]//(-tmp[1])))
    tmp[0]*=a
    tmp[1]*=a
    ls.append([tmp[0],tmp[1]])
print((ls[-1][0]+ls[-1][1]))
# Original solution
def main():
    n = int(eval(input()))
    t = []
    a = []
    for i in range(n):
        in_t,in_a = list(map(int,input().split(' ')))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        while True:
            if tmp_t/tmp_a == t[i]/a[i]:
                break
            elif tmp_t/tmp_a < t[i]/a[i]:
                tmp_t += 1
            else:
                tmp_a += 1
    return tmp_t+tmp_a

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

# Optimized solution
def main():
    n = int(eval(input()))
    t = []
    a = []
    for i in range(n):
        in_t,in_a = list(map(int,input().split(' ')))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        if tmp_t%t[i] != 0:
            x = (tmp_t - tmp_t%t[i] + t[i])//t[i]
        else:
            x = tmp_t//t[i]

        if tmp_a%a[i] != 0:
            y = (tmp_a - tmp_a%a[i] + a[i])//a[i]
        else:
            y = tmp_a//a[i]

        if x <= y:
            x = y
        else:
            y = x
        tmp_t = t[i]*x
        tmp_a = a[i]*y
    return tmp_t+tmp_a

if __name__ == '__main__':
    print((main()))
# Original solution
from sys import stdin

n = int(stdin.readline())

t_votes, a_votes = (int(x) for x in stdin.readline().split())

p_t, p_a = t_votes, a_votes

for _ in range(n-1):
    t, a = (int(x) for x in stdin.readline().split())
    if (t, a) == (p_t, p_a):
        continue
    for i in range(1, 1000000):
        t_v, a_v = t * i, a * i
        if t_v >= t_votes and a_v >= a_votes:
            break
    t_votes, a_votes = t_v, a_v
    p_t, p_a = t, a

print((t_votes + a_votes))


# Optimized solution
from sys import stdin

n = int(stdin.readline())

m = 10 ** 18 + 7


t_votes, a_votes = (int(x) for x in stdin.readline().split())

p_t, p_a = t_votes, a_votes

for _ in range(n-1):
    t, a = (int(x) for x in stdin.readline().split())
    if (t, a) == (p_t, p_a):
        continue
    for i in range(max(t_votes // t, a_votes // a) - 1, m):
        t_v, a_v = t * i, a * i
        if t_v >= t_votes and a_v >= a_votes:
            break
    t_votes, a_votes = t_v, a_v
    p_t, p_a = t, a

print((t_votes + a_votes))
# Original solution
import sys
input = sys.stdin.readline

def I(): return int(eval(input()))
def MI(): return list(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
        xa=NA//A
        x=min(xt,xa)
        tempT=T*x
        tempA=A*x
        while tempT<NT or tempA<NA:
            tempT+=T
            tempA+=A
        NT=tempT
        NA=tempA
    print((NT+NA))
            

main()


# Optimized solution
import sys
input = sys.stdin.readline

def I(): return int(eval(input()))
def MI(): return list(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()