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:
n = int(input())

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    if t == 1 and a == 1:
      pt[i] = max(pt[i-1], pa[i-1])
      pa[i] = max(pt[i-1], pa[i-1])
    elif t == 1:
      pt[i] = pt[i-1]
      pa[i] = pt[i-1] * a
    elif a == 1:
      pt[i] = pa[i-1] * t
      pa[i] = pa[i-1]
    else:
      tmp = max([pt[i-1]/t, pa[i-1]/a])
      pt[i]=tmp*t
      pa[i]=tmp*a
      

print(pt[-1] + pa[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    if t == 1 and a == 1:
      pt[i] = max(pt[i-1], pa[i-1])
      pa[i] = max(pt[i-1], pa[i-1])
    elif t == 1:
      pt[i] = pt[i-1]
      pa[i] = pt[i-1] * a
    elif a == 1:
      pt[i] = pa[i-1] * t
      pa[i] = pa[i-1]
    else:
      tmp = (pt[i-1]+pa[i-1]) // (t+a)
      if (pt[i-1]+pa[i-1]) % (t+a) != 0: tmp += 1
      while(1):
        pt[i] = tmp * t
        pa[i] = tmp * a
        if pt[i] >= pt[i-1] and pa[i] >= pa[i-1]:
          break
        tmp += 1

      
print(pt[-1] + pa[-1])

Submission status: Wrong Answer

Solution code:
#C問題
import math
N=int(input())
T,A=1,1
for i in range(N):
    t,a=map(int,input().split())
    tc=T/t
    ac=A/a
    n=math.ceil(max(tc,ac))
    T=n*t
    A=n*a
print(T+A)

Submission status: Wrong Answer

Solution code:
#C問題
import math
N=int(input())
T=1
A=1
for i in range(N):
    t,a=map(int,input().split())
    tc=math.ceil(T/t)
    ac=math.ceil(A/a)
    n=max(tc,ac)
    T=n*t
    A=n*a
print(T+A)

Submission status: Wrong Answer

Solution code:
#C問題
import math
N=int(input())
T=1
A=1
for i in range(N):
    t,a=map(int,input().split())
    
    n=max(math.ceil(T/t),math.ceil(A/a))
    T=n*t
    A=n*a
print(T+A)

Submission status: Wrong Answer

Solution code:
#C問題
import math
N=int(input())
T=0
A=0
for i in range(N):
    t,a=map(int,input().split())
    if i == 0:
        T = t
        A = a
    else:
        n=max(math.ceil(T/t),math.ceil(A/a))
        T=n*t
        A=n*a
print(T+A)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
tmin = 1
amin = 1
for i in range(N):
    t, a = map(int, input().split())
    multiple = int(max(math.ceil(tmin/t), math.ceil(amin/a)))
    tmin = t * multiple
    amin = a * multiple
print(tmin + amin)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
tmin = 1
amin = 1
for i in range(N):
    t, a = map(int, input().split())
    if tmin % t == 0:
        tmul = tmin // t
    else:
        tmul = math.ceil(tmin / t)
    if amin % a == 0:
        amul = amin // a
    else:
        amul = math.ceil(amin / a)
    multiple = max(tmul, amul) 
    tmin = t * multiple
    amin = a * multiple
print(tmin + amin)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
tmin = 1
amin = 1
for i in range(N):
    t, a = map(int, input().split())
    multiple = max(math.ceil(float(tmin) / t), math.ceil(float(amin) / a))
    tmin = t * multiple
    amin = a * multiple
print(tmin + amin)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
tmin = 1
amin = 1
for i in range(N):
    t, a = map(int, input().split())
    multiple = max(math.ceil(tmin/t), math.ceil(amin/a))
    tmin = t * multiple
    amin = a * multiple
print(tmin + amin)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

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

ans_t, ans_a = 1, 1
for ti, ai in zip(T, A):
    n = max(math.floor(ans_t/ti)+1, math.floor(ans_a/ai)+1)
    if ans_t>ti*n or ans_a>ai*n:
        n += 1
    ans_t = ti*n
    ans_a = ai*n

print(ans_t+ans_a)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

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

ans_t, ans_a = 1, 1
for ti, ai in zip(T, A):
    n = max(math.ceil(ans_t/ti), math.ceil(ans_a/ai))
    if ans_t>ti*n or ans_a>ai*n:
        n += 1
    ans_t = ti*n
    ans_a = ai*n

print(ans_t+ans_a)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

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

ans_t, ans_a = 1, 1
for ti, ai in zip(T, A):
    n = max(math.ceil(ans_t/ti), math.ceil(ans_a/ai))
    ans_t = ti*n
    ans_a = ai*n

print(ans_t+ans_a)

Submission status: Wrong Answer

Solution code:
def INNUM():
	return int(input())

def INNUM_S():
	return tuple(map(int, input().split()))

def INNUM_SM(n):
	return [INNUM_S() for _ in range(n)]

N = INNUM()
XY = INNUM_SM(N)

import math

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max(int(math.ceil(a/x)), int(math.ceil(b/y)))
        a, b = x*c, y*c
    print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a-1)//(x+1), (b-1)/(y+1))
        a, b = x*c, y*c
    print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max(math.ceil(a/x), math.ceil(b/y))
        a, b = x*c, y*c
    print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = 1, 1
for x, y in zip(T, A):
    if a>x or b>y:
        c = max(math.ceil(a//x), math.ceil(b//y))
        a, b = x*c, y*c
    else:
        a, b = x, y
    print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = 1, 1
for x, y in zip(T, A):
    if a>x or b>y:
        c = max(math.ceil(a/x), math.ceil(b/y))
        a, b = x*c, y*c
    else:
        a, b = x, y
    print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        if a>x or b>y:
            c = max(math.ceil(a/x), math.ceil(b/y))
            a, b = x*c, y*c
        else:
            a, b = x, y
    print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
for x, y in zip(T[1:], A[1:]):
    if a>x or b>y:
        c = max(math.ceil(a/x), math.ceil(b/y))
        a, b = x*c, y*c
    else:
        a, b = x, y
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

N=int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math

N=int(input())

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math

N=int(input())

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

Submission status: Wrong Answer

Solution code:
N = int(input())
min_T, min_A = 1,1
def ceil(a):
    if a == int(a):
        return int(a)
    else:
        return int(a) + 1

for _ in range(N):
    T, A = map(int,input().split())
    i =max(ceil(min_A / A) , ceil(min_T / T))
    min_T = T * i
    min_A = A * i
print(min_T+min_A)

Submission status: Wrong Answer

Solution code:
N = int(input())
min_T, min_A = map(int,input().split())
def ceil(a):
    if a == int(a):
        return int(a)
    else:
        return int(a) + 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
min_T, min_A = map(int,input().split())
def ceil(a):
    if a == int(a):
        return int(a)
    else:
        return int(a) + 1

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

Submission status: Wrong Answer

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

for i in range(n-1):
    bai = max(int(ta[i][0]/ta[i+1][0])+1, int(ta[i][1]/ta[i+1][1])+1)
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])

Submission status: Wrong Answer

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

for i in range(n-1):
    bai = max(int(ta[i][0]/ta[i+1][0]), int(ta[i][1]/ta[i+1][1]))
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])

