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

T, A = map(float, raw_input().split())

for i in range(N - 1):
    t, a = map(float, raw_input().split())

    s1 = math.ceil(T / t)

    s2 = math.ceil(A / a)

    s = max(s1, s2)

    T = s * t
    A = s * a

print "%d" % (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]
		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(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):
    if t[i][0]>=min_[0] and t[i][1]>=min_[1]:
        min_[0] = t[i][0]
        min_[1] = t[i][1]
    else:
        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:
time=input()

aok=1
tak=1

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

Submission status: Wrong Answer

Solution code:
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):
    if t[i][0]>=min_[0] and t[i][1]>=min_[1]:
        min_[0] = t[i][0]
        min_[1] = t[i][1]
    else:
        cnt = max(min_[0]/t[i][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())
t=a=1

for i in range(n):
    x,y=map(int,raw_input().split())
    if t<=x and a<=y:
        t=x
        a=y
    else:
        tmp1=(2*t-1)/x
        tmp2=(2*a-1)/y
        tmp1,tmp2=min(tmp1,tmp2),max(tmp1,tmp2)
        if x*tmp1>=t and y*tmp1>=a:
            t=x*tmp1
            a=y*tmp1
        else:
            t=x*tmp2
            a=y*tmp2
print t+a
exit()

Submission status: Wrong Answer

Solution code:
import fractions
 
n = int(input())
 
t = 1
a = 1
 
for i in range(n):
	x,y = map(int, input().split())
	t = fractions.gcd(x,t)
	a = fractions.gcd(y,a)
	
print(t + a)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a,b =b, a%b
    return a


n = input()
t= [0]*n
a= [0]*n
for i in range(n):
    t[i], a[i] = map(int, raw_input().split())
ans = t[0]+a[0]
for i in range(n-1):
    if ans % t[i+1] != 0 and ans % a[i+1] != 0:
        ans *= a[i+1]
        ans /= gcd(ans, a[i+1])
        ans *= t[i+1]
        ans /= gcd(ans, t[i+1])
        # ans /= gcd(a[i+1], t[i+1])                                                                            
    elif ans % t[i+1] != 0:
        ans *= t[i+1]
        ans /= gcd(ans, t[i+1])
    elif ans % a[i+1] != 0:
        ans *= a[i+1]
        ans /= gcd(ans, a[i+1])
    if ans% (t[i+1]+a[i+1]) != 0:
        ans *= t[i+1]+a[i+1]
        ans /= gcd(ans, t[i+1]+a[i+1])
print ans

Submission status: Wrong Answer

Solution code:
N = int(input())
T = []
A = []
for i in range(N):
    s = input().split()
    T.append(int(s[0]))
    A.append(int(s[1]))


tc = T[0]
ac = A[0] 

if N > 1:
    for i in range(1,N):
        if T[i] * ac == A[i] * tc:
            continue
        tc += (T[i] - (tc % T[i])) % T[i]
        ac += (A[i] - (ac % A[i])) % A[i]
        if (tc / T[i] * A[i]) - ac > (ac / A[i] * T[i]) - tc:
            ac = int(tc / T[i] * A[i])
        else:
            tc = int(ac / A[i] * T[i])
        
ret = int(tc + ac)
print(ret)

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:
import sys
import math
def gcd(a,b):
    while b>0:
        a,b=b,a%b
    return int(a)
def lcm(a,b):
    return int(a*b/gcd(a,b))

lines = sys.stdin.readlines()
n = int(lines[0])
ret = [1,1]
before_sum = 2
for line in lines[1:]:
    line = line.rstrip().split(" ")
    for l in range(len(line)):
        line[l] = int(line[l])
    #print ("line=",line)
    #print ("ret=",ret)
    #print ("before_sum=",before_sum)
    a,b = int(line[0]),int(line[1])
    if (ret[0]<=a) and (ret[1]<=b):
        ret[0]=a
        ret[1]=b
    else:
        check_a = ret[0]/a
        check_b = ret[1]/b
        if (check_a>check_b):
            ret[0]=math.ceil(check_a)*line[0]
            ret[1]=math.ceil(check_a)*line[1]
        elif (check_a<=check_b):
            ret[0]=math.ceil(check_b)*line[0]
            ret[1]=math.ceil(check_b)*line[1]
    g = gcd(ret[0],ret[1])
    #print (ret[0],ret[1],g)
    ret[0]=int(ret[0]/g)
    ret[1]=int(ret[1]/g)
    if (before_sum>(ret[0]+ret[1])):
        #print ("before_sum=",before_sum,ret)
        check_ret = [ret[0],ret[1]]
        i=2
        while((check_ret[0]+check_ret[1])<before_sum):
            check_ret[0]=ret[0]*i
            check_ret[1]=ret[1]*i
            i+=1
        ret[0] = check_ret[0]
        ret[1] = check_ret[1]
        before_sum=ret[0]+ret[1]
    else:
        before_sum=ret[0]+ret[1]


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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a,b =b, a%b
    return a


n = input()
t= [0]*n
a= [0]*n
for i in range(n):
    t[i], a[i] = map(int, raw_input().split())
ans = t[0]+a[0]
for i in range(n-1):
    if ans % t[i+1] != 0 and ans % a[i+1] != 0:
        ans *= a[i+1]
        ans /= gcd(ans, a[i+1])
        ans *= t[i+1]
        ans /= gcd(ans, t[i+1])
        # ans /= gcd(a[i+1], t[i+1])                                                                            
    elif ans % t[i+1] != 0:
        ans *= t[i+1]
        ans /= gcd(ans, t[i+1])
    elif ans % a[i+1] != 0:
        ans *= a[i+1]
        ans /= gcd(ans, a[i+1])
    # ans *= gcd(ans, t[i+1]+a[i+1])                                                                            
print ans

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

ans = [0, 0]

T, A = [0] * 1001, [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 (math.ceil(T[i  - 1] / T[i]) >= (math.ceil(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:
def gcd(a, b):
    while b:
        a,b =b, a%b
    return a


n = input()
t= [0]*n
a= [0]*n
for i in range(n):
    t[i], a[i] = map(int, raw_input().split())
ans = t[0]+a[0]
for i in range(n-1):
    if ans % t[i+1] != 0 and ans % a[i+1] != 0:
        ans *= gcd(ans, a[i+1])
        ans *= gcd(ans, t[i+1])
        # ans /= gcd(a[i+1], t[i+1])                                                                            
    elif ans % t[i+1] != 0:
        ans *= gcd(ans, t[i+1])
    elif ans % a[i+1] != 0:
        ans *= gcd(ans, a[i+1])
    ans *= gcd(ans, t[i+1]+a[i+1])
print ans

Submission status: Wrong Answer

Solution code:
N = int(input())
T = []
A = []
for i in range(N):
    s = input().split()
    T.append(int(s[0]))
    A.append(int(s[1]))


tc = T[0]
ac = A[0] 

if N > 1:
    for i in range(1,N):
        if T[i] * ac == A[i] * tc:
            continue
        tc += (T[i] - (tc % T[i])) % T[i]
        ac +=  (A[i] - (ac % A[i])) % A[i]
        if tc / T[i] * A[i] >= ac:
            ac = tc / T[i] * A[i]
        else:
            tc = ac / A[i] * T[i]            
        
ret = int(tc + ac)
print(ret)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
for i in range(n):
    r = list(map(int, input().split()))
    if i == 0:
        t = r[0]
        a = r[1]
    else:
        if t <= r[0] and a <= r[1]:
            t = r[0]
            a = r[0]
        else:
            k = max(math.ceil(t / r[0]), math.ceil(a / r[1]))
            t = k * r[0]
            a = k * r[1]
print(t + a)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a,b =b, a%b
    return a


n = input()
t= [0]*n
a= [0]*n
for i in range(n):
    t[i], a[i] = map(int, raw_input().split())
ans = t[0]+a[0]
for i in range(n-1):
    if ans % t[i+1] != 0 and ans % a[i+1] != 0:
        ans *= gcd(ans, a[i+1])
        ans *= gcd(ans, t[i+1])
        # ans /= gcd(a[i+1], t[i+1])                                                                            
    elif ans % t[i+1] != 0:
        ans *= gcd(ans, t[i+1])
    elif ans % a[i+1] != 0:
        ans *= gcd(ans, a[i+1])

print ans

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

ans = [0, 0]

T, A = [0] * 1001, [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(raw_input())

ans = [0, 0]

T, A = [0] * 1001, [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, a = 1, 1
for i in range(N):
    ti, ai = map(int, input().split())
    n1 = math.ceil(t / ti)
    n2 = math.ceil(a / ai)
    n = max([n1, n2])
    t, a = ti * n, ai * n
    
print(t + a)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
t_real, a_real = map(int, raw_input().split())
for i in xrange(0, n-1):
    ti, ai = map(int, raw_input().split())
    while (ti <= t_real) and (ai <= a_real):
        ti = ti*2 
        ai = ai*2
    t_real = t_real + (ti - t_real)
    a_real = a_real + (ai - a_real)
print(t_real+a_real)

Submission status: Wrong Answer

Solution code:
n = input()
t= [0]*n
a= [0]*n
for i in range(n):
    t[i], a[i] = map(int, raw_input().split())
ans = t[0]+a[0]
for i in range(n-1):
    if ans % t[i+1] != 0 and ans % a[i+1] != 0:
        ans *= a[i+1]
        ans *= t[i+1]
        # ans /= gcd(a[i+1], t[i+1])                                                                            
    elif ans % t[i+1] != 0:
        ans *= t[i+1]
    elif ans % a[i+1] != 0:
        ans *= a[i+1]

print ans

Submission status: Wrong Answer

Solution code:
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):
    if min_[0] > min_[1]:
        large_index = 0
    else:
        large_index = 1
    cnt = 1
    while cnt*t[i][large_index]<min_[large_index]:
        cnt = cnt+1
    min_[0] = cnt*t[i][0]
    min_[1] = cnt*t[i][1]
print min_[0]+min_[1]

Submission status: Wrong Answer

Solution code:
import sys
import math

lines = sys.stdin.readlines()
n = int(lines[0])
ret = [1,1]
before_sum = 2
for line in lines[1:]:
    line = line.rstrip().split(" ")
    for l in range(len(line)):
        line[l] = int(line[l])
    #print ("line=",line)
    #print ("ret=",ret)
    a,b = int(line[0]),int(line[1])
    if (ret[0]<=a) and (ret[1]<=b):
        ret[0]=a
        ret[1]=b
    else:
        check_a = ret[0]/a
        check_b = ret[1]/b
        if (check_a>check_b):
            ret[0]=math.ceil(check_a)*line[0]
            ret[1]=math.ceil(check_a)*line[1]
        elif (check_a<=check_b):
            ret[0]=math.ceil(check_b)*line[0]
            ret[1]=math.ceil(check_b)*line[1]
    if (before_sum>(ret[0]+ret[1])):
        check_ret = [ret[0],ret[1]]
        i=2
        while((check_ret[0]+check_ret[1])<before_sum):
            check_ret[0]=ret[0]*i
            check_ret[1]=ret[1]*i
            i+=1
        ret[0] = check_ret[0]
        ret[1] = check_ret[1]
        before_sum=ret[0]+ret[1]
    else:
        before_sum=ret[0]+ret[1]


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

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

ans = [0, 0]
T, A = [0] * 1001, [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]]

        T[i] /= m
        A[i] /= m

print "%d" % sum(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = []
A = []
for i in range(N):
    s = input().split()
    T.append(int(s[0]))
    A.append(int(s[1]))


tc = T[0]
ac = A[0] 

if N > 1:
    for i in range(1,N):
        if T[i] * ac == A[i] * tc:
            continue
        if tc % T[i] != 0:
            tc += T[i] - (tc % T[i]) 
        if tc / T[i] * A[i] >= ac:
            ac = tc / T[i] * A[i]
        else:
            ac +=  A[i] - (ac % A[i])
            tc = ac / A[i] * T[i]            
       
ret = int(tc + ac)
print(ret)

Submission status: Wrong Answer

Solution code:
def solve(t,a,tp,ap):

    # if t/a == tp/ap:
    #     return t,a
    
    next_t=0
    next_a=0
    
    num_a = max( int(a/ap)  , int(t/tp) )
    next_t = num_a*tp
    next_a = num_a*ap

    while not(next_t > t and next_a > a):
        next_t += tp
        next_a += ap
    return next_t,next_a


N = int(raw_input())
l = []
for i in range(N):
    l.append( map(float,raw_input().split()) )

t = 1.0
a = 1.0

while len(l):
    tp,ap = l.pop(0)
    t,a = solve(t,a,tp,ap)

print int(t+a)

Submission status: Wrong Answer

Solution code:
import sys
import math

lines = sys.stdin.readlines()
n = int(lines[0])
ret = [1,1]
before_sum = 2
for line in lines[1:]:
    line = line.rstrip().split(" ")
    for l in range(len(line)):
        line[l] = int(line[l])
    #print ("line=",line)
    #print ("ret=",ret)
    a,b = int(line[0]),int(line[1])
    if (ret[0]<=a) and (ret[1]<=b):
        ret[0]=a
        ret[1]=b
    else:
        check_a = ret[0]/a
        check_b = ret[1]/b
        if (check_a>check_b):
            ret[0]=math.ceil(check_a)*line[0]
            ret[1]=math.ceil(check_a)*line[1]
        elif (check_a<=check_b):
            ret[0]=math.ceil(check_b)*line[0]
            ret[1]=math.ceil(check_b)*line[1]
    if (before_sum>(ret[0]+ret[1])):
        check_ret = [ret[0],ret[1]]
        i=2
        while((check_ret[0]+check_ret[1])<before_sum):
            check_ret[0]=ret[0]*i
            check_ret[1]=ret[1]*i
            i+=1
        ret[0] = check_ret[0]
        ret[1] = check_ret[1]
    else:
        before_sum=ret[0]+ret[1]


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

Submission status: Wrong Answer

Solution code:
def solve(a, b, c):
    sm = 0
    while True:
        if (c - b * sm) % (a - b) == 0:
            x = (c - b * sm) // (a - b)
            return x, sm - x
        sm += 1

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, y = solve(a2, -t2, a * t2 - t * a2)
    t, a = t + x, a + y

print(t + a)

Submission status: Wrong Answer

Solution code:
def solve(t,a,tp,ap):

    # if t/a == tp/ap:
    #     return t,a
    
    next_t=0
    next_a=0
    
    num_a = max( int(a/ap)  , int(t/tp) )
    next_t = num_a*tp
    next_a = num_a*ap

    while next_t < t or next_a < a:
        next_t += tp
        next_a += ap
    return next_t,next_a


N = int(raw_input())
l = []
for i in range(N):
    l.append( map(float,raw_input().split()) )

t = 1.0
a = 1.0

while len(l):
    tp,ap = l.pop(0)
    t,a = solve(t,a,tp,ap)

print int(t+a)

Submission status: Wrong Answer

Solution code:
import math
from decimal import *
N = input()

t = []
a = []

for i in range(N):
    z = raw_input()
    x,y = [int(j) for j in z.split()]
    t.append(x)
    a.append(y)

t_get = 1
a_get = 1

for i in range(N):
#    times = int(max(math.ceil(float(t_get)/t[i]),math.ceil(float(a_get)/a[i])))
    times = int(max(math.ceil(Decimal(t_get)/Decimal(t[i])),math.ceil(Decimal(a_get)/Decimal(a[i]))))
    t_get = t[i]*times
    a_get = a[i]*times

print int(t_get + a_get)

Submission status: Wrong Answer

Solution code:
def solve(a, b, c):
    sm = 0
    while True:
        if (c - b * sm) % (a - b) == 0:
            x = (c - b * sm) / (a - b)
            return x, sm - x
        sm += 1

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, y = solve(a2, -t2, a * t2 - t * a2)
    t, a = t + x, a + y

print(t + a)

Submission status: Wrong Answer

Solution code:
def solve(a, b, c):
    sm = 0
    while True:
        if (c - b * sm) % (a - b) == 0:
            x = (c - b * sm) / (a - b)
            return x, sm - x
        sm += 1

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()]
    print('{}:{} -> {}:{}'.format(t, a, t2, a2))
    x, y = solve(a2, -t2, a * t2 - t * a2)
    print(x, y)
    t, a = t + x, a + y

print(t + a)

Submission status: Wrong Answer

Solution code:
def solve(t,a,tp,ap):

    if t/a == tp/ap:
        return t,a
    
    next_t=0
    next_a=0
    
    num_a = max( int(a/ap)  , int(t/tp) )
    next_t = num_a*tp
    next_a = num_a*ap

    while next_t < t or next_a < a:
        next_t += tp
        next_a += ap
    return next_t,next_a


N = int(raw_input())
l = []
for i in range(N):
    l.append( map(float,raw_input().split()) )

t = 1.0
a = 1.0

while len(l):
    tp,ap = l.pop(0)
    t,a = solve(t,a,tp,ap)

print int(t+a)

Submission status: Wrong Answer

Solution code:
import math
N = input()
datas = []
for _ in range(N):
	data = map(long, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t = datas[_+1][0]
	o = datas[_+1][1]
	t_mul = t_min/t + 1
	o_mul = o_min/o + 1
	if t_mul < o_mul:
		t_min = o_mul*t
		o_min = o_mul*o
	else:
		t_min = t_mul*t
		o_min = t_mul*o

print type(t_min+o_min),t_min+o_min

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

ans = [0, 0]
T, A = [0] * 1001, [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:
n = int(input())
for i in range(n):
    r = list(map(int, input().split()))
    if i == 0:
        t = r[0]
        a = r[1]
    else:
        s = r
        while 1:
            if r[0] >= t and r[1] >= a:
                t = r[0]
                a = r[1]
                break
            r[0] += s[0]
            r[1] += s[1]
print(t + a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a_t = 1
a_a = 1
for i in range(n):
    line = input().split()
    l = list(map(int, line))
    t = l[0]
    a = l[1]
    if t >= a_t and a >= a_a:
        a_t = t
        a_a = a
    else:
        r1 = math.ceil(a_t/t)
        r2 = math.ceil(a_a/a)
        r = max(r1, r2)
        a_t = t * r
        a_a = a* r
print (a_t + a_a)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    r = list(map(int, input().split()))
    if i == 0:
        t = r[0]
        a = r[1]
    else:
        while 1:
            if r[0] >= t and r[1] >= a:
                t = r[0]
                a = r[1]
                break
            r[0] += r[0]
            r[1] += r[1]
print(t + a)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    r = list(map(int, input().split()))
    if i == 0:
        t = r[0]
        a = r[1]
    else:
        j = 1
        while 1:
            if r[0] >= t and r[1] >= a:
                t = r[0]*j
                a = r[1]*j
                break
            r[0] += r[0]
            r[1] += r[1]
print(t + a)

Submission status: Wrong Answer

Solution code:
import sys
import math

lines = sys.stdin.readlines()
n = int(lines[0])
ret = [1,1]
for line in lines[1:]:
    line = line.rstrip().split(" ")
    for l in range(len(line)):
        line[l] = int(line[l])
    #print ("line=",line)
    #print ("ret=",ret)
    a,b = int(line[0]),int(line[1])
    if (ret[0]<=a) and (ret[1]<=b):
        ret[0]=a
        ret[1]=b
    else:
        check_a = ret[0]/a
        check_b = ret[1]/b
        if (check_a>check_b):
            ret[0]=math.ceil(check_a)*line[0]
            ret[1]=math.ceil(check_a)*line[1]
        elif (check_a<=check_b):
            ret[0]=math.ceil(check_b)*line[0]
            ret[1]=math.ceil(check_b)*line[1]

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

Submission status: Wrong Answer

Solution code:
import math
N = input()

t = []
a = []

for i in range(N):
    z = raw_input()
    x,y = [int(j) for j in z.split()]
    t.append(x)
    a.append(y)

t_get = 1
a_get = 1

for i in range(N):
    times = int(max(math.ceil(float(t_get)/t[i]),math.ceil(float(a_get)/a[i])))
    t_get = t[i]*times
    a_get = a[i]*times

print int(t_get + a_get)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a_t = 0
a_a = 0
for i in range(n):
    line = input().split()
    l = list(map(int, line))
    t = l[0]
    a = l[1]
    if t >= a_t and a >= a_a:
        a_t = t
        a_a = a
    else:
        r1 = math.ceil(a_t/t)
        r2 = math.ceil(a_a/a)
        r = max(r1, r2)
        a_t = t * r
        a_a = a* r
print (a_t + a_a)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    r = list(map(int, input().split()))
    print(r)
    if i == 0:
        t = r[0]
        a = r[1]
    else:
        j = 1
        while 1:
            if r[0]*j >= t and r[1]*j >= a:
                t = r[0]*j
                a = r[1]*j
                break
            j += 1
print(t + a)

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

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

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 = input()
datas = []
for _ in range(N):
	data = map(float, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t = datas[_+1][0]
	o = datas[_+1][1]
	t_mul = long(math.ceil(t_min/t))
	o_mul = long(math.ceil(o_min/o))
	if t_mul < o_mul:
		t_min = o_mul*long(t)
		o_min = o_mul*long(o)
	else:
		t_min = t_mul*long(t)
		o_min = t_mul*long(o)

print t_min+o_min

Submission status: Wrong Answer

Solution code:
n = int(input())
t, a = map(int, input().split())
k = t + a
for i in range(n - 1):
    t1 = t
    a1 = a
    dt, da = map(int, input().split())
    if t > a:
        while t % dt != 0:
            t += 1
        a = da * (t // dt)
    else:
        while a % da != 0:
            a += 1
        t = dt * (a // da)
    k += t - t1 + a - a1
print(k)

Submission status: Wrong Answer

Solution code:
import math
N = input()
datas = []
for _ in range(N):
	data = map(float, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t = datas[_+1][0]
	o = datas[_+1][1]
	t_mul = long(math.ceil(t_min/t))
	o_mul = long(math.ceil(o_min/o))
	if t_mul < o_mul:
		t_min = o_mul*t
		o_min = o_mul*o
	else:
		t_min = t_mul*t
		o_min = t_mul*o

print t_min+o_min

Submission status: Wrong Answer

Solution code:
from math import ceil

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

while n:
    n -= 1
    a, t = map(int, input().split())
    r = max(ceil(sa / a), ceil(st / t))
    sa, st = a * r, t * r

print(sa + st)

Submission status: Wrong Answer

Solution code:
import sys
import math

lines = sys.stdin.readlines()
n = int(lines[0])
ret = [1,1]
for line in lines[1:]:
    line = line.rstrip().split(" ")
    for l in range(len(line)):
        line[l] = int(line[l])
    #print ("line=",line)
    #print ("ret=",ret)
    a,b = int(line[0]),int(line[1])
    if (ret[0]<=a) and (ret[1]<=b):
        ret[0]=a
        ret[1]=b
    else:
        check_a = math.ceil(ret[0]/a)
        check_b = math.ceil(ret[1]/b)
        if (check_a>check_b):
            ret[0]=check_a*line[0]
            ret[1]=check_a*line[1]
        elif (check_a<=check_b):
            ret[0]=check_b*line[0]
            ret[1]=check_b*line[1]

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

Submission status: Wrong Answer

Solution code:
import math
N = input()
datas = []
for _ in range(N):
	data = map(float, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t_mul = 1
	o_mul = 1
	t = datas[_+1][0]
	o = datas[_+1][1]
	t_mul = math.ceil(t_min/t)
	o_mul = math.ceil(o_min/o)
	if t_mul < o_mul:
		t_min = o_mul*t
		o_min = o_mul*o
	else:
		t_min = t_mul*t
		o_min = t_mul*o

print long(t_min+o_min)

Submission status: Wrong Answer

Solution code:
import math

N  = int(raw_input())

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

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

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

    if i != 0:
        while (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:
def getLnInput():
    return input().split()


def getNewVote(currentVote, newRatio):
    multFacCeil = []
    for i in range(2):
        multFacCeil.append((currentVote[i] - 1) // newRatio[i] + 1)
    newVote = []
    maxMF = max(multFacCeil)
    for i in range(2):
        newVote.append(newRatio[i] * maxMF)
    return newVote


def main():
    N = int(getLnInput()[0])
    voteNum = list(map(int, getLnInput()))
    for i in range(N - 1):
        print(voteNum)
        newRatio = list(map(int, getLnInput()))
        voteNum = getNewVote(voteNum, newRatio)
    print(sum(voteNum))
    return


main()

Submission status: Wrong Answer

Solution code:
import math
N = input()
datas = []
for _ in range(N):
	data = map(float, raw_input().split(" "))
	datas.append(data)

t_min = datas[0][0]
o_min = datas[0][1]
for _ in range(N-1):
	t_mul = 1
	o_mul = 1
	t = datas[_+1][0]
	o = datas[_+1][1]
	t_mul = math.ceil(t_min/t)
	o_mul = math.ceil(o_min/o)
	if t_mul < o_mul:
		t_min = o_mul*t
		o_min = o_mul*o
	else:
		t_min = t_mul*t
		o_min = t_mul*o

print int(t_min+o_min)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

while n:
    n -= 1
    a, t = map(int, input().split())
    if sa <= a:
        if st <= t:
            sa, st = a, t
        else:
            r = ceil(st / t)
            sa, st = a * r, t * r
    else:
        ra = ceil(sa / a)
        if st <= t * ra:
            sa, st = a * ra, t * ra
        else:
            rt = ceil(st / t)
            sa, st = a * rt, t * rt

print(sa + st)

Submission status: Wrong Answer

Solution code:
N  = int(raw_input())

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

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

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

    if i != 0:
        while (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]

            else:
                m = A[i - 1] - A[i]

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

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

print sum(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A, T =[1, 1]
for i in range(N):
    newA, newT = [int(j) for j in input().split()]
    minimal_ratio = 1
    if newA < A:
        minimal_ratio = math.ceil(A/ newA)
    if newT < T:
        minimal_ratio = max(minimal_ratio,math.ceil(T / newT))
    A = minimal_ratio*newA
    T = minimal_ratio*newT
print(A+T)

Submission status: Wrong Answer

Solution code:


N = int(input())
T = list()
A = list()

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

ans = 1

for i in range(N):
    while (ans % (T[i] + A[i])) != 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:


N = int(input())
T = list()
A = list()

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

ans = 1

for i in range(N):
    while (ans % (T[i] + A[i])) != 0:
        ans += 1
    print(ans)

print(ans)