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):
taka, aoki = 1, 1
for _ in range(int(input())):
    a, b = map(int, input().split())
    ratio = max(-(-taka//a), -(-aoki//b))
    taka = ratio * a
    aoki = ratio * b
print(taka + aoki)

Solution (Python):
taka, aoki = 1, 1
for _ in range(int(input())):
    a, b = map(int, input().split())
    ratio = max(taka//a + [0, 1][taka%a != 0], aoki//b + [0, 1][aoki%b != 0])
    taka = a * ratio
    aoki = b * ratio
print(taka + aoki)

Solution (Python):
from fractions import math


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

    for i in range(N - 1):
        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            KT = T[i]//T[i + 1] if T[i]%T[i + 1]==0 else (T[i]//T[i + 1])+1
            KA = A[i]//A[i + 1] if A[i]%A[i + 1]==0 else (A[i]//A[i + 1])+1
            mul = max([KT,KA])
            A[i + 1] *= mul
            T[i + 1] *= mul
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

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

T,A = 0,0

for i in range(N):
    F = 0
    Ti,Ai = map(int,input().split())
    if Ti<T or Ai<A: 
        KT = T//Ti if T%Ti==0 else (T//Ti)+1
        KA = A//Ai if A%Ai==0 else (A//Ai)+1
        K = max([KT,KA])
        T = Ti*K
        A = Ai*K
    else: 
        T = Ti
        A = Ai
        
print(T+A)

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

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

numT, numA = 1, 1
for T, A in TAs:
    m = max(-(-numT // T), -(-numA // A))
    numT, numA = m * T, m * A

print(numT + numA)

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

Solution (Python):

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

ans_t = list_ta[0][0]
ans_a = list_ta[0][1]
for i in range(1,n):
    if ans_t % list_ta[i][0] != 0:
        ans_t = list_ta[i][0] * (ans_t // list_ta[i][0] + 1)
    if ans_a % list_ta[i][1] != 0:
        ans_a = list_ta[i][1] * (ans_a // list_ta[i][1] + 1)
    if ans_t * list_ta[i][1] // list_ta[i][0] >= ans_a:
        ans_a = ans_t * list_ta[i][1] // list_ta[i][0]
    else:
        ans_t = ans_a * list_ta[i][0] // list_ta[i][1]

print(ans_a + ans_t)

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

    A = t * n
    B = a * n
print(A + B)

Solution (Python):
ri = lambda: list(map(int,input().split()))

n = int(input())
v = [ri() for _ in range(n)]
for i in range(n-1):
    a,t = v[i]
    aa,tt = v[i+1]
    p = max(-(-a//aa),-(-t//tt))
    if p:
        v[i+1] = [aa*p, tt*p]
print(sum(v[-1]))

Solution (Python):

import math
n = int(input())
T = 1
A = 1
for _ in range(n):
    line = input().split(" ")
    t = int(line[0])
    a = int(line[1])
    c = max((T+t-1)//t, (A+a-1)//a)
    T = c*t
    A = c*a

print(A+T)

Solution (Python):
n = input()

v = [[0, 0] for i in range(n)]
for i in range(n):
	v[i] = map(int, raw_input().split(' '))

a, b = 1, 1

for i in range(n):
	change = v[i][0] * b - a * v[i][1]
	while change != 0:
		if change < 0:
			additions = (-change + v[i][0] - 1) / v[i][0]
			change += additions * v[i][0]
			b += additions
		if change > 0:
			additions = (change + v[i][1] - 1) / v[i][1]
			change -= additions * v[i][1]
			a += additions

print a + b

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

Solution (Python):
N = int(input())
ratio = []
for i in range(N):
  ratio.append([int(j) for j in input().split(" ")])
               
vote = ratio[0]

for i in range(len(ratio)-1):
  if ratio[i+1][0] >= vote[0] and ratio[i+1][1] >= vote[1]:
    vote = ratio[i+1]
  
  else:
    a0 = 0
    b0 = 0
    if ratio[i+1][0] < vote[0]:
      seed = ratio[i+1][0]
      mul = vote[0]//ratio[i+1][0]
      if vote[0]%ratio[i+1][0] != 0:
        mul += 1
      seed *= mul
      a0 = seed
      a1 = mul * ratio[i+1][1]
      la = [a0,a1] 
    
    if ratio[i+1][1] < vote[1]:
      seed = ratio[i+1][1]
      base = ratio[i+1][1]
      
      mul = vote[1]//ratio[i+1][1]
      if vote[1]%ratio[i+1][1] != 0:
        mul += 1
      seed *= mul
      b1 = seed
      b0 = mul * ratio[i+1][0]
      lb = [b0,b1]
    if a0 > b0:
      vote = [la[0],la[1]]
    else:
      vote = [lb[0],lb[1]]
print(sum(vote))

Solution (Python):
n = int(input())
t = []
a = []
for i in range(n):
    c = list(map(int,input().split()))
    t.append(c[0])
    a.append(c[1])
for i in range(n-1):
    d = max(1,-(-t[i]//t[i+1]),-(-a[i]//a[i+1]))
    t[i+1] =t[i+1]*d
    a[i+1] =a[i+1]*d
print(t[-1]+a[-1])

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

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

T,A = 0,0

for i in range(N):
    F = 0
    Ti,Ai = map(int,input().split())
    if Ti<T: F += 2
    if Ai<A: F += 1
    
    if F==3: 
        KT = T//Ti if T%Ti==0 else (T//Ti)+1
        KA = A//Ai if A%Ai==0 else (A//Ai)+1
        T = Ti*max([KT,KA])
        A = Ai*max([KT,KA])
        
    elif F==2: 
        K = T//Ti if T%Ti==0 else (T//Ti)+1
        T = Ti*K
        A = Ai*K
        
    elif F==1: 
        K = A//Ai if A%Ai==0 else (A//Ai)+1
        T = Ti*K
        A = Ai*K
        
    else: 
        T = Ti
        A = Ai
        
print(T+A)

Solution (Python):
from math import ceil
from decimal import *
n=int(input())
prea=Decimal("1.0")
pret=Decimal("1.0")
for i in range(n):
    
    t,a=map(Decimal,input().split())
    i=max(ceil(prea/a),ceil(pret/t))
    pret,prea=t*i,a*i

print(pret+prea)

Solution (Python):
from decimal import *
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max(t//x + (1 if t%x else 0),a//y + (1 if a%y else 0))
    t=x*nxt
    a=y*nxt
print(t+a)

Solution (Python):
import math
from decimal import *
a=b=Decimal("1.0")
for i in range(int(input())):
    p,q=map(Decimal,input().split())
    x=math.ceil(max(a/p,b/q))
    a,b=p*x,q*x
print(a+b)

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

Solution (Python):
import math
N=int(input())
T,A=1,1
for i in range(N):
  t,a=map(int,input().split())
  k=(T+t-1) //t
  l=(A+a-1) //a
  T=t*max(k,l)
  A=a*max(k,l)
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())
    d = max(A // a, B // b)
    while (a * d < A) or (b * d < B):
        d += 1
    A = a * d
    B = b * d
print(A + B)

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

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

Solution (Python):

import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range

n = int(input())

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

Solution (Python):
n = input()
t = []
a = []
c_t = 1
c_a = 1
for i in xrange(n):
    p,q = map(int, raw_input().split())
    t.append(p)
    a.append(q)

for i in xrange(n):
    if t[i] >= c_t and a[i] >= c_a:
        c_t = t[i]
        c_a = a[i]
    else:
        m = max(-(-c_t/t[i]), -(-c_a/a[i]))
        c_t = t[i]*m
        c_a = a[i]*m

print c_t+c_a

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


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = (limit[0] + a - 1) // a
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc

    cnt = (limit[1] + b - 1) // b
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print(sum(now))

Solution (Python):
n = int(input())
p = []
for i in range(n):
    t,a = map(int, input().split())
    p.append((t,a))
q = [p[0][i] for i in range(2)]
for i in range(1, n):
    l = 0
    r = 10**18 + 1
    while l+1 < r:
        m = (l+r) //2 
        if any([p[i][j] * m < q[j] for j in range(2)]):
            l = m
        else:
            r = m
    for j in range(2):
        q[j] = r * p[i][j]

print(sum(q))

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

Solution (Python):
import sys

N = int(raw_input())
votes = []
for _ in range(N):
	t, a = map(int, raw_input().split())
	votes.append((t, a))

pt, pa = 0, 0

for v in votes:
	if (v[0] >= pt and v[1] >= pa):
		pt, pa = v[0], v[1]
	else:
		if (pt % v[0]):
			nt = pt / v[0] + 1
		else:
			nt = pt / v[0]
		if (pa % v[1]):
			na = pa / v[1] + 1
		else:
			na = pa / v[1]
		m = max(nt, na)
		pt, pa = v[0] * m, v[1] * m

print str(pt + pa)

Solution (Python):
import math
from decimal import *

def main():
    votes = int(input())
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    votesTemp = [0, 0]
    for i in range(votes):
        if i == 0:
            votesTemp = ratio[i]
            continue

        ceil = [ math.ceil(Decimal(votesTemp[j]) / Decimal(ratio[i][j])) for j in range(2)]

        votesTemp = [ max(ceil) * ratio[i][j] for j in range(2) ]

        """
        print("turn: " + str(i))
        print("votes: " + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print("Temp: " +str(votesTemp[0])+":"+str(votesTemp[1]))
        """
    print(sum(votesTemp))

if __name__ == '__main__':
  main()

Solution (Python):
import math

def cceil(x,y):
	res = x //y
	if x % y != 0:res += 1
	return res

def gcd(x, y):
	if(x == 0):return y
	return gcd(y % x, x)
 
def main():
    votes = int(input())
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]
 
    votesTemp = [0, 0]
    for i in range(votes):
        if i == 0:
            votesTemp = ratio[i]
            continue
        if(gcd(ratio[i][0], ratio[i][1]) != 1):
        	x = 1 / 0
        ceil = [ cceil(votesTemp[j], ratio[i][j]) for j in range(2)]
 
        votesTemp = [ max(ceil) * ratio[i][j] for j in range(2) ]
        
        
        
        
        
    print(sum(votesTemp))
 
if __name__ == '__main__':
  main()

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

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

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

Solution (Python):


N=int(raw_input())

a_num = 1
b_num = 1

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        base_n = max( (a_num - 1) // ratio_a + 1 , (b_num - 1 ) // ratio_b + 1)

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print int(a_num + b_num)

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

def aa(a,t,na,nt):
    c = max( (1+(a-1)//na,1+(t-1)//nt) )
    return (na*c,nt*c)
t = T[0]
a = A[0]
for i in range(N):
    a,t = aa(a,t,A[i],T[i])
print(t+a)

Solution (Python):
from sys import stdin
n = int(stdin.readline())
a = []
b = []
for _ in xrange(n):
 x,y = map(int,stdin.readline().split())
 a.append(x)
 b.append(y)
x = a[0]
y = b[0]
for i in xrange(1,n):
 fir = a[i]
 sec = b[i]
 if fir>=x and sec >= y:
  x = fir;y=sec
 elif fir>=x:
  k = y/sec
  if y%sec:
   k+=1
  x = fir * k
  y = sec * k
 elif sec>=y:
  k = x/fir
  if x%fir:
   k += 1
  x = fir * k
  y = sec * k
 else:
  u = x/fir
  if x%fir:
   u+=1
  v = y/sec
  if y%sec:
   v+=1
  k = u
  if v > k:
   k = v
  x = fir * k
  y = sec * k
 
 
 
print x + y

Solution (Python):


from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N = int(input())

va, vb = 1, 1
for i in range(N):
    pa, pb = [int(x) for x in input().split(" ")]
    r = int(max((va + pa - 1) // pa, (vb + pb - 1) // pb))
    va = pa * r
    vb = pb * r
print(va + vb)

Solution (Python):
N = int(input())
TA = []
for i in range(N):
	TA.append(list(map(int, input().split())))
 
TA.reverse()
(voteA, voteB) = (1,1)
while TA:
	(Ti, Ai) = TA.pop()
	tmp = max((voteA + Ti -1) // Ti, (voteB + Ai -1) // Ai)
	voteA = Ti * tmp
	voteB = Ai * tmp
print(voteA + voteB)

Solution (Python):

ans = 0

for i in range(int(input())):
    t_i, a_i = list(map(lambda x: int(x), input().split()))

    if i == 0:
        t, a = t_i, a_i

    else:
        n = max((t + t_i - 1) // t_i, (a + a_i - 1) // a_i)
        t = n*t_i
        a = n*a_i

    ans = t + a

print(ans)

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

Solution (Python):
def increase(a, b, c, d):
    k = (b + d - 1) // d
    return k*c, k*d

n = int(raw_input())
a, b = map(int, raw_input().split())
for i in range(n - 1):
    c, d = map(int, raw_input().split())
    if a*d == b*c:
        continue
    if a*d < b*c:
        a, b = increase(a, b, c, d)
    else:
        b, a = increase(b, a, d, c)
print(a + b)

Solution (Python):





N=int(input())

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

print(a+t)

Solution (Python):
N = int(input())
T,A = [0 for i in range(N)],[0 for i in range(N)]
for i in range(N):
    T[i],A[i] = map(int,input().split())
a = 1
b = 1
for i in range(N):
    low = 0
    high = 10**18
    while high - low > 1:
        x = (high + low) // 2
        if a <= T[i] * x and b <= A[i] * x:
            high = x
        else:
            low = x
    a = high * T[i]
    b = high * A[i]
print(a + b)

Solution (Python):
def f(a, b, c, d):
    n = max(1,a//c, b//d)
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(input())):
        c, d = map(int, input().split())
        a, b = f(a, b, c, d)
    print(a+b)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n=int(raw_input())
    ta=[map(int,raw_input().split()) for _ in xrange(n)]
    for i in xrange(1,n):
        if ta[i-1][0]>ta[i][0] and ta[i-1][1]>ta[i][1]:
            mx=max((ta[i-1][0]-1)/ta[i][0]+1,(ta[i-1][1]-1)/ta[i][1]+1)
            ta[i][0]=ta[i][0]*mx
            ta[i][1]=ta[i][1]*mx
        elif ta[i-1][0]>ta[i][0]:
            ta[i][1]=ta[i][1]*((ta[i-1][0]-1)/ta[i][0]+1)
            ta[i][0]=ta[i][0]*((ta[i-1][0]-1)/ta[i][0]+1)
        elif ta[i-1][1]>ta[i][1]:
            ta[i][0]=ta[i][0]*((ta[i-1][1]-1)/ta[i][1]+1)
            ta[i][1]=ta[i][1]*((ta[i-1][1]-1)/ta[i][1]+1)
    print(ta[n-1][0]+ta[n-1][1])
main()

Solution (Python):
n = int(raw_input())
t = []
a = []
for i in xrange(n):
    mem = map(int, raw_input().split())
    t.append(mem[0])
    a.append(mem[1])

for i in xrange(n):
    if i == 0:
        tn = t[0]
        an = a[0]
    else:
        mt = tn / t[i] if (tn%t[i] == 0) else tn / t[i] + 1
        ma = an / a[i] if (an%a[i] == 0) else an / a[i] + 1
        if mt > ma:
            tn = mt * t[i]
            an = mt * a[i]
        else:
            tn = ma * t[i]
            an = ma * a[i]
print tn + an

Solution (Python):


def f(a, b, c, d):
    n = max(1,a//c, b//d)
    while a > c * n or b > d * n : n += 1
    return c * n, d * n
    
def main():
    a, b = 0, 0
    for i in range(int(input())):
        c, d = map(int, input().split())
        a, b = f(a, b, c, d)
    print(a+b)

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

Solution (Python):



N=int(input())

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)

def func1(x, xi):
    if x % xi == 0:
        return x
    else:
        return xi * (x // xi) + xi

for i in range(N):
    ti,ai = map(int,input().split())
    if i == 0:
        t,a = ti,ai
    else:
        t,a = func1(t, ti),func1(a, ai)

        
        if ti / ai < t / a:
            a = t // ti * ai
        else:
            t = a // ai * ti

    
print(a+t)

Solution (Python):
import math

def GCD(a, b):
    if a > b: 
        return GCD(b, a)
    if a == 0:
        return b
    return GCD(b%a, a)

def LCM(a, b):
    return a * b / GCD(a, b)

def GetSmallest(a, b, c, d):
    
    tgt = max([a * d, b * c])
    lcm = LCM(c, d)
    if tgt % lcm == 0:
        factor = tgt / lcm
    else:
        factor = tgt / lcm + 1

    cm = factor * lcm
    newA = cm / d
    newB = cm / c

    return newA, newB

N = int(raw_input())
qn = []
for n in xrange(N):
    qn.append(map(int, raw_input().split()))

cur = (qn[0][0], qn[0][1])
for n in xrange(1, N):
    cur = GetSmallest(cur[0], cur[1], qn[n][0], qn[n][1])

print cur[0] + cur[1]

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

xx = 1
yy = 1
for i in xrange(n):
  [x, y] = [int(e) for e in raw_input().strip().split()]
  
  if i == 0:
    xx = x
    yy = y
  else:
    
    if x >= xx and y >= yy:
	  xx = x
	  yy = y
    else:
	  multi_x = -1
	  multi_y = -1
	  if x < xx:
	    multi_x = xx / x
	    if xx % x != 0: multi_x += 1
	  if y < yy:
	    multi_y = yy / y
	    if yy % y != 0: multi_y += 1
	  multi = max(multi_x, multi_y)
	  xx = x * multi
	  yy = y * multi
	  
print xx + yy

Solution (Python):
if __file__ == '/tmp/code.py':
	import sys
	sys.stdin = open('input.txt')

n = int(raw_input())

a, b = 0, 0
for _ in xrange(n):
	x, y = map(int, raw_input().split())

	k = 1
	if x < a:
		k = (a + x - 1) / x
	if y < b:
		k = max(k, (b + y - 1) / y)

	a, b = k * x, k * y

print a + b

Solution (Python):
n = input()
p, q = [-1, -1]
for i in xrange(n):
    t, a = map(int, raw_input().split())
    if p == -1 or q == -1:
        p = t
        q = a
        continue
    if t >= p and a >= q:
        p = t
        q = a
    else:
        z = max(p / t + (p % t != 0), q / a + (q % a != 0))
        p = t * z
        q = a * z
print p + q

Solution (Python):
def f(x, y):
    return y * (x // y + (1 if x % y else 0))
n = int(input())
x, y = 1, 1
for i in range(n):
    t, a = (int(_) for _ in input().split())
    nx = f(x, t)
    ny = max(nx // t * a, f(y, a))    
    nx = ny // a * t
    x, y = nx, ny
print(x + y)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def f():
    n = int(input())
    a,b = 1,1
    t = 0
    for _ in range(n):
        l,r = list(map(int, input().split()))
        ll = l
        rr = r
        if ll < a:
            s = a - ll
            ss = (s // l)
            while ss * l + ll < a:
                ss += 1
            ll += l*ss
            rr += r*ss
        if rr < b:
            s = b - rr
            ss = (s // r)
            while ss * r + rr < b:
                ss += 1
            ll += l*ss
            rr += r*ss
        a = ll
        b = rr
        t = ll + rr
    return t

print(f())

Solution (Python):
n = int(raw_input())
x = y = 1
for _ in xrange(n):
    t, a = map(int, raw_input().split())
    xi = x / t + (x % t != 0)
    yi = y / a + (y % a != 0)
    k = max(xi, yi)
    x = k * t
    y = k * a
print x + y

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N = n()

z, x = ln()

for i in xrange(N - 1):
    t, a = ln()
    q = t + a
    r1 = (z + x) / q
    if (z + x) % q != 0:
        r1 += 1
    r2 = z / t
    if z % t != 0:
        r2 += 1
    r3 = x / a
    if x % a != 0:
        r3 += 1
    m = max(r1, r2, r3)
    z = t * m
    x = a * m

print z + x

Solution (Python):
N = input()
t, a = map(int, raw_input().split())
for i in xrange(N-1):
    new_t, new_a = map(int, raw_input().split())
    d = max((t-1)/new_t+1, (a-1)/new_a+1, 1)
    t, a = new_t*d, new_a*d
print t+a

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


T = 1
A = 1

for n in range(N):
    t, a = map(int, raw_input().split())
    k = max(int(T/t), int(A/a))
    if T > t*k or A > a*k:
        T = t*(k+1)
        A = a*(k+1)
    else:
        T = t*k
        A = a*k

print T+A

Solution (Python):
n = int(input())
x, y = 0, 0
for i in range(n):
    a, b = map(int, input().split())
    lb, ub = 0, 10 ** 19
    while ub - lb > 1:
        md = (lb + ub) // 2
        if a * md >= x and b * md >= y:
            ub = md
        else:
            lb = md
    x, y = a * ub, b * ub
print(x + y)

Solution (Python):



def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

T =        int( stdin.readline().strip() )

ct = 1
ca = 1
for icase in range(1, T+1):
    t, a = map(int, stdin.readline().strip().split())
    n = max((ct + t - 1) // t,
            (ca + a - 1) // a)
    ct = n*t
    ca = n*a

print ct + ca