Submission status: Wrong Answer

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

import math
for i in range(n-1):
    bai = max(math.ceil(ta[i][0]/ta[i+1][0]),math.ceil(ta[i][1]/ta[i+1][1]))
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])

Submission status: Wrong Answer

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

ct = ta[0][0]
ca = ta[0][1]

for i in range(1, n):
    t, a = ta[i]

    if ct / t > ca / a:
        if ct%t == 0:
            rate = ct//t
        else:
            rate = ct//t+1
    else:
        if ca%a == 0:
            rate = ca//a
        else:
            rate = ca//a+1
    ct = rate * t
    ca = rate * a
    print(ct+ca)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = int(max(math.ceil(a/x), math.ceil(b/y)))
  a,b = l*x,l*y
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = int(max(math.ceil(a/x), math.ceil(b/y)))
  while l*x<a or l*y<b:
    l += 1
  a,b = l*x,l*y
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(math.ceil(a/x), math.ceil(b/y))
  while l*x<a or l*y<b:
    l += 1
  a,b = l*x,l*y
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(math.ceil(a/x), math.ceil(b/y))
  a,b = l*x,l*y
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(math.ceil(a/x), math.ceil(b/y))
  a,b = l*x,l*y
print(x+y)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
x,y = 1,1
for _ in range(n):
  a,b = [int(_) for _ in input().split(" ")]
  if x*b == y*a:
    pass
  elif x*b > y*a:
    l = math.ceil(x/a)
    x,y = l*a,l*b
  else:
    l = math.ceil(y/b)
    x,y = l*a,l*b
print(x+y)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
x,y = 1,1
for _ in range(n):
  a,b = [int(_) for _ in input().split(" ")]
  if x*b == y*a:
    pass
  elif x*b > y*a:
    l = math.ceil(x/a)*a
    x,y = l,l*b//a
  else:
    l = math.ceil(y/b)*b
    x,y = l*a//b,l
print(x+y)

Submission status: Wrong Answer

Solution code:
import math

def gcd(a,b):
  while b > 0:
    a,b=b, a%b
  return a

