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



Sample input:
3
2 3
1 1
3 2


Sample output:
10

Submission status: Accepted

Solution code:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    c,d=map(int,input().split())
    if a<=c and b<=d:
        a,b=c,d
    elif c<a and b<=d:
        a,b=c*(-(-a//c)),d*(-(-a//c))
    elif a<=c and d<b:
        a,b=c*(-(-b//d)),d*(-(-b//d))
    elif c<a and d<b:
        if -(-a//c) > -(-(b//d)):
            a,b=c*(-(-a//c)),d*(-(-a//c))
        elif -(a//c) < -(-(b//d)):
            a,b=c*(-(-b//d)),d*(-(-b//d))
print(a+b)

Submission status: Accepted

Solution code:
n = int(input())
x = [list(map(int,input().split())) for i in range(n)]
a = x[0][0]
b = x[0][1]
x.pop(0)
for i in x:
  m = a//i[0]
  n = b//i[1]
  if a % i[0] != 0:
    m+=1
  if b % i[1] != 0:
    n+=1
  a = max(m,n) * i[0]
  b = max(m,n) * i[1]
print(a+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n)]

def ceil(n,d):
 if n%d==0:
  return n/d
 else:
  return n/d+1

a = 1
b = 1
for i in range(n):
	x, y = arr[i]
	t = max(ceil(a,x), ceil(b,y))

	a = x*t; b = y*t

print a+b

Submission status: Accepted

Solution code:
N = int(input())


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


x, y = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    p = max(ceil(x, T), ceil(y, A))
    x = T * p
    y = A * p
print(x + y)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

tx, ax = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    fac = max(tx//T, ax//A)
    if T * fac < tx or A * fac < ax:
        fac += 1
    tx = T * fac
    ax = A * fac

print(tx + ax)

Submission status: Accepted

Solution code:
N = int(input())
T = 1
A = 1
for i in range(N):
  ti, ai = map(int, input().split())
  m = max(-(-T // ti), -(-A // ai))
  T = ti * m
  A = ai * m
print(T + A)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    D = [li_input() for _ in range(N)]

    t, a = 1, 1

    # t = t_rate * x
    # a = a_rate * x
    for t_rate, a_rate in D:
        x = t // t_rate if t % t_rate == 0 else t // t_rate + 1
        y = a // a_rate if a % a_rate == 0 else a // a_rate + 1

        t = t_rate * max(x, y)
        a = a_rate * max(x, y)

    print(a + t)


main()

Submission status: Accepted

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

x = t[0]
y = a[0]

for i in range(1, n):
    j = max(x//t[i], y//a[i])
    xn = t[i] * j
    yn = a[i] * j
    if xn >= x and yn >= y:
        x = xn
        y = yn
    else:
        x = t[i] * (j+1)
        y = a[i] * (j+1)

print(x + y)

Submission status: Accepted

Solution code:
n = int(input())

T = 1
A = 1
for _ in range(n):
    t, a = map(int, input().split())
    m = max([T // t, A // a])
    for i in range(1000):
        i += m
        if T <= t * i and A <= a * i:
            T = t * i
            A = a * i
            break

print(A + T)

Submission status: Accepted

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

nt,na = src[0]
for t,a in src[1:]:
    t1 = -(-nt//t) * t
    a1 = t1 * a // t
    a2 = -(-na//a) * a
    t2 = a2 * t // a
    if t2 < nt or a2 < na:
        nt,na = t1,a1
    else:
        nt,na = t2,a2
print(nt+na)

Submission status: Accepted

Solution code:
import sys
sdin = sys.stdin.readline

INF = float("inf")

n = int(sdin())
ta = []
for _ in range(n):
    ta.append(tuple(map(int, sdin().split())))
    
    
t_real = [ta[0][0]]
a_real = [ta[0][1]]
for i in range(1,n):
    t_k = t_real[i-1]//ta[i][0] + bool(t_real[i-1]%ta[i][0])
    a_k = a_real[i-1]//ta[i][1] + bool(a_real[i-1]%ta[i][1])
    
    # t_realとa_realの次の候補
    if t_k * ta[i][1] < a_real[i-1]:
        t_real_t = INF
        a_real_t = INF
    else:
        t_real_t = t_k * ta[i][0]
        a_real_t = t_k * ta[i][1]
        
    if a_k * ta[i][0] < t_real[i-1]:
        t_real_a = INF
        a_real_a = INF
    else:
        t_real_a = a_k * ta[i][0]
        a_real_a = a_k * ta[i][1]
        
    # 選択
    if (t_real_t + a_real_t) <= (t_real_a + a_real_a):
        t_real.append(t_real_t)
        a_real.append(a_real_t)
    else:
        t_real.append(t_real_a)
        a_real.append(a_real_a)
        
print(t_real[-1] + a_real[-1])

Submission status: Accepted

Solution code:
N=int(input())
T=[]
A=[]
for i in range(N):
    Ti,Ai=[int(i) for i in input().split()]
    T.append(Ti)
    A.append(Ai)
T_ans=1
A_ans=1
k=1
for i in range(N):
    if T_ans>T[i] or A_ans>A[i]:
        k=max(-(-T_ans//T[i]),-(-A_ans//A[i]))
        T_ans=T[i]*k
        A_ans=A[i]*k
    else:
        T_ans=T[i]
        A_ans=A[i]
print(T_ans+A_ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

def main():
    n = int(input())
    arry = [list(map(int, input().split())) for _ in range(n)]
    ans = [arry[0]]

    for i in range(1, n):
        a, b = arry[i]
        if a >= ans[i-1][0] and b >= ans[i-1][1]:
            ans.append([a, b])
        else:
            num = max(-(-ans[i-1][0] // a), -(-ans[i-1][1] // b))
            a *= num
            b *= num
            ans.append([a, b])
    print(sum(ans[-1]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    #nit = math.ceil(tp/ti)
    #nia = math.ceil(ap/ai)
    nit = -(-tp//ti)
    nia = -(-ap//ai)
    ni = max(nit, nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    #nit = math.ceil(tp/ti)
    #nia = math.ceil(ap/ai)
    nit = -tp//ti
    nia = -ap//ai
    ni = max(-nit, -nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
for i in range(n):
  a,b=map(int,input().split())
  if not i:
    c,d=a,b
  else:
    if c>a or d>b:
      p=c//a
      if c%a:
        p+=1
      q=d//b
      if d%b:
        q+=1
      r=max(p,q)
      c,d=a*r,b*r
    else:
      c,d=a,b
print(c+d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inpl(): return input().split()

n = int(input())
M = [list(map(int, inpl())) for _ in range(n)]
for i in range(n - 1):
    v = max(((M[i][1] - 1) // M[i+1][1] + 1), ((M[i][0] - 1) // M[i+1][0] + 1))
    M[i+1][0] *= v
    M[i+1][1] *= v     
print(M[n - 1][0] + M[n - 1][1])

Submission status: Accepted

Solution code:
N = int(input())

# initial
p_t, p_a = 1, 1

for i in range(N) :
    t, a = map(int, input().split())
    t_up, a_up = t, a
    
    if t >= p_t and a >= p_a : 
        p_t, p_a = t, a
    else :
        f = max(
            p_t // t if p_t % t == 0 else p_t // t + 1,  
            p_a // a if p_a % a == 0 else p_a // a + 1
        )
        
        p_t, p_a = t*f, a*f

print(p_t + p_a)

Submission status: Accepted

Solution code:
N = int(input())
A,B = 1,1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

""" 解説動画を参考にDPにしてみた版(改) """

from fractions import Fraction

N = int(input())

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

# 比率を何倍したら実際の値なのかでDPを埋めてく
dp = [0] * (N)
# 始めの基準を1倍とする
dp [0] = 1

for i in range(1,N):
    # 今回 * 前回 の計算が終わったあとで整数未満を切り上げる
    # 小数が17桁以降おかしくなるぽいので、Fractionで分数を使用
    dp[i] = int(-(-(max(Fraction(T[i-1], T[i]), Fraction(A[i-1], A[i])) * dp[i-1]) // 1))

print((T[-1]+A[-1]) * dp[-1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

for i in range(N-1):
    t,a = map(int, input().split())
    # 多く増やす必要のある方に合わせて、同じ比で両方増やす
    tmp = max(-(-T // t), -(-A // a))
    T = t * tmp
    A = a * tmp

print(T + A)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

for i in range(N-1):
    t,a = map(int, input().split())
    tmp1,tmp2 = 1,1
    # ループで足していくより、1回で出せる方法にする
    if t < T:
        # 切り上げはmath.ceilより演算子のみのが速い
        tmp1 = -(-T // t)
    if a < A:
        tmp2 = -(-A // a)
    # 多く増やす必要のある方に合わせて、同じ比で両方増やす
    T = t * max(tmp1,tmp2)
    A = a * max(tmp1,tmp2)

print(T + A)

Submission status: Accepted

Solution code:

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

n = int(input())
a=1
b=1

for i in range(n):
    c, d=map(int, input().split())
    n1=ceil(a,c)
    n2=ceil(b,d)
    
    n = max(n1, n2)
    
    a=n*c
    b=n*d

print(a+b)

Submission status: Accepted

Solution code:
n = int(input())
x, y = [int(i) for i in input().split()]

for i in range(n-1):
  t, a = [int(i) for i in input().split()]
 
  c = max(-(-x//t), -(-y//a))

  x = t * c
  y = a * c
    
print(x+y)

Submission status: Accepted

Solution code:
n = int(input())
x, y = [int(i) for i in input().split()]

for i in range(n-1):
  t, a = [int(i) for i in input().split()]
  
  if t >= x and a >= y:
    x = t
    y = a



  else:
    c = max(-(-x//t), -(-y//a))

    x = t * c
    y = a * c
    
print(x+y)

Submission status: Accepted

Solution code:
n = int(input())
t = []
a = []

for i in range(0, n):
    ti, ai = [int(_) for _ in input().split()]
    t.append(ti)
    a.append(ai)

newest_t = t[0]
newest_a = a[0]

for i in range(0, n):
    div_t = newest_t // t[i]
    div_a = newest_a // a[i]

    for j in range(max(div_t, div_a)-1, max(div_t, div_a)+2):
        if j * t[i] >= newest_t and j * a[i] >= newest_a:
            newest_t = j * t[i]
            newest_a = j * a[i]
            break

print(newest_t + newest_a)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7

N = int(input())
sumt = suma = 0

for i in range(N):
	nt,na = map(int,input().split())
	if i==0:
		sumt = nt
		suma = na
	else:
		timest = (sumt-1)//nt+1
		timesa = (suma-1)//na+1
		times = max(timest,timesa)
		sumt = nt * times
		suma = na * times

print(sumt+suma)

Submission status: Accepted

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

t_real = [TA[0][0]]
a_real = [TA[0][1]]

for i in range(1,N):
    t_cand = (t_real[i-1]//TA[i][0] + bool(t_real[i-1]%TA[i][0])) * TA[i][0]
    a_cand = (a_real[i-1]//TA[i][1] + bool(a_real[i-1]%TA[i][1])) * TA[i][1]
    
    if t_cand//TA[i][0] * TA[i][1] >= a_real[i-1]:
        t_real.append(t_cand)
        a_real.append(t_cand//TA[i][0] * TA[i][1])
        
    elif a_cand//TA[i][1] * TA[i][0] >= t_real[i-1]:
        a_real.append(a_cand)
        t_real.append(a_cand//TA[i][1] * TA[i][0])
        
    else:
        print("error")
        
print(t_real[-1]+a_real[-1])

Submission status: Accepted

Solution code:
from math import ceil
from fractions import Fraction
N=int(input())
a=1
b=1
for i in range(N):
    x,y=map(int,input().split())
    n=max(ceil(Fraction(a,x)),ceil(Fraction(b,y)))
    a,b=n*x,n*y
print(a+b)

Submission status: Accepted

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

nt, na = 1, 1
for i in range(n):
    rt, ra = list(map(int, input().split()))
    r = max([ceil(Fraction(nt, rt)), ceil(Fraction(na, ra))])
    nt = r*rt
    na = r*ra
    # print(nt, na)

print(nt+na)

Submission status: Accepted

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

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

for i in range(1, n):
    if ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]:
        multi = max(
            round_up(ta[i-1][0], ta[i][0]),
            round_up(ta[i-1][1], ta[i][1])
        )
        ta[i][0] *= multi
        ta[i][1] *= multi

print(ta[-1][0] + ta[-1][1])

Submission status: Accepted

Solution code:
from math import ceil
from fractions import Fraction
N = int(input())
A, B = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    n = max(ceil(Fraction(A,x)), ceil(Fraction(B,y)))
    A, B = n*x, n*y
print(A+B)

Submission status: Accepted

Solution code:
def ans():
    n = int(input())
    nowt, nowa = 1,1
    for _ in range(n):
        t, a = map(int, input().split())
        c = max(nowt//t,nowa//a)
        if nowt > c * t or nowa > c * a:
            c += 1
        nowt, nowa = max(c*t,t), max(c*a,a)
    return int(nowa+nowt)

print(ans())

Submission status: Accepted

Solution code:
import math
N = int(input())
def ceil(x,y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1
t=1
a=1
for i in range(N):
    T , A = [int(i) for i in input().split(' ')]
 #   print(T,A)
    n1 = ceil(t , T)
    n2 = ceil(a , A)
    n = max(n1,n2)
    #while T*n <= t and A*n <= a:
     #   n += 1
    
    t = T*n
    a = A*n
#    print(t,a)

print(t+a)

Submission status: Accepted

Solution code:
N = int(input())
t = []
a = []
for i in range(0,N):
	tokuhyousuu = list(map(int,input().split()))
	t.append(tokuhyousuu[0])
	a.append(tokuhyousuu[1])

T = 1
A = 1

for j in range(0,N):
	if(T<=t[j] and A<=a[j]):
		T = t[j]
		A = a[j]

	elif(T>t[j] and A>a[j]):
		if(T%t[j] == 0):
			r_1 = T//t[j]
		else:
			r_1 = T//t[j] + 1

		if(A%a[j] == 0):
			r_2 = A//a[j]
		else:
			r_2 = A//a[j] + 1

		r = max(r_1,r_2)

		T = t[j]*r
		A = a[j]*r


	elif(T>t[j]):
		if(T%t[j]==0):
			r = T//t[j]
		else:
			r = T//t[j]+1
		
		T = t[j]*r
		A = a[j]*r

	elif(A>a[j]):
		if(A%a[j] == 0):
			r = A//a[j]
		else:
			r = A//a[j]+1			
		T = t[j]*r
		A = a[j]*r

print(T+A)

Submission status: Accepted

Solution code:
n = int(input())
x, y = 1, 1
for _ in range(n):
    t, a = map(int,input().split())
    if x*a == y*t:
        continue
    elif x*a > y*t:
        y = (x//t+(x%t!=0))*a
        x = y//a*t
    else:
        x = (y//a+(y%a!=0))*t
        y = x//t*a
print(x+y)

Submission status: Accepted

Solution code:
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
nt,na = src[0]
for t,a in src[1:]:
    t1 = nt + (-nt)%t
    a1 = t1//t * a
    a2 = na + (-na)%a
    t2 = a2//a * t
    if a1 < na:
        nt,na = t2,a2
    else:
        nt,na = t1,a1
print(nt+na)

Submission status: Accepted

Solution code:
N = int(input())
T, A = 1, 1

for _ in range(N):
    t, a = map(int, input().split())
    if T <= t and A <= a:
        T, A = t, a
        continue
    z = max(-(-T//t), -(-A//a))
    T, A = t*z, a*z

print(T+A)

Submission status: Accepted

Solution code:
n=int(input())
t=[[int(i)for i in input().split()]for i in range(n)]
import math
from fractions import Fraction
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil(max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1])
print(dp[-1]*(t[n-1][0]+t[n-1][1]))

Submission status: Accepted

Solution code:
import math
from fractions import Fraction
n=int(input())
x=[1,1]
for i in range(n):
  a0,b0=x
  a ,b =[int(i) for i in input().split()]
  m=math.ceil(max(Fraction(a0,a),Fraction(b0,b)))
  x=[m*a,m*b]
  
print(int(sum(x)))

Submission status: Accepted

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

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

        if t != t0 or a != a0:
            x = max((v1+t-1)//t, (v2+a-1)//a)
            v1, v2 = x * t, x * a

        t0, a0 = t, a

    print(v1+v2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
from fractions import Fraction
import math
t=[[int(i)for i in input().split()]for i in range(n)]
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil((max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1]))
print(dp[-1]*(t[n-1][0]+t[n-1][1]))

Submission status: Accepted

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

t = 1
a = 1

for i in range(n):
    ti, ai = map(int, input().split())
    si = ceil(max(Fraction(t,ti),Fraction(a,ai)))
    t = ti*si
    a = ai*si

print(a+t)

Submission status: Accepted

Solution code:
def c_atcodeer_and_election_report(N, R):
    t, a = 1, 1  # 高橋, 青木の票数
    for x, y in R:
        # t<=nx ∧ a<=ny を満たす最小のnを求める
        n = max(t // x, a // y)
        if t > n * x or a > n * y:
            n += 1
        t = n * x
        a = n * y
    return t + a

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_atcodeer_and_election_report(N, R))

Submission status: Accepted

Solution code:
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt//t),(aa//a))))
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

Submission status: Accepted

Solution code:
N = int(input())
V = [list(map(int,input().split())) for k in range(N)]
T = 1
A = 1

for k in V:
    t = max(T//k[0],A//k[1])
    if t*k[0] < T or t*k[1] < A:
        t += 1
    T = k[0]*t
    A = k[1]*t

print(T+A)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

a, b = 1, 1
n = 1
for i in range(N):
    n = max(-((-a) // rates[i][0]), -((-b) // rates[i][1]))
    a = rates[i][0] * n
    b = rates[i][1] * n
print(a + b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
import math
from fractions import Fraction
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil(max(Fraction(a[i-1],a[i]),Fraction(b[i-1],b[i]))*dp[i-1])
x=dp[-1]
print(x*(a[-1]+b[-1]))

Submission status: Accepted

Solution code:
n = int(input())
t, a = list(map(int, input().split()))
ans = t + a
for i in range(n-1):
    new_t, new_a = list(map(int, input().split()))
    bairitsu = max((t - 1) // new_t + 1, (a - 1) // new_a + 1)
    new_t, new_a = bairitsu * new_t, bairitsu * new_a
    ans = new_t + new_a
    t, a = new_t, new_a
    
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    if N == 1:
        print(sum(A[0]))
        return

    before_t = A[0][0]
    before_a = A[0][1]
    for t, a in A[1:]:
        n1 = -(-before_t // t)
        n2 = -(-before_a // a)
        n = max(n1, n2)
        taka, aoki = t * n, a * n
        before_t, before_a = taka, aoki

    print(taka + aoki)

main()

Submission status: Accepted

Solution code:
n = int(input())
t,a = map(int,input().split())
for i in range(n-1):
  T,A=map(int,input().split())
  count = max(a//A,t//T)
  while (A*count < a) or (T*count < t):
    count += 1
  a = count * A
  t = count * T
print(a+t)

Submission status: Accepted

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

ans_t, ans_a = src[0]
for t,a in src[1:]:
    t1 = ans_t + (t - ans_t%t)%t
    a1 = t1 // t * a
    a2 = ans_a + (a - ans_a%a)%a
    t2 = a2 // a * t
    if a1 < ans_a:
        ans_t, ans_a = t2,a2
    else:
        ans_t, ans_a = t1,a1
print(ans_t + ans_a)

Submission status: Accepted

Solution code:
from decimal import *
from math import ceil
n = int(input())
a, b = 1, 1

for i in range(n):
  x, y = map(int, input().split())
  m = Decimal(max(ceil(a/x), ceil(b/y)))
  a = x*m
  b = y*m

print(a+b)

Submission status: Accepted

Solution code:
n=int(input())
t=[tuple(map(int,input().split()))for i in range(n)]
import math
from fractions import Fraction
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil(max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1])
x=dp[-1]
print(x*t[n-1][0]+x*t[n-1][1])

Submission status: Accepted

Solution code:
from math import ceil
from fractions import Fraction
n = int(input())
nums = [list(map(int,input().split())) for _ in range(n)]
a, b = 1, 1
p = 1
for i in range(n):
    x, y = nums[i][0], nums[i][1]
    p = ceil(max(Fraction(a, x), Fraction(b, y)))
    a, b = p * x, p * y
        
print(a + b)

Submission status: Accepted

Solution code:
from decimal import * 
from math import ceil
N = int(input())
T,A = 1,1
for i in range(N):
    Ti,Ai = map(int,input().split())
    r = Decimal(max(ceil(T/Ti),ceil(A/Ai)))
    T,A = Ti*r,Ai*r
print(T+A)

Submission status: Accepted

Solution code:
n = int(input())
tal = [[int(i) for i in input().split()] for i in range(n)]
t,a = 1,1 
for i in range(n):
    m = max(t//tal[i][0],a//tal[i][1])
    if t>tal[i][0]*m or a>tal[i][1]*m:
        m += 1
    t = m*tal[i][0]
    a = m*tal[i][1]
print(a+t)

Submission status: Accepted

Solution code:
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())
TT=T[0]
AA=A[0]
for i in range(1,N):
    g=max([-((-AA)//A[i]),-((-TT)//T[i])])
    AA=g*A[i]
    TT=g*T[i]
    #print(g,TT,AA)
print(AA+TT)

Submission status: Accepted

Solution code:
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n)]
for i in range(n-1):
	if x[i][0]>x[i+1][0] or x[i][1]>x[i+1][1]:
		a = ((x[i][0]-x[i][0]%x[i+1][0])//x[i+1][0])+1
		b = ((x[i][1]-x[i][1]%x[i+1][1])//x[i+1][1])+1
		if x[i][0]%x[i+1][0]==0: a -= 1
		if x[i][1]%x[i+1][1]==0: b -= 1
		x[i+1] = [x[i+1][0]*max(a,b),x[i+1][1]*max(a,b)]
print(x[-1][0]+x[-1][1])

Submission status: Accepted

Solution code:
from math import ceil

def votes(t, a):
    def ceil(a, b):
        return (a + b - 1) // b
    
    votes_t = votes_a = 1
    for i in range(len(t)):
        k = max(ceil(votes_t, t[i]), ceil(votes_a, a[i]))
        votes_t = t[i] * k
        votes_a = a[i] * k
    return votes_t + votes_a


if __name__ == '__main__':
    lines = [list(map(int, input().split())) for _ in range(int(input()))]
    t = [l[0] for l in lines]
    a = [l[1] for l in lines]
    print(votes(t, a))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
N = int(input())
t,a = map(int,input().split(" "))
for i in range(N-1):
	T,A = map(int,input().split(" "))
	if a % A == 0:
		pla = a // A
	else:
		pla = (a + (A - a % A)) // A

	if t % T == 0:
		plt = t // T
	else:
		plt = (t + (T - t % T)) // T
	t = max(pla,plt) * T
	a = max(pla,plt) * A

print(t+a)

Submission status: Accepted

Solution code:
n=int(input())
t,a=map(int,input().split())
for i in range(1,n):
  c,d=map(int,input().split())
  if(t/c>a/d):
    if(t%c==0):times=t//c
    else:times=t//c+1
  else:
    if(a%d==0):times=a//d
    else:times=a//d+1
  #print(times)
  t,a=c*times,d*times
  #print(t,a)
print(t+a)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
t = 1; a = 1;
for _ in range(n):
    ti,ai = map(int,input().split())
    if t%ti != 0 : t = (t//ti+1)*ti
    if a%ai != 0 : a = (a//ai+1)*ai
    r = max(t//ti,a//ai)
    t = ti*r
    a = ai*r

print(a+t)

Submission status: Accepted

Solution code:
import math
N=int(input())
min_a=1
min_b=1
for i in range(N):
  a,b=map(int,input().split())
  at=min_a//a
  if min_a%a!=0:
    at+=1
  bt=min_b//b
  if min_b%b!=0:
    bt+=1
  n=max(at,bt)
  min_a=a*n
  min_b=b*n
print(min_a+min_b)

Submission status: Accepted

Solution code:
def c_AtCoDeer_and_ElectionReport(N, R):
    from math import ceil
    from decimal import Decimal
    t = 1  # 高橋の票数
    a = 1  # 青木の票数
    for x, y in R:
        n = Decimal(max(ceil(t / x), ceil(a / y)))
        t = n * x
        a = n * y
    return t + a

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_AtCoDeer_and_ElectionReport(N, R))

Submission status: Accepted

Solution code:
n = int(input())
t = 1; a = 1;
for _ in range(n):
    ti,ai = map(int,input().split())
    if t%ti != 0 : t = (t//ti+1)*ti
    if a%ai != 0 : a = (a//ai+1)*ai
    r = max(t//ti,a//ai)
    t = ti*r
    a = ai*r

print(a+t)

Submission status: Accepted

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

for t, a in TA:
    z = max(T//t, A//a)
    if (T > t*z) or (A > a*z):
        z += 1

    T = t * z
    A = a * z

print(T+A)

Submission status: Accepted

Solution code:
import math
N=input()
x,y=1,1
for i in range(N):
	t,a=map(int,raw_input().split())
	n=max(1+(x-1)/t,1+(y-1)/a)
	x,y=n*t,n*a
print x+y

Submission status: Accepted

Solution code:
n = int(input())

tnum = 1
anum = 1
for i in range(n):
    t, a = list(map(int, input().split()))
    ct = tnum // t
    if tnum % t != 0:
        ct += 1
    ca = anum // a
    if anum % a != 0:
        ca += 1
    n = max(ct, ca)
    tnum = n * t
    anum = n * a
print(tnum + anum)

Submission status: Accepted

Solution code:
import math
N = int(input())

A=1
T=1
for i in range(N):
  t, a = [int(n) for n in input().split()]
  ct = T//t
  if T % t != 0:
    ct += 1
  ca = A//a
  if A % a != 0:
    ca += 1
  n = max(ct, ca)
  T = n*t
  A = n*a

print(A+T)

Submission status: Accepted

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

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x:
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

Submission status: Accepted

Solution code:
from collections import defaultdict
from decimal import Decimal


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


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


if __name__ == '__main__':
    main()