Problem:


Score : 300 points

Problem Statement

AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.

Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

Constraints

1≦N≦1000

1≦T_i,A_i≦1000 (1≦i≦N)

T_i and A_i (1≦i≦N) are coprime.

It is guaranteed that the correct answer is at most 10^{18}.

Input

The input is given from Standard Input in the following format:

N
T_1 A_1
T_2 A_2
:
T_N A_N

Output

Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

Sample Input 1

3
2 3
1 1
3 2

Sample Output 1

10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Sample Input 2

4
1 1
1 1
1 5
1 100

Sample Output 2

101

It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.

Sample Input 3

5
3 10
48 17
31 199
231 23
3 2

Sample Output 3

6930



Sample input:
3
2 3
1 1
3 2


Sample output:
10

Submission status: Wrong Answer

Solution code:
import math

def calc_vote(T, A, TN_prev, AN_prev):
    '''
    input:
        T, A: rate of vote
        TN_prev, AN_prev: previous minimum number of vote
    output:
        TN, AN: minimum number of vote 
    '''
    k = int(max(math.ceil(TN_prev/T), math.ceil(AN_prev/A)))
    TN = k * T
    AN = k * A
    
    return TN, AN
  
# input N
N = int(input())

TN, AN = map(int, input().split())

for _ in range(2, N + 1):
    T, A = map(int, input().split())
    TN, AN = calc_vote(T, A, TN, AN)

print(TN + AN)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)

n = II()
ratio = [LI() for _ in range(n)]
taka = 1
ao = 1
for a, b in ratio:
    q = max(math.ceil(taka / a), math.ceil(ao / b))
    taka = a * q
    ao = b * q
print(taka+ao)

Submission status: Wrong Answer

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

import math

n = int(input())
ta = [[0,0] for i in range(n)]
for i in range(n):
    ta[i][0],ta[i][1] = map(int,input().split())

left = ta[0][0]
right = ta[0][1]
for i in range(n):
    j = max(math.ceil(left / ta[i][0]), math.ceil(right / ta[i][1]))
    left = ta[i][0] * j
    right = ta[i][1] * j

print(left + right)

Submission status: Wrong Answer

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

import math

n = int(input())
ta = [[0,0] for i in range(n)]
for i in range(n):
    ta[i][0],ta[i][1] = map(int,input().split())

left = ta[0][0]
right = ta[0][1]
for i in range(n):
    j = max(math.ceil(left / ta[i][0]), math.ceil(right / ta[i][1]))
    left = ta[i][0] * j
    right = ta[i][1] * j
    print(left,right)

print(left + right)

Submission status: Wrong Answer

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

import math

n = int(input())
ta = [[0,0] for i in range(n)]
for i in range(n):
    ta[i][0],ta[i][1] = map(int,input().split())

left = ta[0][0]
right = ta[0][1]
for i in range(n):
    j = max(math.ceil((left + right) / (ta[i][0] + ta[i][1])), math.ceil(left / ta[i][0]), math.ceil(right / ta[i][1]))
    left = ta[i][0] * j
    right = ta[i][1] * j

print(left + right)

Submission status: Wrong Answer

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

n = int(input())
ta = [[0,0] for i in range(n)]
for i in range(n):
    ta[i][0],ta[i][1] = map(int,input().split())

left = ta[0][0]
right = ta[0][1]
for i in range(n):
    for j in range(1000000):
        if (ta[i][0] + ta[i][1]) * j >= (left + right) and ta[i][0] * j >= left and ta[i][1] * j >= right:
            left = ta[i][0] * j
            right = ta[i][1] * j
            break

print(left + right)

Submission status: Wrong Answer

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

t = 1
a = 1

for i in range(N):
  k = max(int((t+ta[i][0]-1)/ta[i][0]), int((a+ta[i][1]-1)/ta[i][1]))
  t = ta[i][0]*k
  a = ta[i][1]*k
  
print(t+a)

Submission status: Wrong Answer

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

t = ta[0][0]
a = ta[0][1]

for i in range(N-1):
  print(str(t)+ " " + str(a))
  k = 1
  while t > ta[i+1][0]*k or a > ta[i+1][1]*k:
    k += 1
  t = ta[i+1][0]*k
  a = ta[i+1][1]*k
print(t+a)

Submission status: Wrong Answer

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

t = ta[0][0]
a = ta[0][1]

