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())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1
ah = 1
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x),math.ceil(ah/y))
     th = m*x
     ah = m*y
     h += 1
print(th+ah)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = int(max(math.ceil(float(th)/x),math.ceil(float(ah)/y)))
     th = m*x
     ah = m*y
     h += 1
print(int(th+ah))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(int((th+x-1)/x), int((ah+y-1)/y))
     th = m*x
     ah = m*y
     h += 1
print(int(th+ah))

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0

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

while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(f1(th,x),f1(ah,y))
     th = m*x
     ah = m*y
     h += 1
print(int(th+ah))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(float(math.ceil(th/x)),float(math.ceil(ah/y)))
     th = m*x
     ah = m*y
     h += 1
print(int(th+ah))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x),math.ceil(ah/y))
     th = m*x
     ah = m*y
     h += 1
print(int(th+ah))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = float(listh[0])
     y = float(listh[1])
     m = max(math.ceil(th/x),math.ceil(ah/y))
     th = m*x
     ah = m*y
     h += 1
print(int(th+ah))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = float(listh[0])
     y = float(listh[1])
     m = max(math.ceil(float(th)/x),math.ceil(float(ah)/y))
     th = m*x
     ah = m*y
     h += 1
print(th+ah)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1
ah = 1
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x),math.ceil(ah/x))
     th = m*x
     ah = m*y
     h += 1
print(th+ah)

Submission status: Wrong Answer

Solution code:
# C
from math import ceil
N = int(input())
T = [[int(i) for i in input().split()] for n in range(N)]
m = T[0]
for n in range(1, N):
    a = max(ceil(m[0]/T[n][0]), ceil(m[1]/T[n][1]))
    m = [T[n][0] * a, T[n][1] * a]
print(sum(m))

Submission status: Wrong Answer

Solution code:
# C
from math import ceil
N = int(input())
T = [[int(i) for i in input().split()] for n in range(N)]
m = T[0]
for n in range(1, N):
    a = ceil(max(m[0]/T[n][0], m[1]/T[n][1]))
    m = [T[n][0] * a, T[n][1] * a]
print(sum(m))

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
T = [[int(i) for i in input().split()] for n in range(N)]
m = T[0]
for n in range(1, N):
    if T[n] != T[n-1]:
        if T[n][0]>=m[0] and T[n][1]>=m[1]:
            m = T[n]
        else:
            a = ceil(max(m[0]/T[n][0], m[1]/T[n][1]))
            m = [T[n][0] * a, T[n][1] * a]
print(sum(m))

Submission status: Wrong Answer

Solution code:
# C
from math import ceil
N = int(input())
T = [[int(i) for i in input().split()] for n in range(N)]
m = T[0]
for n in range(1, N):
    if T[n] is not T[n-1]:
        if T[n][0]>=m[0] == T[n][1]>=m[1]:
            m = T[n]
        else:
            if m[0]/T[n][0] > m[1]/T[n][1]:
                a = ceil(m[0]/T[n][0])
                m = [T[n][0] * a, T[n][1] * a]
            else:
                a = ceil(m[1]/T[n][1])
                m = [T[n][0] * a, T[n][1] * a]
print(sum(m))

Submission status: Wrong Answer

Solution code:
# C
from math import ceil
N = int(input())
T = [[int(i) for i in input().split()] for n in range(N)]
m = T[0]
for n in range(1, N):
    if T[n] is not T[n-1]:
        if T[n][0]>=m[0] and T[n][1]>=m[1]:
            m = T[n]
        else:
            if m[0]/T[n][0] > m[1]/T[n][1]:
                a = ceil(m[0]/T[n][0])
                m = [T[n][0] * a, T[n][1] * a]
            else:
                a = ceil(m[1]/T[n][1])
                m = [T[n][0] * a, T[n][1] * a]
print(sum(m))

Submission status: Wrong Answer

Solution code:
n = int(input())

t, a = map(int,input().split())
vote1 = t
vote2 = a

