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 = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    c = max(-(-a // x), -(-b // y))
    
    a, b = c* x, c* y
print(a + b)

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

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

    
    kake = 1
    sum_tmp = 0
    t_tmp = 0
    a_tmp = 0
    for i in range(n):
        if i == 0:
            kake = 1
        else:
            
            if sum_tmp % (T[i]+A[i]) == 0:
                kake_sum = sum_tmp // (T[i]+A[i])
            else:
                kake_sum = sum_tmp // (T[i]+A[i]) + 1
            
            if t_tmp % T[i] == 0:
                kake_t = t_tmp // T[i]
            else:
                kake_t = t_tmp // T[i] + 1
            
            if a_tmp % A[i] == 0:
                kake_a = a_tmp // A[i]
            else:
                kake_a = a_tmp // A[i] + 1
            
            kake = max(kake_sum, kake_t, kake_a)

        sum_tmp = kake*(T[i]+A[i])
        t_tmp = kake*T[i]
        a_tmp = kake*A[i]

    ans = kake * (T[n-1]+A[n-1])
    print(ans)

if __name__ == "__main__":
    main()

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

print(t0 + a0)

Solution (Python):
from collections import namedtuple

Report = namedtuple('Report', ['a', 'b'])

def main():
    n = int(input())
    reports = []
    for _ in range(n):
        a, b = map(int, input().split())
        reports.append(Report(a, b))
    
    print(solve(reports))

def solve(reports):
    x, y = reports[0].a, reports[0].b

    for a, b in reports[1:]:
        c = ceil(x, a)
        d = ceil(y, b)
        if d // b * a > c:
            x = d // b * a
            y = d
        else:
            x = c
            y = c // a * b
    
    return x + y

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

main()

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

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

print(t0+a0)

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

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

tmp1 = 1
tmp2 = 1

for l in L:
    i = max(1, tmp1//l[0] if tmp1%l[0] == 0 else tmp1//l[0] + 1, tmp2//l[1] if tmp2%l[1] == 0 else tmp2//l[1] + 1)
    tmp1 = i * l[0] 
    tmp2 = i * l[1] 
            
print(tmp1 + tmp2)

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

for _ in range(N):
  _t, _a = map(int, input().split())
  n = max(-(-t // _t), -(-a // _a))
  t, a = n*_t, n*_a
print(t + a)

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

Solution (Python):
N = int(input())
num_t, num_a = 0, 0

for i in range(N):
    t, a = map(int, input().split())
    if i == 0 or (num_t <= t and num_a <= a):
        num_t, num_a = t, a
    else:
        mul_t = num_t // t if num_t % t == 0 else num_t // t + 1
        mul_a = num_a // a if num_a % a == 0 else num_a // a + 1
        mul = max(mul_t, mul_a)
        num_t, num_a = t*mul, a*mul

print(num_t + num_a)

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

Solution (Python):
N = int(input())
T, A = [], []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
t_pred, a_pred = 1, 1
for t, a in zip(T, A):
    if t_pred <= t and a_pred <= a:
        t_pred, a_pred = t, a
    else:
        times = max(-(-t_pred//t), -(-a_pred//a))
        t_pred, a_pred = times*t, times*a
print(t_pred + a_pred)

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

Solution (Python):
import math

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

t = T[0]
a = A[0]
for i in range(1, N):
    r1 = -(-t // T[i])
    r2 = -(-a // A[i])
    minR = min(r1, r2)
    maxR = max(r1, r2)
    if minR * T[i] >= t and minR * A[i] >= a:
        t = minR * T[i]
        a = minR * A[i]
    else:
        t = maxR * T[i]
        a = maxR * A[i]

    
    
    

print(t + a)

Solution (Python):
from math import ceil
from decimal import Decimal as Deci
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m0 = ceil(Deci(a[k-1][0])/Deci(a[k][0]))
        m1 = ceil(Deci(a[k-1][1])/Deci(a[k][1]))
        m = max(m0, m1)
        a[k] = [m*a[k][0], m*a[k][1]]
print(sum(a[n-1]))

Solution (Python):
N = int(input())
A = []
B = []
for i in range(N) :
    in_a,in_b = map(int,input().split())
    A.append(in_a)
    B.append(in_b)
    
for i in range(1,N) :
    if A[i-1] > A[i] :
        if A[i-1] % A[i] == 0 :
            a = A[i-1]//A[i]
        else :
            a = A[i-1]//A[i] + 1
    else :
        a = 1
    
    if B[i-1] > B[i] :
        if B[i-1] % B[i] == 0 :
            b = B[i-1]//B[i]
        else :
            b = B[i-1]//B[i] + 1
    else :
        b = 1
    
    p = max(a,b)
    
    A[i] *= p
    B[i] *= p

ans = A[-1] + B[-1]

print(ans)

Solution (Python):
import math
from decimal import Decimal
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m0 = math.ceil(Decimal(a[k-1][0])/Decimal(a[k][0]))
        m1 = math.ceil(Decimal(a[k-1][1])/Decimal(a[k][1]))
        m = max(m0, m1)
        a[k] = [m*a[k][0], m*a[k][1]]
print(sum(a[n-1]))

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

A,B=1,1
for _ in [0]*n:
    t,a=map(int,input().split())
    v=max((A+t-1)//t,(B+a-1)//a)
    A,B=v*t,v*a

print(A+B)

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

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

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

Solution (Python):
from math import *
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [int(x) for x in input().split()]
    T.append(ti)
    A.append(ai)

prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = (prevT + T[i] - 1) // T[i]
    nextfacA = (prevA + A[i] - 1) // A[i]
    nextfac = max(nextfacT, nextfacA)
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]

print(prevA+prevT)

Solution (Python):
from math import *
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [int(x) for x in input().split()]
    T.append(ti)
    A.append(ai)

prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = int(ceil((prevT + T[i] - 1) // T[i]))
    nextfacA = int(ceil((prevA + A[i] - 1) // A[i]))
    nextfac = max(nextfacT, nextfacA)
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]

print(prevA+prevT)

Solution (Python):
from math import *
from decimal import * 
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [Decimal(int(x)) for x in input().split()]
    T.append(ti)
    A.append(ai)

prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = int(ceil(prevT / T[i]))
    nextfacA = int(ceil(prevA / A[i]))
    nextfac = max(nextfacT, nextfacA)
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]

print(prevA+prevT)

Solution (Python):
def compute_current_score(previous_t_score, previous_a_score, current_t_ratio, current_a_ratio):
    initial_divisor = max(previous_t_score // current_t_ratio, previous_a_score // current_a_ratio)
    current_t_score = 0
    current_a_score = 0
    while(True):
        current_t_score = initial_divisor * current_t_ratio
        current_a_score = initial_divisor * current_a_ratio
        if((current_t_score >= previous_t_score) and (current_a_score >= previous_a_score)):
            break
        initial_divisor += 1
    return current_t_score, current_a_score

N = int(input())
t_score, a_score = list(map(int, input().strip().split()))

for  n in range(N-1):
    t_ratio, a_ratio = list(map(int, input().strip().split()))
    t_score, a_score = compute_current_score(t_score, a_score, t_ratio, a_ratio)
    
print(t_score + a_score)

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())
sumt=1
suma=1
for i in range(n):
    t,a=map(int,input().split())
    check=0
    k=int(max(sumt//t,suma//a))
    while check==0:
        if sumt<=t*k and suma<=a*k:
            check+=1
            sumt=t*k
            suma=a*k
        k+=1
print(sumt+suma)

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

N = int(input())
T = []
A = []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
    m1 = ceil(curT, T[i])
    m2 = ceil(curA, A[i])
    m = max(m1, m2)
    curT = m * T[i]
    curA = m * A[i]
print(curT+curA)

Solution (Python):


N  = int(input())

ans = 0
T, A = [0] * 1001, [0] * 1001

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

    if i != 0 and T[i-1] >= T[i] or A[i-1] >= A[i]:
        t = T[i-1] // T[i] if T[i-1] % T[i] == 0 else T[i-1] // T[i] + 1
        s = A[i-1] // A[i] if A[i-1] % A[i] == 0 else A[i-1] // A[i] + 1

        m = max(t, s)

        T[i] *= m
        A[i] *= m

    ans = sum([T[i], A[i]])

print (ans)

Solution (Python):


N  = int(input())

ans = [0, 0]
T, A = [0] * 1001, [0] * 1001

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

    if i != 0 and T[i - 1] - T[i] >= 0 or A[i - 1] - A[i] >= 0:
        t = T[i-1] // T[i] if T[i-1] % T[i] == 0 else T[i-1] // T[i] + 1
        s = A[i-1] // A[i] if A[i-1] % A[i] == 0 else A[i-1] // A[i] + 1

        m = max(t, s)

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

print (int(sum(ans)))

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

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

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N): 
    mul = max(floordiv(tak,TA[i][0]), floordiv(aok,TA[i][1]))
    tak = TA[i][0] * mul
    aok = TA[i][1] * mul

print(tak+aok)

Solution (Python):
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
    
    
    k1 = l1[0]//l2[0]
    k2 = l1[1]//l2[1]
    k = max(k1,k2)
    for i in range(k,k+2):
        if l2[0] * i >= l1[0] and l2[1] * i >= l1[1]:
            l2[0] *= i
            l2[1] *= i
            break
for i in range(N-1):
    modify(info[i],info[i+1])
ans = sum(info[-1])
print(ans)

Solution (Python):
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
for i in range(1,N):
    c = max(-(-ta[i-1][0]//ta[i][0]),-(-ta[i-1][1]//ta[i][1]))
    ta[i][0] = ta[i][0]*c
    ta[i][1] = ta[i][1]*c
print(sum(ta[N-1]))

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

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

t,a = 1,1
for i in range(N):
    r = Decimal(max(ceil(t/T[i]),ceil(a/A[i])))
    t = r*T[i]
    a = r*A[i]

print(t+a)

Solution (Python):
n = int(input())
Ratio = [list(map(int,input().split())) for _ in range(n)]
t,a = Ratio[0][0],Ratio[0][1]

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

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

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

Solution (Python):
import math
from decimal import *

n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]

def newT(t, ratio):
    if t[0] <= ratio[0] and t[1] <= ratio[1]:
        return ratio
    else:
        
        c = max((t[0]+ratio[0]-1)//ratio[0], (t[1]+ratio[1]-1)//ratio[1])
        return [i*c for i in ratio]

to = l[0]
for li in l[1:]:
    to = newT(to, li)

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

Solution (Python):
import math
from decimal import *

n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]

def newT(t, ratio):
    a = Decimal(t[0]) / Decimal(ratio[0])
    b = Decimal(t[1]) / Decimal(ratio[1])
    if a <= 1 and b <= 1:
        return ratio
    else:
        c = math.ceil(max([a, b]))
        return [i*c for i in ratio]

to = l[0]
for li in l[1:]:
    to = newT(to, li)

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

Solution (Python):
n = int(input())
t = a = 1

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

    t = k * ti
    a = k * ai

print(t + a)

Solution (Python):
n = int(input())
t_list = []
a_list = []
for i in range(n):
    t, a = map(int, input().split())
    t_list.append(t)
    a_list.append(a)

t_num = t_list[0]
a_num = a_list[0]
for i in range(1, n):
    t, a = t_list[i], a_list[i]
    num = max((a_num+a-1)//a, (t_num+t-1)//t)
    t_num = num * t
    a_num = num * a
print(t_num + a_num)

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

Solution (Python):
import math
n = int(input())
c = []
d = []
for i in range(n):
    c.append([int(m) for m in input().split()])
    d.append([])
d[0].append(c[0][0])
d[0].append(c[0][1])

def f(x,y):
    return x//y + (1 if x%y > 0 else 0)

for i in range(1, n):
    
    zz = max(f(d[i - 1][0], c[i][0]),f(d[i - 1][1], c[i][1]))
    d[i].append(c[i][0] * zz)
    d[i].append(c[i][1] * zz)

    
print(d[n - 1][0] + d[n - 1][1])

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

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

Solution (Python):
def main():
    n = int(input())
    t0, a0 = 1, 1
    for _ in range(n):
        t, a = map(int, input().split())
        mult = max((t0 + t - 1) // t, (a0 + a - 1) // a)
        t0, a0 = t * mult, a * mult
    print(t0 + a0)


if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())
vote = [0, 0]




vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if vote[0] % t == 0:
        k = vote[0] // t
    else:
        k = vote[0] // t + 1
    if vote[1] % a == 0:
        k = max(k, vote[1] // a)
    else:
        k = max(k, vote[1] // a + 1)
    
    vote = [t * k, a * k]
    
    
print(vote[0] + vote[1])

Solution (Python):
from math import ceil

N = int(input())
ta, ao = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    if ta <= T and ao <= A:
        ta = T
        ao = A
    else:
        if ta % T == 0:
            n = ta//T
        else:
            n = ta//T + 1
        if ao % A == 0:
            m = ao//A
        else:
            m = ao//A + 1
        
        ta = max(n, m) * T
        ao = max(n, m) * A
print(ta+ao)

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

s, t = 1, 1
for i in range(0, n):

    j = max((s+a[i][0]-1)//a[i][0], (t+a[i][1]-1)//a[i][1])
    s, t = a[i][0]*j, a[i][1]*j

print(s+t)

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

NOW=(TA[0][0],TA[0][1])

def next(NOW,NEXT):
    i,j=NOW
    k,l=NEXT

    if k>=i and l>=j:
        return k,l

    MAX=max(-(-i//k),-(-j//l))

    return MAX*k,MAX*l

for i in range(1,N):
    NOW=next(NOW,TA[i])

print(sum(NOW))

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

n_t, n_a = 1, 1
for t, a in TA:
    
    v = max(-(-n_t//t), -(-n_a//a))
    n_t, n_a = t*v, a*v

print(n_t+n_a)

Solution (Python):

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

for i in range(1, N):
    Tprev, Aprev = TA[i - 1]
    Ti, Ai = TA[i]
    
    if Ti >= Tprev and Ai >= Aprev: continue
    
    if (Tprev / Ti) > (Aprev / Ai): rate = -(-Tprev // Ti)
    else: rate = -(-Aprev // Ai)
    
    TA[i][0] = Ti * rate
    TA[i][1] = Ai * rate

print(sum(TA[-1]))

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

for i in range(N-1):
    t_i, a_i = list(map(int, input().split()))
    mul = max((t + t_i - 1) // t_i, (a + a_i - 1) // a_i)
    t = mul * t_i
    a = mul * a_i
    
print(int(t+a))

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

Solution (Python):
N = int(input())
TA = [[int(_) for _ in input().split()] for _ in range(N)]
x, y = TA.pop(0)
for ta in TA:
    if ta[1] * x - ta[0] * y < 0:
        y = ta[1] * (1 + (y - 1) // ta[1])
        x = y * ta[0] // ta[1]
    elif ta[1] * x - ta[0] * y > 0:
        x = ta[0] * (1 + (x - 1) // ta[0])
        y = x * ta[1] // ta[0]
print(x + y)

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

Solution (Python):
class Point:
    def __init__(self, t, a):
        self.t = t
        self.a = a


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

T = 1
A = 1

for p in points:
    
    n = max((-1*T//p.t)*-1, (-1*A//p.a)*-1)
    T = n*p.t
    A = n*p.a
print(T+A)

Solution (Python):
import math

def quot(p, q):
  return p // q + (p % q != 0)

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

k = 1
for i in range(n-1):
  k1 = quot(ratio[i][0] * k , ratio[i+1][0])
  k2 = quot(ratio[i][1] * k , ratio[i+1][1])
  k = max(k1, k2)

print(sum(ratio[n-1]) * k)

Solution (Python):
import math


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


T = 1 
A = 1 
ans = 2

for i in range(0, N):
    
    
    m = max(T // TA[i][0] + (T % TA[i][0] != 0), A // TA[i][1] + (A % TA[i][1] != 0))
    T = TA[i][0] * m
    A = TA[i][1] * m
    ans = T + A

print(ans)

Solution (Python):
import math


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


T = 1 
A = 1 
ans = 2

for i in range(0, N):
    
    m = max(-(-T // TA[i][0]), -(-A // TA[i][1]))
    T = TA[i][0] * m
    A = TA[i][1] * m
    ans = T + A

print(ans)

Solution (Python):
N = int(input())
t, a = [int(x) for x in input().split()]
for i in range(N - 1):
    T, A = [int(x) for x in input().split()]
    t_T = t // T + (t % T != 0)
    a_A = a // A + (a % A != 0)
    b = max(t_T, a_A)
    t, a = T * b, A * b

print(t + a)

Solution (Python):


N = int(input())
A = 1
B = 1

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

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

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

nowa = 1
nowt = 1
for i in range(n):
    
    (t, a) = list(map(int, input().split()))
    bai = max((nowa * -1 // a) * -1, (nowt * -1 // t) * -1)
    nowa = a * bai
    nowt = t * bai

print(nowa + nowt)

Solution (Python):

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

t0,a0 = 0,0
for i in range(N):
    t,a = TA[i]
    if t0 == t and a0 == a:
        pass
    else:
        if t0 > t or a0 > a:
            tmp = max([t0//t + min([1, t0 % t]), a0//a + min([1, a0 % a])])
            t0 = t*tmp
            a0 = a*tmp
        else:
            t0 = t
            a0 = a

print(t0+a0)

Solution (Python):
def solve(N, TAs):
    T, A = 1, 1
    for t, a in TAs:
        m = (t * A) % a
        y = max(0, (T * a - t * A) // t)
        while True:
            if (m + (y * t)) % a == 0:
                break
            y += 1
        x = (t * A + t * y) // a - T
 
        T += x
        A += y
    return T + A
  
if __name__ == "__main__":
    N = int(input())
    TAs = [(tuple)(map(int, input().split(" "))) for l in range(N)]
    print(solve(N, TAs))

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

Solution (Python):
def solve(N, TAs):
    T, A = 1, 1
    for t, a in TAs:
        m = (t * A) % a
        y = max(0, (T * a - t * A) // t)
        while True:
            if (m + (y * t)) % a == 0:
                break
            y += 1
        x = (t * A + t * y) // a - T

        T += x
        A += y
    return T + A











if __name__ == "__main__":
    N = int(input())
    TAs = [(tuple)(map(int, input().split(" "))) for l in range(N)]
    print(solve(N, TAs))

Solution (Python):


n=int(input())

x,y=map(int, input().split())
for i in range(n-1):
    t,a=map(int, input().split())
    if (x<=t and y<=a):
        x=t
        y=a
    else:
        tmp=0
        k=max(x//t,y//a)
        tk=t*k
        ak=a*k
        while 1:

            if x<=tk+(tmp*t) and y<=ak+(tmp*a):
                x=tk+(tmp*t)
                y=ak+(tmp*a)
                break
            tmp+=1
print(x+y)

Solution (Python):
import math
from decimal import *

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:
            mul = Decimal(max(math.ceil(T[i] / T[i + 1]), math.ceil(A[i] / A[i + 1])))
            A[i + 1] *= mul
            T[i + 1] *= mul
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

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

Solution (Python):
N = int(input())
A = list()
T = list()

for i in range(N):
    x, y = map(int, input().split())
    A.append(x)
    T.append(y)

x = T[0]
y = A[0]

for i in range(1, N):
    k1 = T[i] - x
    k2 = A[i] - y
    if k1 == 0 and k2 == 0:
        continue

    l = 0
    r = 1000000000000000000
    mid = 0
    t1 = k1
    t2 = k2
    while r - l > 1:
        mid = (r + l) // 2
        k1 = T[i] * mid - x
        k2 = A[i] * mid - y
        if k1 == 0 and k2 == 0:
            t1 = 0
            t2 = 0
            break
        if k1 >= 0 and k2 >= 0:
            t1 = k1
            t2 = k2
            r = mid
        else:
            l = mid
    x += t1
    y += t2
    

print(x + y)

Solution (Python):
N = int(input())
T = 1
A = 1


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

    if max(t,a)%min(t,a) == 0:
        if t > a:
            t = t//a
            a = a
        else:
            t = t
            a = a//t

    j = max(T//t,A//a)
    while T > t*j or A > a*j:
        j += 1

    T = t*j
    A = a*j

print(T+A)

Solution (Python):
import sys
def 解():
    iN = int(input())
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    iT = aD[0][0]
    iA = aD[0][1]
    for a in aD[1:]:
        iTn = a[0]
        iAn = a[1]
        if iT <= iTn and iA <= iAn:
            iT = iTn
            iA = iAn
        else:
            iD = iT/iA
            iDn = iTn/iAn
            if iD > 1 > iDn or iD < 1 < iDn:
                if iDn < 1:
                    iG = iT//iTn
                    if iT % iTn !=0 :
                        iG += 1
                else:
                    iG = iA//iAn
                    if iA % iAn !=0 :
                        iG += 1
                iA = iAn * iG
                iT = iTn * iG
            else :
                if iA/iAn > iT/iTn:
                    iG = iA//iAn
                    if iA % iAn !=0 :
                        iG += 1
                else:
                    iG = iT//iTn
                    if iT % iTn !=0 :
                        iG += 1
                iA = iAn * iG
                iT = iTn * iG
    return iA+iT
print(解())

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

num=[ratio[0]]
for i in range(1,N):
    beta = max(num[i-1][0]//ratio[i][0],
               num[i-1][1]//ratio[i][1])
    num_next = list(map(lambda x:beta*x,ratio[i]))
    if num[i-1][0]<=num_next[0] and num[i-1][1]<=num_next[1]:
        num.append(num_next)
    else:
        num.append(list(map(lambda x:(beta+1)*x,ratio[i])))



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

Solution (Python):
from math import ceil
N = int(input())

def ceil_N(a,b):
  if a%b == 0:
    return a//b
  else:
    return a//b +1
  
T, A = 1,1
for i in range(N):
  t, a = map(int, input().split())

  
  N = max(ceil_N(T,t), ceil_N(A,a))

  T = t * N
  A = a * N
  
print(T+A)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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


def main():
    N = int(input())
    a, b = map(int, input().split())
    for _ in range(N - 1):
        T, A = map(int, input().split())
        for i in count(max(a // T, b // A) - 1):
            if T * i >= a and A * i >= b:
                a, b = T * i, A * i
                break
    print(a + b)


if __name__ == '__main__':
    main()

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

Solution (Python):
def roof(i, j):
    if i % j == 0:
        return i//j
    else:
        return (i//j) + 1

N = int(input())
A, B = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    n = max(roof(A, x), roof(B, y))
    A, B = n*x, n*y

print(A + B)

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


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


tx, ax = 1, 1
for i in range(n):
    t, a = [int(j) for j in input().split()]
    n = max(ceil(tx, t), ceil(ax, a))
    tx, ax = n * t, n * a
print(tx + ax)

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

Solution (Python):
t=a=1
for i in[0]*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):
t=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):
t=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):
t=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())
t=a=1
for i in range(n):
    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())
t = a = 1
for i in range(n):
    T, A = map(int, input().split())
    n = max(-(-t // T), -(-a // A))
    t = n * T
    a = n * A
print(t + a)

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

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

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

n = int(input())
x,y = 1,1

for _ in range(n):
    t,a  = map(int,input().split())
    temp = max(ceil(x,t),ceil(y,a))
    x = t*temp
    y = a*temp

print(x+y)

Solution (Python):
from decimal import *
import math
n = int(input())
a, b = map(int, input().split())
for i in range(n - 1):
    c, d = map(int, input().split())
    q = Decimal(max(math.ceil(a / c), math.ceil(b / d)))
    a, b = c * q, d * q

print(a + b)

Solution (Python):
from decimal import *
import math

N = int(input())
input_list = [[int(i) for i in input().split()] for j in range(N)]

T, A = input_list[0][0], input_list[0][1]

for i in range(1, N):
    n = Decimal(max(math.ceil(T/input_list[i][0]), math.ceil(A/input_list[i][1])))
    T = input_list[i][0] * n
    A = input_list[i][1] * n

print(T + A)