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:
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""

#B
"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""

#C
"""
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
"""

#D
"""
n = II()
d = LIR(n)
q = II()
p = IIR(q)
d.insert(0,[0 for i in range(n+1)])
for i in range(n):
    d[i+1].insert(0,0)
for i in range(n):
    for j in range(n):
        d[i+1][j+1] += d[i+1][j]+d[i][j+1]-d[i][j]
ans = [0 for i in range(n**2+1)]

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

for i in p:
    an = 0
    for a in range(i+1):
        an = max(an, ans[a])
    print(an)
"""
#E

"""
s = list(S())
ans = -1
s.insert(0,0)
d = 0
for i in range(1,len(s)):
    if s[i] != d:
        d = s[i]
        ans += 1
print(ans)
"""

#F
n = II()
x,y = LI()
for _ in range(n-1):
    a,b = LI()
    if a == b:
        x = max(x,y)
        y = x
    else:
        for i in range(10000):
            if (a*y-b*x+a*i)%b == 0 and a*y-b*x+a*i >= 0:break
        x += (a*y-b*x+a*i)//b
        y += i
print(x+y)
#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Wrong Answer

Solution code:
#a
"""
import math
a, b = map(str, input().split())
j = int(a + b)
if math.sqrt(j).is_integer():
    print("Yes")
else:
    print("No")
"""

#b
"""
ans = ["Positive","Negative"]
a, b = map(int, input().split())
if 0 < a:
    print("Positive")
elif b >= 0:
    print("Zero")
else:
    print(ans[(b-a)%2-1])
"""

#C
"""
import itertools
n = int(input())
MARCH = ["M", "A", "R", "C", "H"]
march = [0 for _ in range(5)]
for i in range(n):
    s = input()
    if s[0] in MARCH:
        march[MARCH.index(s[0])] += 1
num = list(range(5))
a = list(itertools.combinations(num, 3))
ans = 0
for i in a:
    bf = 1
    for k in i:
        bf *= march[k]
    ans += bf
print(ans)
"""

#D
"""
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]
q = int(input())
p = [int(input()) for _ in range(q)]
for i in range(n):
    D[i].insert(0, 0)
    D[i].insert(n+1, 0)
D.insert(0,[0 for _ in range(n + 2)])
D.insert(n + 2, [0 for _ in range(n + 2)])
print(D)
"""

#E
"""
s = input()
bf = s[0]
ans = 0
for i in range(1,len(s)):
    if bf != s[i]:
        ans += 1
        bf = s[i]
print(ans)
"""

#F
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
bf = ta[0]
ans = ta[0]
for i in ta:
    if bf == i:
        continue
    elif bf[0] <= i[0] and bf[1] <= i[1]:
        ans[0] += i[0] - bf[0]
        ans[1] += i[1] - bf[1]
        bf = ans
    else:
        a = i[0]
        b = i[1]
        while bf[0] > i[0] or bf[1] > i[1]:
            i[0] += a
            i[1] += b
        ans[0] += i[0] - bf[0]
        ans[1] += i[1] - bf[1]
        bf = ans
        print(bf)
print(ans[0]+ans[1])

Submission status: Wrong Answer

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

