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())
a, b = [int(x) for x in input().split()]
for _ in range(n - 1):
	c, d = [int(x) for x in input().split()]
	k = max((a - 1) // c + 1, (b - 1) // d + 1)
	a, b = c * k, d * k
print(a + b)

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)

Solution (Python):
def main():
    N = int(input())
    A, B = 1, 1
    for _ in range(N):
        t, a = (int(i) for i in input().split())
        mul = max(-(-A//t), -(-B//a))
        A = t*mul
        B = a*mul
    print(A+B)


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = max((C+t-1)//t , (D+a-1)//a)
        
        C,D = n*t,n*a
    ans = C+D
    print(int(ans))
if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = max( -(-C//t), -(-D//a))
        C,D = n*t,n*a
    ans = C+D
    print(ans)
if __name__ == '__main__':
    main()

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

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

ans = t + a

for _ in range(N - 1):
    T, A = map(int, input().split())

    n = max(t // T + (1 if t % T else 0), a // A + (1 if a % A else 0))

    ans = (T + A) * n

    t, a = T * n, A * n

print(ans)

Solution (Python):
N=int(input())
A,B=map(int,input().split())
for i in range(N-1):
  a,b=map(int,input().split())
  if a==b:
    if A<B:
      A=B
    else:
      B=A
    
  else:
    if a/b > A/B:
      
      if B%b!=0:
        plus=b-(B%b)
        B+=plus
      A=(B*a)//b
    else:
      
      if A%a!=0:
        plus=a-(A%a)
        A+=plus
      B=(A*b)//a

print(A+B)

Solution (Python):
N = int(input())
T = 0
A = 0
for _ in range(N):
    t, a = map(int, input().split())
    i = max(T//t, A//a, 1)
    while T > i*t or A > i*a:
        i += 1
    T = i*t
    A = i*a
    
print(T+A)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    x,y=1,1
    for _ in range(n):
        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)
resolve()

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

Solution (Python):
import sys
import math
n = int(input())
ls = []
for i in range(n):
    t, a = [int(i) for i in sys.stdin.readline().split()]
    ls.append((t, a))
_min = 1e-10
_min_a = 1
_min_t = 1
res = []
for l in ls:
    t, a = l
    _sum = t + a
    cnt = max(-(-_min_a//a), -(-_min_t//t))
    _min_a = cnt * a
    _min_t = cnt * t
    _min = cnt * _sum
    res.append(_min)
print(res[-1])

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

N = int(input())
s, t = 1, 1
for _ in range(N):
    a, b = map(int, input().split())
    g = gcd(a, b)
    a, b = a//g, b//g
    mi = max(-(-s//a), -(-t//b))
    s, t = a*mi, b*mi
print(s+t)

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

def UP(V1,V2,R1,R2):
    n=max(-(-V1//R1),-(-V2//R2))
    return(n*R1,n*R2)

for i in range(N):
    up=UP(Taka,Aoki,TA[i][0],TA[i][1])

    Taka=up[0]
    Aoki=up[1]

print(Taka+Aoki)

Solution (Python):
import sys

def read():
	return tuple([int(d) for d in sys.stdin.readline().rstrip().split(" ")])

N, = read()

cur_T = 1
cur_A = 1

for i in range(N):
	T, A = read()

	current = cur_T + cur_A
	sum = T + A

	mult1 = (current + sum - 1) // sum
	mult2 = (cur_T + T - 1) // T
	mult3 = (cur_A + A - 1) // A

	mult = mult1
	if mult2 > mult: mult = mult2
	if mult3 > mult: mult = mult3

	cur_T = T * mult
	cur_A = A * mult

print(cur_T + cur_A)

Solution (Python):
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = 1,1
for t,a in ta:
  mul = max(-(-A//a), -(-T//t))
  T,A = t * mul,a * mul
print(T+A)

Solution (Python):

import math
from decimal import *
N = int(input())
TA = [list(map(int,input().split())) for i in range(N)]

t,a = 1,1
for i in range(N):
    ti,ai = TA[i]
    n = Decimal(max(math.ceil(t/ti),math.ceil(a/ai)))
    t = n*ti
    a = n*ai
        
    
    
print(t+a)

Solution (Python):
n=int(input())
b,u=map(int,input().split())
x,c,v=1,1,1
for i in range(n-1):
  a,t=map(int,input().split())
  c=b if b%a==0 else (b//a+1)*a
  v=u if u%t==0 else (u//t+1)*t
  x=max(c//a,v//t)
  b=a*x
  u=t*x
print(b+u)

Solution (Python):
import math
n=int(input())
A=B=1
for i in range(n):
    x,y=[int(i) for i in input().split()]
    n=max(-(-A//x),-(-B//y))
    A=n*x
    B=n*y
print(A+B)

Solution (Python):
def ceil(a, b):
    return a//b+(1 if a % b else 0)


n = int(input())
x, y = 1, 1
for _ in range(n):
    t, a = [int(i) for i in input().split()]
    k = max(ceil(x, t), ceil(y, a))
    x, y = t * k, a * k
print(x+y)

Solution (Python):
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
T=ta[0][0]
A=ta[0][1]
for i in range(1,n):
    t,a=ta[i]
    if T%t==0:
        s=T//t
    else:
        s=T//t+1
    if A%a==0:
        b=A//a
    else:
        b=A//a+1
    T=t*max(s,b)
    A=a*max(s,b)
print(T+A)

Solution (Python):
n=int(input())
x,y=1,1
for i in range(n):
  a,b=map(int,input().split())
  if x%a==0:
    x1=x//a
  else:
    x1=x//a+1
  if y%b==0:
    y1=y//b
  else:
    y1=y//b+1
  z1=max(x1,y1)
  x,y=a*z1,b*z1
print(x+y)

Solution (Python):
from math import ceil

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

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

Solution (Python):
import math

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

T,A=1,1

for i in range(N):
	n = max(-(-A//a[i]), -(-T//t[i]))
	A = a[i] * n
	T = t[i] * n

print(A+T)

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

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

Solution (Python):
from math import ceil
from fractions import Fraction

N = int(input())

t, a = 1, 1
for T, A in [tuple(map(int, input().split())) for _ in range(N)]:
    n = max(ceil(Fraction(t, T)), ceil(Fraction(a, A)))
    t, a = n * T, n * A
print(t + a)

Solution (Python):

import sys
input = sys.stdin.readline


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


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

print(t+a)

Solution (Python):
def examC():
    N = I()
    cur = [1,1]
    for i in range(N):
        T, A = LI()
        k = max((cur[0]+T-1)//T,(cur[1]+A-1)//A)
        cur[0] = T * k
        cur[1] = A * k

    print(sum(cur))



import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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


t_votes = TA[0][0]
a_votes = TA[0][1]
for n in range(1, N):
    t_ratio = TA[n][0]
    a_ratio = TA[n][1]
    
    
    
    
    coeff = max((t_ratio + t_votes - 1) // t_ratio,
                (a_ratio + a_votes - 1) // a_ratio)

    t_votes = coeff * t_ratio
    a_votes = coeff * a_ratio

print(t_votes + a_votes)

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

taka = l[0][0]
ao = l[0][1]

for i in range(1,n):
    rt = (taka+l[i][0]-1) // l[i][0]
    ra = (ao+l[i][1]-1) // l[i][1]
    r = max(rt,ra)
    taka = r * l[i][0]
    ao = r * l[i][1]

print(taka+ao)

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

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

    A, B = 1, 1
    for (x, y) in LIS:
        
        
        if x == y:
            m = max(x, max(A, B))
            A, B = m, m
        elif A <= x and B <= y:
            A, B = x, y
        else:
            
            div = max((A + x - 1) // x, (B + y - 1) // y)
            A = x * div
            B = y * div

    return A + B


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

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0])
    Tn = [0] * N
    An = [0] * N
    for i in range(N):
        Tn[i], An[i] = map(int, lines[i + 1].split())
    T = 1
    A = 1
    for Ti, Ai in zip(Tn, An):
        n = max(-(-T // Ti), -(-A // Ai))
        T = n * Ti
        A = n * Ai
    print(T + A)
    return


main()

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)

Solution (Python):
n = int(input())
T = [0]*n
A = [0]*n

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

votes = [T[0],A[0]]

for i in range(1,n):
    m = max(-(-votes[0]//T[i]),-(-votes[1]//A[i]))
    votes[0] = m*T[i]
    votes[1] = m*A[i]

print(votes[0]+votes[1])

Solution (Python):
N = int(input())
t,a = map(int,input().split())
for _ in range(N-1):
    T,A = map(int,input().split())
    b = 1
    if t>T:
        if t%T==0:
            b = t//T
        else:
            b = t//T+1
    T0 = T*b
    A0 = A*b
    c = 1
    if a>A0:
        if a%A0==0:
            c = a//A0
        else:
            c = a//A0+1
    T0 = T0*c
    A0 = A0*c
    c = 1
    if a>A:
        if a%A==0:
            c = a//A
        else:
            c = a//A+1
    T1 = T*c
    A1 = A*c
    b = 1
    if t>T1:
        if t%T1==0:
            b = t//T1
        else:
            b = t//T1+1
    T1 *= b
    A1 *= b
    if T0<=T1:
        t,a = T0,A0
    else:
        t,a = T1,A1
print(t+a)

Solution (Python):

import sys
import math

def solve(N: int, T: "List[int]", A: "List[int]"):
    current = [T[0],A[0]]
    for i in range(1,N):
        t = T[i]
        a = A[i]
        if current[0]>t or current[1]>a:
            multi = max((current[0]+t-1)//t,(current[1]+a-1)//a)
            t = t*multi
            a = a*multi
        
        current[0]=t
        current[1]=a

    print(sum(current))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    T = [int()] * (N)  
    A = [int()] * (N)  
    for i in range(N):
        T[i] = int(next(tokens))
        A[i] = int(next(tokens))
    solve(N, T, A)

if __name__ == '__main__':
    main()

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

x = 1
y = 1
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
    else:
        v = max(-(-x//t), -(-y//a))
        x = v * t
        y = v * a


print(x+y)

Solution (Python):
n=int(input())
lists=[]
import math
for i in range(n):
    a,t=map(int,input().split())
    lists.append([a,t])
x=1
y=1
for i in range(n):
    j=max((x-1)//lists[i][0]+1,(y-1)//lists[i][1]+1)
    x=lists[i][0]*j
    y=lists[i][1]*j
print(x+y)

Solution (Python):
N=int(input())
T=[]

A=[1,1]

for i in range(N):
	t=list(map(int,input().split()))
	
	n0 = (A[0]-1)//t[0] + 1
	n1 = (A[1]-1)//t[1] + 1
	n = max(n0,n1)

	A[0]=t[0]*n
	A[1]=t[1]*n


print(sum(A))

Solution (Python):
import sys


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


if __name__ == '__main__':
    slove()

Solution (Python):
n=int(input())
a,b=map(int,input().split())
for i in range(1,n):
    x,y=map(int,input().split()) 
    if x>=a and y>=b:
        a=x 
        b=y 
        continue 
    mul1=-1 
    mul2=-1 
    if a%x!=0: 
        mul1=a//x  +1 
    else:
        mul1=a//x  
    if b%y==0:
        mul2=b//y 
    else: 
        mul2=b//y+1   
    m=max(mul1,mul2) 
   
    a,b=x*m,y*m   
  
print(a+b)

Solution (Python):





import math

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

a, b = TA[0]
c, d = a, b

for idx in range(1,N):
    c, d = TA[idx]
    multi = max((a+c-1)//c, (b+d-1)//d)
    c *= multi
    d *= multi
    a,b = c,d
    
print(c+d)

Solution (Python):
n = int(input())
nt  =0
na = 0
for _ in range(n):
    t,a = map(int,input().split())
    if nt==0 and na==0:
        nt =t
        na =a
        continue
    if na <= nt*(a/t):
        mod = nt%t
        if not mod==0:
            mod = t - mod
            nt = nt + mod
            na = a*nt//t
        else:
           nt = nt
           na = a*nt//t
    else:
        mod = na%a
        if not mod==0:
            mod = a - mod
            na = na + mod
            nt = t*na//a
        else:
           na = na
           nt = na*t//a 
        

print(na+nt)

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

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

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

x = 1
y = 1
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    m = max(-(-x // a), -(-y // b))
    x = m * a
    y = m * b
print(x + y)

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

Solution (Python):
n=int(input())
ans=1
p=1
q=1
for i in range(n):
    a,b=map(int,input().split())
    c=a+b
    k=ans//c
    if ans%c!=0:
        k+=1
    l=p//a
    if p%a!=0:
        l+=1
    m=q//b
    if q%b!=0:
        m+=1
    g=max(k,l,m)
    ans=c*g
    p=a*g
    q=b*g
print(ans)

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

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

t = [0 for i in range(n)]
a = [0 for i in range(n)]

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

t_num = t[0]
a_num = a[0]

for i in range(1,n):
    k = max(-(-t_num//t[i]),-(-a_num//a[i]))
    
    t_num,a_num = k*t[i],k*a[i]

print(t_num + a_num)

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)

Solution (Python):
def ceil(a0,b0):
  if a0%b0 == 0:
    return a0//b0
  else:
    return a0//b0 +1

t_num,a_num = 1,1

n = int(input())

for i in range(n):
    t,a = map(int,input().split())
    k = max(ceil(t_num,t),ceil(a_num,a))
    
    t_num = k*t
    a_num = k*a
    

print(t_num + a_num)

Solution (Python):
n = int(input())
L = []
for i in range(n):
	L.append([int(i) for i in input().split()])

x = L[0][0]
y = L[0][1]

for i in range(n-1):
  n = max(-(-x//L[i+1][0]), -(-y//L[i+1][1]))
  x = n*L[i+1][0]
  y = n*L[i+1][1]

print(x+y)

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

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

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

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

Solution (Python):
N=int(input())
import copy
inp=[]
for i in range(N):
    inp.append(list(map(int,input().split(" "))))

def compare(A,B):
    if A[0]>=B[0] and A[1]>=B[1]:
        return A
    else:
        if B[0]%A[0]!=0:
            i=B[0]//A[0]+1
        else:
            i=B[0]//A[0]
        if B[1]%A[1]!=0:
            j=B[1]//A[1]+1 
        else:
            j=B[1]//A[1]
        m=max(i,j)
        return [A[0]*m,A[1]*m]
st=inp[0]
for i in range(1,N):
    st=compare(inp[i],st)
print(sum(st))

Solution (Python):
import math

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

tmp_tuple = t_a[0]
ans = sum(tmp_tuple)

for i in range(1, n):
    if (tmp_tuple[0] / t_a[i][0]) == (tmp_tuple[1] / t_a[i][1]):
        continue
    else:
        
        factor = max(math.ceil((tmp_tuple[0] + t_a[i][0] - 1) // t_a[i][0]), math.ceil((tmp_tuple[1] + t_a[i][1] - 1) // t_a[i][1]))

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))
    
    
    ans = sum(tmp_tuple)
    
print(sum(tmp_tuple))

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

Solution (Python):
n = int(input())
ls = [list(map(int, input().split())) for _ in range(n)]
x, y = ls[0]
for a, b in ls[1:]:
    if a == b == 1:
        x = y = max(x, y)
    else:
        switch = a < b
        if switch:
            a, b = b, a
            x, y = y, x
        xx = (x + a - 1) // a * a
        yy = b * xx // a
        if yy > y:
            x = xx
            y = yy
        else:
            y = (y + b - 1) // b * b
            x = a * y // b
        if switch:
            x, y = y, x
print(x + y)

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

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

print(sum(vote))

Solution (Python):
from math import ceil
from fractions import Fraction
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
tka, aok = 1, 1

for ta in TA:
    t, a = ta
    time = int(ceil(max((Fraction(tka, t), Fraction(aok, a)))))
    tka, aok = time * t, time * a
print(tka+aok)

Solution (Python):
from math import ceil
from fractions import Fraction
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
tka, aok = 1, 1

for ta in TA:
    t, a = ta
    time = int(ceil(max((Fraction(tka, t), Fraction(aok, a)))))
    tka, aok = time * t, time * a
print(tka+aok)

Solution (Python):
import math

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

for i in range(1, N):
  dt, da = map(int, input().split())
  for j in range(max(A[i-1]//da, T[i-1]//dt)-1, max(A[i-1]//da, T[i-1]//dt)+3):
    if A[i-1] <= j * da and T[i-1] <= j * dt:
      n = j
      break
      
  T[i], A[i] = dt * n, da * n

print(A[N-1] + T[N-1])

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

Solution (Python):
def ceil(x,y):
  return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t, T), ceil(a, A))
  t = T * rate
  a = A * rate
print(t + a)

Solution (Python):

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

lcms = TA[0]

for t,a in TA[1:]:
    tmp = [t,a]

    
    m1 = (lcms[0]+tmp[0]-1)//tmp[0]
    m2 = (lcms[1]+tmp[1]-1)//tmp[1]
    
    m = max(m1,m2)
    if m != 0:
        tmp[0] *= m
        tmp[1] *= m
    lcms = tmp

print(sum(lcms))

Solution (Python):
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  if t_vote % t > 0:
    magni_t = t_vote // t + 1
  else:
    magni_t = t_vote // t
  if a_vote % a > 0:
    magni_a = a_vote // a + 1
  else:
    magni_a = a_vote // a
  magni = max(magni_t, magni_a)
  t_vote = magni * t
  a_vote = magni * a
  count += 1
print(t_vote + a_vote)

Solution (Python):
def ceil(x, y):
    return (x - 1) // y + 1


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

votes = [1, 1]

for t, a in ta:
    mul = max(ceil(votes[0], t), ceil(votes[1], a))
    votes = [t * mul, a * mul]

ans = sum(votes)
print(ans)

Solution (Python):
n=int(input())
a,b=map(int,input().split())
if n!=1:
	for _ in range(n-1):
		A,B=map(int,input().split())
		k=max(1,(a+A-1)//A,(b+B-1)//B)
		a=k*A
		b=k*B
print(a+b)

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
 
n = inp()
l = []
r = []
for i in range(n):
    q,w = inpl()
    l.append(q)
    r.append(w)
for i in range(n-1):
    if l[i+1] >= l[i] and r[i+1] >= r[i]:
        continue
    tmp = max(-(-l[i]//l[i+1]), -(-r[i]//r[i+1]))
    l[i+1] *= tmp
    r[i+1] *= tmp
print(l[n-1] + r[n-1])

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):
def main():
  n = int(raw_input())
  vote_a, vote_b = 1, 1

  for i in xrange(n):
    a, b = [int(x) for x in raw_input().split()]
    mult = max(1+(vote_a-1)/a, 1 + (vote_b-1)/b)
    vote_a, vote_b = mult*a, mult*b

  print(vote_a+vote_b)


main()

Solution (Python):
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi // t), -(-aoki // a))
        
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()

Solution (Python):
n,*l=map(int,open(0).read().split())
for i in range(2,n*2,2):
	m=max(0-l[i-2]//-l[i],0-l[i-1]//-l[i+1]);l[i]*=m;l[i+1]*=m
print(l[-1]+l[-2])

Solution (Python):
n = int(input())
a = [list(map(int,input().split()))for _ in range(n)]
A,B = a[0][0],a[0][1]
for i in range(1,n):
    C = max([1,-(-A//a[i][0]),-(-B//a[i][1])])
    A = a[i][0]*C
    B = a[i][1]*C
print(A+B)

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


































for i in range(1, n):
    s = -(-A[i-1][0] // A[i][0])
    t = -(-A[i-1][1] // A[i][1])
    
    for j in range(2):
        A[i][j] *= max(s, t)
    
    
print(sum(A[-1]))

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
y = 1
for i in range(N):
    k = max(-(-x // T[i]), -(-y // A[i]))
    x = k * T[i]
    y = k * A[i]
else:
    print(x + y)

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

t=1
a=1
for i in ta:
  m=max(-(-t//i[0]),-(-a//i[1]))
  t=m*i[0]
  a=m*i[1]
print(t+a)

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

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

Solution (Python):
N = int(input())
l = []
l.append(list(map(int, input().split())))
for i in range(N - 1):
    l.append(list(map(int, input().split())))
    if (l[i][0] > l[i + 1][0]) or (l[i][1] > l[i + 1][1]):
        T = l[i][0] // l[i + 1][0]
        A = l[i][1] // l[i + 1][1]
        if l[i][0] % l[i + 1][0] != 0:
            T += 1
        if l[i][1] % l[i + 1][1] != 0:
            A += 1
        l[i + 1][0] *= max(T, A)
        l[i + 1][1] *= max(T, A)
print(sum(l[-1]))

Solution (Python):
N = int(input())
HT, HA = map(int, input().split())

for i in range(1,N):
    T, A = map(int, input().split())
    B = max( -(-HT//T), -(-HA//A) )

    HT = B * T
    HA = B * A

print(HT+HA)

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

tt=1
aa=1

for i in ta:
    ta=max(-(-tt//i[0]),-(-aa//i[1]))
    
    tt=ta*i[0]
    aa=ta*i[1]

print(tt+aa)

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

A = 1
B = 1
for _ in range(N):
    x, y = map(int, input().split())
    na = A // x if A % x == 0 else A // x + 1
    nb = B // y if B % y == 0 else B // y + 1
    n = max(na, nb)
    A = n * x
    B = n * y

print(A + B)

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

t = ta[0][0]
a = ta[0][1]

for i in range(1,n):
    mag = max((t+ta[i][0]-1)//ta[i][0],(a+ta[i][1]-1)//ta[i][1])
    t = mag*ta[i][0]
    a = mag*ta[i][1]
    
    
print(t+a)

Solution (Python):
import math

n = int(input())

s0 = 2
t0 = a0 = 1
for i in range(n):
    t, a = map(int, input().split())

    m = max((t0 + t - 1) // t,
            (a0 + a - 1) // a)
    
    

    t0, a0 = t * m, a * m
    s0 = t0 + a0
    

print(s0)

Solution (Python):
import math
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

n = int(input())

t, a = map(int, input().split())
t0, a0 = t, a
s = t + a
for i in range(1, n):
    
    t, a = map(int, input().split())
    g = GCD(t, a)
    t, a = t // g, a // g

    m = max((t0+t-1)//t,
            (a0+a-1)//a)
    s =  (t+a) * m
    t0, a0 = t * m, a * m

print(s)

Solution (Python):
N = int(input())
t = 0
a = 0

for _ in range(N):
  rt,ra = map(int,input().split())
  c = max((t-1)//rt+1,(a-1)//ra+1)
  t = rt*c
  a = ra*c
  if a+t == 0:
    t += rt
    a += ra

print(a+t)