for i in range(N-1):
  if ta[i][0] <= ta[i+1][0] and ta[i][1] <= ta[i+1][1]:
    t = ta[i+1][0]
    a = ta[i+1][1]
  elif ta[i][0] > ta[i+1][0] and ta[i][1] < ta[i+1][1]:
    k = 1
    while t > ta[i+1][0]*k:
      k+= 1
    t = ta[i+1][0]*k
    a = ta[i+1][1]*k  
  elif ta[i][0] < ta[i+1][0] and ta[i][1] > ta[i+1][1]:
     k = 1
     while a > ta[i+1][1]*k:
       k+= 1
     t = ta[i+1][0]*k
     a = ta[i+1][1]*k
  else:
    k = 1
    while t > ta[i+1][0]*k or a > ta[i+1][1]*k:
      k += 1
    t = ta[i+1][0]*k
    a = ta[i+1][1]*k
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t, a = map(int, input().split())
for _ in range(n-1):
    x, y = map(int, input().split())
    l = max(math.ceil(t/x), math.ceil(a/y))
    t = l * x
    a = l * y
print(a+t)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = [None] * N
A = [None] * N
for i in range(N):
  T[i], A[i] = map(int, input().split())

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

for i in range(1, N):
  if ( t < T[i] and a < A[i]):
    t, a = T[i], A[i]
  else:
    n = max(math.ceil(t / T[i]), math.ceil(a / A[i]))
    t, a = n * T[i], n * A[i]

print(t + a)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = [None] * N
A = [None] * N
for i in range(N):
  T[i], A[i] = map(int, input().split())

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

for i in range(1, N):
  if ( t <= T[i] and a <= A[i]):
    t, a = T[i], A[i]
  else:
    n = max(math.ceil(t / T[i]), math.ceil(a / A[i]))
    t, a = n * T[i], n * A[i]

print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [None] * N
A = [None] * N
for i in range(N):
  T[i], A[i] = map(int, input().split())

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

for i in range(1, N):
  if ( t <= T[i] and a <= A[i]):
    t, a = T[i], A[i]
  else:
    n = max(round(t / T[i]), round(a / A[i]))
    t, a = n * T[i], n * A[i]

print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [None] * N
A = [None] * N
for i in range(N):
  T[i], A[i] = map(int, input().split())

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