for i in range(n - 1):
    votesum1 = 10 ** 10
    votesum2 = 10 ** 10
    t, a = map(int,input().split())

    num1 = (vote1 + t - 1) // t
    num2 = (vote2 + a - 1) // a
    pair1 = [t * num1, a * num1]
    pair2 = [t * num2, a * num2]

    if pair1[0] >= vote1 and pair1[1] >= vote2:
        votesum1 = sum(pair1)
    if pair2[0] >= vote1 and pair2[1] >= vote2:
        votesum2 = sum(pair2)

    if votesum1 <= votesum2:
        vote1 = pair1[0]
        vote2 = pair1[1]
    if votesum1 > votesum2:
        vote1 = pair2[0]
        vote2 = pair2[1]

print(vote1 + vote2)

Submission status: Wrong Answer

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

from math import ceil
from functools import reduce

N = int(input())
T, A = zip(*(map(int, input().split()) for _ in range(N)))

ans = sum(reduce(
    lambda x, y: tuple(
        max(ceil(x[0]/y[0]), ceil(x[1]/y[1]), 1) * v for v in y),
    zip(T, A),
    (0, 0)))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
ta_list = []
x, y = 1, 1
for i in range(n):
    t, a = map(int, raw_input().split())
    k = max((x+t-1)/t, (y+a-1)/a)
    x = k*t
    y = k*a

print x * y

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

