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):
N = int(input())
T = 1
A = 1
for i in range(N):
    Tk = [0,0]
    Ak = [0,0]
    Tn,An = map(int,input().rstrip().split(" "))
    if T % Tn == 0:
        Tk[0] = T
    else:
        Tk[0] = (T // Tn + 1) * Tn
    Ak[0] = (Tk[0] // Tn) * An
    if Ak[0] < A:
        Ak[0] = 10 ** 18 + 1

    if A % An == 0:
        Ak[1] = A
    else:
        Ak[1] = (A // An + 1) * An
    Tk[1] = (Ak[1] // An) * Tn
    if Tk[1] < T:
        Tk[1] = 10 ** 18 + 1
    
    if Tk[0] + Ak[0] <= Tk[1] + Ak[1]:
        T = Tk[0]
        A = Ak[0]
    else:
        T = Tk[1]
        A = Ak[1]
print(A + T)

Solution (Python):
N=int(input())
X,Y=map(int,input().split())
T,A=0,0
b,c=0,0
for i in range(N-1):
  T,A=map(int,input().split())
  b=((X+T-1)//T)*T
  c=(b//T)*A
  if c>=Y:
    X,Y=b,c
  else:
    Y=((Y+A-1)//A)*A
    X=(Y//A)*T
print(X+Y)

Solution (Python):

import sys
INF = float("inf")


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

    num = [0, 0]
    for i, (t, a) in enumerate(zip(T, A)):
        
        while True:
            if num[0] <= t and num[1] <= a:
                break
            if num[0] <= t:
                
                c = -(-num[1]//a)
                a *= c
                t *= c
                continue
            if num[1] <= a:
                
                c = -(-num[0]//t)
                199, 17
                a *= c
                t *= c
                continue
            c = max(-(-num[0]//t), -(-num[1]//a))
            
            a *= c
            t *= c
            continue
        num[0] = t
        num[1] = a
        
    print(num[0]+num[1])


if __name__ == '__main__':
    main()

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

T, A = 0, 0
for t, a in TA:
    if T == 0 and A == 0:
        T = t
        A = a
        continue
    if t == a:
        M = max(T, A)
        T = M
        A = M
    elif t < a:
        n = max((T // t) * t, (A // a) * t)
        while n < T or a * (n // t) < A:
            n += t
        T = n
        A = a * (T // t)
    else:
        n = max((A // a) * a, (T // t) * a)
        while n < A or t * (n // a) < T:
            n += a
        A = n
        T = t * (A // a)
print(A + T)

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

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

Solution (Python):
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    T, A = 1, 1
    for _ in range(N):
        Ti, Ai = read_ints()
        
        
        
        
        
        
        if T%Ti == 0:
            x0 = T//Ti
        else:
            x0 = T//Ti+1
        if A%Ai == 0:
            x1 = A//Ai
        else:
            x1 = A//Ai+1
        x = max(x0, x1)
        T, A = Ti*x, Ai*x
    return T+A


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

Solution (Python):
import sys
import numpy as np
import random
import math
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() 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)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	x, y = 1, 1
	for _ in range(n):
		t, a = LI()
		m = max((x+t-1)//t,(y+a-1)//a)
		x, y = m*t, m*a
	print(x+y)


if __name__ == '__main__':
    main()

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



res = [1, 1]
for i in range(n):
    t, a = TA[i]
    
    mx = max(-(-res[0] // t), -(-res[1] // a))
    res = [t * mx, a * mx]

print(sum(res))

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    for i in range(n):
        if i==0:
            t,a=map(int,readline().split())
        else:
            t_i,a_i=map(int,readline().split())
            tmp1=(t+t_i-1)//t_i
            tmp2=(a+a_i-1)//a_i
            x=max(tmp1,tmp2)
            t=t_i*x
            a=a_i*x
    
    print(a+t)

if __name__=="__main__":
    main()

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

ra,rb = 1,1
for i in range(n):
  a,b = map(int,input().split())
  n = max((ra+a-1)//a,(rb+b-1)//b)
  ra = a*n
  rb = b*n
    
print(ra+rb)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    t_pev, a_prev = TA[0]
    for i in range(1, n):
        t_now, a_now = TA[i]
        if t_pev <= t_now and a_prev <= a_now:
            t_pev, a_prev = t_now, a_now
        else:
            d = max((t_pev + (t_now - 1)) // t_now, (a_prev + (a_now - 1)) // a_now)
            t_pev, a_prev = t_now * d, a_now * d
    print(t_pev + a_prev)


if __name__ == '__main__':
    resolve()

Solution (Python):


import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    
    for i in range(max(x//a,y//b),max(x//a,y//b)+2):
        p,q=a*i,b*i
        if p>=x and q>=y:
            break
    return [p,q]
    
    
u,v=pairs[0]
for i in range(n-1):
    u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print(u+v)
    
    
        









'''def pair_revise(x,y,a,b):
    global p
    global q
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return p,q
u,v=1,1
for i in range(n):
    u,v=pair_revise(u,v,pairs[i][0],pairs[i][1])
    print(u,v)
print(u+v)'''

Solution (Python):


import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def ceil(x,y):
    return (-1)*((-x)//y)
    
n=I()
pairs=[LI() for i in range(n)]
x,y=1,1
for i in range(n):
    a=pairs[i][0]
    b=pairs[i][1]
    k=max(ceil(x,a),ceil(y,b))
    x,y=a*k,b*k
print(x+y)





'''def pair_revise(x,y,a,b):
    global p
    global q
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return p,q
u,v=1,1
for i in range(n):
    u,v=pair_revise(u,v,pairs[i][0],pairs[i][1])
    print(u,v)
print(u+v)'''

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

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

for t,a in ta:
  i=(t+tv-1)//t
  j=(a+av-1)//a
  k=max(i,j)
  tv=t*k
  av=a*k
print(tv+av)

Solution (Python):
t = 1
a = 1

for i in range(int(input())):
  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())
ta = []
for i in range(n):
    t,a = map(int,input().split())
    ta.append([t,a])
count = ta[0][0] + ta[0][1]
t = ta[0][0]
a = ta[0][1]
for i in range(1,n):
    if ta[i][0] == ta[i][1]:
        count += max(t,a) - min(t,a)
        t = max(t,a)
        a = max(t,a)
    elif ta[i][0] > ta[i][1]:
        if a % ta[i][1] != 0:
            count += ta[i][1] - (a % ta[i][1])
            a += ta[i][1] - (a % ta[i][1])
        if (a//ta[i][1]) * ta[i][0] >= t:
            count += (a//ta[i][1]) * ta[i][0] - t
            t = (a//ta[i][1]) * ta[i][0]
        else:
            if t % ta[i][0] != 0:
                count += ta[i][0] - (t % ta[i][0])
                t += ta[i][0] - (t % ta[i][0])
            count += (t//ta[i][0]) * ta[i][1] - a
            a = (t//ta[i][0]) * ta[i][1]
    else:
        if t % ta[i][0] != 0:
            count += ta[i][0] - (t % ta[i][0])
            t += ta[i][0] - (t % ta[i][0])
        if (t//ta[i][0]) * ta[i][1] >= a:
            count += (t//ta[i][0]) * ta[i][1] - a
            a = (t//ta[i][0]) * ta[i][1]
        else:
            if a % ta[i][1] != 0:
                count += ta[i][1] - (a % ta[i][1])
                a += ta[i][1] - (a % ta[i][1])
            count += (a//ta[i][1]) * ta[i][0] - t
            t = (a//ta[i][1]) * ta[i][0]
print(count)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





"""
N = rand_N(2, 6)
query = rand_query(2, 10, N)
print(query)
ans_taka, ans_aoki = query[0]
"""

N = getN()
query =  [getList() for i in range(N)]

ans_taka, ans_aoki = query[0]



def vote(taka, aoki, ratio):
    ratio_taka, ratio_aoki = ratio
    taka_multi = (taka + ratio_taka - 1) // ratio_taka
    aoki_multi = (aoki + ratio_aoki - 1) // ratio_aoki
    multi = max(taka_multi, aoki_multi)

    return [ratio_taka * multi, ratio_aoki * multi]


for i in range(1, N):
    ans_taka, ans_aoki = vote(ans_taka, ans_aoki, query[i])
    
print(ans_taka + ans_aoki)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





"""
N = rand_N(2, 6)
query = rand_query(2, 10, N)
print(query)
ans_taka, ans_aoki = query[0]
"""

N = getN()
query =  [getList() for i in range(N)]
ans_taka, ans_aoki = query[0]


def vote(taka, aoki, ratio):
    ratio_taka, ratio_aoki = ratio
    taka_multi = (taka + ratio_taka - 1) // ratio_taka
    aoki_multi = (aoki + ratio_aoki - 1) // ratio_aoki
    multi = max(taka_multi, aoki_multi)

    return [ratio_taka * multi, ratio_aoki * multi]

for i in range(1, N):
    ans_taka, ans_aoki = vote(ans_taka, ans_aoki, query[i])
    
print(ans_taka + ans_aoki)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

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

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

def main():
    n=II()
    ta=LLI(n)
    x=y=-1
    for t,a in ta:
        if x==-1:
            x,y=t,a
            continue
        c=max((t+x-1)//t,(a+y-1)//a)
        x=c*t
        y=c*a
    print(x+y)

main()

Solution (Python):
import math
from fractions import Fraction

N = int(input())
a, b = map(int, input().split())
ret_a = a
ret_b = b
for _ in range(1, N):
    a, b = map(int, input().split())
    x = math.ceil(max(Fraction(ret_a, a), Fraction(ret_b, b)))
    ret_a = a * x
    ret_b = b * x
print(ret_a + ret_b)

Solution (Python):
import sys
def v():
    N=int(sys.stdin.readline())
    P=[]
    pt,pa=tuple(map(int,sys.stdin.readline().split()))
    res=pt+pa
    for _ in [0]*(N-1):
        xt,xa=tuple(map(int,sys.stdin.readline().split()))
        xs=xt+xa
        kt=pt//xt if pt%xt ==0 else pt//xt+1
        ka=pa//xa if pa%xa ==0 else pa//xa+1
        k=max([kt,ka])
        pt,pa=k*xt,k*xa
        res=pt+pa
    print(res)
if __name__=='__main__':v()

Solution (Python):
def main():
    N = int(input())
    TA = [list(map(int, input().split(' '))) for _ in range(N)]
    if N == 1:
        print(sum(TA[0]))
        return
    cur_t, cur_a = TA[0]
    for t, a in TA[1:]:
        ratio = max([(cur_t + t - 1) // t, (cur_a + a - 1) // a])
        cur_t, cur_a = ratio * t, ratio * a
    print(cur_t + cur_a)


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil 
N = int(input())
votes = [1,1]
rate = 1
for i in range(N):
    t,a = map(int,input().split())
    rate = max((votes[0] - 1) // t, (votes[1] - 1) // a) + 1
    
    votes = [t * rate, a * rate]

print(sum(votes))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


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


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A,B = [1,1]
for _ in range(N):
  a,b = IL()
  if A*b > B*a: 
    A = -(-A//a)*a
    B = (A//a)*b
  else:
    B = -(-B//b)*b
    A = (B//b)*a
print(A+B)

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

Solution (Python):

import math

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

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

n = int(input())
tv = av = 1
t = [0]*n; a = [0]*n
for i in range(n):
    t[i], a[i] = imap()
for i in range(n):
    tmp = max(tv//t[i]+(tv%t[i]!=0), av//a[i]+(av%a[i]!=0))
    tv = t[i]*tmp; av=a[i]*tmp
print(tv+av)

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

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

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

print(T + A)

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

print(t + a)

Solution (Python):
import math

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

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

print(x + y)

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

anst = 1
ansa = 1
for _ in range(n):
    ti, ai = map(int, input().split())
    anst = ti * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))
    ansa = ai * math.ceil(max(Fraction(anst, ti), Fraction(ansa, ai)))
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        
print(int(anst + ansa))

Solution (Python):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
T = [0]*N
A = [0]*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):
    s = T[i] + A[i]
    now = 1
    l = 1
    r = 10**18//s + 1
    mae = -1
    while now != mae:
        mae = now
        if T[i]*now < t or A[i]*now < a:
            l = now
        else:
            r = now
        now = (l+r+1)//2
    t,a = T[i]*now,A[i]*now
print(t+a)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    A, B = [0] * N, [0] * N

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

    x = 1

    for i in range(N-1):
        x = max(-(-A[i]*x // A[i+1]), -(-B[i]*x // B[i+1]))

    print(x*(A[N-1]+B[N-1]))


resolve()

Solution (Python):
from decimal import Decimal, ROUND_CEILING

N = int(input())
pairs = (map(Decimal, input().split()) for _ in range(N))

t = Decimal('1')
a = Decimal('1')
ceil = lambda d: d.to_integral_exact(rounding=ROUND_CEILING)

for ti, ai in pairs:
    mul = max(ceil(t / ti), ceil(a / ai))
    t = ti * mul
    a = ai * mul

print(int(t + a))

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

print(t + a)

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

Solution (Python):
from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())
 
takahashi,aoki = 1,1
 
for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(str(takahashi))/Decimal(a)),ceil(Decimal(str(aoki))/Decimal(b)))
    takahashi = c*a
    aoki = c*b
 
print(takahashi+aoki)

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

N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(takahashi/Decimal(a)),ceil(aoki/Decimal(b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Solution (Python):
from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(takahashi)/Decimal(a)),ceil(Decimal(aoki)/Decimal(b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

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

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max((takahashi-1)//a+1,(aoki-1)//b+1)
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Solution (Python):
from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = [int(x) for x in stdin.readline().rstrip().split()]
 
for _ in range(N-1):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = max((t + T - 1) // T,(a + A - 1) // A)
    t = n*T
    a = n*A
    
print(t+a)

Solution (Python):
from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = 1,1
 
for _ in range(N):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = max((t + T - 1) // T,(a + A - 1) // A)
    t = n*T
    a = n*A
    
print(t+a)

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

A, B = 1, 1

for i in range(N):
    XA, XB = map(int, input().split())

    if A * XB > XA * B:
        d = (A + XA - 1) // XA
        A, B = d * XA, d * XB
    else:
        d = (B + XB - 1) // XB
        A, B = d * XA, d * XB

print(A + B)

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

vt=va=1
for _ in range(N):
  T,A=map(int,input().split())
  kt=-(-vt//T)
  ka=-(-va//A)
  
  k=max(kt,ka)
  vt=k*T
  va=k*A  
  
  
print(vt+va)

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

vt=va=0
for _ in range(N):
  T,A=map(int,input().split())
  kt=-(-vt//T)
  ka=-(-va//A)
  
  k=max(kt,ka,1)
  vt=k*T
  va=k*A  
  
  
print(vt+va)

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

vt=va=0
for _ in range(N):
  T,A=map(int,input().split())
  kt=-(-vt//T)
  ka=-(-va//A)
  if kt==0 and ka==0:
    vt=T
    va=A
  else:
    k=max(kt,ka)
    vt=k*T
    va=k*A
  
  
  
print(vt+va)

Solution (Python):
import math
N = int(input())
ta = [tuple(map(int,input().split())) for _ in range(N)]
left = ta[0][0]
right = ta[0][1]
res = left+right
for t,a in ta[1:]:
    tmp1 = (left+t-1)//t
    tmp2 = (right+a-1)//a
    buff = max(tmp1,tmp2)
    right = buff*a
    left = buff*t
print(int(right+left))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Solution (Python):


import sys

import math




























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        
        multiply_rate = max((a + s - 1) // s, (b + t - 1) // t)
        return (s * multiply_rate, t * multiply_rate)
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 1, 1
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        
    
    
    print(a + b)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  
  t_rate = (ary[0] - 1) // tmp_ary[0] + 1
  a_rate = (ary[1] - 1) // tmp_ary[1] + 1
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))
print(int(ary[0] + ary[1]))

Solution (Python):
n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  t_rate = (ary[0] - 1) // tmp_ary[0] + 1
  a_rate = (ary[1] - 1) // tmp_ary[1] + 1
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))
print(int(ary[0] + ary[1]))

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

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

Solution (Python):
import sys

def resolve():
    readline=sys.stdin.readline

    n=int(readline())
    a,b=map(int, readline().rstrip().split())
    for _ in range(n-1):
        x,y=map(int, readline().rstrip().split())
        start=max(a//x,b//y)
        for z in range(start,start+1000):
            if x*z>=a and y*z>=b:
                a,b=x*z,y*z
                break
    print(a+b)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    
    
    n=int(readline())
    for i in range(n):
        x,y=map(int, readline().rstrip().split())
        if i==0:
            a,b=x,y
            continue
        start=max(a//x,b//y)
        zz=start-1
        for z in range(start,start+1000):
            if x*z>=a and y*z>=b:
                zz=z
                break
        a,b=x*z,y*z
    print(a+b)
    
    

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()