for i in range(1, N):
  if ( t < T[i] and a < A[i]):
    t, a = T[i], A[i]
  else:
    n = max(t // T[i], a // A[i])
    t, a = n * T[i], n * A[i]

print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [None] * N
A = [None] * N
for i in range(N):
  T[i], A[i] = map(int, input().split())

t, a = 1, 1

for i in range(N):
  if ( t < T[i] and a < A[i]):
    t, a = T[i], A[i]
  else:
    n = max(t // T[i], a // A[i])
    t, a = n * T[i], n * A[i]

print(t + a)

Submission status: Wrong Answer

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

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

for i in range(1, N):
  if t < T[i] and a < A[i]:
    t = T[i]
    a = A[i]
  else:
    x = int((t + T[i] - 1) / T[i])
    y = int((a + A[i] - 1) / A[i])
    t = T[i] * max(x, y)
    a = A[i] * max(x, y)

print(t + a)

Submission status: Wrong Answer

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

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

for i in range(1, N):
  if t < T[i] and a < A[0]:
    t = t[i]
    a = A[i]
  else:
    x = int((t + T[i] - 1) / T[i])
    y = int((a + A[i] - 1) / A[i])
    t = T[i] * max(x, y)
    a = A[i] * max(x, y)

print(t + a)

Submission status: Wrong Answer

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

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

for i in range(1, N):
  x = int((t + T[i] - 1) / T[i])
  y = int((a + A[i] - 1) / A[i])
  t = T[i] * max(x, y)
  a = A[i] * max(x, y)

print(t + a)

Submission status: Wrong Answer

Solution code:
n=int(input())
a0,b0=1,1
for _ in range(n):
  a,b=map(int,input().split())
  k=max(a0//a+a0%a>0,b0//b+b0%b>0)
  a0,b0=a*k,b*k
print(a0+b0)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=2
for _ in range(n):
  a,b=map(int,input().split())
  m=(m//(a+b)+((m%(a+b))>0))*(a+b)
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=2
for _ in range(n):
  a,b=map(int,input().split())
  m=(m//(a+b)+m%(a+b)>0)*(a+b)
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=2
for _ in range(n):
  a,b=map(int,input().split())
  m=(m%(a+b)+m%(a+b)>0)*(a+b)
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=0
for _ in range(n):
  a,b=map(int,input().split())
  m=(m%(a+b)+m%(a+b)>0)*(a+b)
print(m)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [[int(item) for item in input().split()] for _ in range(n)]

p, q = ta[0]
for t, a in ta[1:]:
    rate1 = math.ceil(p/t)
    rate2 = math.ceil(q/a)
    rate = max(rate1, rate2)
    p = t*rate 
    q = a*rate 
print(p + q)

Submission status: Wrong Answer

Solution code:
N = int(input())
TA = []
AO = []
for i in range(N):
    T, A = map(int, input().split())
    TA += [T]
    AO += [A]

for i in range(N-1):
    D = ((TA[i]-1)//TA[i+1])+1
    E = ((AO[i]-1)//AO[i+1])+1
    F = max(D, E)
ans = int(TA[N-1] + AO[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
TA = []
AO = []
for i in range(N):
    T, A = map(int, input().split())
    TA += [T]
    AO += [A]

for i in range(N-1):
    D = TA[i]/TA[i+1]
    E = AO[i]/AO[i+1]
    F = max(D, E)
    if F%1 == 0:
        TA[i+1] *= F
        AO[i+1] *= F
    else:
        TA[i+1] *= (F//1)+1
        AO[i+1] *= (F//1)+1
ans = int(TA[N-1] + AO[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
TA = []
AO = []
for i in range(N):
    T, A = map(int, input().split())
    TA += [T]
    AO += [A]

for i in range(N-1):
    D = round((TA[i]/TA[i+1]),1)
    E = round((AO[i]/AO[i+1]),1)
    F = max(D, E)
    if F%1 == 0:
        TA[i+1] *= F
        AO[i+1] *= F
    else:
        TA[i+1] *= ((F//1)+1)
        AO[i+1] *= ((F//1)+1)
ans = int(TA[N-1] + AO[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
TA = []
AO = []
for i in range(N):
    T, A = map(int, input().split())
    TA += [T]
    AO += [A]

for i in range(N-1):
    D = round((TA[i]/TA[i+1]),1)
    E = round((AO[i]/AO[i+1]),1)
    F = max(D, E)
    if F%1 == 0:
        TA[i+1] *= (F)
        AO[i+1] *= (F)
    else:
        TA[i+1] *= ((F//1)+1)
        AO[i+1] *= ((F//1)+1)
ans = int(TA[N-1] + AO[N-1])
print(ans)

Submission status: Wrong Answer

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

now_A,now_T = 1,1
for i in range(N):
  x,y = map(int,input().split())
  n = max(math.ceil(now_A/x),math.ceil(now_T/y))
  now_A,now_T = n*x,n*y
ans = now_A + now_T
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def gcd(a,b):
  while(b>0):
    a,b = b,a%b
  return a
def lcm(a,b):
  G = gcd(a,b)
  L = (a*b)//G
  return L

for i in range(N):
  A,T = map(int,input().split())
  if(i == 0):
    now_A,now_T = A,T
  else:
    if((now_A <= A)and(now_T <= T)):
      now_A,now_T = A,T
    elif((now_A >= A)and(now_T <= T)):
      if(now_A%A == 0):tmp = now_A//A
      else: tmp = (now_A//A) + 1
      now_A,now_T = tmp*A,tmp*T
    elif((now_A <= A)and(now_T >= T)):
      if(now_T%T == 0):tmp = now_T//T
      else: tmp = (now_T//T) + 1
      now_A,now_T = tmp*A,tmp*T    
    else:     
     L1 = lcm(now_A,A)
     tmp1 = L1//A
     tmp1_A,tmp1_T = L1,tmp1*T
     L2 = lcm(now_T,T)
     tmp2 = L2//T
     tmp2_A,tmp2_T = tmp2*A,L2
      
     if(tmp1_A+tmp1_T <= tmp2_A+tmp2_T):
      if((now_A<=tmp1_A)and(now_T<=tmp1_T)):
        now_A,now_T = tmp1_A,tmp1_T
      else:
        now_A,now_T = tmp2_A,tmp2_T
     else:
      if((now_A<=tmp2_A)and(now_T<=tmp2_T)):
        now_A,now_T = tmp2_A,tmp2_T
      else:
        now_A,now_T = tmp1_A,tmp1_T

ans = now_A + now_T
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

T, A = 1, 1
for i in range(N):
  if T >= A:
    if TA[i][0] / TA[i][1] >= T / A:
      a = math.ceil(A / TA[i][1])
    else:
      a = math.ceil(T / TA[i][0])
  else:
    if TA[i][1] / TA[i][0] >= A / T:
      a = math.ceil(T / TA[i][0])
    else:
      a = math.ceil(A / TA[i][1])
  T = TA[i][0] * a
  A = TA[i][1] * a
  #print("{0} {1}".format(T, A))

print(T + A)

Submission status: Wrong Answer

Solution code:
import math

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

T, A = 1, 1
for i in range(N):
  a = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
  T = TA[i][0] * a
  A = TA[i][1] * a
  #print("{0} {1}".format(T, A))

print(T + A)

Submission status: Wrong Answer

Solution code:
import math

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

T, A = 1, 1
for i in range(N):
  a = math.ceil(T / TA[i][0])
  if T >= A:
    if TA[i][0] / TA[i][1] >= T / A:
      a = math.ceil(A / TA[i][1])
  else:
    if TA[i][1] / TA[i][0] >= A / T:
      a = math.ceil(T / TA[i][0])
  T = TA[i][0] * a
  A = TA[i][1] * a
  #print("{0} {1}".format(T, A))

print(T + A)

Submission status: Wrong Answer

Solution code:
import sys
import math
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
m = 0
t0, a0 = 1, 1
for i in range(n):
    t, a = nm()
    m = max(int(math.ceil(a0 / a)), int(math.ceil(t0 / t)))
    a0 = a * m
    t0 = t * m
print(a0 + t0)

Submission status: Wrong Answer

Solution code:
import sys
import math
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
m = 0
t0, a0 = 1, 1
for i in range(n):
    t, a = nm()
    m = max(math.ceil(a0 / a), math.ceil(t0 / t))
    a0 = a * m
    t0 = t * m
print(a0 + t0)

Submission status: Wrong Answer

Solution code:
import sys
import math
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
m = 0
t0, a0 = nm()
for i in range(n - 1):
    t, a = nm()
    m = max(math.ceil(a0 / a), math.ceil(t0 / t))
    a0 = a * m
    t0 = t * m
print(a0 + t0)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
T, A = 1, 1

for _ in range(N):
    ti, ai = map(int, input().split())
    param_t = T // ti if T % ti == 0 else math.ceil(T / ti)
    param_a = A // ai if A % ai == 0 else math.ceil(A / ai)
    ratio = max(param_t, param_a)
    T = ratio * ti
    A = ratio * ai
print(T + A)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
T, A = 1, 1

for _ in range(N):
    ti, ai = map(int, input().split())
    ratio = max(int(math.ceil(T / ti)), int(math.ceil(A / ai)))
    T = ratio * ti
    A = ratio * ai
print(T + A)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
T, A = 1, 1

for _ in range(N):
    ti, ai = map(int, input().split())
    ratio = max(math.ceil(T / ti), math.ceil(A / ai))
    T = ratio * ti
    A = ratio * ai
print(T + A)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())

t_prev,a_prev=1,1
for i in range(n):
  t,a=map(int,input().split())
  n_koho1=math.ceil(t_prev/t)
  n_koho2=math.ceil(a_prev/a)
  
  n=max(n_koho1,n_koho2)
  t=n*t
  a=n*a
    
  t_prev=t
  a_prev=a

print(t_prev+a_prev)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())

t_prev,a_prev=map(int,input().split())
for i in range(n-1):
  t,a=map(int,input().split())
  n_koho1=math.ceil(t_prev/t)
  n_koho2=math.ceil(a_prev/a)
  
  n=max(n_koho1,n_koho2)
  t=n*t
  a=n*a
    
  t_prev=t
  a_prev=a

print(t_prev+a_prev)

Submission status: Wrong Answer

Solution code:
n = int(input())
a,b = 1,1
for i in range(n):
    s,t = map(int,input().split())
    n =  max(a/s,b/t)
    a,b = s*n,t*n
print(int(a+b))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t, a = map(int, input().split())
for _ in range(n-1):
    t1, a1 = map(int, input().split())
    s = max(math.ceil(t/t1), math.ceil(a/a1))
    t = s * t1
    a = s * a1
ans = a + t
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
P=[list(map(int,input().split(' '))) for i in range(N)]
T=[P[i][0] for i in range(N)]
A=[P[i][1] for i in range(N)]
t=T[0]
a=A[0]
k=1
for i in range(1,N):
	k1 = math.ceil(T[i-1]*k/T[i])
	k2 = math.ceil(A[i-1]*k/A[i])
	k = max(k1,k2)
print(k*(T[-1]+A[-1]))

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
P=[list(map(int,input().split(' '))) for i in range(N)]
T=[P[i][0] for i in range(N)]
A=[P[i][1] for i in range(N)]
t=T[0]
a=A[0]
k=1
for i in range(1,N):
	k1 = math.ceil(T[i-1]*k/T[i])
	k2 = math.ceil(A[i-1]*k/A[i])
	k = max(k1,k2)
	t = k * T[i]
	a = k * A[i]
print(t+a)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
pt = 1
pa = 1
for i in range(N):
    t, a = map(int, input().split())
    min_ratio = int(max(math.ceil(pt / t), math.ceil(pa / a)))
    pt = t * min_ratio
    pa = a * min_ratio

print(pt+pa)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
pt = 1
pa = 1
for i in range(N):
    t, a = map(int, input().split())
    min_ratio = max(math.ceil(pt / t), math.ceil(pa / a))
    pt = t * min_ratio
    pa = a * min_ratio

print(pt+pa)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=2
cnt1=1
cnt2=1
for _ in range(n):
  t,a=map(int,input().split())
  i=c
  while i%(t+a)!=0:
    i+=1
  cnt1=i//(t+a)*t
  cnt2=i//(t+a)*a
  c=cnt1+cnt2
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=2
cnt1=1
cnt2=1
for _ in range(n):
  t,a=map(int,input().split())
  i=c
  while i%(t+a)!=0:
    i+=1
  cnt1=i/(t+a)*t
  cnt2=i/(t+a)*a
  c=cnt1+cnt2
print(c)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
voterate = [[int(_) for _ in input().split()] for _ in range(N)]
numT = 0
numA = 0

for i in voterate:
    if numT == 0 and numA == 0:
        numT = i[0]
        numA = i[1]
    else:
        denom = sum(i)
        m = max(math.ceil(numT*denom/i[0]), math.ceil(numA*denom/i[1]))
        m = math.ceil(m/denom)*denom
        numT = i[0]*m//denom
        numA = i[1]*m//denom

print(numT+numA)

Submission status: Wrong Answer

Solution code:
import math

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

total_T = 1
total_A = 1

for t,a in _input:
    n = max(math.ceil(total_T/t),math.ceil(total_A/a))
    total_T = int(t*n)
    total_A = int(a*n)

print(total_A+total_T)

Submission status: Wrong Answer

Solution code:
import math

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

total_T = 1
total_A = 1

for t,a in _input:
    n = max(math.ceil(total_T/t),math.ceil(total_A/a))
    total_T = t*n
    total_A = a*n

print(total_A+total_T)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = 1
B = 1
for i in range(N):
  p = math.ceil(A/L[i][0])
  q = math.ceil(B/L[i][1])
  k = max(p,q)
  A = L[i][0]*k
  B = L[i][1]*k
print(A+B)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = 1
B = 1
for i in range(N):
  k = max(int(math.ceil(A/L[i][0])),int(math.ceil(B/L[i][1])))
  A = L[i][0]*k
  B = L[i][1]*k
print(A+B)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = L[0][0]
B = L[0][1]
for i in range(1,N):
  if A < L[i][0] and B < L[i][1]:
    A = L[i][0]
    B = L[i][1]
  else:
    k = max(math.ceil(A/L[i][0]),math.ceil(B/L[i][1]))
    A = L[i][0]*k
    B = L[i][1]*k
print(A+B)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = 1
B = 1
for i in range(N):
  k = max(math.ceil(A/L[i][0]),math.ceil(B/L[i][1]))
  A = L[i][0]*k
  B = L[i][1]*k
print(A+B)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = 1
B = 1
for i in range(N):
  if A <= L[i][0] and B <= L[i][1]:
    A = L[i][0]
    B = L[i][1]
  else:
    k = max(math.ceil(A/L[i][0]),math.ceil(B/L[i][1]))
    A = L[i][0]*k
    B = L[i][1]*k
print(A+B)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = L[0][0]
B = L[0][1]
for i in range(1,N):
  if A <= L[i][0] and B <= L[i][1]:
    A = L[i][0]
    B = L[i][1]
  else:
    k = max(math.ceil(A/L[i][0]),math.ceil(B/L[i][1]))
    A = L[i][0]*k
    B = L[i][1]*k
print(A+B)

Submission status: Wrong Answer

Solution code:
n = int(input())
a, b = 1, 1
for i in range(n):
    tmp_a, tmp_b = map(int, input().split())
    cnt = 1
    while tmp_a*cnt < a or tmp_b*cnt < b:
        cnt += 1
    a = tmp_a*cnt
    b = tmp_b*cnt
else:
    print(a, b)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a,b=map(int,input().split())
d=a+b
for i in range(n-1):
    e,f=map(int,input().split())
    d=d*(e+f)//gcd(d,e+f)
print(d)

Submission status: Wrong Answer

Solution code:
s = input()

l = len(s)

point = 0
for a, b in zip(s[0::2], s[1::2]):
    if a == 'p':
        point -= 1
    if b == 'g':
        point += 1
print(point)

Submission status: Wrong Answer

Solution code:
s = input()

l = len(s)

point = 0
for a, b in zip(s, s[1:]):
    if a == 'p':
        point -= 1
    if b == 'g':
        point += 1
print(point)

Submission status: Wrong Answer

Solution code:
# ABC 062
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def gcd(x, y): # 最大公約数
    m = max(x,y)
    n = min(x,y)
    while m%n != 0:
        w = m%n
        m = n
        n = w
    return n

def lcm(x, y): return x*y//gcd(x,y) # 最小公倍数
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
TA = zeros(N)
for i in range(N):
    TA[i] = getIntList()
db(TA)
real = TA[0]
for i in range(1,N):
    if real[0]>real[1]:
        lc = (real[0]+TA[i][0]-1)//TA[i][0]*TA[i][0]
        real[0] = lc 
        real[1] = lc * TA[i][1] // TA[i][0]  
    else:
        lc = (real[1]+TA[i][1]-1)//TA[i][1]*TA[i][1]
        real[1] = lc 
        real[0] = lc * TA[i][0] // TA[i][1]  
    lc0 = (real[0]+TA[i][0]-1)//TA[i][0]*TA[i][0]
    lc1 = (real[1]+TA[i][1]-1)//TA[i][1]*TA[i][1]
    lc10 = lc1 * TA[i][0] // TA[i][1]  
    lc = min(lc0,lc10)
    real[0] = lc 
    real[1] = lc * TA[i][1] // TA[i][0]  
    db((lc,real))
print(sum(real))

Submission status: Wrong Answer

Solution code:
# ABC 062
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def gcd(x, y): # 最大公約数
    m = max(x,y)
    n = min(x,y)
    while m%n != 0:
        w = m%n
        m = n
        n = w
    return n

def lcm(x, y): return x*y//gcd(x,y) # 最小公倍数
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
TA = zeros(N)
for i in range(N):
    TA[i] = getIntList()
db(TA)
real = TA[0]
for i in range(1,N):
    if real[0]>real[1]:
#        for k in range(1,99999999999):
#            lc = TA[i][0]*k
#            if  lc>=real[0]: break
        lc = (real[0]+TA[i][0]-1)//TA[i][0]*TA[i][0]
        real[0] = lc 
        real[1] = lc * TA[i][1] // TA[i][0]  
    else:
        lc = (real[1]+TA[i][1]-1)//TA[i][1]*TA[i][1]
        real[1] = lc 
        real[0] = lc * TA[i][0] // TA[i][1]  
    db((lc,real))
print(sum(real))

Submission status: Wrong Answer

Solution code:
# ABC 062
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def gcd(x, y): # 最大公約数
    m = max(x,y)
    n = min(x,y)
    while m%n != 0:
        w = m%n
        m = n
        n = w
    return n

def lcm(x, y): return x*y//gcd(x,y) # 最小公倍数
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
TA = zeros(N)
for i in range(N):
    TA[i] = getIntList()
db(TA)
real = TA[0]
for i in range(1,N):
    if real[0]>real[1]:
        for k in range(1,99999999999):
            lc = TA[i][0]*k
            if  lc>=real[0]: break
        real[0] = lc 
        real[1] = lc * TA[i][1] // TA[i][0]  
    else:
        for k in range(1,99999999999):
            lc = TA[i][1]*k
            if  lc>=real[1]: break
        real[1] = lc 
        real[0] = lc * TA[i][0] // TA[i][1]  
    db((lc,real))
print(sum(real))

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*i >= x and b*i >= y:break
        x += a*i-x
        y += b*i-y
print(x+y)
#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

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
        for j in range(10000):
            if (b*x-a*y+b*j)%a == 0 and b*x-a*y+b*j >= 0:break
        if i+(a*y-b*x+a*i)//b <= j+(b*x-a*y+b*j)//a:
            x += (a*y-b*x+a*i)//b
            y += i
        else:
            x += j
            y += (b*x-a*y+b*j)//a
print(x+y)
#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T