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 = 0
b = 0

for _ in range(n):
    x, y = map(int, input().split())
    if not a:
        a, b = x, y
        continue
    z = max(-(-a // x), -(-b // y))
    a, b = z * x, z * y

print(a + b)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import math
import decimal


N = int(input())
tn,an = [1,1]
for _ in range(N):
  t,a = map(int, input().split())
  x = max(math.ceil(decimal.Decimal(tn)/decimal.Decimal(t)),math.ceil(decimal.Decimal(an)/decimal.Decimal(a)))
  tn,an = [t*x,a*x]
print(tn+an)

Submission status: Accepted

Solution code:
from math import ceil
from decimal import Decimal

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

a = 1
b = 1
for x, y in TA:
    n = max(ceil(Decimal(a) / Decimal(x)), ceil(Decimal(b) / Decimal(y)))
    a = n * x
    b = n * y
print(a + b)

Submission status: Accepted

Solution code:
from math import ceil

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

def ceil(a, b):
    return a // b + int(a % b != 0)

a = 1
b = 1
for x, y in TA:
    n = max(ceil(a, x), ceil(b, y))
    a = n * x
    b = n * y
print(a + b)

Submission status: Accepted

Solution code:
from math import ceil

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

a = 1
b = 1
for x, y in TA:
    n = max(-(-a // x), -(-b // y))
    a = n * x
    b = n * y
print(a + b)

Submission status: Accepted

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

    
answer = t+a
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy as copy
n = int(input())
T = [1]
A = [1]
for i in range(n):
    t, a = map(int, input().split())
    tc = copy(t)
    ac = copy(a)
    if T[-1] > t or A[-1] > a:
        multi = max(T[-1] // t, A[-1] // a) + 1
        t *= multi
        a *= multi
        while t - tc >= T[-1] and a - ac >= A[-1]:
            t -= tc
            a -= ac
    T.append(t)
    A.append(a)
print(T[-1] + A[-1])

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]


    mint, mina =  f()
    for i in range(n-1):
        t,a = f()

        m = max((mint+t-1)//t, (mina+a-1)//a)
        
        mint = m * t
        mina = m * a

    print(mint + mina)


solve()

Submission status: Accepted

Solution code:
N = int(input())
T, A = map(int, input().split())
for i in range(N - 1):
    Ti, Ai = map(int, input().split())
    mt = T // Ti + (1 if T % Ti > 0 else 0)
    ma = A // Ai + (1 if A % Ai > 0 else 0)
    m = max(mt, ma)
    Ti *= m
    Ai *= m
    T, A = Ti, Ai
print(T + A)

Submission status: Accepted

Solution code:
def ceil_div(x, y):
    return (x + y - 1) // y

n = int(input())
ans = 1
tt = 1
aa = 1
for i in range(n):
    t, a = map(int, input().split())
    x = t + a
    p = max(ceil_div(ans, x), ceil_div(tt, t), ceil_div(aa, a))
    ans = x * p
    aa = a * p
    tt = t * p
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    mt = t // ti if t % ti == 0 else t // ti + 1
    ma = a // ai if a % ai == 0 else a // ai + 1
    m = max(mt, ma)

    t = m * ti
    a = m * ai

print(t + a)

Submission status: Accepted

Solution code:
N = int(input())

t_pre = 1
a_pre = 1
for i in range(N):
    t, a = map(int, input().split())
    if t_pre<=t and a_pre<=a:
        t_pre = t
        a_pre = a
    else:
        n = max((t_pre+t-1)//t,(a_pre+a-1)//a)        
        t_pre = n*t
        a_pre = n*a
print(t_pre+a_pre)

Submission status: Accepted

Solution code:
n = int(input())
t_, a_ = 1, 1
for _ in range(n):
    x, y = map(int, input().split())
    l = max(((t_ - 1) // x), ((a_ - 1) // y)) + 1
    t_ = l * x
    a_ = l * y
print(t_ + a_)

Submission status: Accepted

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

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

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

l, r = 1, 1

for x, y in L:
    c = max(l // x, r // y)
    while True:
        xx = x * c
        yy = y * c
            
        if l <= xx and r <= yy:
            l, r = xx, yy
            break
        else:
            c += 1

print(l + r)

Submission status: Accepted

Solution code:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
  ta,tb=map(int,input().split())
  if ta>=a:
    a=ta
  else:
    if a%ta!=0:
      a=(a//ta+1)*ta
  if tb>=b:
    b=tb
  else:
    if b%tb!=0:
      b=(b//tb+1)*tb
  qa,qb=a//ta,b//tb
  if qa!=qb:
    if qa>qb:
      b=b*qa//qb
    elif qb>qa:
      a=a*qb//qa
print(a+b)

Submission status: Accepted

Solution code:
from decimal import Decimal, ROUND_CEILING

n = int(input())
ta_array = [[int(x) for x in input().split()] for y in range(n)]
res = 1
prev_t, prev_a = ta_array.pop(0)
for t, a in ta_array:
    res_a = Decimal(prev_a*res/a).quantize(Decimal(0.0), rounding=ROUND_CEILING)
    res_t = Decimal(prev_t*res/t).quantize(Decimal(0.0), rounding=ROUND_CEILING)
    res = max(res_a, res_t)
    prev_t = t
    prev_a = a
print(prev_t*res+prev_a*res)

Submission status: Accepted

Solution code:
from math import ceil
from decimal import *

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

Submission status: Accepted

Solution code:
from math import ceil

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
T,A=1,1
for _ in range(N):
    t,a = map(int,input().split())
    kt=(T-1)//t + 1
    ka=(A-1)//a + 1
    if ka*t<T:
        k=kt
    elif kt*a<A:
        k=ka
    elif t<a:
        k=kt
    else:
        k=ka
    T=k*t
    A=k*a
print(A+T)

Submission status: Accepted

Solution code:
N = int(input())

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

import math
from decimal import Decimal

check1 = (1, 1)
for i in range(N):
    check2 = L[i]
    
    x1 = check1[0]
    y1 = check1[1]
    
    x2 = check2[0]
    y2 = check2[1]
    check2 = L[i]
    
#     print('11', x1, y1)
#     print('22', x2, y2)
    
    a1 = Decimal(math.ceil(x1 / x2))
    a2 = Decimal(math.ceil(y1 / y2))
    
#     print('aa', a1, a2)
        
    a = max(a1, a2)
        
    check1 = (x2*a, y2*a) 
    
#     print(check1)
#     print('~~~~~~~~~~~~~~~~~~~~')

# print(check1)

print(sum(check1))

Submission status: Accepted

Solution code:
import math

n = int(input())

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

    if t_ % t == 0:
        pt = 0
    else:
        pt = 1
    
    if a_ % a == 0:
        pa = 0
    else:
        pa = 1

    m = max((t_//t + pt), (a_//a + pa))
    t_, a_ = t * m, a * m
    
ans = t_ + a_
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
T = R[0][0]
A = R[0][1]
for r in R[1:]:
    i = T // r[0]
    if T % r[0] != 0:
        i += 1
    j = A // r[1]
    if A % r[1] != 0:
        j += 1
    T = r[0] * max(i, j)
    A = r[1] * max(i, j)
print(T+A)

Submission status: Accepted

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

	total_t = T[0]
	total_a = A[0]
	for i in range(N):
		if total_t == T[i] and total_a == A[i]:
			continue
		current_t = total_t//T[i] if total_t%T[i]==0 else (total_t//T[i])+1
		current_a = total_a//A[i] if total_a%A[i]==0 else (total_a//A[i])+1
		n = max(current_t, current_a)
		total_t = n*T[i]
		total_a = n*A[i]

	print(total_a+total_t)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import math


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

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

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

    base = div_ceil(sum(ex_votes), (ratio[0] + ratio[1]))
    base = int(base)
    while True:
        test_votes = (ratio[0] * base, ratio[1] * base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0]/ratio[0] < diff_votes[1]/ratio[1]:
                base += div_ceil(-diff_votes[0], ratio[0])
            else:
                base += div_ceil(-diff_votes[1], ratio[1])
            base = int(base)


def submit():
    n, ratios = read_input()

    votes = ratios[0]
    for ratio in ratios[1:]:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
n = int(input())
x = y = 1
for i in range(n):
    t, a = map(int, input().split())
    bx = 1 if x % t else 0
    by = 1 if y % a else 0
    k = max(x//t + bx, y//a + by)
    x, y = t*k, a*k
print(x+y)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    T, A = 1, 1
    for _ in range(N):
        t, a = map(int, input().split())

        n = max((T+t-1)//t, (A+a-1)//a)
        T = t * n
        A = a * n

    return T + A


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
n = int(input())
ta = [[int(item) for item in input().split()] for _ in range(n)]

p, q = ta[0]
for t, a in ta[1:]:
    rate1 = p//t
    rate2 = q//a
    if p % t != 0:
        rate1 += 1
    if q % a != 0:
        rate2 += 1
    rate = max(rate1, rate2)
    p = t*rate 
    q = a*rate 
print(p + q)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_atcodeer_and_election_report(N, R):
    vote_takahashi, vote_aoki = 1, 1
    for x, y in R:
        # v_t<=nx ∧ v_a<=ny を満たす最小のnを求める(切り上げを先に行う)
        n = max(-(-vote_takahashi // x), -(-vote_aoki // y))
        vote_takahashi = n * x
        vote_aoki = n * y
    return vote_takahashi + vote_aoki

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:
import math


def ceil(a: int, b: int) -> int:
    '''a / b の切り上げを求める。
    '''
    n = a // b
    return n if n * b == a else n + 1


def atcodeer_and_election_report(N: int, ratios: list) -> int:
    t, a = ratios[0]

    for nt, na in ratios[1:]:
        # t <= nt * k and a <= na * k
        # を満たす最小の k を求めたい
        k = max(ceil(t, nt), ceil(a, na))
        t, a = nt * k, na * k

    return t + a


if __name__ == "__main__":
    N = int(input())
    ratios = [tuple(int(s) for s in input().split()) for _ in range(N)]
    ans = atcodeer_and_election_report(N, ratios)
    print(ans)

Submission status: Accepted

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for x, y in TA:
	# n = max(ceil(vote_T/x),ceil(vote_A/y))
	# n = max(-(-vote_T // x), -(-vote_A // y))
	n = max((vote_T//x + (vote_T%x!=0)),vote_A//y + (vote_A%y!=0))
	vote_T = x * n
	vote_A = y * n
print(vote_A + vote_T)

Submission status: Accepted

Solution code:
n = int(input())

li_hi = list()
a = 1
b = 1
for i in range(n):
    li_hi.append(list(map(int, input().split())))

for l in li_hi:
    w = max(-(-a // l[0]), -(-b // l[1]))
    a = w * l[0]
    b = w * l[1]

print(a + b)

Submission status: Accepted

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(Fraction(pt[i-1], t), Fraction(pa[i-1], a)))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Accepted

Solution code:
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    # N, A = [int(_) for _ in input().split()]
    # X = [int(_) for _ in input().split()]
    N = int(input().rstrip())
    T=[]
    A=[]
    x=[]
    ans = 0
    for i in range(N):
        t, a = [int(_) for _ in input().rstrip().split(' ')]
        T.append(t)
        A.append(a)
    x.append(1)
    for i in range(1,N):
        x.append(max(-1*(-1*(T[i-1] *  x[i-1])//T[i]),-1*(-1*(A[i-1] *  x[i-1])//A[i])))
        t = x[i] * T[i]
        a = x[i] * A[i]
    print(t+a)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
from fractions import Fraction
N = int(input())
ta = [list(map(int,input().split())) for _ in range(N)]
x = 1
y = 1
for i in range(N):
    if i == 0:
        x , y = ta[i][0] , ta[i][1]
    else:
        temp = int(math.ceil(max( Fraction(x ,  ta[i][0])  , Fraction(y , ta[i][1]))))
        x = temp * ta[i][0]
        y = temp * ta[i][1]
        
print(x + y)

Submission status: Accepted

Solution code:
import sys
n=int(input())
l=[[int(i) for i in l.split()] for l in sys.stdin]
for i in range(n-1):
  if l[i]==l[i+1]:
    continue
  x=max((l[i][0]+l[i+1][0]-1)//l[i+1][0],(l[i][1]+l[i+1][1]-1)//l[i+1][1])
  l[i+1][0]*=x
  l[i+1][1]*=x
print(sum(l[-1]))

Submission status: Accepted

Solution code:
import math
from fractions import Fraction
N = int(input())
tmin = 1
amin = 1
for i in range(N):
    t, a = map(int, input().split())
    multiple = math.ceil(max(Fraction(tmin, t), Fraction(amin, a)))
    tmin = t * multiple
    amin = a * multiple
print(tmin + amin)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

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

ans_t, ans_a = 1, 1
for ti, ai in zip(T, A):
    n = max(ans_t//ti, ans_a//ai)
    if ans_t>ti*n or ans_a>ai*n:
        n += 1
    ans_t = ti*n
    ans_a = ai*n

print(ans_t+ans_a)

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())
  m=max((a-1)//c,(b-1)//d)+1
  a,b=c*m,d*m
print(a+b)

Submission status: Accepted

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a+x-1)//x, (b+y-1)//y)
        a, b = x*c, y*c
    print(a+b)

Submission status: Accepted

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a-1)//x+1, (b-1)//y+1)
        a, b = x*c, y*c
    print(a+b)

Submission status: Accepted

Solution code:
from math import ceil
from fractions import Fraction
n = int(input())
res1,res2 = 1,1
for i in range(n):
    t,a = map(int,input().split())
    r = ceil(max(Fraction(res1,t),Fraction(res2,a)))
    res1 = t*r
    res2 = a*r
print(res1+res2)

Submission status: Accepted

Solution code:
from fractions import gcd
import math

N=int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
min_T, min_A = 1,1

for _ in range(N):
    T, A = map(int,input().split())
    i =max(-(-min_A // A) , -(-min_T // T))
    min_T = T * i
    min_A = A * i
print(min_T+min_A)

Submission status: Accepted

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

import math
for i in range(n-1):
    bai = max(math.ceil((ta[i][0]-1)//ta[i+1][0]+1),math.ceil((ta[i][1]-1)//ta[i+1][1]+1))
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])

Submission status: Accepted

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

ct = ta[0][0]
ca = ta[0][1]

for i in range(1, n):
    t, a = ta[i]

    if ct / t > ca / a:
        if ct%t == 0:
            rate = ct//t
        else:
            rate = ct//t+1
    else:
        if ca%a == 0:
            rate = ca//a
        else:
            rate = ca//a+1
    ct = rate * t
    ca = rate * a
print(ct+ca)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    T = 1
    A = 1
    for _ in range(N):
        t, a = map(int, input().split())
        m1 = -(-T//t)
        m2 = -(-A//a)
        T1, T2 = min(m1, m2) * t, max(m1, m2) * t
        A1, A2 = min(m1, m2) * a, max(m1, m2) * a
        if T <= T1 and A <= A1:
            T = T1
            A = A1
        else:
            T = T2
            A = A2
    print(T+A)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
cur=[1,1]
for i in T:
    K=max(cur[0]//i[0]+(cur[0]%i[0]!=0),cur[1]//i[1]+(cur[1]%i[1]!=0))
    cur=[j*K for j in i]
print(sum(cur))

Submission status: Accepted

Solution code:
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max(-(-t//nt), -(-a//na))
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Accepted

Solution code:
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max((t-1)//nt+1, (a-1)//na+1)
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Accepted

Solution code:
n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = max(a // x, b // y)
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)

Submission status: Accepted

Solution code:
import math


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

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        # n = max(math.ceil(A / x), math.ceil(B / y))
        n = max(A // x + (A % x != 0),
                B // y + (B % y != 0))
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#ABC046C
N=int(input())
A=[[]*N]
a,b=1,1
for n in range(N):
    A,B=map(int,input().split())
    if a%A!=0:
        ka=a//A+1
    else:
        ka=a//A
    if b%B!=0:
        kb=b//B+1
    else:
        kb=b//B
    k=max(ka,kb)
    a,b=A*k,B*k
print(a+b)

Submission status: Accepted

Solution code:
from math import ceil
n = int(input())
#a,b = map(int,input().split())
T=1
A=1

for i in range(n):
    a,b = map(int,input().split())
    num = max(ceil((T)//a)+(T%a!=0),ceil((A)//b)+(A%b!=0))
    T = a*(num)
    A = b*(num)
    #print(T,A)
print(T+A)

Submission status: Accepted

Solution code:
def solve(l: list):
    x, y = 1, 1

    for t, a in l:
        nx = x // t + 1 - (x%t==0)
        ny = y // a + 1 - (y%a==0)
        n = max(nx, ny)
        x = n * t
        y = n * a
    return x + y


def main():
    N = int(input())
    l = []
    for i in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    print(solve(l))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
l=1000
r=1000
tmp=1
for i in range(n):
    if (a[i][0]>=l and a[i][1]>=r) or i == 0:
        tmp=sum(a[i])
        seki=1
    else:
        if l/a[i][0] > r/a[i][1]:
            seki=-1*(-1*l//a[i][0])
            tmp=sum(a[i])*seki
        else:
            seki=-1*(-1*r//a[i][1])
            tmp=sum(a[i])*seki
    l,r=[a[i][0]*seki,a[i][1]*seki]
print(tmp)

Submission status: Accepted

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

cnt_l = info[0][0]
cnt_r = info[0][1]
#print(cnt_l,cnt_r)
for i in range(1,n):
  tmpcnt_l = info[i][0]
  tmpcnt_r = info[i][1]
  
  if cnt_l > tmpcnt_l and cnt_l/tmpcnt_l >= cnt_r/tmpcnt_r:
    cnt_l = (cnt_l//tmpcnt_l+int(bool(cnt_l%tmpcnt_l))) * tmpcnt_l
    cnt_r = (cnt_l//tmpcnt_l+int(bool(cnt_l%tmpcnt_l))) * tmpcnt_r
  elif cnt_r > tmpcnt_r and cnt_l/tmpcnt_l <= cnt_r/tmpcnt_r:
    cnt_l = (cnt_r//tmpcnt_r+int(bool(cnt_r%tmpcnt_r))) * tmpcnt_l
    cnt_r = (cnt_r//tmpcnt_r+int(bool(cnt_r%tmpcnt_r))) * tmpcnt_r
  else:
    cnt_l = tmpcnt_l
    cnt_r = tmpcnt_r
#  print(cnt_l,cnt_r)
print(cnt_l+cnt_r)

Submission status: Accepted

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

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max(-(-takahashi // t), -(-aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max(-(-takahashi // t), -(-aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]

x, y = A[0]
for a, b in A[1:]:
    m = max(-(-x // a), -(-y // b))
    x = a * m
    y = b * m
    #print(x, y)
        
print(x + y)

Submission status: Accepted

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]

x, y = 1, 1
for i in range(n):
    a, b = A[i]
    m = max(-(-x // a), -(-y // b))
    x, y = a * m, b * m
    #print(x, y)
        
print(x + y)

Submission status: Accepted

Solution code:
N = int(input())
a, b = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    c = max(-(-a // x), -(-b // y))
    #マイナスの//は切り上げになる（math.ceil()でも良い）
    a, b = c* x, c* y
print(a + b)

Submission status: Accepted

Solution code:
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:
            #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する
            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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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