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:
from math import ceil
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t / T), ceil(a / A))
  t = T * rate
  a = A * rate
print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  if t <= T and a <= A:
    t = T
    a = A
  elif t > T and a <= A:
    rate = ceil(t / T)
    t = T * rate
    a = A * rate
  elif t <= T and a > A:
    rate = ceil(a / A)
    t = T * rate
    a = A * rate
  else:
    rate = max(ceil(t / T), ceil(a / A))
    t = T * rate
    a = A * rate
print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 0, 0
for T, A in TA:
  if t <= T and a <= A:
    t = T
    a = A
  elif t > T and a <= A:
    rate = ceil(t / T)
    t = T * rate
    a = A * rate
  elif t <= T and a > A:
    rate = ceil(a / A)
    t = T * rate
    a = A * rate
  else:
    rate = max(ceil(t / T), ceil(a / A))
    t = T * rate
    a = A * rate
print(t + a)

Submission status: Wrong Answer

Solution code:

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

lcms = TA[0]

for t,a in TA[1:]:
    tmp = [t,a]
    
    if tmp[0] < lcms[0]:
        m = (lcms[0]+tmp[0]-1)//tmp[0]
        tmp[0] *= m
        tmp[1] *= m
    if tmp[1] < lcms[1]:
        m = (lcms[1]+tmp[1]-1)//tmp[1]
        tmp[0] *= m
        tmp[1] *= m
    lcms = tmp

print(sum(lcms))

Submission status: Wrong Answer

Solution code:

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

lcms = TA[0]

for t,a in TA[1:]:
    print(t,a,lcms)
    tmp = [t,a]
    
    while tmp[0] < lcms[0]:
        tmp[0] += t
        tmp[1] += a
    while tmp[1] < lcms[1]:
        tmp[0] += t
        tmp[1] += a
    lcms = tmp

print(sum(lcms))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  magni = max(math.ceil(t_vote / t), math.ceil(a_vote / a))
  t_vote = int(magni) * t
  a_vote = int(magni) * a
  count += 1
print(t_vote + a_vote)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  magni = max(1, math.ceil(t_vote / t), math.ceil(a_vote / a))
  t_vote = magni * t
  a_vote = magni * a
  count += 1
print(t_vote + a_vote)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  magni = max(1, math.ceil(t_vote / t), math.ceil(a_vote / a))
  t_vote = magni * t
  a_vote = magni * a
  count += 1
  print("{} {}".format(t_vote, a_vote))
print(t_vote + a_vote)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  magni = max(math.ceil(t_vote / t), math.ceil(a_vote / a))
  t_vote = magni * t
  a_vote = magni * a
  count += 1
print(t_vote + a_vote)

Submission status: Wrong Answer

Solution code:
n = int(input())
t_vote = 1
a_vote = 1
count = 0
while count < n:
  t, a = map(int, input().split(" "))
  if t_vote == a_vote:
    if t < a:
      while t_vote % t != 0:
        t_vote += 1
      a_vote = int((t_vote / t) * a)
    else:
      while a_vote % a != 0:
        a_vote += 1
      t_vote = int((a_vote / a) * t)
  elif t_vote > a_vote:
    while t_vote % t != 0:
      t_vote += 1
    a_vote = int((t_vote / t) * a)
  else:
    while a_vote % a != 0:
      a_vote += 1
    t_vote = int((a_vote / a) * t)
  count += 1
print(t_vote + a_vote)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from math import ceil

n = int(input())
ta = [map(int, input().split()) for _ in range(n)]

votes = [1, 1]

for t, a in ta:
    mul = max(ceil(Fraction(votes[0] / t)), ceil(Fraction(votes[1] / a)))
    votes = [t * mul, a * mul]

ans = sum(votes)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
ta = [map(int, input().split()) for _ in range(n)]

votes = [1, 1]

for t, a in ta:
    mul = max(ceil(votes[0] / t), ceil(votes[1] / a))
    votes = [t * mul, a * mul]

ans = sum(votes)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
l = []
r = []
for i in range(n):
    q,w = inpl()
    l.append(q)
    r.append(w)
for i in range(n-1):
    if l[i+1] >= l[i] and r[i+1] >= r[i]:
        continue
    tmp = int(max(math.ceil(l[i]/l[i+1]), math.ceil(r[i]/r[i+1])))
    l[i+1] *= tmp
    r[i+1] *= tmp