p,q = 0,0
for i in range(n):
    tmp = max(p//t[i]+1,q//a[i]+1)
    p = t[i]*tmp 
    q = a[i]*tmp
print(p+q)

Submission status: Wrong Answer

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

p,q = 0,0
for i in range(n):
    tmp = max(p//t[i],q//a[i])
    p = t[i]*tmp 
    q = a[i]*tmp
print(p+q)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
ans1 = 0
ans2 = 0
for i in range(N) :
    t,a = map(int,input().split())
    if (ans1 <= t) and (ans2 <= a) :
        ans1 = t
        ans2 = a
    else :
        if (ans1 > t) and (ans2 <= a) :
            mu = ceil(ans1/t)
        elif (ans1 <= t) and (ans2 > a) :
            mu = ceil(ans2/a)
        else :
            mu1 = ceil(ans1/t)
            mu2 = ceil(ans2/a)
            mu = max(mu1,mu2)
        ans1 = mu*t
        ans2 = mu*a
ans = ans1+ans2
print(ans)

Submission status: Wrong Answer

Solution code:
import decimal
N=int(input())

Taka,Ao=map(int,input().split())


for i in range(N-1):
    T,A=map(int,input().split())
    """if T>=Taka and A>=Ao:
        Taka=T
        Ao=A"""
    if Taka/T > Ao/A:
        if decimal.Decimal(Taka/T)==int(Taka/T):
            Taka0=T*int(Taka/T)
            Ao0=A*int(Taka/T)
            Taka=Taka0
            Ao=Ao0
        else:
            Taka0=T*(int(Taka/T)+1)
            Ao0=A*(int(Taka/T)+1)
            Taka=Taka0
            Ao=Ao0
    else:
        if decimal.Decimal(Ao/A)==int(Ao/A):
            Ao0=A*int(Ao/A)
            Taka0=T*int(Ao/A)
            Ao=Ao0
            Taka=Taka0
        else:
            Taka0=T*(int(Ao/A)+1)
            Ao0=A*(int(Ao/A)+1)
            Taka=Taka0
            Ao=Ao0
print(Taka+Ao)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

import math

N = int(input())
for i in range(0, N):
    t, a = map(int, input().split())
    if i == 0:
        tt = t
        aa = a
    else:
        rt = math.ceil(tt / t)
        ra = math.ceil(aa / a)
        ratio = max(rt, ra)
        tt = t * ratio
        aa = a * ratio
    # print("{} {}".format(tt, aa))

print("{}".format(tt + aa))

Submission status: Wrong Answer

Solution code:
s = input()
hmp = 0
ans = 0
for i in s:
    if i == 'g' and hmp > 0:
        hmp -= 1
        ans += 1
    elif i == 'g':
        hmp += 1
    elif hmp > 0:
        hmp -= 1
    else:
        hmp += 1
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l ,r = 1, 1
import math as m
for i in range(n):
    t, a = list(map(int, input().split()))

    k = max(m.ceil(l/t), m.ceil(r/a))
    l = t*k
    r = a*k
print(l+r)

Submission status: Wrong Answer

Solution code:
from math import *

def up(a, b):
	ans = trunc(a / b)

	if abs(a) % abs(b) > 0:
		ans += 1

	return ans

def down(a, b):
	ans = trunc(a / b)

	if abs(a) % abs(b) > 0:
		ans -= 1

	return ans

def egcd(a, b):
	xx = y = 0
	yy = x = 1

	while b != 0:
		q = trunc(a / b)
		t = b; b = a % b; a = t;
		t = xx; xx = x - q * xx; x = t;
		t = yy; yy = y - q * yy; y = t;

	return [ a, x, y ]

n = int(input())

A = [ 0 for i in range(n) ]
B = [ 0 for i in range(n) ]

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

for i in range(0, n - 1):
	a = A[i]
	b = B[i]
	c = A[i + 1]
	d = B[i + 1]

	o = egcd(d, c)

	g = o[0]
	x = o[1]
	y = o[2]

	v = (c * b - d * a) // g
	x = x * v
	y = -y * v

	k_neg = max(up(x * g, c), up(y * g, d)) + 1

	x = x - k_neg * c // g
	y = y - k_neg * d // g

	k = min(down(x * g, c), down(y * g, d))

	x = x - k * c // g
	y = y - k * d // g

	A[i + 1] = a + x
	B[i + 1] = b + y

print(A[n - 1] + B[n - 1])

Submission status: Wrong Answer

Solution code:
from math import *

def up(a, b):
	ans = trunc(a / b)

	if abs(a) % abs(b) > 0:
		ans += 1

	return ans

def down(a, b):
	ans = trunc(a / b)

	if abs(a) % abs(b) > 0:
		ans -= 1

	return ans

def egcd(a, b):
	xx = y = 0
	yy = x = 1

	while b != 0:
		q = a // b
		t = b; b = a % b; a = t;
		t = xx; xx = x - q * xx; x = t;
		t = yy; yy = y - q * yy; y = t;

	return [ a, x, y ]

n = int(input())

A = [ 0 for i in range(n) ]
B = [ 0 for i in range(n) ]

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

for i in range(0, n - 1):
	a = A[i]
	b = B[i]
	c = A[i + 1]
	d = B[i + 1]

	o = egcd(d, c)

	g = o[0]
	x = o[1]
	y = o[2]

	v = (c * b - d * a) // g
	x = x * v
	y = -y * v

	k_neg = max(up(x * g, c), up(y * g, d)) + 1

	x = x - k_neg * c // g
	y = y - k_neg * d // g

	k = min(down(x * g, c), down(y * g, d))

	x = x - k * c // g
	y = y - k * d // g

	A[i + 1] = a + x
	B[i + 1] = b + y

print(A[n - 1] + B[n - 1])

Submission status: Wrong Answer

Solution code:
from math import *

def egcd(a, b):
	xx = y = 0
	yy = x = 1

	while b > 0:
		q = a // b
		t = b; b = a % b; a = t;
		t = xx; xx = x - q * xx; x = t;
		t = yy; yy = y - q * yy; y = t;

	return [ a, x, y ]

n = int(input())

A = [ 0 for i in range(n) ]
B = [ 0 for i in range(n) ]

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

ans = A[0] + B[0]

for i in range(0, n - 1):
	a = A[i]
	b = B[i]
	c = A[i + 1]
	d = B[i + 1]

	o = egcd(d, c)

	g = o[0]
	x = o[1]
	y = o[2]

	v = (c * b - d * a) // g
	x = x * v
	y = -y * v

	k_neg = max(ceil(x * g / c), ceil(y * g / d)) + 1

	x = x - k_neg * c // g
	y = y - k_neg * d // g

	k = min(floor(x * g / c), floor(y * g / d))

	x = x - k * c // g
	y = y - k * d // g

	A[i + 1] = a + x
	B[i + 1] = b + y

print(A[n - 1] + B[n - 1])

Submission status: Wrong Answer

Solution code:
from math import ceil
N=int(input())
table=[]
for i in range(N):
    t,x=map(int,input().split())
    table.append((t,x))
A,B=1,1
for x,y in table:
    t=max(ceil(A/x),ceil(B/y))
    A=t*x
    B=t*y
print(A+B)

Submission status: Wrong Answer

Solution code:
taka, aoki = 1, 1
for _ in range(int(input())):
    a, b = map(int, input().split())
    ratio = max(-(-taka//a), -(-aoki//b))
    print(ratio)
    taka = ratio * a
    aoki = ratio * b
print(taka + aoki)

Submission status: Wrong Answer

Solution code:
taka, aoki = 1, 1
for _ in range(int(input())):
    a, b = map(int, input().split())
    ratio = max(taka//a + [0, 1][taka%a != 0], aoki//b + [0, 1][aoki%b != 0])
    taka = a * ratio
    aoki = b * ratio
    print(taka, aoki)
print(taka + aoki)

Submission status: Wrong Answer

Solution code:
from fractions import math

N = int(input())

T,A = 0,0

for i in range(N):
    F = 0
    Ti,Ai = map(int,input().split())
    if Ti<T: F += 2
    if Ai<A: F += 1
    
    if F==3: #両方大
        K = max(math.ceil(T/Ti),math.ceil(A/Ai))
        T = Ti*K
        A = Ai*K
        
    elif F==2: #T側大
        K = math.ceil(T/Ti)
        T = Ti*K
        A = Ai*K
        
    elif F==1: #A側大
        K = math.ceil(A/Ai)
        T = Ti*K
        A = Ai*K
        
    else: #両方小
        T = Ti
        A = Ai
        
print(T+A)

Submission status: Wrong Answer

Solution code:
from fractions import math

N = int(input())

T,A = 0,0

for i in range(N):
    F = 0
    Ti,Ai = map(int,input().split())
    if 1<T/Ti: F += 2
    if 1<A/Ai: F += 1
    
    if F==3: #両方大
        K = max(math.ceil(T/Ti),math.ceil(A/Ai))
        T = Ti*K
        A = Ai*K
        
    elif F==2: #T側大
        K = math.ceil(T/Ti)
        T = Ti*K
        A = Ai*K
        
    elif F==1: #A側大
        K = math.ceil(A/Ai)
        T = Ti*K
        A = Ai*K
        
    else: #両方小
        T = Ti
        A = Ai
        
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

numT, numA = 1, 1
for T, A in TAs:
    m = max(ceil(numT / T), ceil(numA / A))
    numT, numA = m * T, m * A

print(numT + numA)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

numT, numA = TAs[0]
for T, A in TAs:
    m = max(ceil(numT / T), ceil(numA / A))
    numT, numA = m * T, m * A

print(numT + numA)

Submission status: Wrong Answer

Solution code:
N=int(input())
A,B=map(int,input().split())
for i in range(N-1):
    a,b=map(int,input().split())
    if a>=A and b>=B:
        A=a
        B=b
    else:
        if (a/A) < (b/B):
            if a*int(A/a)>=A and b*int(A/a)>=B:
                A1=a*int(A/a)
                B1=b*int(A/a)
            else:
                A1=a*int(A/a+1)
                B1=b*int(A/a+1)
        else:
            if a*int(B/b)>=A and b*int(B/b)>=B:
                A1=a*int(B/b)
                B1=b*int(B/b)
            else:
                A1=a*int(B/b+1)
                B1=b*int(B/b+1)
        A=A1
        B=B1
    #print(A,B)
print(A+B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())
t = []
a = []
for _ in range(n):
    line = input().split(" ")
    t.append(int(line[0]))
    a.append(int(line[1]))

T = 1
A = 1

for i in range(n):
    c = max(math.ceil(T/t[i]), math.ceil(A/a[i]))
    T = t[i]*c
    A = a[i]*c

print(T+A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())
t = []
a = []
for _ in range(n):
    line = input().split(" ")
    t.append(int(line[0]))
    a.append(int(line[1]))

T = t[0]
A = a[0]

for i in range(1,n):
    c = max(math.ceil(T/t[i]), math.ceil(A/a[i]))
    T = t[i]*c
    A = a[i]*c

print(T+A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
n = int(input())
t = []
a = []
for _ in range(n):
    line = input().split(" ")
    t.append(int(line[0]))
    a.append(int(line[1]))

T = t[0]
A = a[0]

for i in range(1,n):
    c = math.ceil(max(T/t[i], A/a[i]))
    T = t[i]*c
    A = a[i]*c

print(T+A)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 2
tp, ap = 1, 1
for i in range(N):#ans以上での比からの最小値でans更新,
    #A+Tのn倍、ただしn>=ans/(t+a)
    t, a = map(int, input().split())
    k = max(math.ceil(tp/t), math.ceil(ap/a))
    t, a = t*k, a*k
    c = math.ceil(ans/(t+a))
    while True:#ansが前回のans以上になるようにする
        if (t+a)*c >= ans:
            ans = (t+a)*c
            break
        c += 1
    tp, ap = t*c, a*c
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from decimal import *
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max(t//x + (1 if t%x else 0),a//y + (1 if t%y else 0))
    t=x*nxt
    a=y*nxt
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nt,na=t/x,a/y
    if nt==int(nt):
        nt-0.1
    if na==int(na):
        na-0.1
    nxt=max(math.ceil(nt),math.ceil(na))
    t=x*nxt
    a=y*nxt
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max(math.floor(t/x+0.9999999),math.floor(a/y+0.9999999))
    t=x*nxt
    a=y*nxt
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max((t/x+0.5)//1,(a/y+0.5)//1)
    t=x*nxt
    a=y*nxt
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max(int(t/x+0.5),int(a/y+0.5))
    t=x*nxt
    a=y*nxt
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
log=[]
H=[]
for i in range(n):
    log.append(tuple(map(int,input().split())))
t,a=1,1
for x,y in log:
    nxt=max(math.ceil(t/x),math.ceil(a/y))
    t=x*nxt
    a=y*nxt
print(t+a)

Submission status: Wrong Answer

Solution code:
import math

a=b=1
for i in range(int(input())):
    p,q=map(int,input().split())
    x=math.ceil(max(a/p,b/q))
    a,b=p*x,q*x
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

TT = 0
AA = 0

for i in range(N):
    T, A = map(int, input().split())
    if TT == 0:
        TT = T
        AA = A
    else:
        ratioT = TT / T
        ratioA = AA / A
        ratio = math.ceil(max(ratioT, ratioA))
        #print(ratioT,ratioA,ratio)
        TT = T * ratio
        AA = A * ratio
        #print(TT,AA)
    #math.ceil(x)
    #max(x, y)

print(TT+AA)

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

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=1
for i in range(N):
  a,b=map(int,input().split())
  ans=(a+b)*math.ceil(ans/(a+b))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(raw_input())
votes = []
for _ in range(N):
	t, a = map(int, raw_input().split())
	votes.append((t, a))

pt, pa = 0, 0

for v in votes:
	if (v[0] >= pt and v[1] >= pa):
		pt, pa = v[0], v[1]
	else:
		if (pt % v[0]):
			nt = pt / v[0] + 1
		else:
			nt = pt / v[0]
		if (pa % v[1]):
			na = pa / v[1] + 1
		else:
			na = pa / v[1]
		m = max(nt, na)
		pt, pa = v[0] * m, v[1] * m
	print '(pt, pa) : ' + str((pt, pa))

print str(pt + pa)

Submission status: Wrong Answer

Solution code:
import math

def cceil(x,y):
	res = x //y
	if x % y != 0:res += 1
	return res

def gcd(x, y):
	if(x == 0):return y
	return gcd(y % x, x)
 
def main():
    votes = int(input())
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]
 
    votesTemp = [0, 0]
    for i in range(votes):
        if i == 0:
            votesTemp = ratio[i]
            continue
        if(gcd(ratio[i][0], ratio[i][1]) != 1):
        	x = 1 / 0
        ceil = [ cceil(votesTemp[j], ratio[i][j]) for j in range(2)]
 
        votesTemp = [ max(ceil) * ratio[i][j] for j in range(2) ]
 
        print("turn: " + str(i))
        print("votes: " + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print("Temp: " +str(votesTemp[0])+":"+str(votesTemp[1]))
        
    print(sum(votesTemp))
 
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math
 
def gcd(x, y):
	if(x == 0):return y
	return gcd(y % x, x)
 
def main():
    votes = int(input())
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]
 
    votesTemp = [0, 0]
    for i in range(votes):
        if i == 0:
            votesTemp = ratio[i]
            continue
        if(gcd(ratio[i][0], ratio[i][1]) != 1):
        	x = 1 / 0
        ceil = [ math.ceil(votesTemp[j] / ratio[i][j]) for j in range(2)]
 
        votesTemp = [ max(ceil) * ratio[i][j] for j in range(2) ]
 
        print("turn: " + str(i))
        print("votes: " + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print("Temp: " +str(votesTemp[0])+":"+str(votesTemp[1]))
        
    print(sum(votesTemp))
 
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    votes = int(input())
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    votesTemp = [0, 0]
    for i in range(votes):
        if i == 0:
            votesTemp = ratio[i]
            continue

        ceil = [ math.ceil(votesTemp[j] / ratio[i][j]) for j in range(2)]

        votesTemp = [ max(ceil) * ratio[i][j] for j in range(2) ]

        """
        print("turn: " + str(i))
        print("votes: " + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print("Temp: " +str(votesTemp[0])+":"+str(votesTemp[1]))
        """
    print(sum(votesTemp))

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    votes = int(input());
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    votesTemp = [0, 0]
    for i in range(votes):
        floor = [ math.ceil(votesTemp[j] / ratio[i][j]) for j in range(2)]

        times = max(floor)
        if times == 0: times = 1
        votesTemp = [ times * ratio[i][j] for j in range(2) ]

        """
        print("turn: " + str(i))
        print("votes: " + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print("Temp: " +str(votesTemp[0])+":"+str(votesTemp[1]))
        """
    print(sum(votesTemp))

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:

def main():
    votes = int(input());
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    tak = aok = 0
    for i in range(votes):
        takTemp,  aokTemp = ratio[i][0], ratio[i][1]

        while tak > takTemp or aok > aokTemp:
            takTemp += ratio[i][0]
            aokTemp += ratio[i][1]

        tak, aok = takTemp, aokTemp

        #print("turn:" + str(i))
        #print("votes:" + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print(tak, aok)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:

def main():
    votes = int(input());
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    tak = aok = 0
    for i in range(votes):
        takTemp,  aokTemp = ratio[i][0], ratio[i][1]

        while tak > takTemp or aok > aokTemp:
            takTemp += ratio[i][0]
            aokTemp += ratio[i][1]

        tak, aok = takTemp, aokTemp

        #print("turn:" + str(i))
        #print("votes:" + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print(tak, aok)


    print(tak + aok)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:

def main():
    votes = int(input());
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    tak = aok = 0
    for i in range(votes):
        takTemp,  aokTemp = ratio[i][0], ratio[i][1]

        while tak > takTemp or aok > aokTemp:
            takTemp += ratio[i][0]
            aokTemp += ratio[i][1]

        tak, aok = takTemp, aokTemp

        print("turn:" + str(i))
        print("votes:" + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print(tak, aok)


    print(tak + aok)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

N=int(raw_input())

a_num = 1
b_num = 1

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        base_n = max(math.floor(a_num / ratio_a), math.floor(b_num / ratio_b))

        if (ratio_a * base_n) < a_num:
                base_n += 1

        if (ratio_b * base_n) < b_num:
                base_n += 1

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print int(a_num + b_num)

Submission status: Wrong Answer

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

N=int(raw_input())

a_num = 1
b_num = 1

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        base_n = max(math.floor(a_num / ratio_a), math.floor(b_num / ratio_b))

        while a_num > ratio_a * base_n or b_num > ratio_b * base_n:
                base_n += 1

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print int(a_num + b_num)

Submission status: Wrong Answer

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

N=int(raw_input())

a_num = 1
b_num = 1

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        base_n = max(math.floor(a_num / ratio_a), math.floor(b_num / ratio_b))

        while a_num > ratio_a * base_n or b_num > ratio_b * base_n:
                base_n += 1

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n
        print "current point :    ",int(a_num),int(b_num)

print int(a_num + b_num)

Submission status: Wrong Answer

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

N=int(raw_input())

a_num = 0
b_num = 0

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        # 初期化
        if a_num == 0 or b_num == 0:
                a_num = ratio_a
                b_num = ratio_b
                continue

        base_n = max(math.floor(a_num / ratio_a), math.floor(b_num / ratio_b))

        while a_num > ratio_a * base_n or b_num > ratio_b * base_n:
                base_n += 1

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print int(a_num + b_num)

Submission status: Wrong Answer

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

N=int(raw_input())

a_num = 0
b_num = 0

for i in xrange(N):
        ratio_a, ratio_b = map(int,raw_input().split())

        # 初期化
        if a_num == 0 or b_num == 0:
                a_num = ratio_a
                b_num = ratio_b
                continue

        base_n = max(math.ceil(a_num / ratio_a), math.ceil(b_num / ratio_b))

        while a_num > ratio_a * base_n or b_num > ratio_b * base_n:
                base_n += 1

        a_num = ratio_a * base_n
        b_num = ratio_b * base_n

print int(a_num + b_num)

Submission status: Wrong Answer

Solution code:
n = int(raw_input().rstrip())
import math

score_a = 1
score_b = 1

for i in xrange(n):
  a, b = map(float,raw_input().rstrip().split(" "))
  p_a = math.ceil(score_a / a)
  p_b = math.ceil(score_b / b)
  p = max(p_a,p_b)
  score_a = a * p
  score_b = b * p

print int(score_a + score_b)

Submission status: Wrong Answer

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


t_min =1
a_min =1
def f(t,a,t_min,a_min):
    #div_t *t >= t_min
    div_t = math.ceil(t_min/t)
    div_a = math.ceil(a_min /a)
    div =max(div_t, div_a)
    return (t*div,a*div)


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


    t_min2,a_min2 = f(t,a,t_min,a_min)

    t_min = t_min2
    a_min = a_min2


#print(t_min,a_min)
print(t_min+a_min)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N = int(input())

va, vb = 1, 1
for i in range(N):
    pa, pb = [int(x) for x in input().split(" ")]
    r = int(max((va + pa - 1) // pa, (vb + pb - 1) / pb))
    va = pa * r
    vb = pb * r
print(va + vb)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N = int(input())

va, vb = 1, 1
for i in range(N):
    pa, pb = [int(x) for x in input().split(" ")]
    r = int(max((va + pa - 1) / pa, (vb + pb - 1) / pb))
    va = pa * r
    vb = pb * r
print(va + vb)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N = int(input())

va, vb = 1, 1
for i in range(N):
    pa, pb = [int(x) for x in input().split(" ")]
    r = math.ceil(max(va/pa, vb/pb))
    va = pa * r
    vb = pb * r
print(va + vb)

Submission status: Wrong Answer

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

TA.reverse()
(voteA, voteB) = (1,1)
while TA:
	(Ti, Ai) = TA.pop()
	tmp = max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
	voteA = Ti * tmp
	voteB = Ai * tmp
print(voteA + voteB)