def calcn(r, x):
    n = int(x / r) - 1
    while n * r < x:
        n += 1
    return n

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(calcn(ra, a))
    nt = int(calcn(rt, t))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print(t + a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c_t = 0
c_a = 0
for i in range(n):
    t, a = [int(x) for x in input().split(" ")]
    #print(min(c_t / t, c_a / a))
    init = int(max(c_t / t, c_a / a, 1))
    for j in range(init,10**18):
        if t*j >= c_t and a*j >= c_a:
            c_t = t*j
            c_a = a*j
            #print("->" + str(j))
            break
print(c_t + c_a)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

def calcn(r, x):
    n = int(x / r)
    while n * r < x:
        n += 1
    return n

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(calcn(ra, a))
    nt = int(calcn(rt, t))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

def calcn(r, x):
    n = int(ceil(x / r))
    while n * r < x:
        n += 1
    return n

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(calcn(ra, a))
    nt = int(calcn(rt, t))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

def calcn(r, x):
    n = int(ceil(x / r))
    if n * r < x:
        n += 1
    return n

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(calcn(ra, a))
    nt = int(calcn(rt, t))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print(t + a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c_t = 0
c_a = 0
for i in range(n):
    t, a = [int(x) for x in input().split(" ")]
    #print(min(c_t / t, c_a / a))
    init = int(math.ceil(max(c_t / t, c_a / a, 1)))
    for j in range(init,10**18):
        if t*j >= c_t and a*j >= c_a and (t*j > c_t or a*j > c_a):
            c_t = t*j
            c_a = a*j
            #print("->" + str(j))
            break
print(c_t + c_a)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
data = []
for i in range(n):
    elems = input().split()
    t, a = int(elems[0]), int(elems[1])
    data.append((t, a))

t, a = data[0]

for i in range(1, n):
    rt, ra = data[i][0], data[i][1]
    na = int(ceil(a / ra))
    nt = int(ceil(t / rt))
    n = max(na, nt)
    t = n * rt
    a = n * ra

print(t + a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c_t = 0
c_a = 0
for i in range(n):
    t, a = [int(x) for x in input().split(" ")]
    #print(min(c_t / t, c_a / a))
    init = int(math.floor(max(c_t / t, c_a / a, 1)))
    for j in range(init,10**18):
        if t*j >= c_t and a*j >= c_a:
            c_t = t*j
            c_a = a*j
            #print("->" + str(j))
            break
print(c_t + c_a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c_t = 0
c_a = 0
for i in range(n):
    t, a = [int(x) for x in input().split(" ")]
    #print(min(c_t / t, c_a / a))
    init = int(math.ceil(max(c_t / t, c_a / a, 1)))
    for j in range(init,10**18):
        if t*j >= c_t and a*j >= c_a:
            c_t = t*j
            c_a = a*j
            #print("->" + str(j))
            break
print(c_t + c_a)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
t = 1
a = 1
for i in range(n):
    x, y = map(int, raw_input().split())
    if x < y:
        if t <= a:
            if t % x != 0:
                t += x - (t % x)
            a = y * (t / x)
        else:
            if t % x != 0:
                t += x - (t % x)
            a = y * (t / x)
    elif x > y:
        if t <= a:
            if a % y != 0:
                a += y - (a % y)
            t = x * (a / y)
        else:
            if t % x != 0:
                t += x - (t % x)
            a = y * (t / x)
    else:  # x = y
        tmp = max(t, a)
        t = tmp
        a = tmp
print t+a

Submission status: Wrong Answer

Solution code:
import math                                             
                                                        
N = input()                                             
t = []                                                  
a = []                                                  
for i in range(int(N)):                                 
    t_n, a_n = input().split()                          
    t.append(int(t_n))                                  
    a.append(int(a_n))                                  
                                                        
t_ans = 0                                               
a_ans = 0                                               
for t_n, a_n in zip(t, a):                              
    k = max(math.ceil(t_ans/t_n), math.ceil(a_ans/a_n)) 
    if not k:                                           
        k = 1                                           
    t_ans = int(k*t_n)                                  
    a_ans = int(k*a_n)                                  
print(t_ans+a_ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

N = int(input())

votes = []

for _ in range(N):
    votes.append([float(n) for n in input().split()])

befa = 1
befb = 1

for a, b in votes:
    kakeru = max(math.ceil(befa / a), math.ceil(befb / b))
    befa = a * kakeru
    befb = b * kakeru
    #print(befa,befb)

print(int(befa)+int(befb))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

N = int(input())

votes = []

for _ in range(N):
    votes.append([float(n) for n in input().split()])

befa = 1
befb = 1

for a, b in votes:
    kakeru = max(math.ceil(befa / a), math.ceil(befb / b))
    befa = a * kakeru
    befb = b * kakeru
    #print(befa,befb)

print((befa+befb))

Submission status: Wrong Answer

Solution code:
import math                                                             
                                                                        
N = input()                                                             
t = []                                                                  
a = []                                                                  
for i in range(int(N)):                                                 
    t_n, a_n = input().split()                                          
    t.append(int(t_n))                                                  
    a.append(int(a_n))                                                  
                                                                        
ma = 0                                                                  
t_prev = 0                                                              
a_prev = 0                                                              
t_ans = 0                                                               
a_ans = 0                                                               
for t_n, a_n in zip(t, a):                                              
    summ = t_n + a_n                                                    
    summ_cp = summ                                                      
    #i = 0                                                              
    #while 1:                                                           
    #    i += 1                                                         
    #    summ = summ_cp * i                                             
    #    if summ >= ma and ((t_n*i) >= t_prev) and ((a_n*i) >= a_prev): 
    #        ma = summ                                                  
    #        break                                                      
        #summ = summ_cp * i                                             
    k = max(math.ceil(t_ans/t_n), math.ceil(a_ans/a_n))                 
    if not k:                                                           
        k = 1                                                           
    t_ans = k*t_n                                                       
    a_ans = k*a_n                                                       
print(t_ans+a_ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

N = int(input())

votes = []

for _ in range(N):
    votes.append([float(n) for n in input().split()])


sum = 0
befa = 1
befb = 1

for a, b in votes:
    kakeru = max(math.ceil(befa / a), math.ceil(befb / b))
    befa = a * kakeru
    befb = b * kakeru
    #print(befa,befb)

print(int(befa+befb))

Submission status: Wrong Answer

Solution code:
N = input()                                                           
t = []                                                                
a = []                                                                
for i in range(int(N)):                                               
    t_n, a_n = input().split()                                        
    t.append(int(t_n))                                                
    a.append(int(a_n))                                                
                                                                      
ma = 0                                                                
t_prev = 0                                                            
a_prev = 0                                                            
for t_n, a_n in zip(t, a):                                            
    summ = t_n + a_n                                                  
    summ_cp = summ                                                    
    i = 0                                                             
    while 1:                                                          
        i += 1                                                        
        summ = summ_cp * i                                            
        if summ > ma and ((t_n*i) >= t_prev) and ((a_n*i) >= a_prev): 
            ma = summ                                                 
            break                                                     
        #summ = summ_cp * i                                           
    t_prev = t_n*i                                                    
    a_prev = a_n*i                                                    
print(ma)

Submission status: Wrong Answer

Solution code:
N = input()                                                           
t = []                                                                
a = []                                                                
for i in range(int(N)):                                               
    t_n, a_n = input().split()                                        
    t.append(int(t_n))                                                
    a.append(int(a_n))                                                
                                                                      
ma = 0                                                                
t_prev = 0                                                            
a_prev = 0                                                            
for t_n, a_n in zip(t, a):                                            
    summ = t_n + a_n                                                  
    summ_cp = summ                                                    
    i = 0                                                             
    while 1:                                                          
        i += 1                                                        
        summ = summ_cp * i                                            
        if summ > ma and ((t_n*i) >= t_prev) and ((a_n*i) >= a_prev): 
            ma = summ                                                 
            break                                                     
        #summ = summ_cp * i                                           
    t_prev = t_n*i                                                    
    a_prev = a_n*i                                                    
    print(ma)                                                         
    print(t_n*i, a_n*i)                                               
    print()                                                           
print(ma)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())

votes = []

for _ in range(N):
    votes.append([int(n) for n in input().split()])

an = votes[0][0]
bn = votes[0][1]

# for a, b in votes:
#     i = 1
#     while(True):
#         if((a * i) % an == 0 and (b * i) % bn == 0):
#             break
#         else:
#             i += 1
#     an = a * i
#     bn = b * i
#     print(an)
#     print(bn)
#     print()

sum = 0
befa = 0
befb = 0

for a, b in votes:
    a_m = a
    b_m = b
    while(a < befa or b < befb):
        a += a_m
        b += b_m
    t = a + b;
    i = 1
    while(t * i <= sum):
        i += 1
    sum = t * i
    befa = a
    befb = b

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
beg=np.array([1,1])
for i in range(n):
    cur=np.array(list(map(int,input().split())))
    beg=cur*np.ceil(beg/cur).max()
print(beg.sum().astype(int))

Submission status: Wrong Answer

Solution code:
n = int(input())
at =[input().split(' ') for i in range (n)]
av = at[0]
for i in range(n-1):
    if int(at[i][0]) <= int(at[i+1][0]) and  int(at[i][1]) <= int(at[i+1][1]):
        av = at[i+1]
    
    elif int(at[i][0]) > int(at[i+1][0]) and  int(at[i][1]) <= int(at[i+1][1]):
        if int(av[0])%int(at[i+1][0]) == 0:
            x = int(av[0])//int(at[i+1][0])
        else:
            x = int(int(av[0])//int(at[i+1][0])) + 1
        av =[x*int(at[i+1][0]),x*int(at[i+1][1])]
    
    elif int(at[i][0]) <= int(at[i+1][0]) and  int(at[i][1]) > int(at[i+1][1]):
        if int(av[1])%int(at[i+1][1]) == 0:
            x = int(av[1])//int(at[i+1][1])
        else:
            x =int(int(av[1])//int(at[i+1][1])) + 1
        av =[x*int(at[i+1][0]),x*int(at[i+1][1])]
    
    elif int(at[i][0]) > int(at[i+1][0]) and  int(at[i][1]) > int(at[i+1][1]):
        if int(av[0])/int(at[i+1][0]) > int(av[1])/int(at[i+1][1]):
            if int(av[0])%int(at[i+1][0]) == 0:
                x = int(av[0])/int(at[i+1][0])
            else:
            	x = int(int(av[0])/int(at[i+1][0])) +1
        else:
            if int(av[1])%int(at[i+1][1]) == 0:
                x = int(av[1])/int(at[i+1][1])
            else:
            	x = int(int(av[1])/int(at[i+1][1])) +1
        
        av =[x*int(at[i+1][0]),x*int(at[i+1][1])]
print(int(av[0]) + int(av[1]))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T, A = [int(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [int(x) for x in input().split()]
        n = max(math.ceil(T/T2),math.ceil(A/A2))
        T = T2*n
        A = A2*n

print(T + A)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T, A = [int(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [int(x) for x in input().split()]
        n = max(math.ceil(T/T2),math.ceil(A/A2))
        print('n = ',n)
        T = T2*n
        A = A2*n
        print('T = ',T)
        print('A = ',A)

print(T + A)

Submission status: Wrong Answer

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

for i in range(1,N):
        n = max(math.ceil(TA[i-1][0] / TA[i][0]),math.ceil(TA[i-1][1] / TA[i][1]))
        TA[i] = [TA[i][0]*n, TA[i][1]*n ]

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

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

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

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

    if i != 0 and T[i - 1] - T[i] > 0 or A[i - 1] - A[i] > 0:

        if (T[i - 1] / T[i]) > (A[i - 1] / A[i]):
            m  = math.ceil(T[i - 1] / T[i])

        else:
            m = math.ceil(A[i - 1] / A[i])

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

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

print "%d" % sum(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t=1
a=1
for i in range(n):
    t_, a_ = map(int, input().split())
    if t_>=t and a_>=a:
        t=t_
        a=a_
##    elif t_>=t and a_<a:
##        at=math.ceil(a/a_)
##        a = a_*at
##        t = t_*at
##    elif t_<t and a_>=a:
##        tt=math.ceil(t/t_)
##        a = a_*tt
##        t = t_*tt
    else:
        if a % a_ ==0:
            at = math.floor(a/a_)
        else:
            at=math.ceil(a/a_)
        if t % t_ ==0:
            tt = math.floor(t/t_)
        else:
            tt=math.ceil(t/t_)
        att = max(at, tt)
#        print(att)
        a = a_*att
        t = t_*att
#    print(t, a)
        
print(t+a)

Submission status: Wrong Answer

Solution code:
time=input()

aok=1
tak=1

for i in range(time):
	l=map(int, raw_input().split())
	if aok<tak:
		if tak%l[1]!=0:
			tak=(tak/l[1]+1)*l[1]
		if aok>tak/l[1]*l[0]:
			if aok%l[0]!=0:
				aok=(aok/l[0]+1)*l[0]
			tak=aok/l[0]*l[1]
		else:
			aok=tak/l[1]*l[0]
	elif aok==tak:
		if l[0]<=l[1]:
			if aok%l[0]!=0:
				aok=(aok/l[0]+1)*l[0]
			tak=aok/l[0]*l[1]
		else:
			if tak%l[1]!=0:
				tak=(tak/l[1]+1)*l[1]
			aok=tak/l[1]*l[0]
	else:
		if aok%l[0]!=0:
			aok=(aok/l[0]+1)*l[0]
		if tak>aok/l[0]*l[1]:
			if tak%l[1]!=0:
				tak=(tak/l[1]+1)*l[1]
			aok=tak/l[1]*l[0]
		else:
			tak=aok/l[0]*l[1]
	print aok, tak
print aok+tak

Submission status: Wrong Answer

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

for i in range(1,N):
        while TA[i][0] < TA[i-1][0]:
                a = math.ceil(TA[i-1][0] / TA[i][0])
                TA[i] = [TA[i][0]*a, TA[i][1]*a ]

        while TA[i][1] < TA[i-1][1]:
                b = math.ceil(TA[i-1][1] / TA[i][1])
                TA[i] = [TA[i][0]*b, TA[i][1]*b ]

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t=1
a=1
for i in range(n):
    t_, a_ = map(int, input().split())
    if t_>=t and a_>=a:
        t=t_
        a=a_
##    elif t_>=t and a_<a:
##        at=math.ceil(a/a_)
##        a = a_*at
##        t = t_*at
##    elif t_<t and a_>=a:
##        tt=math.ceil(t/t_)
##        a = a_*tt
##        t = t_*tt
    else:
        at=math.ceil(a/a_)
        tt=math.ceil(t/t_)
        att = max(at, tt)
#        print(att)
        a = a_*att
        t = t_*att
#    print(t, a)
        
print(t+a)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
sa, st = 1, 1

for a, t in (map(int, input().split(' ')) for _ in range(n)):
    r = ceil(max(sa / a, st / t))
    sa, st = a * r, t * r

print(sa + st)

Submission status: Wrong Answer

Solution code:
time=input()

aok=1
tak=1

for i in range(time):
	l=map(int, raw_input().split())
	if aok<tak:
		if tak%l[1]!=0:
			tak=(tak/l[1]+1)*l[1]
		aok=tak/l[1]*l[0]
	elif aok==tak:
		if l[0]<=l[1]:
			if aok%l[0]!=0:
				aok=(aok/l[0]+1)*l[0]
			tak=aok/l[0]*l[1]
		else:
			if tak%l[1]!=0:
				tak=(tak/l[1]+1)*l[1]
			aok=tak/l[1]*l[0]
	else:
		if aok%l[0]!=0:
			aok=(aok/l[0]+1)*l[0]
		tak=aok/l[0]*l[1]
print aok+tak

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t=1
a=1
for i in range(n):
    t_, a_ = map(int, input().split())
    if t_>=t and a_>=a:
        t=t_
        a=a_
    elif t_>=t and a_<a:
        at=math.ceil(a/a_)
        a = a_*at
        t = t_*at
    elif t_<t and a_>=a:
        tt=math.ceil(t/t_)
        a = a_*tt
        t = t_*tt
    else:
        at=math.floor(a/a_)
        tt=math.floor(t/t_)
        att = max(at, tt)
#        print(att)
        a = a_*att
        t = t_*att
#    print(t, a)
        
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
N = int(raw_input())
t = [[0,0] for i in range(N)]
for i in range(N):
    l = []
    l = raw_input().split()
    t[i][0] = int(l[0])
    t[i][1] = int(l[1])
min_ = [0,0]
min_[0] = t[0][0]
min_[1]= t[0][1]
for i in range(1,N):
    cnt = max(int(math.ceil(1.0*min_[0]/t[i][0])),int(math.ceil(1.0*min_[1]/t[i][1])))
    min_[0] = cnt*t[i][0]
    min_[1] = cnt*t[i][1]
print min_[0]+min_[1]

Submission status: Wrong Answer

Solution code:
N  = int(raw_input())

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

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

    if i != 0 and T[i - 1] - T[i] > 0 or A[i - 1] - A[i] > 0:

        if (T[i  - 1] / T[i]) > (A[i - 1] / A[i]):
            m  = T[i  - 1] / T[i]
            if T[i - 1] % T[i] != 0:
                m += 1 

        else:
            m = A[i - 1] / A[i]
            if A[i - 1] % A[i] != 0:
                m += 1

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

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

print sum(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t, a = [int(x) for x in input().split()]
for i in range(1, n):
    t2, a2 = [int(x) for x in input().split()]
    x = math.ceil(max(t / t2, a / a2))
    t, a = x * t2, x * a2

print(t + a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t=1
a=1
for i in range(n):
    t_, a_ = map(int, input().split())
    if t_>=t and a_>=a:
        t=t_
        a=a_
    elif t_>=t and a_<a:
        at=math.ceil(a/a_)
        a = a_*at
        t = t_*at
    elif t_<t and a_>=a:
        tt=math.ceil(t/t_)
        a = a_*tt
        t = t_*tt
    else:
        at=math.ceil(a/a_)
        tt=math.ceil(t/t_)
        att = max(at, tt)
#        print(att)
        a = a_*att
        t = t_*att
#    print(t, a)
        
print(t+a)

Submission status: Wrong Answer

Solution code:
N  = int(raw_input())

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

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

    if i != 0 and T[i - 1] - T[i] >= 0 or A[i - 1] - A[i] >= 0:

        if (T[i  - 1] / T[i]) >= (A[i - 1] / A[i]):
            m  = T[i  - 1] / T[i]
            if T[i - 1] % T[i] != 0:
                m += 1 

        else:
            m = A[i - 1] / A[i]
            if A[i - 1] % A[i] != 0:
                m += 1

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

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

print sum(ans)