n = int(input())
x,y = 1,1
for _ in range(n):
  a,b = [int(_) for _ in input().split(" ")]
  if x*b >= y*a:
    l = math.ceil(x/a)*a
    x,y = l,l*b//a
  else:
    l = math.ceil(y/b)*b
    x,y = l*a//b,l
print(x+y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import copy
S=list(input())
N=len(S)
point=0
hand=copy.deepcopy(S)
panum=sum([j=="p" for j in hand])
pamax=N//2#ポイントの上限
for i in range(N):
    pa=sum([hand[j]=="p" for j in range(i+1)])#今まで出したパーの数
    if pa<(i+1)//2 and point<pamax-panum:
        hand[i]="p"
        point+=1
print(point)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
cur=[1,1]
for i in range(len(T)):
    K=int(max(math.ceil(cur[0]/T[i][0]),math.ceil(cur[1]/T[i][1])))
    cur=[j*K for j in T[i]]
print(sum(cur))

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N = int(input())

T, A = [], []

for _ in range(N):
    t, a = s_inpl()
    T.append(t)
    A.append(a)

c_t, c_a = 1, 1

for t, a in zip(T, A):
    n = max(math.ceil(c_t/t), math.ceil(c_a/a))
    c_t = n*t
    c_a = n*a

print(c_t+c_a)

Submission status: Wrong Answer

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

for nt,na in ratio:
    if nt<t or na<a:
        r = max(ceil(t/nt), ceil(a/na))
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Wrong Answer

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

for nt,na in ratio:
    r = max(ceil(t/nt), ceil(a/na), 1)
    nt *= r
    na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Wrong Answer

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

for nt,na in ratio:
    if nt<t:
        r = ceil(t/nt)
        nt = r*nt
        na = r*na
    if na<a:
        r = ceil(a/na)
        na = r*na
        nt = r*nt
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Wrong Answer

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

for nt,na in ratio:
    while not(nt>=t and na>=a):
        if nt<t:
            r = ceil(t/nt)
            nt = r*nt
            na = r*na
        elif na<a:
            r = ceil(a/na)
            na = r*na
            nt = r*nt
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Wrong Answer

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

for nt,na in ratio:
    while not(nt>=t and na>=a):
        if nt<t:
            r = ceil(t/nt)
            nt = r*nt
            na = r*na
        elif na<a:
            r = ceil(a/na)
            na = r*na
            nt = r*nt
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Wrong Answer

Solution code:
import math


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

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        n = max(math.ceil(A / x), math.ceil(B / y))
        # n = max(A // x + (A % x != 0),
        #         B // y + (B % y != 0))
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


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

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        # n = max(math.ceil(A / x), math.ceil(B / y))
        n = max(A // x + A % x != 0,
                B // x + B % x != 0)
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


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

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        n = max(math.ceil(A / x), math.ceil(B / y))
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        n = max(A // x, B // y)
        A, B = n * x, n * y

    ans = A + B
    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    # ans = f(N, TA)
    ans = editorial(N, TA)
    print(ans)


def editorial(N, TA):
    A, B = 1, 1
    for x, y in TA:
        n = max(A // x, B // y)
        A, B = n * A, n * B

    ans = A + B
    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    ans = f(N, TA)
    print(ans)


def f(N, TA):
    nt, na = TA[0]
    bef_t, bef_a = nt, na
    for t, a in TA[1:]:
        if (bef_t, bef_a) == (t, a):
            # 変化なし
            pass
        elif (t, a) == (1, 1):
            # 同票なので、合わせる
            m = max(nt, na)
            nt, na = m, m
        elif t == 1:
            na = nt * a
        elif a == 1:
            nt = na * t
        elif (bef_t, bef_a) == (1, 1):
            # 1:1 -> 3,3
            # 3:2 -> 3,2(NG) 6:4 -> 6,4(OK)
            i = 1
            while nt <= t or na <= a:
                nt, na = t * i, a * i
                i += 1

        elif bef_t == t and bef_a < a:
            # 2:3 -> 4,6
            # 2:7 -> 4,14
            na = na // bef_a * a
        elif bef_t < t and bef_a == a:
            nt = nt // bef_t * t
        else:
            aa = na // a
            tt = nt // t
            if aa > 0 and tt > 0 and aa == tt:
                pass
            else:
                x = nt % t
                y = na % a
                if x != 0:
                    add_t = t - x
                    nt += add_t
                if y != 0:
                    add_a = a - y
                    na += add_a
                aa = na // a
                tt = nt // t
                if aa > tt:
                    nt = t * aa
                elif aa < tt:
                    na = a * tt
            # (nt + x): (na + y) = t: a
            # na * t + y * t = (nt + x) * a
            #          y * t = (nt + x) * a     - na * t
            #          y     = (nt + x) * a / t - na
            # x,y >= 0
            # (nt + x) / t is int
            #     a    / t is int
        bef_t, bef_a = t, a
        # print(nt, na, (t, a))

    ans = nt + na
    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
#a,b = map(int,input().split())
T=1
A=1

for i in range(n):
    a,b = map(int,input().split())
    num = max(ceil((T)/a),ceil((A)/b))
    T = a*(num)
    A = b*(num)
    #print(T,A)
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a,b = map(int,input().split())
T=a
A=b

for i in range(n-1):
    a,b = map(int,input().split())
    if(T<=a and A<=b):
        T=a
        A=b
    else:
        num = max(ceil((T)/a),ceil((A)/b))
        T = a*(num)
        A = b*(num)
    #print(T,A)
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a,b = map(int,input().split())
T=a
A=b

for i in range(n-1):
    a,b = map(int,input().split())
    if(T<=a and A<=b):
        T=a
        A=b
    else:
        num = max(ceil((T)/a),ceil((A)/b))
        T = a*(num+1)
        A = b*(num+1)
   # print(T,A)
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a,b = map(int,input().split())
T=a
A=b

for i in range(n-1):
    a,b = map(int,input().split())
    if(T<=a and A<=b):
        T=a
        A=b
    else:
        num = max(ceil((T-a)/a),ceil((A-b)/b))
        T = a*(num+1)
        A = b*(num+1)
   # print(T,A)
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a,b = map(int,input().split())
T=a
A=b

for i in range(n-1):
    a,b = map(int,input().split())
    if(T<=a and A<=b):
        T=a
        A=b
    else:
        num = max(ceil((T-a)/a),ceil((A-b)/b))
        T = a*(num+1)
        A = b*(num+1)
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a,b = map(int,input().split())
T=a
A=b
print(T,A)
for i in range(n-1):
    a,b = map(int,input().split())
    if(T<=a and A<=b):
        T=a
        A=b
    else:
        num = max(ceil((T-a)/a),ceil((A-b)/b))
        T = a*(num+1)
        A = b*(num+1)
print(T+A)

Submission status: Wrong Answer

Solution code:
import math


def solve(l: list):
    x, y = 1, 1

    for t, a in l:
        n = max(int(math.ceil(x/t)), int(math.ceil(y/a)))
        x = n * t
        y = n * a
    return x + y


def main():
    N = int(input())
    l = []
    for i in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    print(solve(l))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
l=1000
r=1000
tmp=1
for i in range(n):
    if (a[i][0]>=l and a[i][1]>=r) or i == 0:
        tmp=sum(a[i])
        seki=1
    else:
        if l/a[i][0] > r/a[i][1]:
            seki=int(l/a[i][0]-0.00001)+1
            tmp=sum(a[i])*seki
        else:
            seki=int(r/a[i][1]-0.00001)+1
            tmp=sum(a[i])*seki
    l,r=[a[i][0]*seki,a[i][1]*seki]
print(tmp)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
l=1000
r=1000
tmp=1
for i in range(n):
    if (a[i][0]>=l and a[i][1]>=r) or i == 0:
        tmp=sum(a[i])
        seki=1
    else:
        if l/a[i][0] > r/a[i][1]:
            seki=int(l/a[i][0]+0.9999)
            tmp=sum(a[i])*seki
        else:
            seki=int(r/a[i][1]+0.9999)
            tmp=sum(a[i])*seki
    l,r=[a[i][0]*seki,a[i][1]*seki]
print(tmp)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
t,a=[int(i) for i in input().split()]
one=t
two=a
for i in range(1,n):
    t,a=[int(j) for j in input().split()]
    m=max(math.ceil(one/t),math.ceil(two/a))
    one,two=m*t,m*a
print(one+two)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
t,a=[int(i) for i in input().split()]
one=t
two=a
print("{} {}".format(one,two))
for i in range(1,n):
    t,a=[int(j) for j in input().split()]
    m=max(math.ceil(one/t),math.ceil(two/a))
    one,two=m*t,m*a
print(one+two)

Submission status: Wrong Answer

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

def main():
	n = int(input())
	
	ins = []
	for _ in range(n):
		t, a = map(int, input().split(" "))
		ins.append((t, a))
		
	takahashi = 0
	aoki = 0
	takahashi, aoki = ins[0]
	
	for i, val in enumerate(ins):
		if i == 0: continue
		t, a = val
		m = max((takahashi // t), (aoki // a))
		takahashi, aoki = t * m, a * m
		
	print(takahashi + aoki)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

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