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: Wrong Answer

Solution code:
import math
n = int(input())
l = [input().split() for _ in range(n)]
ans = [1,1]
for i in range(n):
    ref_1 = int(l[i][0])
    ref_2 = int(l[i][1])
    a = max(math.ceil(ans[0]/ref_1),math.ceil(ans[1]/ref_2))
    ans[0], ans[1] = a*ref_1, a*ref_2
print(ans[0] + ans[1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
l = [input().split() for _ in range(n)]
ans = [1,1]
for i in range(n):
    ref_1 = int(l[i][0])
    ref_2 = int(l[i][1])
    a = max(math.ceil(ans[0]/ref_1),math.ceil(ans[1]/ref_2))
    ans[0], ans[1] = a*ref_1, a*ref_2
print(sum(ans))

Submission status: Wrong Answer

Solution code:
from math import ceil
n, *TA = map(int, open(0).read().split())
x, y = TA[0], TA[1]
for t, a in zip(TA[2::2], TA[3::2]):
    if x <= t and y <= a:
        x, y = t, a
    elif x <= t and y > a:
        k = ceil(y/a)
        x, y = k*t, k*a
    elif x > t and y <= a:
        k = ceil(x/t)
        x, y = k*t, k*a
    else:
        k = max(ceil(x/t), ceil(y/a))
        x, y = k*t, k*a
print(x+y)

Submission status: Wrong Answer

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

t0, a0 = 1, 1

for i in range(n):
    t1, a1 = map(int, input().split())   
    f = max(math.ceil(t0/t1), math.ceil(a0/a1))
    t0, a0 = t1*f, a1*f
print(t0 + a0)

Submission status: Wrong Answer

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

t0, a0 = map(int, input().split())

for i in range(n-1):
    t1, a1 = map(int, input().split())   
    f = max(math.ceil(t0/t1), math.ceil(a0/a1))
    t0, a0 = t1*f, a1*f
print(t0 + a0)

Submission status: Wrong Answer

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

f, a0 = map(int, input().split())

for i in range(n-1):
    t1, a1 = map(int, input().split())   
    if f % t1 != 0: f += t1 - f % t1
    f += max(0, math.ceil(a0 / a1) - (f // t1)) * t1
    a0 = (f // t1) * a1
print(f + a0)

Submission status: Wrong Answer

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

f, a0 = map(int, input().split())

for i in range(n-1):
    t1, a1 = map(int, input().split())   
    if f % t1 != 0:
        f += t1 - f % t1
    f += max(0, math.ceil((a0 / a1 - (f // t1)))) * t1
    a0 = (f // t1) * a1
print(f + a0)

Submission status: Wrong Answer

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

f, a0 = map(int, input().split())

for i in range(n-1):
    t1, a1 = map(int, input().split())   
    if f % t1 != 0:
        f += t1 - f % t1
    f += max(0, math.ceil((a0 - a1 * (f // t1)) / a1)) * t1
    a0 = (f // t1) * a1
print(f + a0)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
x,y = [list(i) for i in zip(*l)]
A,B = 1,1
for i in range(n):
    m = max(ceil(A/x[i]),ceil(B/y[i]))
    A = x[i]*m
    B = y[i]*m
print(A+B)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

T = 1
A = 1
for i in range(N):
    x, y = TA[i]
    n = max(ceil(T/x), ceil(A/y))
    T = n*x
    A = n*y
print(T+A)

Submission status: Wrong Answer

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

T = 1
A = 1
for i in range(N):
    bai = max(math.ceil(T/ls[i][0]),math.ceil(A/ls[i][1]))
    T = bai * ls[i][0]
    A = bai * ls[i][1]
print(T+A)

Submission status: Wrong Answer

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

T = ls[0][0]
A = ls[0][1]
for i in range(1,N):
    bai = max(math.ceil(T/ls[i][0]),math.ceil(A/ls[i][1]))
    T = bai * ls[i][0]
    A = bai * ls[i][1]
print(T+A)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    t, a = map(int, input().split())
    for _ in range(N - 1):
        nt, na = map(int, input().split())
        if t * na == a * nt: continue
        # ceilで不動小数点誤差が出てWAになるケースは初めて！
        # C++と同じ流儀で繰り上げしないとダメなんだ。。。
        k = max((t + nt - 1) / nt, (a + na - 1) / na)
        t, a = nt * k, na * k

    print(t + a)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    t, a = map(int, input().split())
    for _ in range(N - 1):
        nt, na = map(int, input().split())
        if t * na == a * nt: continue
        k = max(ceil(t / nt), ceil(a / na))
        t, a = nt * k, na * k

    print(t + a)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    t, a = map(int, input().split())
    for _ in range(N - 1):
        nt, na = map(int, input().split())
        if t * na == a * nt: continue
        if t % nt == 0:
            t1, a1 = t, na * t // nt
        else:
            t1, a1 = t * (1 + t // nt), a * (1 + t // nt)
        if a % na == 0:
            t2, a2 = t * a // na, a
        else:
            t2, a2 = nt * (1 + a // na), na * (1 + a // na)
        if a1 < a:
            t, a = t2, a2
        elif t2 < t:
            t, a = t1, a1
        else:
            add1 = (t1 - t) + (a1 - a)
            add2 = (t2 - t) + (a2 - a)
            if add1 < add2:
                t, a = t1, a1
            else:
                t, a = t2, a2
    print(t + a)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    t, a = map(int, input().split())
    for _ in range(N - 1):
        nt, na = map(int, input().split())
        if t * na == a * nt: continue
        t1, a1 = nt * ceil(t / nt), na * ceil(t / nt)
        t2, a2 = nt * ceil(a / na), na * ceil(a / na)
        if a1 < a:
            t, a = t2, a2
        elif t2 < t:
            t, a = t1, a1
        else:
            add1 = (t1 - t) + (a1 - a)
            add2 = (t2 - t) + (a2 - a)
            if add1 < add2:
                t, a = t1, a1
            else:
                t, a = t2, a2
    print(t + a)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=0
nowT=0
nowA=0
beforeT=0
beforeA=0
T,A=map(int,input().split())
beforeA=A
beforeT=T
ans=A+T
for i in range(1,N):
    T,A=map(int,input().split())
    sumTA=T+A
    kouho=math.ceil(ans/sumTA)*sumTA
    ans=kouho
    while(1):
        nowT=(ans*T)//sumTA
        nowA=(ans*A)//sumTA
        #print(nowT,nowA)
        if nowA>=beforeA and nowT>=beforeT :
            beforeA=nowA
            beforeT=nowT
            break
        else:
            ans+=sumTA
        
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=0
nowT=0
nowA=0
beforeT=0
beforeA=0
T,A=map(int,input().split())
beforeA=A
beforeT=T
ans=A+T
for i in range(1,N):
    T,A=map(int,input().split())
    sumTA=T+A
    kouho=math.ceil(ans/sumTA)*sumTA
    ans=kouho
    while(1):
        nowT=(ans*T)//sumTA
        nowA=(ans*A)//sumTA
        #print(nowT,nowA)
        if nowA>=beforeA and nowT>=beforeT :
            beforeA=nowA
            beforeT=nowT
            break
        else:
            ans+=kouho
        
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=0
nowT=0
nowA=0
beforeT=0
beforeA=0
T,A=map(int,input().split())
beforeA=A
beforeT=T
ans=A+T
for i in range(1,N):
    T,A=map(int,input().split())
    sumTA=T+A
    kouho=math.ceil(ans/sumTA)*sumTA
    ans=kouho
    while(1):
        nowT=(ans*T)//sumTA
        nowA=(ans*A)//sumTA
        print(nowT,nowA)
        if nowA>=beforeA and nowT>=beforeT :
            beforeA=nowA
            beforeT=nowT
            break
        else:
            ans+=kouho
        
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ratio = [tuple(map(int, input().split())) for _ in range(N)]
from math import ceil
Vote = (1, 1)
for t,a in Ratio:
    p = max(ceil(Vote[0]/t), ceil(Vote[1]/a))
    Vote = (p*t, p*a)
print(int(sum(Vote)))

Submission status: Wrong Answer

Solution code:
N = int(input())
Ratio = [tuple(map(int, input().split())) for _ in range(N)]
from math import ceil
Vote = (1, 1)
for t,a in Ratio:
    p = max(ceil(Vote[0]/t),ceil(Vote[1]/a))
    Vote = (p*t, p*a)
print(sum(Vote))

Submission status: Wrong Answer

Solution code:
# 解説AC #
from math import ceil
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
x,y = [list(i) for i in zip(*l)]
A = 1
B = 1
for i in range(n):
    m = max(ceil(A / x[i]),ceil(B / y[i]))
    A = m * x[i]
    B = m * y[i]
print(A + B)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
x,y=1,1
for t,a in l:
    mt=x//t if x/t==x//t else x//t+1
    ma=y//a if y/a==y//a else y//a+1
    m=max(mt,ma)
    x,y=m*t,m*a
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
bt,ba=l[0]
for t,a in l[1:]:
    j=1
    if bt>t or ba>a:
        if bt>ba:
            j=bt//t if bt/t==bt//t else bt//t+1
        else:
            j=ba//a if ba/a==ba//a else ba//a+1
    bt=t*j
    ba=a*j
print(bt+ba)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ans_t=1
ans_a=1
for i in range(n):
    t,a=map(int,input().split())
    k1=math.ceil(ans_t/t)
    k2=math.ceil(ans_a/a)
    k=max(k1,k2)
    ans_t=k*t
    ans_a=k*a
print(ans_t+ans_a)

Submission status: Wrong Answer

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

        if y % a == 0:
            i_y = y // a
        else:
            i_y = y // a + 1

        if i_x == i_y:
            continue
        bigger = max(i_x, i_y)
        x = bigger*t
        y = bigger*a
print(x+y)

Submission status: Wrong Answer

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

        if y % a == 0:
            i_y = y // a
        else:
            i_y = y // a + 1
        if i_x == i_y:
            continue
        bigger = max(i_x, i_y)
        x = bigger*t
        y = bigger*a
print(x+y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T,A = (int(T) for T in input().split())
for TN in range(1,N):
    TNext,ANext = (int(T) for T in input().split())
    if TNext<T:
        Cnt = math.ceil(T/TNext)
        TNext *= Cnt
        ANext *= Cnt
    if ANext<A:
        Cnt = math.ceil(A/ANext)
        TNext *= Cnt
        ANext *= Cnt
    T = TNext
    A = ANext
print(T+A)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=1,1

for i in range(n):
  x,y=map(int,input().split())
  s=(-a//x)
  t=(-b//y)
  a,b=max(s,t)*x,max(s,t)*y

print(a+b)

Submission status: Wrong Answer

Solution code:
import math

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

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

print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
a,b=map(int,input().split())

for i in range(n-1):
  x,y=map(int,input().split())
  if x>=a and y>=b:
    a,b=x,y
    
  else:
    s=math.ceil(a/x)
    t=math.ceil(b/y)
    a,b=max(s,t)*x,max(s,t)*y

print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
a,b=map(int,input().split())

for i in range(n-1):
  x,y=map(int,input().split())
  if x>=a and y>=b:
    a,b=x,y
  elif x<a and y>=b:
    b=y
    b*=math.ceil(a/x)
    x=math.ceil(a/x)*x
  elif x>=a and y<b:
    a=x
    a*=math.ceil(b/y)
    y=math.ceil(b/y)*y
    
  elif x<a and y<b:
    cnt=1
    while True:
      cnt+=1
      if x*cnt>=a and y*cnt>=b:
        a=x*cnt
        b=y*cnt
        break

print(a+b)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    T1, A1 = map(int, input().split())
    if N == 1:
        print(T1 + A1)
    for _ in range(N-1):
        T2, A2 = map(int, input().split())
        n = max(-(-T1//T2),-(-A1//A2))
        T1,A1 = T2*n,A2*n
    print(T1 + A1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    T1, A1 = map(int, input().split())
    if N == 1:
        print(T1 + A1)
    for _ in range(N-1):
        T2, A2 = map(int, input().split())
        n = max(math.ceil(T1/T2),math.ceil(A1/A2))
        T1,A1 = T2*n,A2*n
    print(T1 + A1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    T1, A1 = map(int, input().split())
    for _ in range(N-1):
        if N == 0:
            print(T1 + A1)
        else:
            T2, A2 = map(int, input().split())
            n = max(math.ceil(T1/T2),math.ceil(A1/A2))
            T1,A1 = T2*n,A2*n
    print(T1 + A1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys 
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
data = []
X = []
for i in range(N):
    T, A = map(int, readline().split())
    data.append((T,A))

T_pre,A_pre = data[0] 
for i in range(1,N):
    T,A = data[i]
    n = max(math.ceil(T_pre/T),math.ceil(A_pre/A))
    T_pre = n*T
    A_pre = n*A
print(T_pre+A_pre)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys 
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
data = []
X = []
for i in range(N):
    T, A = map(int, readline().split())
    data.append((T,A))

T_pre = 1
A_pre = 1
for i in range(N):
    T,A = data[i]
    n = max(math.ceil(T_pre/T),math.ceil(A_pre/A))
    T_pre = n*T
    A_pre = n*A
print(T_pre+A_pre)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
t_v = a_v = 1
for _ in range(n):
    t, a = [int(x) for x in input().split()]
    r = max(ceil(t_v / t), ceil(a_v / a))
    t_v, a_v = r * t, r * a
print(t_v + a_v)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
t_v = a_v = 1
for _ in range(n):
    t, a = [int(x) for x in input().split()]
    r = max(ceil(t_v / t), ceil(a_v / a))
    t_v, a_v = r * t, r * a
print(t_v + a_v)

Submission status: Wrong Answer

Solution code:
import math
from fractions import Fraction
# ex) Fraction(2,6) > 1/3 > 0.33333

n = int(input())
x, y = map(int, input().split())
t, a = x, y

for _ in range(n - 1):
    tt, aa = map(int, input().split())

    #c = 1
    '''
    if (t >= a):
        c = math.ceil(tt / t)

    else:
        c = math.ceil(aa / a)
    '''
    #c = math.ceil(max(t / tt, a / aa))
    c = math.ceil(max(Fraction(t, tt), Fraction(a / aa)))

    t = tt * c
    a = aa * c


ans = t + a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = 1
y = 1
for i in range(N):
    T, A = map(int, input().split())
    p = (T + x - 1) / T
    q = (A + y - 1) / A
    x = T * max(p, q)
    y = A * max(p, q)
    #print(f"[{x} {y}]")
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = 1
y = 1
for i in range(N):
    T, A = map(int, input().split())
    p = math.ceil(x/T)
    q = math.ceil(y/A)
    x = T * max(p, q)
    y = A * max(p, q)
    #print(f"[{x} {y}]")
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x = 1
y = 1
for i in range(N):
    T, A = map(int, input().split())
    p = math.floor((x+T-1)/T)
    q = math.floor((y+A-1)/A)
    x = T * max(p, q)
    y = A * max(p, q)
    #print(f"[{x} {y}]")
print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil


def main():
    n = int(input())
    takahashi = 1
    aoki = 1
    for i in range(n):
        t, a = map(int, input().split())
        diff = max(ceil(takahashi / t), ceil(aoki / a))
        takahashi = t * diff
        aoki = a * diff
    print(takahashi + aoki)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import *
n=int(input())
t,a=1,1
for i in range(n):
    tt,aa=map(int,input().split())
    m=max(ceil(t/tt),ceil(a/aa))
    t,a=tt*m,aa*m
print(a+t)

Submission status: Wrong Answer

Solution code:
from math import *
n=int(input())
t,a=map(int,input().split())
for i in range(n-1):
    tt,aa=map(int,input().split())
    m=max(ceil(t/tt),ceil(a/aa))
    t,a=tt*m,aa*m
print(a+t)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

import math

c = [0] * n
d = [0] * n

c = 1
d = 1


for i in range(n):
    x = max(math.ceil(c/a[i]), math.ceil(d/b[i])) 
    c, d= a[i]*x, b[i]*x


print(c+d)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

import math

c = [0] * n
d = [0] * n

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


for i in range(n-1):
    x = max(math.ceil(c[i]/a[i+1]), math.ceil(d[i]/b[i+1])) 
    c[i+1],d[i+1] = a[i+1]*x, b[i+1]*x


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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

c = [0] * n
d = [0] * n

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

for i in range(n-1):
    x = max((a[i+1]//c[i]+1), (a[i+1]//c[i]+1))
    c[i+1], d[i+1] = a[i+1]*x, b[i+1]*x 


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

Submission status: Wrong Answer

Solution code:
import math

def main():
    n=int(input())
    na,nb=1,1
    for i in range(0,n):
        pa,pb=map(int,input().split())
        r=max(math.ceil(na/pa),math.ceil(nb/pb))
        na=pa*r
        nb=pb*r
    print(na+nb)

    
main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    n=int(input())
    na,nb=1,1
    for i in range(0,n):
        pa,pb=map(int,input().split())
        if(pa>=na and pb>=nb):
            na,nb=pa,pb
        else:
            r=max(math.ceil(na/pa),math.ceil(nb/pb))
            na=pa*r
            nb=pb*r
    print(na+nb)

    
main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    n=int(input())
    na,nb=map(int,input().split())
    for i in range(1,n):
        pa,pb=map(int,input().split())
        if(pa>=na and pb>=nb):
            na,nb=pa,pb
        else:
            r=max(math.ceil(na/pa),math.ceil(nb/pb))
            na=pa*r
            nb=pb*r
    print(na+nb)

    
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L =[[1, 1]]
for _ in range(N):
  L.append(list(map(int, input().split())))
for i in range(1, N+1):
  m = max(math.ceil(L[i-1][0]/L[i][0]),math.ceil(L[i-1][1]/L[i][1]))
  L[i][0] *= m
  L[i][1] *= m
print(L[N][0]+L[N][1])

Submission status: Wrong Answer

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

    now_t, now_a = 1,1
    for _ in range(N):
        t, a = map(int,input().split())
        n = max(-(-now_t/t), -(-now_a//a))
        now_t = t * n
        now_a = a * n
    
    print(now_t + now_a)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

    now_t, now_a = 1,1
    for _ in range(N):
        t, a = map(int,input().split())
        n = max(-(now_t/t), -(-now_a//a))
        now_t = t * n
        now_a = a * n
    
    print(now_t + now_a)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from math import ceil
def solve():
    N = int(input())
    T = []
    A = []

    now_t, now_a = 1,1
    for _ in range(N):
        t, a = map(int,input().split())
        n = max(ceil(now_t/t), ceil(now_a/a))
        now_t = t * n
        now_a = a * n
    
    print(now_t + now_a)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

x, y = map(int, input().split())
t, a = x, y

for _ in range(n - 1):
    tt, aa = map(int, input().split())

    #c = 1
    '''
    if (t >= a):
        c = math.ceil(tt / t)

    else:
        c = math.ceil(aa / a)
    '''
    #c = math.ceil(max(t / tt, a / aa))
    c = math.ceil(max(Fraction(t, tt), Fraction(a / aa)))

    t = tt * c
    a = aa * c


ans = t + a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
pt, pa = 0, 0
for _ in range(n):
    t, a = tuple(map(int, input().split()))
    l = 0
    r = 10**8+1
    while (r-l) > 1:
        mid = (l+r)//2
        if (t*mid >= pt and a*mid >= pa):
            r = mid
        else:
            l = mid
    pt, pa = t*r, a*r

print(pt+pa)

Submission status: Wrong Answer

Solution code:
from math import gcd
from math import ceil
n = int(input())
T = [0] * n
A = [0] * n
for i in range(n):
    T[i], A[i] = map(int, input().split())

num = 2
t, a = 1, 1
for i in range(n):
    t_rate, a_rate = T[i], A[i]
    #print(t_rate, a_rate)
    t_mul, a_mul = ceil(t / t_rate), ceil(a / a_rate)
    #print(t_mul, a_mul)
    mul_num = max(t_mul, a_mul)
    t, a = mul_num * t_rate, mul_num * a_rate

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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

for _ in range(N - 1):
    nt, na = map(int, input().split(' '))
    if nt >= t and na >= a:
        t = nt
        a = na
    else:
        tr = int((t + nt - 1) / nt)
        ar = int((a + na - 1) / na)
        r = max(tr, ar)
        t = r * nt
        a = r * na

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t, a = map(int, input().split(' '))

for _ in range(N - 1):
    nt, na = map(int, input().split(' '))
    if nt >= t and na >= a:
        t = nt
        a = na
    else:
        tr = math.ceil(t / nt)
        ar = math.ceil(a / na)
        r = max(tr, ar)
        t = r * nt
        a = r * na

print(t + a)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
TA = [LIST() for _ in range(N)]

T = TA[0][0]
A = TA[0][1]

for t, a in TA[1:]:
	p = max(ceil(T/t), ceil(A/a))
	T = t*p
	A = a*p
	
print(T+A)

Submission status: Wrong Answer

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

T, A = 0, 0
for t, a in TA:
    if T == 0 and A == 0:
        T = t
        A = a
        continue
    if t == a:
        M = max(T, A)
        T = M
        A = M
    elif t < a:
        n = max((T // t) * t, (A * t) // a - t)
        while n < T or a * (n // t) < A:
            n += t
        T = n
        A = a * (T // t)
    else:
        n = max((A // a) * a, (T * a) // t - a)
        while n < A or t * (n // a) < T:
            n += a
        A = n
        T = t * (A // a)
print(A + T)

Submission status: Wrong Answer

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

T, A = 0, 0
for t, a in TA:
    if T == 0 and A == 0:
        T = t
        A = a
        continue
    if t == a:
        M = max(T, A)
        T = M
        A = M
    elif t < a:
        n = max((T // t) * t, A * t // a)
        while n < T or a * (n // t) < A:
            n += t
        T = n
        A = a * (T // t)
    else:
        n = max((A // a) * a, T * a // t)
        while n < A or t * (n // a) < T:
            n += a
        A = n
        T = t * (A // a)
print(A + T)

Submission status: Wrong Answer

Solution code:
import fractions 
from decimal import *

N = int(input())
for i in range(N):#1000
  t, a = map(int, input().split())
  if i == 0:
    taka, aoki = t, a
  else:
    one = int(taka / t)
    if Decimal(taka / t) % 1 != 0:
      one += 1
    two = int(aoki / a)
    if Decimal(aoki / a) % 1 != 0:
      two += 1
    m = max(one, two)
    taka, aoki = m * t, m * a
    
print(taka + aoki)

Submission status: Wrong Answer

Solution code:
import fractions 

N = int(input())
for i in range(N):#1000
  t, a = map(int, input().split())
  if i == 0:
    taka, aoki = t, a
  else:
    one = int(taka / t)
    if (taka / t) % 1 != 0:
      one += 1
    two = int(aoki / a)
    if (aoki / a) % 1 != 0:
      two += 1
    m = max(one, two)
    taka, aoki = m * t, m * a
    
print(taka + aoki)

Submission status: Wrong Answer

Solution code:
import fractions 

N = int(input())
for i in range(N):#1000
  t, a = map(int, input().split())
  if i == 0:
    taka, aoki = t, a
    now = [t + a, t, a]
  else:
    now = [10 ** 10, -1, -1]
    for i in range(1001):
      if ((taka + i) * (a / t)) % 1 == 0:
        a2 = int((taka + i) * (a / t))
        if (now[0] >= a2 + taka + i) and (a2 >= aoki):
          now = [taka + i + a2, taka + i, a2]
      if ((aoki + i) * (t / a)) % 1 == 0:
        b2 = int((aoki + i) * (t / a))
        if (now[0] >= b2 + aoki + i) and (b2 >= taka):
          now = [aoki + i + b2, b2, aoki + i]
    taka = now[1]
    aoki = now[2]
    #print(now)
print(now[0])

Submission status: Wrong Answer

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    T, A = 1, 1
    for _ in range(N):
        Ti, Ai = read_ints()
        # T  A   T    A
        # Ti Ai  Ti*x Ai*x
        #
        # Ti*x >= T, Ai*x >= A, min x?
        # x >= T/Ti
        # x >= A/Ai
        x = max(math.ceil(T/Ti), math.ceil(A/Ai))
        T, A = Ti*x, Ai*x
    return T+A


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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import random
import math
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	x, y = LI()
	for _ in range(n-1):
		t, a = LI()
		m = int((max(math.ceil(x/t),math.ceil(y/a))))
		x, y = m*t, m*a
	print(x+y)


if __name__ == '__main__':
    main()