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())
A = [[int(i) for i in input().split()] for i in range(n)]

x, y = 1, 1
for a, b in A:
    m = max(math.ceil(x / a), math.ceil(y / b))
    x, y = a * m, b * m
    #print(x, y)
        
print(x + y)

Submission status: Wrong Answer

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

x, y = 1, 1
for a, b in A:
    m = max(math.ceil(x / a), math.ceil(y / b))
    x = a * m
    y = b * m
    #print(x, y)
        
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
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(math.ceil(x / a), math.ceil(y / b))
    x = a * m
    y = b * m
    #print(x, y)
        
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
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:]:
    if a < x or b < y:
        m = max(math.ceil(x / a), math.ceil(y / b))
        x = a * m
        y = b * m
    else:
        x, y = a, b
    #print(x, y)
        
print(x + y)

Submission status: Wrong Answer

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 % T[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: Wrong Answer

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):
        #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する
        kake = sum_tmp//(T[i]+A[i])+1
        while kake*T[i] < t_tmp or kake*A[i] < a_tmp:
            kake += 1
        
        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: Wrong Answer

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

Solution code:
def ceil(w):
    if w!=int(w):
        return int(w)+1
    else:
        return int(w)
n=int(input())
x=1
y=1
for i in range(n):
    t,a=map(int,input().split())
    c=max(ceil(x/t),ceil(y/a))
    x=t*c
    y=a*c      
