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())
l=[list(map(int,input().split())) for _ in range(n)]

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

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

print(taka+ao)

Submission status: Accepted

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

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

    A, B = 1, 1
    for (x, y) in LIS:
        # print("current:", A, B)
        # print("ratio  :", x, y, "\n")
        if x == y:
            m = max(x, max(A, B))
            A, B = m, m
        elif A <= x and B <= y:
            A, B = x, y
        else:
            # div = max(ceil(A / x), ceil(B / y)) 誤差でWAになる
            div = max((A + x - 1) // x, (B + y - 1) // y)
            A = x * div
            B = y * div

    return A + B


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

Submission status: Accepted

Solution code:
from sys import stdin


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


main()

Submission status: Accepted

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

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

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

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

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

#floatで正確に表示できるのは15桁程度

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

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

    print(sum(current))
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


print(x+y)

Submission status: Accepted

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

Submission status: Accepted

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

A=[1,1]

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

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


print(sum(A))

Submission status: Accepted

Solution code:
import sys


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


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

# 比がa:bとなる合計最小の票分布はa,b
# 次にc:dになったとき、a<=cかつb<=dとなるようにc,dに同じ数をかける

import math

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

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

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

Submission status: Accepted

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

print(na+nt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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())

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

for i in range(1,n):
    k = max(-(-t_num//t[i]),-(-a_num//a[i]))
    #その比に票を合わせる
    t_num,a_num = k*t[i],k*a[i]

print(t_num + a_num)

Submission status: Accepted

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

t_num,a_num = 1,1

n = int(input())

for i in range(n):
    t,a = map(int,input().split())
    k = max(ceil(t_num,t),ceil(a_num,a))
    #その比に票を合わせる
    t_num = k*t
    a_num = k*a
    #print([t_num,a_num])    

print(t_num + a_num)

Submission status: Accepted

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

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

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

print(x+y)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(vote))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

lcms = TA[0]

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

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

print(sum(lcms))

Submission status: Accepted

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

Submission status: Accepted

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


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

votes = [1, 1]

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

ans = sum(votes)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    a, b = 1, 1
    for i in range(N):
        x, y = ta[i]
        if a%x == 0:
            tmp = a//x
        else:
            tmp = a//x + 1
        if b%y == 0:
            tmp = max(tmp, b//y)
        else:
            tmp = max(tmp, b//y + 1)
        a = x * tmp
        b = y * tmp
    print(a+b)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
  n = int(raw_input())
  vote_a, vote_b = 1, 1

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

  print(vote_a+vote_b)


main()

Submission status: Accepted

Solution code:
import math


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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# def gcd(x, y):
#     #print(x, y)
#     while x != 0 and y != 0:
#         x, y = max(x, y), min(x, y)
#         x %= y
#     return y

# def lcm(x, y):
#     return x * y // gcd(x, y)

# for i in range(1, n):
#     lcms = [0] * 2
#     for j in range(2):
#         lcms[j] = lcm(A[i][j], A[i-1][j])
#     print("lcms", lcms)
#     st = 0
#     op = 1
#     if lcms[0] > lcms[1]:
#         st = 1
#         op = 0
#     new_1 = (lcms[st] // A[i][st]) * A[i][op]
#     print(new_1)
#     if new_1 >= A[i-1][op]:
#         A[i][op] = new_1
#         A[i][st] = lcms[0]
#     else:
#         new_0 = lcms[op] // A[i][op] * A[i][st]
#         A[i][st] = new_0
#         A[i][op] = lcms[op]
#     print(A[i])

# print(sum(A[-1]))

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

Submission status: Accepted

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

x = 1
y = 1
for i in range(N):
    k = max(-(-x // T[i]), -(-y // A[i]))
    x = k * T[i]
    y = k * A[i]
else:
    print(x + y)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    HT = B * T
    HA = B * A

print(HT+HA)

Submission status: Accepted

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

tt=1
aa=1

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

print(tt+aa)

Submission status: Accepted

Solution code:
N = int(input())

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

print(A + B)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math

n = int(input())

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

    m = max((t0 + t - 1) // t,
            (a0 + a - 1) // a)
    # m = max(math.ceil(t0 / t),
    #         math.ceil(a0 / a))

    t0, a0 = t * m, a * m
    s0 = t0 + a0
    # print(s0, t0, a0, m)

print(s0)

Submission status: Accepted

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

n = int(input())

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

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

print(s)

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

print(a+t)

Submission status: Accepted

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


def solve(n):
    prev_t, prev_a = -1, -1
    for _ in range(n):
        t, a = map(int, input().split())
        x = 1
        if t < prev_t or a < prev_a:
            div_t = ceil(prev_t, t)
            div_a = ceil(prev_a, a)
            if t < prev_t and a < prev_a:
                x = max(div_t, div_a)
            elif t < prev_t:
                x = div_t
            else:
                x = div_a
        prev_t, prev_a = t*x, a*x

    return prev_t+prev_a


if __name__ == '__main__':
    n = int(input())
    print(solve(n))

Submission status: Accepted

Solution code:
from fractions import Fraction
import math

N = int(input())


taka = [0] * N
aoki = [0] * N

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

print(taka[-1] + aoki[-1])

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())
    k=max(-(-T//t),-(-A//a))
    T,A=t*k,a*k
print(T+A)

Submission status: Accepted

Solution code:
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]
t_an = TA[0][0]
a_an = TA[0][1]
for i in range(1,N):
    t = t_an / TA[i][0]
    a = a_an / TA[i][1]
    if t <= 1 and a <= 1:
        t_an = TA[i][0]
        a_an = TA[i][1]
    else:
        if t_an % TA[i][0] == 0:
            t = t_an // TA[i][0]
        else:
            t = t_an // TA[i][0] + 1
        if a_an % TA[i][1] == 0:
            a = a_an // TA[i][1]
        else:
            a = a_an // TA[i][1] + 1
        s = max(t,a)
        t_an = TA[i][0] * s
        a_an = TA[i][1] * s
print(t_an+a_an)

Submission status: Accepted

Solution code:
n=int(input())
x=y=1
q=10**(-5)
import math
for i in range(n):
	a,b=map(int,input().split())
	# aa=math.ceil((x+q)/a)
	# bb=math.ceil((y+q)/b)
	# if x%a==0:
	# 	aa=x//a
	# if y%b==0:
	# 	bb=y//b
	aa=(x-1)//a+1
	bb=(y-1)//b+1
	p=max(aa,bb)
	x=p*a
	y=p*b
print(x+y)

Submission status: Accepted

Solution code:
import sys
import copy
import math
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)


stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7
n = ni()
st, sa = 1, 1
for i in range(n):
    t, a = na()
    k = max((st - 1) // t, (sa - 1) // a) + 1
    st = t * k
    sa = a * k
print(st + sa)

Submission status: Accepted

Solution code:
import sys
import copy
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)


stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

n = ni()
st, sa = na()
for i in range(1, n):
    t, a = na()
    if st <= t and sa <= a:
        st = t
        sa = a
    elif st > t and sa <= a:
        if st % t == 0:
            k = st // t
        else:
            k = st // t + 1
        st = t * k
        sa = a * k
    elif st <= t and sa > a:
        if sa % a == 0:
            k = sa // a
        else:
            k = sa // a + 1
        st = t * k
        sa = a * k
    elif st > t and sa > a:
        if st % t == 0:
            k = st // t
        else:
            k = st // t + 1
        if sa % a == 0:
            l = sa // a
        else:
            l = sa // a + 1
        st = t * max(k, l)
        sa = a * max(k, l)
print(st + sa)

Submission status: Accepted

Solution code:
N = int(input())
Tl, Al = map(int, input().split())
for i in range(N-1):
    Tr, Ar = map(int, input().split())
    k = max((Tl-1)//Tr, (Al-1)//Ar) + 1
    Tl, Al = k * Tr, k * Ar

print(Tl+Al)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc046/tasks/arc062_a
# C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

N = int(input().split()[0])
ta_list = []

for _ in range(N):
    t, a = list(map(int, input().split()))
    ta_list.append((t, a))

# 最初のやつ
t, a = ta_list[0]
total_p = t + a
now_t, now_a = t, a

for t, a in ta_list[1:]:
    w_t, w_a = t, a

    c = max(now_t // w_t, now_a // w_a)
    w_t *= c
    w_a *= c

    while w_t < now_t or w_a < now_a:
        w_t += t
        w_a += a

    now_t = w_t
    now_a = w_a
    total_p = now_t + now_a

print(total_p)

Submission status: Accepted

Solution code:
n = int(input())

t_votes = a_votes = 1
for i in range(n):
    t_rate, a_rate = (int(x) for x in input().split())
    count = max(-(-t_votes // t_rate), -(-a_votes // a_rate))
    t_votes = t_rate*count
    a_votes = a_rate*count

print(t_votes+a_votes)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(A+B)

Submission status: Accepted

Solution code:
import math

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

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

print(a+b)

Submission status: Accepted

Solution code:
import math

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

a = 1
b = 1
for i in range(n):
    #n = max(math.floor(a/ta[i][0]), math.floor(b/ta[i][1]))
    n = max(~-a//ta[i][0] + 1, ~-b//ta[i][1] + 1)
    a = n * ta[i][0]
    b = n * ta[i][1]

print(a+b)

Submission status: Accepted

Solution code:
N=int(input())

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

print(A+B)

Submission status: Accepted

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  r = max(a // va, b // vb)
  if va * r < a or vb * r < b:
    r += 1
  
  return va * r, vb * r

t, a = [int(x) for x in input().split()]
for n in range(N - 1):
  ti, ai = [int(x) for x in input().split()]
  t, a = adjust(t, a, ti, ai)

print(t + a)

Submission status: Accepted

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  r = max(a // va, b // vb)
  if va * r < a or vb * r < b:
    r += 1
  
  return va * r, vb * r

t, a = [int(x) for x in input().split()]
for n in range(N - 1):
  ti, ai = [int(x) for x in input().split()]
  t, a = adjust(t, a, ti, ai)

print(t + a)

Submission status: Accepted

Solution code:
import math

N = int(input())
x, y = map(int, input().split())
for _ in range(N-1):
  a, b = map(int, input().split())
  # n = max(math.ceil(x/a), math.ceil(y/b))
  na = nb = 0
  if x%a == 0:
    na = x//a
  else:
    na = x//a+1
  if y%b == 0:
    nb = y//b
  else:
    nb = y//b+1
  n = max(na, nb)
  x, y = n*a, n*b
print(x+y)

Submission status: Accepted

Solution code:
n=int(input())
t0,a0=1,1
for i in range(n):
  t,a=map(int,input().split())
  if t0/a0>t/a:
    while t0%t != 0:
      t0+=1
    a0=t0*a//t
  elif t0/a0<t/a:
    while a0%a != 0:
      a0+=1
    t0=a0*t//a
print(t0+a0)

Submission status: Accepted

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

ta = [0] * N
ao = [0] * N

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

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

Submission status: Accepted

Solution code:
import math
def main():
    N = int(input())
    rate = []
    for _ in range(N):
        T, A = map(int, input().split())
        rate.append([T, A])
    cur = [rate[0][0], rate[0][1]]
    # print(cur, rate[0])
    for i in range(1, N):
        if cur[0] % rate[i][0] == 0:
            dT = cur[0] // rate[i][0]
        else:
            dT = cur[0] // rate[i][0] + 1
        if cur[1] % rate[i][1] == 0:
            dA = cur[1] // rate[i][1]
        else:
            dA = cur[1] // rate[i][1] + 1
        d = max(dT, dA)

        cur = [d*rate[i][0], d*rate[i][1]]
        # print(cur, rate[i])
    return sum(cur)

if __name__ == '__main__':

    print(main())