Problem:
 Score : 300 points    Problem Statement AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i -th (1≦i≦N) time, the ratio was T_i:A_i .
It is known that each candidate had at least one vote when he checked the report for the first time.  Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N -th time.
It can be assumed that the number of votes obtained by each candidate never decreases.      Constraints  1≦N≦1000  1≦T_i,A_i≦1000 (1≦i≦N)  T_i and A_i  (1≦i≦N) are coprime.  It is guaranteed that the correct answer is at most 10^{18} .         Input The input is given from Standard Input in the following format:  N  T_1  A_1  T_2  A_2  :  T_N  A_N       Output Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N -th time.        Sample Input 1 3
2 3
1 1
3 2      Sample Output 1 10  When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4 , the total number of votes at the end is 10 , which is the minimum possible number.       Sample Input 2 4
1 1
1 1
1 5
1 100      Sample Output 2 101  It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.       Sample Input 3 5
3 10
48 17
31 199
231 23
3 2      Sample Output 3 6930

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    from math import ceil

    t_cur, a_cur = list(map(int, readline().split()))

    for _ in range(n - 1):
        t, a = list(map(int, readline().split()))
        i_t = (t_cur + t - 1) // t
        i_a = (a_cur + a - 1) // a
        x = max(i_t, i_a)
        t_cur, a_cur = t * x, a * x

    print(t_cur + a_cur)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

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

    ans = A + B
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from fractions import Fraction
import math

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


"""

・Ti, Ai を i回目の二人の得票数の比
・Pti, Pai をi回目の二人の得票数とすると、

Pti : Pai = Ti : Ai なので、　Pti = M * Ti, Pai = M * Ai (M=1,2,3,...)と表せる。

とあらわせる。ここで、
Pti-1 <= Pti
Pai-1 <= Pai
なので、Mは
M >= Pti-1 / Ti
M >= Pai-1 / Ai
の両方を満たすものになり、得票数を最小に保つにはMもなるべく小さくとる
"""
t,a = 0,0
for i in range(N):
    if i == 0:
        t,a = TA[i][0], TA[i][1]

    else:
        M = math.ceil(max(Fraction(t , TA[i][0]), Fraction(a , TA[i][1])))
        t = M * TA[i][0]
        a = M * TA[i][1]


print(t+a)

