N = int(eval(input()))

TA = []

for i in range(N):

    TA.append(list(map(int, input().split())))



t_real = [TA[0][0]]

a_real = [TA[0][1]]



for i in range(1,N):

    t_cand = (t_real[i-1]//TA[i][0] + bool(t_real[i-1]%TA[i][0])) * TA[i][0]

    a_cand = (a_real[i-1]//TA[i][1] + bool(a_real[i-1]%TA[i][1])) * TA[i][1]

    

    if t_cand//TA[i][0] * TA[i][1] >= a_real[i-1]:

        t_real.append(t_cand)

        a_real.append(t_cand//TA[i][0] * TA[i][1])

        

    elif a_cand//TA[i][1] * TA[i][0] >= t_real[i-1]:

        a_real.append(a_cand)

        t_real.append(a_cand//TA[i][1] * TA[i][0])

        

    else:

        print("error")

        

print((t_real[-1]+a_real[-1]))
import sys

sdin = sys.stdin.readline



INF = float("inf")



n = int(sdin())

ta = []

for _ in range(n):

    ta.append(tuple(map(int, sdin().split())))

    

    

t_real = [ta[0][0]]

a_real = [ta[0][1]]

for i in range(1,n):

    t_k = t_real[i-1]//ta[i][0] + bool(t_real[i-1]%ta[i][0])

    a_k = a_real[i-1]//ta[i][1] + bool(a_real[i-1]%ta[i][1])

    

    # t_realとa_realの次の候補

    if t_k * ta[i][1] < a_real[i-1]:

        t_real_t = INF

        a_real_t = INF

    else:

        t_real_t = t_k * ta[i][0]

        a_real_t = t_k * ta[i][1]

        

    if a_k * ta[i][0] < t_real[i-1]:

        t_real_a = INF

        a_real_a = INF

    else:

        t_real_a = a_k * ta[i][0]

        a_real_a = a_k * ta[i][1]

        

    # 選択

    if (t_real_t + a_real_t) <= (t_real_a + a_real_a):

        t_real.append(t_real_t)

        a_real.append(a_real_t)

    else:

        t_real.append(t_real_a)

        a_real.append(a_real_a)

        

print((t_real[-1] + a_real[-1]))
N = int(eval(input()))
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))
t_real = [TA[0][0]]
a_real = [TA[0][1]]
for i in range(1, N):
    t_cand = (t_real[i - 1] // TA[i][0] + bool(t_real[i - 1] % TA[i][0])) * TA[i][0]
    a_cand = (a_real[i - 1] // TA[i][1] + bool(a_real[i - 1] % TA[i][1])) * TA[i][1]
    if t_cand // TA[i][0] * TA[i][1] >= a_real[i - 1]:
        t_real.append(t_cand)
        a_real.append(t_cand // TA[i][0] * TA[i][1])
    elif a_cand // TA[i][1] * TA[i][0] >= t_real[i - 1]:
        a_real.append(a_cand)
        t_real.append(a_cand // TA[i][1] * TA[i][0])
    else:
        print("error")
print((t_real[-1] + a_real[-1]))

import sys

sdin = sys.stdin.readline
INF = float("inf")
n = int(sdin())
ta = []
for _ in range(n):
    ta.append(tuple(map(int, sdin().split())))
t_real = [ta[0][0]]
a_real = [ta[0][1]]
for i in range(1, n):
    t_k = t_real[i - 1] // ta[i][0] + bool(t_real[i - 1] % ta[i][0])
    a_k = a_real[i - 1] // ta[i][1] + bool(a_real[i - 1] % ta[i][1])
    # t_realとa_realの次の候補
    if t_k * ta[i][1] < a_real[i - 1]:
        t_real_t = INF
        a_real_t = INF
    else:
        t_real_t = t_k * ta[i][0]
        a_real_t = t_k * ta[i][1]
    if a_k * ta[i][0] < t_real[i - 1]:
        t_real_a = INF
        a_real_a = INF
    else:
        t_real_a = a_k * ta[i][0]
        a_real_a = a_k * ta[i][1]
    # 選択
    if (t_real_t + a_real_t) <= (t_real_a + a_real_a):
        t_real.append(t_real_t)
        a_real.append(a_real_t)
    else:
        t_real.append(t_real_a)
        a_real.append(a_real_a)
print((t_real[-1] + a_real[-1]))

-N = int(eval(input())) -TA = [] -for i in range(N): -    TA.append(list(map(int, input().split()))) -t_real = [TA[0][0]] -a_real = [TA[0][1]] -for i in range(1, N): -    t_cand = (t_real[i - 1] // TA[i][0] + bool(t_real[i - 1] % TA[i][0])) * TA[i][0] -    a_cand = (a_real[i - 1] // TA[i][1] + bool(a_real[i - 1] % TA[i][1])) * TA[i][1] -    if t_cand // TA[i][0] * TA[i][1] >= a_real[i - 1]: -        t_real.append(t_cand) -        a_real.append(t_cand // TA[i][0] * TA[i][1]) -    elif a_cand // TA[i][1] * TA[i][0] >= t_real[i - 1]: -        a_real.append(a_cand) -        t_real.append(a_cand // TA[i][1] * TA[i][0]) +import sys + +sdin = sys.stdin.readline +INF = float("inf") +n = int(sdin()) +ta = [] +for _ in range(n): +    ta.append(tuple(map(int, sdin().split()))) +t_real = [ta[0][0]] +a_real = [ta[0][1]] +for i in range(1, n): +    t_k = t_real[i - 1] // ta[i][0] + bool(t_real[i - 1] % ta[i][0]) +    a_k = a_real[i - 1] // ta[i][1] + bool(a_real[i - 1] % ta[i][1]) +    # t_realとa_realの次の候補 +    if t_k * ta[i][1] < a_real[i - 1]: +        t_real_t = INF +        a_real_t = INF -        print("error") +        t_real_t = t_k * ta[i][0] +        a_real_t = t_k * ta[i][1] +    if a_k * ta[i][0] < t_real[i - 1]: +        t_real_a = INF +        a_real_a = INF +    else: +        t_real_a = a_k * ta[i][0] +        a_real_a = a_k * ta[i][1] +    # 選択 +    if (t_real_t + a_real_t) <= (t_real_a + a_real_a): +        t_real.append(t_real_t) +        a_real.append(a_real_t) +    else: +        t_real.append(t_real_a) +        a_real.append(a_real_a)