print(int(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())
    c=max(math.ceil(x/t),math.ceil(y/a))
    x=t*c
    y=a*c      
print(int(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())
    c=max(math.ceil(x/t),math.ceil(y/a))
    x=t*c
    y=a*c      
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())
    x=t*max(math.ceil(x/t),math.ceil(y/a))
    y=a*max(math.ceil(x/t),math.ceil(y/a))          
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
def gauss(m):
    if m!=int(m):
        return int(m)+1
    else:
        return int(m)
x=1
y=1
for i in range(n):
    t,a=map(int,input().split())
    x=t*max(gauss(x/t),gauss(y/a))
    y=a*max(gauss(x/t),gauss(y/a))
          
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
def gauss(m):
    if m!=int(m):
        return int(m)+1
    else:
        return int(m)
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        if t==1 and a==1:
            x=max(x,y)
            y=max(x,y)
        else:
            x=t*max(gauss(x/t),gauss(y/a))
            y=a*max(gauss(x/t),gauss(y/a))
          
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
def gauss(m):
    if m!=int(m):
        return int(m)+1
    else:
        return int(m)
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        if t==1 and a==1:
            x=max(x,y)
            y=max(x,y)
        else:
            print(max(gauss(x/t),gauss(y/a)))
            x=t*max(gauss(x/t),gauss(y/a))
            y=a*max(gauss(x/t),gauss(y/a))
            print(x)
            print(y)
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
def gauss(m):
    if m!=int(m):
        return int(m)+1
    else:
        return int(m)
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        if t==1 and a==1:
            x=max(x,y)
            y=max(x,y)
        else:
            t=t*max(gauss(x/t),gauss(y/a))
            a=a*max(gauss(x/t),gauss(y/a))
            x=t
            y=a
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        v=t
        w=a
        if t==1 and a==1:
            x=max(x,y)
            y=max(x,y)
        else:
            while v<x or w<y:
                if max(x,y)%min(t,a)!=0:
                    v=t*(max(x,y)//min(t,a))+t
                    w=a*(max(x,y)//min(t,a))+a
                else:
                    v=t*(max(x,y)//min(t,a))
                    w=a*(max(x,y)//min(t,a))
            x=v
            y=w
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        v=t
        w=a
        if t==1 and a==1:
            x=max(x,y)
            y=max(x,y)
        else:
            while v<x or w<y:
                v=t*(max(x,y)//min(t,a))+t
                w=a*(max(x,y)//min(t,a))+a
            x=v
            y=w
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        v=t
        w=a
        while v<x or w<y:
            v=t*(max(x,y)//min(t,a))+t
            w=a*(max(x,y)//min(t,a))+a
        x=v
        y=w
print(x+y)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
p,q=map(int,input().split())
for i in range(n-1):
  a,b=map(int,input().split())
  r=int(math.ceil(max(p/a,q/b)))
  p,q=a*r,b*r
print(p+q)

Submission status: Wrong Answer

Solution code:
import math

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

tmp1 = 1
tmp2 = 1

for l in L:
    i = max(math.ceil(tmp1/l[0]), math.ceil(tmp2/l[1]))
    tmp1 = i * l[0] 
    tmp2 = i * l[1] 
            
print(tmp1 + tmp2)

Submission status: Wrong Answer

Solution code:
import math

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

tmp1 = 1
tmp2 = 1

res = 2
for l in L:
    i = max(math.ceil(tmp1/l[0]), math.ceil(tmp2/l[1]))
    res += (i * l[0] - tmp1) + (i * l[1] - tmp2)
    tmp1 = i * l[0] 
    tmp2 = i * l[1] 
            
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
at = []
for i in range(N):
    at.append(list(map(int,input().split())))
a,b = 1,1
import math
for i in range(N):
    v = math.ceil( (a + b) / (at[i][0] +at[i][1]))
    x = math.ceil(a /at[i][0])
    y = math.ceil(b /at[i][1])
    s = max([v,x,y])
    a,b = at[i][0]*s,at[i][1]*s
print(a+b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
from math import ceil
N = int(input())
T, A = [], []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
t_pred, a_pred = T[0], A[0]
for t, a in zip(T, A):
    print(t_pred, a_pred)
    if t_pred <= t and a_pred <= a:
        t_pred, a_pred = t, a
    else:
        times = max(ceil(Decimal(str(t_pred))/Decimal(str(t))),
                    ceil(Decimal(str(a_pred))/Decimal(str(a))))
        t_pred, a_pred = times*t, times*a
print(t_pred, a_pred)
print(t_pred + a_pred)

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
T, A = [], []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)

t_pred, a_pred = T[0], A[0]
for t, a in zip(T, A):
    if t_pred <= t and a_pred <= a:
        t_pred, a_pred = t, a
    else:
        times = max(ceil(t_pred/t), ceil(a_pred/a))
        t_pred, a_pred = times*t, times*a
print(t_pred + a_pred)

Submission status: Wrong Answer

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))
    a, b = c* x, c* y
    print(a + b)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(n - 1):
    a, b, x, y = A[i][0], A[i][1], A[i + 1][0], A[i + 1][1]
    if a > x or b > y:
        A[i + 1][0] = max(math.ceil(a / x), math.ceil(b / y)) * x
        A[i + 1][1] = max(math.ceil(a / x), math.ceil(b / y)) * y
        
print(A[-1][0] + A[-1][1])

Submission status: Wrong Answer

Solution code:
import math

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

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

    # print("r1:{},r2:{}".format(r1, r2))
    # print("t:{},a:{}".format(t, a))
    # print("---")

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

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

t = T[0]
a = A[0]
for i in range(1, N):
    r1 = math.ceil(t / T[i])
    r2 = math.ceil(a / A[i])

    t1 = T[i] * r1
    a1 = A[i] * r1

    t2 = T[i] * r2
    a2 = A[i] * r2

    if t1 <= t2:
        if t <= t1 and a <= a1:
            t = t1
            a = a1
        else:
            t = t2
            a = a2
    else:
        if t <= t2 and a <= a2:
            t = t2
            a = a2
        else:
            t = t1
            a = a1

    # print("r1:{},r2:{}".format(r1, r2))
    # print("t:{},a:{}".format(t, a))
    # print("---")

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

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

t = T[0]
a = A[0]
for i in range(1, N):
    r1 = math.ceil(t / T[i])
    r2 = math.ceil(a / A[i])

    t1 = T[i] * r1
    a1 = A[i] * r1

    t2 = T[i] * r2
    a2 = A[i] * r2

    if t1 < t2:
        if t <= t1 and a <= a1:
            t = t1
            a = a1
        else:
            t = t2
            a = a2
    else:
        if t <= t2 and a <= a2:
            t = t2
            a = a2
        else:
            t = t1
            a = a1

    # print("r1:{},r2:{}".format(r1, r2))
    # print("t:{},a:{}".format(t, a))
    # print("---")

print(t + a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=eval(input())
k=1
T=[]
A=[]
for i in range(n):
     if i==0:
          a,b=map(int,input().split())
          T.append(a)
          A.append(b)
     else:
          a,b=map(int,input().split())
          T.append(a)
          A.append(b)
          if T[i]==A[i]:
               T[i]=A[i]=max(T[i-1],A[i-1])
          elif T[i]>A[i]:
               if A[i]<A[i-1]:
                    T[i]=T[i]/A[i]*A[i-1]
                    A[i]=A[i-1]
               if T[i]%int(T[i])!=0.0 or T[i]%int(T[i])!=0:
                    T[i]=int(2*T[i])
                    A[i]=2*A[i]
               T[i]=int(T[i])
          else:
               if T[i]<T[i-1]:
                    A[i]=A[i]/T[i]*T[i-1]
                    T[i]=T[i-1]
               if A[i]%int(A[i])!=0.0 or A[i]%int(A[i])!=0:
                    T[i]=2*T[i]
                    A[i]=int(2*A[i])
               A[i]=int(A[i])               
print(T[n-1]+A[n-1])

Submission status: Wrong Answer

Solution code:
n=eval(input())
k=1
T=[]
A=[]
for i in range(n):
     if i==0:
          a,b=map(int,input().split())
          T.append(a)
          A.append(b)
     else:
          a,b=map(int,input().split())
          T.append(a)
          A.append(b)
          if T[i]==A[i]:
               T[i]=A[i]=max(T[i-1],A[i-1])
          elif T[i]>A[i]:
               while A[i]*2**(k-1)<A[i-1]:
                    k+=1
               if k>=2:
                    A[i]=A[i]*2*(k-1)
                    T[i]=T[i]*2*(k-1)
               k=1
          else:
               while T[i]*2**(k-1)<T[i-1]:
                    k+=1
               if k>=2:
                    T[i]=T[i]*2*(k-1)
                    A[i]=A[i]*2*(k-1)
               k=1
print(T[n-1]+A[n-1])

Submission status: Wrong Answer

Solution code:
from math import ceil
n=int(input())
t,a=[0]*n,[0]*n

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

A,B=1,1
for i,j in zip(t,a):
    v=max(ceil(A/i),ceil(B/j))
    A,B=v*i,v*j

print(A+B)

Submission status: Wrong Answer

Solution code:
from math import ceil
n=int(input())
t,a=[0]*n,[0]*n

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

A,B=1,1
for i in range(n):
    v=max(ceil(A/t[i]),ceil(B/a[i]))
    A,B=v*t[i],v*a[i]

print(A+B)

Submission status: Wrong Answer

Solution code:
from math import ceil
n=int(input())
t,a=[0]*n,[0]*n

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

for i in range(1,n):
    v=max(ceil(t[i-1]/t[i]),ceil(a[i-1]/a[i]),1)
    t[i]*=v
    a[i]*=v

print(t[-1]+a[-1])

Submission status: Wrong Answer

Solution code:
from math import ceil
n=int(input())
t,a=[0]*n,[0]*n

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

for i in range(1,n):
    v=max(ceil(t[i-1]/t[i]),ceil(a[i-1]/a[i]))
    t[i]*=v
    a[i]*=v

print(t[-1]+a[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
t=l[0][0]
a=l[0][1]
for j in range(1,n):
  if t%l[j][0]==0:
    x=int(t/l[j][0])
  else:
    x=int(t/l[j][0])+1
  if a%l[j][1]==0:
    y=int(a/l[j][1])
  else:
    y=int(a/l[j][1])+1
  z=max(x,y)
  t=l[j][0]*z
  a=l[j][1]*z
print(t+a)

Submission status: Wrong Answer

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

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

print(prevA+prevT)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

print(int(prevA+prevT))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
t, a = 1, 1

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

Submission status: Wrong Answer

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

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

print(prevA+prevT)

Submission status: Wrong Answer

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

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

print(int(prevA+prevT))

Submission status: Wrong Answer

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

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

print(prevA+prevT)

Submission status: Wrong Answer

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

prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = ceil(prevT / T[i])
    nextfacA = ceil(prevA / A[i])
    nextfromT = (T[i]*nextfacT, A[i]*nextfacT)
    nextfromA = (T[i]*nextfacA, A[i]*nextfacA)
    if nextfromT[1] < prevA:
        prevT = nextfromA[0]
        prevA = nextfromA[1]
    elif nextfromA[0] < prevT:
        prevT = nextfromT[0]
        prevA = nextfromT[1]
    else:
        if sum(nextfromT) > sum(nextfromA):
            prevT = nextfromA[0]
            prevA = nextfromA[1]
        else:
            prevT = nextfromT[0]
            prevA = nextfromT[1]

print(prevA+prevT)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = []
A = []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
    if curT > curA:
        if curT % T[i] != 0:
            curT += T[i] - curT % T[i]
        curA = curT // T[i] * A[i]
    else:
        if curA % A[i] != 0:
            curA += A[i] - curA % A[i]
        curT = curA // A[i] * T[i]
print(curT+curA)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N  = int(input())

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

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

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

        m = max(t, s)

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

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

print (int(sum(ans)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N  = int(input())

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

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

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

        if t >= s:
            m = t 
        else:
            m = s

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

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

print (int(sum(ans)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
    k1 = math.ceil(l1[0]/l2[0])
    k2 = math.ceil(l1[1]/l2[1])
    k = max(k1,k2)
    l2[0] *= k
    l2[1] *= k
for i in range(N-1):
    modify(info[i],info[i+1])
ans = sum(info[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
    i = 1
    while True:
        if l2[0] * i >= l1[0] and l2[1] * i > l1[1] or l2[0] * i > l1[0] and l2[1] * i >= l1[1]:
            l2[0] *= i
            l2[1] *= i
            break
        i += 1
for i in range(N-1):
    modify(info[i],info[i+1])
ans = sum(info[-1])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
ans = sum(ta[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
ans = sum(ta[N-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

print(t+a)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

print(t+a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(1,n):
    if t/Ratio[i][0] == t//Ratio[i][0]:
        x = t//Ratio[i][0]
    else:
        x = t//Ratio[i][0]+1
    if a/Ratio[i][1] == a//Ratio[i][1]:
        y = a//Ratio[i][1]
    else:
        y = a//Ratio[i][1]+1
    z = max(x,y)
    t,a = Ratio[i][0]*z,Ratio[i][1]*z

print(int(t+a))