print(l[n-1] + r[n-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
l = []
r = []
for i in range(n):
    q,w = inpl()
    l.append(q)
    r.append(w)
for i in range(n-1):
    if l[i+1] >= l[i] and r[i+1] >= r[i]:
        continue
    tmp = max(math.ceil(l[i]/l[i+1]), math.ceil(r[i]/r[i+1]))
    l[i+1] *= tmp
    r[i+1] *= tmp
print(l[n-1] + r[n-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
for i in range(N):
    if i == 0:
        X, Y = map(int, input().split())
        #print(f'X:{X} Y:{Y}')
        continue
    T, A = map(int, input().split())
    if T == A:
        X = max(X, Y)
        Y = max(X, Y)
        #print(f'X:{X} Y:{Y}')
        continue
    elif not (X > Y)^(T > A):
        X = (X + X%T)
        Y = X//T * A
        #print(f'X:{X} Y:{Y}')
    else:
        tmp = max(-(-X//T), -(-Y//A))
        X = T*tmp
        Y = A*tmp
        #print(f'X:{X} Y:{Y}')
        
print(X+Y)

Submission status: Wrong Answer

Solution code:
N = int(input())
for i in range(N):
    if i == 0:
        X, Y = map(int, input().split())
        #print(f'X:{X} Y:{Y}')
        continue
    T, A = map(int, input().split())
    if T == A:
        #print(f'X:{X} Y:{Y}')
        continue
    elif not (X > Y)^(T > A):
        X = (X + X%T)
        Y = X//T * A
        #print(f'X:{X} Y:{Y}')
    else:
        tmp = max(-(-X//T), -(-Y//A))
        X = T*tmp
        Y = A*tmp
        #print(f'X:{X} Y:{Y}')
        
print(X+Y)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
if n>=2:
    lists=[]
    for x in range(n):
        x,y=map(int,input().split())
        lists.append([x,y])
    lists.append([1,1])
    a=lists[0][0]
    b=lists[0][1]
    cnt=0
    while cnt<n:
        k=max(math.ceil(a/lists[cnt+1][0]),math.ceil(b/lists[cnt+1][1]))
        a=lists[cnt+1][0]*k
        b=lists[cnt+1][1]*k 
        if cnt==n-2:
            ans=a
            anss=b

        cnt+=1    
    print(ans+anss)
else:
    x,y=map(int,input().split())
    print(x+y)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
lists=[]
for x in range(n):
    x,y=map(int,input().split())
    lists.append([x,y])
lists.append([1,1])
a=lists[0][0]
b=lists[0][1]
cnt=0
while cnt<n:
    k=max(math.ceil(a/lists[cnt+1][0]),math.ceil(b/lists[cnt+1][1]))
    a=lists[cnt+1][0]*k
    b=lists[cnt+1][1]*k   
    cnt+=1    

print(a+int(a*(min(lists[n-1][0],lists[n-1][1])/max(lists[n-1][0],lists[n-1][1]))))

Submission status: Wrong Answer

Solution code:
#greedy方法
import math
n=int(input())
lists=[]
for x in range(n):
    x,y=map(int,input().split())
    lists.append([x,y])
lists.append([1,1])
a=lists[0][0]
b=lists[0][1]
k=0
cnt=0
while cnt<n:
    k=max(math.ceil(a/lists[cnt+1][0]),math.ceil(b/lists[cnt+1][1]))
    a=lists[cnt+1][0]*k
    b=lists[cnt+1][1]*k   
    cnt+=1    
print(a+int(a*(min(lists[n-1][0],lists[n-1][1])/max(lists[n-1][0],lists[n-1][1])) ))

Submission status: Wrong Answer

Solution code:
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi / t), -(-aoki / a))
        # k = max(math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = 1, 1
    for t, a in ta:
        k = max(1, math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = 1, 1
    for t, a in ta:
        k = max(math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
t, a = map(int, input().split())
for _ in range(N-1):
    T, A = map(int, input().split())
    k = int(max(ceil(t/T), ceil(a/A)))
    t, a = k*T, k*A
print(t+a)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
input = sys.stdin.readline

def main():
    N = int(input())
    ta = [list(map(int, input().split())) for i in range(N)]

    a, b = ta[0]
    for i in range(1, N):
        x, y = ta[i]
        n = max(ceil(a/x), ceil(b/y))
        a = n * x
        b = n * y
        # print(a, b)
    print(a+b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
l = []
l.append(list(map(int, input().split())))
for i in range(N - 1):
    l.append(list(map(int, input().split())))
    if (l[i][0] > l[i + 1][0]) or (l[i][1] > l[i + 1][1]):
        TA = [l[i][0] / l[i + 1][0], l[i][1] / l[i + 1][1]]
        l[i + 1][0] *= math.ceil(max(TA))
        l[i + 1][1] *= math.ceil(max(TA))
print(sum(l[-1]))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A, T = [0] * N, [0] * N
T[0], A[0] = map(int, input().split())

for i in range(1, N):
  dt, da = map(int, input().split())
  
  n = math.ceil(max(T[i-1]/dt-1, A[i-1]/da-1, 0))
  
  T[i], A[i] = dt * (n+1), da * (n+1)
  
print(A[N-1] + T[N-1])

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
B=[]


for i in range(N):
    a,b, = map(int, input().split())
    B.append([a,b])

a=1
b=1

for i in range(N):
        a=max(math.ceil(a/B[i][0]),math.ceil(b/B[i][1]))*B[i][0]
        b=max(math.ceil(a / B[i][0]), math.ceil(b / B[i][1])) * B[i][1]

print(a+b)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
B=[]


for i in range(N):
    a,b, = map(int, input().split())
    B.append([a,b])

a=B[0][0]
b=B[0][1]

for i in range(1,N):
        a=max(math.ceil(a/B[i][0]),math.ceil(b/B[i][1]))*B[i][0]
        b=max(math.ceil(a / B[i][0]), math.ceil(b / B[i][1])) * B[i][1]

print(a+b)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
B=[]


for i in range(N):
    a,b, = map(int, input().split())
    B.append([a,b])

a=B[0][0]
b=B[0][1]

for i in range(1,N):
    if a>B[i][0] or b>B[i][1]:
        a=max(math.ceil(a/B[i][0]),math.ceil(b/B[i][1]))*B[i][0]
        b=max(math.ceil(a / B[i][0]), math.ceil(b / B[i][1])) * B[i][1]
    else:
        a=B[i][0]
        b=B[i][1]
    
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

s0 = 2
t0 = a0 = 1
for i in range(n):
    t, a = map(int, input().split())

    m = max((t0 + t - 1) // t,
            (a0 + a - 1) // a)
    # m = max(math.ceil(t0 / t),
    #         math.ceil(a0 / a))

    t0, a0 = t * m, a * m
    s0 = t0 + a0
    print(s0, t0, a0, m)

print(s0)

Submission status: Wrong Answer

Solution code:
import math
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

n = int(input())

t, a = map(int, input().split())
t0, a0 = t, a
s = t + a
for i in range(1, n):
    # print(s, t0, a0)
    t, a = map(int, input().split())
    g = GCD(t, a)
    t, a = t // g, a // g

    m = max(
            math.ceil(t0 / t),
            math.ceil(a0 / a))
    s =  (t+a) * m
    t0, a0 = t * m, a * m

print(s)

Submission status: Wrong Answer

Solution code:
import math
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

n = int(input())

s = 2
t0 = a0 = 1
for i in range(n):
    # print(s, t0, a0)
    t, a = map(int, input().split())
    g = GCD(t, a)
    t, a = t // g, a // g

    m = max(math.ceil(s / (t+a)),
            math.ceil(t0 / t),
            math.ceil(a0 / a))
    s =  (t+a) * m
    t0, a0 = t * m, a * m

print(s)

Submission status: Wrong Answer

Solution code:
import math
def GCD(a:int , b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

n = int(input())

t, a = map(int, input().split())
t0, a0 = t, a
s = t + a
for i in range(1, n):
    # print(s, t0, a0)
    t, a = map(int, input().split())
    g = GCD(t, a)
    t, a = t // g, a // g

    m = max(math.ceil(s / (t+a)),
            math.ceil(t0 / t),
            math.ceil(a0 / a))
    s =  (t+a) * m
    t0, a0 = t * m, a * m

print(s)

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve(n):
    prev_t, prev_a = -1, -1
    for _ in range(n):
        t, a = map(int, input().split())
        x = 1
        if t < prev_t or a < prev_a:
            div_t = ceil(prev_t/t)
            div_a = ceil(prev_a/a)
            if t < prev_t and a < prev_a:
                x = max(div_t, div_a)
            elif t < prev_t:
                x = div_t
            else:
                x = div_a
        prev_t, prev_a = t*x, a*x

    return prev_t+prev_a


if __name__ == '__main__':
    n = int(input())
    print(solve(n))

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve(n):
    prev_t, prev_a = -1, -1
    for _ in range(n):
        t, a = map(int, input().split())
        if t <= prev_t or a <= prev_a:
            div_t = ceil(prev_t/t)
            div_a = ceil(prev_a/a)
            if t <= prev_t and a <= prev_a:
                x = max(div_t, div_a)
                prev_t = t*x
                prev_a = a*x
            elif t <= prev_t:
                x = div_t
                prev_t = t*x
                prev_a = a*x
            else:
                x = div_a
                prev_t = t*x
                prev_a = a*x
        else:
            prev_t, prev_a = t, a

    return prev_t+prev_a


if __name__ == '__main__':
    n = int(input())
    print(solve(n))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ratio_list = [list(map(int, input().split(' '))) for i in range(N)]
#print(ratio)

Tnum = 1
Anum = 1

for ratio in ratio_list:
    k = 1
    k = max(math.ceil(Tnum / ratio[0]), math.ceil(Anum / ratio[1]))
    Tnum = ratio[0] * k
    Anum = ratio[1] * k
    #print('Tnum = ', Tnum)
    #print('Anum = ', Anum)
print(Tnum + Anum)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=y=1
q=10**(-5)
import math
for i in range(n):
	a,b=map(int,input().split())
	aa=math.ceil((x+q)/a)
	bb=math.ceil((y+q)/b)
	if x%a==0:
		aa=x//a
	if y%b==0:
		bb=y//b
	p=max(aa,bb)
	x=p*a
	y=p*b
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=y=1
import math
for i in range(n):
	a,b=map(int,input().split())
	aa=math.ceil(x/a+10**-4)
	bb=math.ceil(y/b+10**-4)
	if x%a==0:
		aa=x//a
	if y%b==0:
		bb=y//b
	p=max(aa,bb)
	x=p*a
	y=p*b
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=y=1
import math
for i in range(n):
	a,b=map(int,input().split())
	aa=math.ceil(x/a+10**-12)
	bb=math.ceil(y/b+10**-12)
	if x%a==0:
		aa=x//a
	if y%b==0:
		bb=y//b
	p=max(aa,bb)
	x=p*a
	y=p*b
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=y=1
import math
for i in range(n):
	a,b=map(int,input().split())
	aa=math.ceil(x/a+10**-7)
	bb=math.ceil(y/b+10**-7)
	if x%a==0:
		aa=x//a
	if y%b==0:
		bb=y//b
	p=max(aa,bb)
	x=p*a
	y=p*b
print(x+y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)


stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

n = ni()
st, sa = 1, 1
for i in range(n):
    t, a = na()
    k = max(math.ceil(st / t), math.ceil(sa / a))
    st = t * k
    sa = a * k
print(st + sa)

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import string
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)


stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

n = ni()
st, sa = na()
for i in range(1, n):
    t, a = na()
    k = max(math.ceil(st / t), math.ceil(sa / a))
    st = t * k
    sa = a * k
print(st + sa)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

A = 1
B = 1
for i in range(N):
    a,b = map(int, input().split())
    n = max(math.floor(A/a), math.floor(B/b))
    A, B = n*a, n*b

print(A+B)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ta = [[int(i) for i in input().split()] for j in range(n)]

a = 1
b = 1
for i in range(n):
    n = max(math.floor(a/ta[i][0]), math.floor(b/ta[i][1]))
    
    a = n * ta[i][0]
    b = n * ta[i][1]

print(a+b)

Submission status: Wrong Answer

Solution code:
import math

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

A = 1
B = 1
for i in T:
    a = i[0]
    b = i[1]
    n = max(math.ceil(A/a), math.ceil(B/b))
    A, B = n*a, n*b

print(A+B)

Submission status: Wrong Answer

Solution code:
import math

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

A = 1
B = 1
for i in T:
    a = i[0]
    b = i[1]
    n = max(A/a, B/b)
    n = math.ceil(n)
    A, B = n*a, n*b

print(A+B)

Submission status: Wrong Answer

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

A = 1
B = 1
for i in T:
    a = i[0]
    b = i[1]
    n = max(A/a, B/b)
    if n%1 != 0:
        n = int(n)+1
    n = int(n)
    A, B = n*a, n*b

print(A+B)

Submission status: Wrong Answer

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

A = 1
B = 1
for i in T:
    a = i[0]
    b = i[1]
    n = max(A/a, B/b)
    if n%1 != 0:
        n = int(n)+1
    A, B = n*a, n*b

print(int(A+B))

Submission status: Wrong Answer

Solution code:
N=int(input())

A=1
B=1
for _ in range(N):
    x,y=map(int,input().split())
    na=int((A+x-1)/x)
    nb=int((B+y-1)/y)
    n=max(na, nb)
    A=n*x
    B=n*y

print(A+B)

Submission status: Wrong Answer

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

A=1
B=1
for _ in range(N):
    x,y=map(int,input().split())
    n=max(ceil(A/x), ceil(B/y))
    A=n*x
    B=n*y

print(A+B)

Submission status: Wrong Answer

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

na,nb=1,1
for _ in range(n):
    ia,ib=map(int,input().split())
    fac=max(ceil(na/ia), ceil(nb/ib))
    na, nb=fac*ia, fac*ib

print(na+nb)

Submission status: Wrong Answer

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

na,nb=1,1
for _ in range(n):
    ia,ib=map(int,input().split())
    if na<=ia and nb<=ib:
        na, nb=ia, ib
    else:
        fac=max(ceil(na/ia), ceil(nb/ib))
        na, nb=fac*ia, fac*ib

print(na+nb)

Submission status: Wrong Answer

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

na,nb=0,0
for _ in range(n):
    ia,ib=map(int,input().split())
    if na<=ia and nb<=ib:
        na, nb=ia, ib
    else:
        fac=max(ceil(na/ia), ceil(nb/ib))
        na, nb=fac*ia, fac*ib

print(na+nb)

Submission status: Wrong Answer

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  if va == 1 and vb == 1:
    return a, b
  r = max(a // va, b // vb)
  if va * r < a or vb * r < b:
    r += 1
  
  return va * r, vb * r

t, a = [int(x) for x in input().split()]
for n in range(N - 1):
  ti, ai = [int(x) for x in input().split()]
  t, a = adjust(t, a, ti, ai)

print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  if a == 0 and b == 0:
    return va, vb
  if va == 1 and vb == 1:
    return a, b
  r = max(a // va, b // vb)
  if va * r < a or vb * r < b:
    r += 1
  
  return va * r, vb * r

t, a = [int(x) for x in input().split()]
for n in range(N - 1):
  ti, ai = [int(x) for x in input().split()]
  t, a = adjust(t, a, ti, ai)

print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  if a == 0 and b == 0:
    return va, vb
  if va == 1 and vb == 1:
    return a, b
  r = max(a // va, b // vb)
  if va * r < a or vb * r < b:
    r += 1
  
  return va * r, vb * r

t = 0
a = 0
for n in range(N):
  ti, ai = [int(x) for x in input().split()]
  t, a = adjust(t, a, ti, ai)

print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  if a == 0 and b == 0:
    return va, vb
  if va == 1 and vb == 1:
    return a, b
  r = max(a // va, b // vb)
  if va * r < a or vb * r < b:
    r += 1
  
  return va * r, vb * r

t = 0
a = 0
for n in range(N):
  ti, ai = [int(x) for x in input().split()]
  t, a = adjust(t, a, ti, ai)
  print('ti {}:{} ai, t={},a={}'.format(ti, ai, t, a))
print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  if a == 0 and b == 0:
    return va, vb
  if vb == 1:
    return a, b
  while a / b != va / vb:
    if a / b < va / vb:
      a += 1
      if a / b < va / vb:
        a = int(b * (va / vb))
    elif a / b > va / vb:
      b += 1
      if a / b > va / vb:
        b = int(a * (vb / va))
  return a, b

t = 0
a = 0
for n in range(N):
  ti, ai = [int(x) for x in input().split()]
  if ti < ai:
    t, a = adjust(t, a, ti, ai)
  else:
    a, t = adjust(a, t, ai, ti)
print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())

def adjust(a, b, va, vb):
  if a == 0 and b == 0:
    return va, vb
  if vb == 1:
    return a, b
  while a / b != va / vb:
    if a / b < va / vb:
      a += 1
      if a / b < va / vb:
        a = int(b * (va / vb))
    elif a / b > va / vb:
      b += 1
      if a / b > va / vb:
        b = int(a * (vb / va))
  return a, b

t = 0
a = 0
for n in range(N):
  ti, ai = [int(x) for x in input().split()]
  if ti < ai:
    t, a = adjust(t, a, ti, ai)
  else:
    a, t = adjust(a, t, ai, ti)
  print('ti{}:ai{}, t={},a={}'.format(ti, ai, t, a))
print(t + a)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
x, y = map(int, input().split())
for _ in range(N-1):
  a, b = map(int, input().split())
  # n = max(math.ceil(x/a), math.ceil(y/b))
  na = nb = 0
  if x%a == 0:
    na = x//a
  else:
    na = x//a+1
  if x%b == 0:
    nb = y//b
  else:
    nb = y//b+1
  n = max(na, nb)
  x, y = n*a, n*b
print(x+y)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
x, y = map(int, input().split())
for _ in range(N-1):
  n = 1
  a, b = map(int, input().split())
  if n*a < x or n*b < y:
    n = max(math.ceil(x/a), math.ceil(y/b))
  x, y = n*a, n*b
print(x+y)

Submission status: Wrong Answer

Solution code:
x = int(input())

#高橋君と青木くんの得票数の最小値(初期値:1)
t_vote, a_vote = 1, 1

#得票数の比の割合
n = 0

for i in range(x):
  T, A = map(int, input().split())
  
  #nの決定
  n = max(t_vote / T, a_vote / A)
  if int(n) < n:
    n = int(n) + 1
  else:
    n = int(n)
    
  #得票数の更新
  t_vote = T * n
  a_vote = A * n

ans = t_vote + a_vote
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
a=1
b=1
for i in l:
    tmp1=math.ceil(a/i[0])
    tmpa1=tmp1*i[0]
    tmpb1=tmp1*i[1]
    tmp2=math.ceil(b/i[1])
    tmpa2=tmp2*i[0]
    tmpb2=tmp2*i[1]
    if tmpb1<b:a,b=tmpa2,tmpb2
    elif tmpa2<a:a,b=tmpa1,tmpb1
    else:a,b=min(tmpa1,tmpa2),min(tmpb1,tmpb2)
print(a+b)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
ta = []
for i in range(n):
    t, a = map(int, input().split())
    ta.append([t, a])

t = 1
a = 1
ans = 0
for i in range(n):
    m = max(ceil(t/ta[i][0]), ceil(a/ta[i][1]))
    ans += m
    t = m * ta[i][0]
    a = m * ta[i][1]
print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
ta = []
for i in range(n):
    t, a = map(int, input().split())
    ta.append([t, a])

t = ta[0][0]
a = ta[0][1]
ans = 0
for i in range(1, n):
    m = max(ceil(t/ta[i][0]), ceil(a/ta[i][1]))
    ans += m
    t = m * ta[i][0]
    a = m * ta[i][1]
print(t + a)

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    rate = []
    for _ in range(N):
        T, A = map(int, input().split())
        rate.append([T, A])
    cur = rate[0]
    # print(cur, rate[0])
    for i in range(1, N):
        dT = math.ceil(cur[0] / rate[i][0])
        dA = math.ceil(cur[1] / rate[i][1])
        d = max(dT, dA)
        cur = [d*rate[i][0], d*rate[i][1]]
        # print(cur, rate[i])
    return sum(cur)

if __name__ == '__main__':

    print(main())

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    rate = []
    for _ in range(N):
        T, A = map(int, input().split())
        rate.append([T, A])
    cur = rate[0]
    # print(cur, rate[0])
    for i in range(1, N):
        dT = math.ceil(cur[0] / rate[i][0])
        dA = math.ceil(cur[1] / rate[i][1])
        d = max(dT, dA)
        cur = [d*rate[i][0], d*rate[i][1]]
        # print(cur, rate[i])
    return sum(cur)

if __name__ == '__main__':

    print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())

a,b=0,0
for _ in range(n):
    x,y=map(int,input().split())
    if a<=x and b<=y:
        a,b=x,y
    else:
        rate=[]
        if a>x:
            rate.append( int((a+x-1)/x) )
        if b>y:
            rate.append( int((b+y-1)/y) )
        r=max(rate)
        a,b=x*r, y*r
print(a+b)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



def div(a, b):
    if a % b:
        return a // b + 1
    return a // b


def main():
    n = I()
    xy = LIR(n)
    x, y = 1, 1
    for nxt_x, nxt_y in xy:
        ratio_x = x / nxt_x
        ratio_y = y / nxt_y
        mul = math.ceil(max(ratio_x, ratio_y))
        x = mul * nxt_x
        y = mul * nxt_y
    return x + y


print(main())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



def main():
    n = I()
    xy = LIR(n)
    x, y = 1, 1
    for nxt_x, nxt_y in xy:
        ratio_x = x / nxt_x
        ratio_y = y / nxt_y
        if ratio_x > 1 or ratio_y > 1:
            mul = math.ceil(max(ratio_x, ratio_y))
            nxt_x *= mul
            nxt_y *= mul
        x, y = nxt_x, nxt_y



    return x + y


print(main())