Solution (Python):
l,r=1,1
for _ in range(int(input())):
    k,t=map(int,input().split())
    gen = max((l+k-1)//k,(r+t-1)//t)
    l,r=gen*k,gen*t
print(l+r)

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

Solution (Python):
import sys

n = int(sys.stdin.readline())
lst = [list(map(int, i.split())) for i in sys.stdin.readlines()]
a, b = lst[0]
for i, j in lst[1:]:
  if i >= a and j >= b:
    a, b = i, j
  else:
    tmp1 = (a // i) + (a % i != 0)
    tmp2 = (b // j) + (b % j != 0)
    if i < a and j >= b:
      a, b = tmp1 * i, tmp1 * j
    elif i >= a and j < b:
      a, b = tmp2 * i, tmp2 * j
    else:
      if tmp1 > tmp2:
        a, b = tmp1 * i, tmp1 * j
      else:
        a, b = tmp2 * i, tmp2 * j
print(a + b)

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

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    for i in range(1,N):
        if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
            r = max((b[i-1][0]-1)//b[i][0],(b[i-1][1]-1)//b[i][1]) + 1
            b[i][0] *= r
            b[i][1] *= r
    print(sum(b[-1]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math

N = int(sys.stdin.readline().strip())

ratios = []
for _ in range(N):
    t, a = map(int, sys.stdin.readline().strip().split())
    ratios.append((t, a))

ans = 0
for i in range(N-1):
    t1, a1 = ratios[i]
    t2, a2 = ratios[i+1]

    
    
    rate = max((t1 - 1) // t2, (a1 - 1) // a2) + 1
    ratios[i+1] = (t2 * rate, a2 * rate)

print(sum(ratios[N-1]))

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

Solution (Python):
n = int(input())
info = []
for i in range(n):
    info.append(list(map(int, input().split())))
    

for i in range(n-1):
    ratio = max((info[i][0]-1)//info[i+1][0]+1, (info[i][1]-1)//info[i+1][1]+1)
    info[i+1][0]*=ratio
    info[i+1][1]*=ratio

print(sum(info[-1]))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ta = [list(map(int, readline().split())) for _ in range(n)]
t, a = ta.pop(0)
for tt, aa in ta:
    v = max((t + tt - 1) // tt, (a + aa - 1) // aa)
    t = v * tt
    a = v * aa
print(t + a)

Solution (Python):
import math
def  results(a,b):
    return ((a+b-1)//b)
 
n=int(input())
t,a=map(int,input().split())
for i in range(1,n):
    ti,ai=map(int,input().split())
    if ti<=t or ai<=a:
        k=max(results(t,ti),results(a,ai))
        t=k*ti
        a=k*ai
    else:
        t=ti
        a=ai
    
print(t+a)

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

Solution (Python):

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

Solution (Python):
n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
    a,b = map(int,input().split())
    aa = 0
    bb = 0
    if A % a == 0:
        aa = A // a
    else:
        aa = A // a + 1
    if B % b == 0:
        bb = B // b
    else:
        bb = B // b + 1
    m = max(aa, bb)
    A,B = a * m, b * m
print(A+B)

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

Solution (Python):



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

def main():
  n = int(input())
  nt, na = 1, 1
  for i in range(n):
    t, a = map(int, input().split())
    r = max([ceil(nt, t), ceil(na, a)])
    nt, na = r*t, r*a
  print(nt + na)

if __name__=='__main__':
  main()

Solution (Python):



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

def main():
  n = int(input())
  nt, na = 1, 1
  for i in range(n):
    t, a = map(int, input().split())
    r = max([ceil(nt, t), ceil(na, a)])
    nt, na = r*t, r*a
  print(nt + na)

if __name__=='__main__':
  main()

Solution (Python):
n = int(input())
t,a = map(int,input().split())

for i in range(n-1):
    ti, ai = map(int,input().split())
    cand = set()
    cand.add( 1 + (t+a-1)//ti+ai )
    cand.add( 1 + (a-1)//ai )
    cand.add( 1 + (t-1)//ti )

    tn,an = 10**18,10**18
    for i in cand:
        tt,at = ti*i, ai*i
        if(t<=tt)&(a<=at):
            tn = min(tn, tt)
            an = min(an, at)
    t,a = tn, an

print(t+a)

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

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

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

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

Solution (Python):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys


import copy
"""
from collections import *
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
x,y=1,1

for a,b in AB:
    if x<=a and y<=b:
        x=a;y=b

    elif x>a and y>b:
        c=max([x//a+bool(x%a),y//b+bool(y%b)])
        x=a*c
        y=b*c

    elif x>a:
        c=x//a+bool(x%a)
        x=a*c
        y=b*c
    elif y>b:
        c=y//b+bool(y%b)
        x=a*c
        y=b*c
print(sum([x,y]))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

n = INT()
ans = [1, 1]
for i in range(n):
    t,a = MAP()
    k = max((ans[0] + t - 1) // t, (ans[1] + a - 1) // a)
    ans[0] = k * t
    ans[1] = k * a
    
print(sum(ans))

Solution (Python):
def solve():
    n = int(input())
    t1, a1 = map(int, input().split())
    ans = t1 + a1
    for i in range(n - 1):
        t, a = map(int, input().split())
        t1 = (t1 + t - 1) // t * t
        a1 = (a1 + a - 1) // a * a
        if t1 < a1 * t // a:
            t1 = a1 * t // a
        elif a1 < t1 * a // t:
            a1 = t1 * a // t
        ans = t1 + a1
    print(ans)


if __name__ == "__main__":
    solve()

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

taka = 1
aoki = 1

for T,A in TA:
    tmp = max((taka + T - 1) // T, (aoki + A - 1) // A)
    taka = tmp * T
    aoki = tmp * A

print(taka + aoki)

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N = int(input())

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

if __name__ == '__main__':
    main()

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

nx = 1
ny = 1

for _ in range(N):
    x, y = map(int, input().split())
    Xmul = (nx + x - 1) // x
    Ymul = (ny + y - 1) // y
    mul = max(Xmul, Ymul)
    nx = x * mul
    ny = y * mul

ans = nx + ny
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
for i in range(n):
    a,b = inpl()
    if i == 0:
        x = a; y = b
        continue
    if x <= a and y <= b:
        x = a; y = b
        continue
    c = -(-x//a); d = -(-y//b)
    tmp = max(c,d)
    x = a*tmp; y = b*tmp
    
print(x+y)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



def next_mul(x,y):
    if x%y == 0:
        return x
    else:
        return x+y-x%y

N = I()
T,A = LIR(N,2)

t = T[0]
a = A[0]
for i in range(1,N):
    an = next_mul(a,A[i])
    tn = an*T[i]//A[i]
    if tn >= t:
        t = tn
        a = an
    else:
        t = next_mul(t,T[i])
        a = t*A[i]//T[i]
        
print(t+a)

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

Solution (Python):
n = int(input())
ta = []
for i in range(n):
    tmp = list(map(int,input().split()))
    ta.append(tmp)
vote=[1,1]
for v in ta:
    t_ratio=(vote[0]-1)//v[0]+1
    a_ratio=(vote[1]-1)//v[1]+1
    ratio = max(t_ratio,a_ratio)
    vote[0] = v[0] * ratio
    vote[1] = v[1] * ratio

print(sum(vote))

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


def read_list():
    return list(read_values())


def f(p, q):
    t, a = q
    pt, pa = p

    nt = max((pt - 1) // t + 1, 1)
    na = max((pa - 1) // a + 1, 1)

    n = max(nt, na)

    return (n * t, n * a)


def main():
    N = int(input())
    p = (1, 1)
    for _ in range(N):
        q = read_list()
        p = f(p, q)
    
    print(sum(p))


if __name__ == "__main__":
    main()

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

Solution (Python):
N = int(input())
T, A = 0, 0
for i in range(N):
  a1, a2 = map(int, input().split())
  if i == 0:
    T, A = a1, a2
  else:
    if T <= a1 and A <= a2:
      T, A = a1, a2
    elif T > a1 and A <= a2:
      if T % a1 == 0:
        X = T // a1
      else:
        X = T // a1 + 1
      T, A = a1 * X, a2 * X
    elif T <= a1 and A > a2:
      if A % a2 == 0:
        X = A // a2
      else:
        X = A // a2 + 1
      T, A = a1 * X, a2 * X
    elif T > a1 and A > a2:
      X, Y = (T - 1) // a1 + 1, (A - 1) // a2 + 1
      if X <= Y:
        T, A = a1 * Y, a2 * Y
      else:
        T, A = a1 * X, a2 * X
print(T + A)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
t,a = inm()
for i in range(n-1):
    tt,aa = inm()
    k = max((t+tt-1)//tt, (a+aa-1)//aa)
    t = k*tt
    a = k*aa
print(t+a)

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    N = cin.int()
    T = cin.intListList(N)
    a,b = 1,1
    for t in T:
        n = max(Math.roundUp(a , t[0]),Math.roundUp(b , t[1]))
        a,b = n * t[0],n * t[1]
    print(a + b)
    return

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
P = [1,1]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = max(P[0]//t,P[1]//a,1)
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))

Solution (Python):
def ceil_div(a, b):
    return (a + b - 1) // b

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

Solution (Python):
n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)]
x, y = 1, 1
for t, a in ta:
    z = max((x + t - 1) // t, (y + a - 1) // a)
    x = t * z
    y = a * z
print(x + y)

Solution (Python):
import math
N = int(input())
t, a = 1, 1

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
x = 1
y = 1
for _ in range(N):
  t, a = map(int, input().split())
  if x * a != y * t:
    z = -(-(x + y) // (a + t))
    z = max(z, -(-x // t), -(-y // a))
    x = t * z
    y = a * z
  
print(x + y)

Solution (Python):
import math

N = int(input())
ta = list(map(int, input().split()))
T, A = ta[0], ta[1]


for i in range(N - 1):
    tmp_ta = list(map(int, input().split()))
    t, a = tmp_ta[0], tmp_ta[1]
    
    
    
    
    
    
    
    
    
    
    tmpTt = T if T % t == 0 else (T // t + 1) * t
    tmpTa = tmpTt * a // t
    tmpAa = A if A % a == 0 else (A // a + 1) * a
    tmpAt = tmpAa * t // a
    
    if tmpTa < A:
        T = tmpAt
        A = tmpAa
    elif tmpAt < T:
        T = tmpTt
        A = tmpTa
    elif (tmpTt + tmpTa) < (tmpAa + tmpAt):
        T = tmpTt
        A = tmpTa
    else:
        T = tmpAt
        A = tmpAa
    

print(T + A)

Solution (Python):
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  


N = ri()
T_cnt = 1
A_cnt = 1
for _ in range(N):
    t, a = rl()
    n = max(-(-T_cnt//t), -(-A_cnt//a))
    T_cnt, A_cnt = t * n, a * n

answer = T_cnt + A_cnt
print(answer)

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

ma,mb = AB[0]
for a, b in AB[1:]:
  i = -(-ma //a)
  j = -(-mb //b)
  k = max(i, j)
  
  ma = k*a
  mb = k*b
  
print(ma + mb)

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    ta = tb = 1
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        r = max((a + ta - 1) // a, (b + tb - 1) // b)
        ta = a * r
        tb = b * r
    print(ta + tb)


if __name__ == '__main__':
    solve()

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

def bisect(x,X):
  l=0
  r=10**18
  while r>l+1:
    n=(r+l)//2
    if n*x>=X:
      r=n
    else:
      l=n
  return r    

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

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

Solution (Python):
def gcd(a, b): 
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

def main():
    n=int(input())
    a=1
    b=1
    for _ in range(n):
        x,y = map(int,input().split())
        n=a//x
        m=b//y
        if a%x!=0:
            n+=1
        if b%y!=0:
            m+=1
        a=max(n,m)*x
        b=max(n,m)*y
    print(a+b)
        

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
t,a=map(int,input().split())
for i in range(N-1):
    Ti,Ai=map(int,input().split())
    kt=(t+(Ti-1))//Ti;ka=(a+(Ai-1))//Ai
    k=max(kt,ka)
    t=k*Ti;a=k*Ai
print(t+a)

Solution (Python):
N=int(input())
TA=[list(map(int,input().split())) for i in range(N)]
x,y=1,1
for t,a in TA:
    if -(-x//t)*a>=y:
        x,y=-(-x//t)*t,-(-x//t)*a
    else:
        x,y=-(-y//a)*t,-(-y//a)*a
print(x+y)

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    tt = ta = 0
    for i in range(n):
        t, a = list(map(int, input().rstrip('\n').split()))
        if i == 0:
            tt = t
            ta = a
        else:
            r = max((tt + t - 1) // t, (ta + a - 1) // a)
            tt = t * r
            ta = a * r
    print(tt + ta)


if __name__ == '__main__':
    solve()

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

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

print(t + a)

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

import math

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

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    N, *TA = map(int, open(0).read().split())
    t, a = TA[:2]
    for i, j in zip(*[iter(TA[2:])] * 2):
        x = max((t + i - 1) // i, (a + j - 1) // j)
        t, a = i * x, j * x
    print(t + a)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
import os
import math

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

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

Solution (Python):
from fractions import gcd
import math
import sys
N = int(input())
T = []
A = []
for n in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)

if N == 1:
    ans = T[N - 1] + A[N - 1]
    print(ans)
    sys.exit()

for n in range(1, N):
    tmp_a = -(-A[n - 1] // A[n])
    tmp_t = -(-T[n - 1] // T[n])
    if A[n - 1] <= A[n] and T[n - 1] <= T[n]:
        continue
    elif A[n - 1] > A[n] and T[n - 1] <= T[n]:
        A[n] = tmp_a * A[n]
        T[n] = tmp_a * T[n]
    elif A[n - 1] <= A[n] and T[n - 1] > T[n]:
        A[n] = tmp_t * A[n]
        T[n] = tmp_t * T[n]
    elif A[n - 1] > A[n] and T[n - 1] > T[n]:
        if tmp_a * T[n] >= T[n - 1]:
            T[n] = tmp_a * T[n]
            A[n] = tmp_a * A[n]
        elif tmp_t * A[n] >= A[n - 1]:
            T[n] = tmp_t * T[n]
            A[n] = tmp_t * A[n]
print(T[N - 1] + A[N - 1])

Solution (Python):
import math
n = int(input())
rat = [list(map(int, input().split(' '))) for _ in range(n)]
a = 1
b = 1
for i in range(n):
    x = max(-(-a//rat[i][0]), -(-b//rat[i][1]))
    a = x*rat[i][0]
    b = x*rat[i][1]
print(a+b)

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

t,a = TA[0]
for T,A in TA[1:]:
    t1 = t + (-t%T)
    a1 = (t1//T) * A
    a2 = a + (-a%A)
    t2 = (a2//A) * T
    if t > t2:
        t,a = t1,a1
    else:
        t,a = t2,a2
print(t+a)

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

Solution (Python):
import math
n = int(input())
rat = [list(map(int, input().split(' '))) for _ in range(n)]
a = 1
b = 1
for i in range(n):
    x = max(-(-a//rat[i][0]), -(-b//rat[i][1]))
    a = x*rat[i][0]
    b = x*rat[i][1]
print(a+b)

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

A,B=1,1

for at in AT:
  n=max(-(-A//at[0]//1),-(-B//at[1]//1))
  
  
  A=n*at[0]
  B=n*at[1]
  
print(A+B)

Solution (Python):
from math import ceil

N = int(input())
A, B = map(int, input().split())
ans = 1
for i in range(1, N):
    x, y = map(int, input().split())
    ans = max(A//x+min(1, A%x), B//y+min(1, B%y))
    A = ans*x
    B = ans*y
print(A+B)

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

takahasi, aoki = ratio[0]
for i in range(1, N):
    t_ratio, a_ratio = ratio[i]
    n = max(takahasi//t_ratio + min(1, takahasi % t_ratio), aoki//a_ratio + min(1, aoki % a_ratio))
    takahasi = n * t_ratio
    aoki = n * a_ratio

print(takahasi+aoki)

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

def main():
    N = int(input())
    ta = [list(map(int, input().split())) for i in range(N)]

    a, b = 1, 1
    for i in range(N):
        x, y = ta[i]
        if a%x == 0:
            tmp = a//x
        else:
            tmp = a//x + 1
        if b%y == 0:
            tmp = max(tmp, b//y)
        else:
            tmp = max(tmp, b//y + 1)
        a = x * tmp
        b = y * tmp
    print(a+b)

if __name__ == "__main__":
    main()

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

pret,prea = TA[0]
for i in range(1,N):
  t,a = TA[i]
  if pret == t and prea == a:
    continue
  elif pret <= t and prea <= a:
    pret,prea = t,a
  else:
    if (pret+t-1)//t > (prea+a-1)//a:
      pret = (pret+t-1)//t * t
      prea = pret // t * a
    else:
      prea = (prea+a-1)//a * a
      pret = prea // a * t
print(pret+prea)

Solution (Python):
n=int(input())
vote=list(map(int,input().split()))
for i in range(n-1):
    a,b=map(int,input().split())
    if vote[0]%a==0:
        A=vote[0]//a
    else:A=vote[0]//a+1
    if vote[1]%b==0:
        B=vote[1]//b
    else:B=vote[1]//b+1
    if A>B:
        if B*a>=vote[0]:
            vote[0]=B*a;vote[1]=B*b
        else:
            vote[0]=A*a;vote[1]=A*b
    elif A<B:
        if A*b>=vote[1]:
            vote[0]=A*a;vote[1]=A*b
        else:
            vote[0]=B*a;vote[1]=B*b
    else:
        vote[0]=A*a;vote[1]=A*b
print(sum(vote))

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

nowT = 1
nowA = 1
for i in range(N):
    nextT, nextA = map(int, input().split())

    
    mul = max(-(-nowT // nextT), -(-nowA // nextA))
    nowT = nextT * mul
    nowA = nextA * mul

print(nowT + nowA)

Solution (Python):
n = int(input())
x = 0
y = 0
for i in range(n):
    t,a = map(int,input().split())
    if x%t == 0:
        la = x//t
        if la == 0:
            la = 1
    else:
        la = x//t + 1

    if y % a == 0:
        lb = y//a
        if lb == 0:
            lb = 1
    else:
        lb = y//a +1

    l = max(la,lb)
    x = t*l
    y = a*l

print(x+y)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
t,a=ta[0][0],ta[0][1]
for i in range(n-1):
    wa=sum(ta[i+1])
    j=max((t+a+wa-1)//wa,(t+ta[i+1][0]-1)//ta[i+1][0],(a+ta[i+1][1]-1)//ta[i+1][1])
    
    
    t,a=j*ta[i+1][0],j*ta[i+1][1]
    
print(t+a)

Solution (Python):



def main():
    n = int(input())
    vote_t, vote_a = 1, 1

    
    
    
    
    
    for i in range(n):
        ti, ai = map(int, input().split())

        
        m = max((vote_t - 1) // ti + 1, (vote_a - 1) // ai + 1)
        vote_t = ti * m
        vote_a = ai * m

    print(vote_t + vote_a)


if __name__ == '__main__':
    main()

Solution (Python):
import math
N = int(input())
x=0
t=0
n=0
pre_t=1
pre_n=1
for i in range(N):
    t,n = map(int,input().split())
    if(pre_t > t or pre_n > n):
        mul = max(-(-pre_t//t),-(-pre_n//n))
        t *= mul
        n *= mul
    pre_t = t
    pre_n = n
    x = t+n
print(x)

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

Solution (Python):

n=int(input())

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

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

tNow = 1
aNow = 1

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

    n = max(-(-tNow // t), -(-aNow // a))

    tNow = n * t
    aNow = n * a

print(tNow + aNow)

Solution (Python):
n=int(input())
ta=[]
t=0
a=0
ans=[[1,1]]
for i in range(n):
    p=[int(j) for j in input().split()]
    i=max(ans[-1][0]//p[0],ans[-1][1]//p[1])
    while True:
        if p[0]*i>=ans[-1][0] and p[1]*i>=ans[-1][1]:
            ans.append([p[0]*i,p[1]*i])
            break
        i+=1

print(sum(ans[-1]))

Solution (Python):
from math import ceil
N = int(input())
L = [[int(i) for i in input().split()] for _ in range(N)]
T = 1
A = 1
for l in L:
    k = max((T+l[0]-1)//l[0], (A+l[1]-1)//l[1])
    T = k * l[0]
    A = k * l[1]
print(T+A)

Solution (Python):
a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if d <= b and e <= c:
        d = b
        e = c
    else:
        f = max((b + d - 1) // b, (c + e - 1) // c)
        d = b * f
        e = c * f
print(d + e)

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

x = 1
for i in range(N):
    t = T[i] * x
    a = A[i] * x
    if i == N - 1:
        break
    tx = ((T[i] * x) + (T[i+1] - 1)) // T[i+1]
    ax = ((A[i] * x) + (A[i+1] - 1)) // A[i+1]
    x = max(tx , ax)

print(t + a)

Solution (Python):
a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if i == 0:
        d = b
        e = c
    else:
        if d <= b and e <= c:
            d = b
            e = c
        else:
            h = max((b + d - 1) // b, (c + e - 1) // c)
            d = b * h
            e = c * h
print(d + e)

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

ans = 1
ct = 1
ca = 1
for t, a in zip(T, A):
    n = max((ct + t - 1) // t, (ca + a - 1) // a)
    ct = n * t
    ca = n * a

print(ct+ca)

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