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())
TA, AO = map(int, input().split())

for i in range(N-1):
    T, A = map(int, input().split())
    for i in range(1, 100000):
        if T*i >= TA and A*i >= AO:
            TA, AO = T*i, A*i
            break

print(TA+AO)

Submission status: Wrong Answer

Solution code:
N = int(input())
TA, AO = map(int, input().split())

for i in range(N-1):
    T, A = map(int, input().split())
    #print('------------------------',TA, AO)
    for i in range(1, 10000):
        if T*i >= TA and A*i >= AO:
            TA, AO = T*i, A*i
            break

print(TA+AO)

Submission status: Wrong Answer

Solution code:
N = int(input())
TA, AO = map(int, input().split())

for i in range(N-1):
    T, A = map(int, input().split())
    
    for i in range(1, 1000):
        if T*i >= TA and A*i >= AO:
            TA, AO = T*i, A*i
            break

print(TA+AO)

Submission status: Wrong Answer

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

T, A = 1,1
for i in range(N):
  t, a = map(int, input().split())
  #T <= tn and A <= an
  #T/t <= n and A/a <= n
  # max, ceil
  #N = ceil(max(T/t, A/a))
  N = max(ceil(T/t), ceil(A/a))

  T = t * N
  A = a * N
  
print(T+A)

Submission status: Wrong Answer

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

T, A = 1,1
for i in range(N):
  t, a = map(int, input().split())
  #T <= tn and A <= an
  #T/t <= n and A/a <= n
  # max, ceil
  N = ceil(max(T/t, A/a))
  T = t * N
  A = a * N
  
print(T+A)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = 1
B = 1
for i in range(N):
    x, y = map(int, input().split())
    key = max(A / x, B / y)
    if key != int(key):
        key = key + 1
    key = int(key)
    A = x * key
    B = y * key

print(int(A + B))

Submission status: Wrong Answer

Solution code:
N = int(input())
A, B = map(int, input().split())
for i in range(N - 1):
    x, y = map(int, input().split())
    key = max(A / x, B / y)
    if key != int(key):
        key = int(key + 1)
    A = x * key
    B = y * key

print(int(A + B))

Submission status: Wrong Answer

Solution code:
import math

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

tx, ax = 1, 1
for ri in r:
    ti, ai = ri[0], ri[1]
    n = max(math.ceil(tx / ti), math.ceil(ax / ai))
    tx, ax = n * ti, n * ai

print(tx + ax)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t = 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:
import math
n = int(input())
a, b = map(int, input().split())
for i in range(n - 1):
    c, d = map(int, input().split())
    q = max(math.ceil(a / c), math.ceil(b / d))
    a, b = c * q, d * q

print(a + b)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
input_list = [[int(i) for i in input().split()] for j in range(N)]

T, A = input_list[0][0], input_list[0][1]

for i in range(1, N):
    n = int(max(math.ceil(T/input_list[i][0]), math.ceil(A/input_list[i][1])))
    T = input_list[i][0] * n
    A = input_list[i][1] * n

print(T + A)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
input_list = [[int(i) for i in input().split()] for j in range(N)]

T, A = input_list[0][0], input_list[0][1]

for i in range(1, N):
    n = max(math.ceil(T/input_list[i][0]), math.ceil(A/input_list[i][1]))
    T = input_list[i][0] * n
    A = input_list[i][1] * n

print(T + A)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    c,d=map(int,input().split())
    if a<=c and b<=d:
        a,b=c,d
    elif c<a and b<=d:
        a,b=c*(-(-a//c)),d*(-(-a//c))
    elif a<=c and d<b:
        a,b=c*(-(-b//d)),d*(-(-b//d))
    elif c<a and d<b:
        if -(-a//c) > -(-(b//d)):
            a,b=c*(-(-a//c)),d*(-(-a//c))
        elif -(a//c) < -(-(b//d)):
            a,b=c*(-(-b//d)),d*(-(-b//d))
    print("{} {}".format(a,b))
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    c,d=map(int,input().split())
    if a<=c and b<=d:
        a,b=c,d
    elif c<a and b<=d:
        a,b=c*(-(-a//c)),d*(-(-a//c))
    elif a<=c and d<b:
        a,b=c*(-(-b//d)),d*(-(-b//d))
    elif c<a and d<b:
        if -(-a//c) > -(-(b//d)):
            a,b=c*(-(-a//c)),d*(-(-a//c))
        elif -(a//c) <= -(-(b//d)):
            a,b=c*(-(-b//d)),d*(-(-b//d))
    print("{} {}".format(a,b))
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=map(int,input().split())
for i in range(n-1):
    c,d=map(int,input().split())
    if c<a and d>=b:
        a,b=c*(-(-a//c)),d*(-(-a//c))
    elif c>=a and d<b:
        a,b=c*(-(-b//d)),d*(-(-b//d))
    elif c<a and d<b:
        if a//c >= b//d:
            a,b=c*(-(-a//c)),d*(-(-a//c))
        else:
            a,b=c*(-(-b//d)),d*(-(-b//d))
    else:
        a,b=c,d
print(a+b)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
t = 1
a = 1
for nums in grid:
  x = nums[0]
  y = nums[1]
  m = max(math.ceil(t/x),math.ceil(a/y))
  t = x*m
  a = y*m
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
x = [list(map(int,input().split())) for i in range(n)]
a = x[0][0]
b = x[0][1]
x.pop(0)
for i in x:
  m = math.ceil(a/i[0]) 
  n = math.ceil(b/i[1])
  a = max(m,n) * i[0]
  b = max(m,n) * i[1]
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=1,1
import math
for i in range(n):
    x,y=ta[i]
    t=max(-(-a//x),-(b//y))
    a,b=t*x,t*y
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=1,1
import math
for i in range(n):
    x,y=ta[i]
    t=max(math.ceil(a/x),math.ceil(b/y))
    a,b=t*x,t*y
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=1,1
import math
for i in range(n):
    x,y=ta[i]
    j,k=x,y
    t=max(math.ceil(a/j),math.ceil(b/k))
    a,b=j*t,k*t
print(a+b)

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n)]

a = 1
b = 1
import numpy as np
for i in range(n):
	x, y = arr[i]
	t = max(int(np.ceil(a*1.0/x)), int(np.ceil(b*1.0/y)))

	a = x*t; b = y*t

print a+b

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n)]

a,b = arr[0]
import numpy as np
for i in range(1,n):
	x, y = arr[i]
	t = max(int(np.ceil(a*1.0/x)), int(np.ceil(b*1.0/y)))

	a = x*t; b = y*t

print a+b

Submission status: Wrong Answer

Solution code:
N = int(input())

import math
tx, ax = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    fac = math.ceil(max(tx/T, ax/A))
    tx = T * fac
    ax = A * fac

print(tx + ax)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = 1
A = 1
for i in range(N):
  ti, ai = map(int, input().split())
  m = int(max(math.ceil(T / ti), math.ceil(A / ai)))
  T = ti * m
  A = ai * m
print(T + A)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ab = [[int(x) for x in input().split()] for _ in range(N)]

p = 1
for i in range(1, N):
    p = math.ceil(max(ab[i - 1][0] / ab[i][0], ab[i - 1][1] / ab[i][1]) * p)
print(sum(ab[N - 1]) * p)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = 1
A = 1
for i in range(N):
  ti, ai = map(int, input().split())
  m = int(max(math.ceil(T / ti), math.ceil(A / ai)))
  T = ti * m
  A = ai * m
print(int(T + A))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

x, y = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    p = max(math.ceil(x / T), math.ceil(y / A))
    x = T * p
    y = A * p
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = 1
A = 1
for i in range(N):
  ti, ai = map(int, input().split())
  m = max(math.ceil(T / ti), math.ceil(A / ai))
  T = ti * m
  A = ai * m
print(int(T + A))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = 1
A = 1
for i in range(N):
  ti, ai = map(int, input().split())
  m = max(math.ceil(T / min(T, ti)), math.ceil(A / min(A, ai)))
  T = ti * m
  A = ai * m
print(int(T + A))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

x, y = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    if x > T and y > A:
        p = min(math.ceil(x / T), math.ceil(y / A))
        if T * p < x or A * p < y:
            p = max(math.ceil(x / T), math.ceil(y / A))
        x = T * p
        y = A * p
    elif x > T:
        p = math.ceil(x / T)
        x = T * p
        y = A * p
    elif y > A:
        p = math.ceil(y / A)
        x = T * p
        y = A * p
    else:
        x = T
        y = A
print(x + y)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

x, y = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    if x > T or y > A:
        p = min(math.ceil(x / T), math.ceil(y / A))
        if T * p < x or A * p < y:
            p = max(math.ceil(x / T), math.ceil(y / A))
        x = T * p
        y = A * p
    else:
        x = T
        y = A
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T, A = map(int, input().split())
for i in range(N-1):
    Ti, Ai = map(int, input().split())
    n = int(max(math.ceil(T / Ti), math.ceil(A / Ai)))
    T = Ti * n
    A = Ai * n
print(T + A)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T, A = map(int, input().split())
for i in range(N-1):
    Ti, Ai = map(int, input().split())
    n = math.ceil(max(math.ceil(T / Ti), math.ceil(A / Ai)))
    T = Ti * n
    A = Ai * n
print(T + A)

Submission status: Wrong Answer

Solution code:
N = int(input())

import math
tx, ax = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    fac = math.ceil(max(tx/T, ax/A))
    for cand in range(fac - 1, 0, -1):
        if A * cand < ax or T * cand < tx: break
        fac = cand
    tx = T * fac
    ax = A * fac

print(tx + ax)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

x, y = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    if x > T or y > A:
        p = max(math.ceil(x / T), math.ceil(y / A))
        x = T * p
        y = A * p
    else:
        x = T
        y = A
print(x + y)

Submission status: Wrong Answer

Solution code:
N = int(input())

import math
tx, ax = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    if tx / T > ax / A:
        fac = math.ceil(tx/T)
        for cand in range(fac - 1, 0, -1):
            if A * cand < ax or T * cand < tx: break
            fac = cand
        tx = T * fac
        ax = A * fac
    else:
        fac = math.ceil(ax/A)
        for cand in range(fac - 1, 0, -1):
            if A * cand < ax or T * cand < tx: break
            fac = cand
        tx = T * fac
        ax = A * fac
print(tx + ax)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    D = [li_input() for _ in range(N)]

    t, a = 1, 1

    # t = t_rate * x
    # a = a_rate * x
    for t_rate, a_rate in D:
        x = max(math.ceil(t / t_rate), math.ceil(a / a_rate))
        t = t_rate * x
        a = a_rate * x

    print(a + t)


main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    D = [li_input() for _ in range(N)]

    t, a = D[0][0], D[0][1]

    for i in range(1, N):
        t_rate, a_rate = D[i]

        if t_rate == a_rate:
            t = max(t, a)
            a = max(t, a)

        elif t_rate > a_rate:
            if a_rate != 1:
                a = a + (a_rate - (a % a_rate))

            if int(a / a_rate * t_rate) > t:
                t = int(a / a_rate * t_rate)
            else:
                pre_t = t
                t = int(a / a_rate * t_rate)

                insuff = pre_t - t
                need = math.ceil(insuff / t_rate)

                a += (need * a_rate)
                t += (need * t_rate)
        else:
            if t_rate != 1:
                t = t + (t_rate - (t % t_rate))

            if int(t / t_rate * a_rate) > a:
                a = int(t / t_rate * a_rate)
            else:
                pre_a = a
                a = int(t / t_rate * a_rate)

                insuff = pre_a - a
                need = math.ceil(insuff / a_rate)

                a += (need * a_rate)
                t += (need * t_rate)

    print(a + t)


main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    D = [li_input() for _ in range(N)]

    t, a = D[0][0], D[0][1]

    for i in range(1, N):
        t_rate, a_rate = D[i]

        if t_rate == a_rate:
            t = max(t, a)
            a = max(t, a)

        elif t_rate > a_rate:
            if a_rate != 1:
                a = a + (a_rate - (a % a_rate))

            if int(a / a_rate * t_rate) > t:
                t = int(a / a_rate * t_rate)
            else:
                pre_t = t
                t = int(a / a_rate * t_rate)

                while t < pre_t:
                    a += a_rate
                    t += t_rate
        else:
            if t_rate != 1:
                t = t + (t_rate - (t % t_rate))

            if int(t / t_rate * a_rate) > a:
                a = int(t / t_rate * a_rate)
            else:
                pre_a = a
                a = int(t / t_rate * a_rate)

                while a < pre_a:
                    a += a_rate
                    t += t_rate

    print(a + t)


main()

Submission status: Wrong Answer

Solution code:
n = int(input())


def gcd(a, b):
    return gcd(b, a % b) if b != 0 else a


T = 1
A = 1
for _ in range(n):
    t, a = map(int, input().split())
    r = gcd(t, a)
    t //= r
    a //= r
    if T * a == t * A:
        continue
    if t == a:
        T = max([T, A])
        A = max([T, A])
        continue

    if T % t != 0:
        T += t - T % t
    if A < T * a // t:
        A = T * a // t
    else:
        A += a - A % a
        T = A * t // a

print(A + T)

Submission status: Wrong Answer

Solution code:
n = int(input())

T = 1
A = 1
for _ in range(n):
    t, a=map(int, input().split())
    if T * a == t * A:
        continue
    if t == a:
        T = max([T, A])
        A = max([T, A])
        continue

    if T % t != 0:
        T += t - T % t
    if A < T * a // t:
        A = T * a // t
    else:
        A += a - A % a
        T = A * t // a

print(A + T)

Submission status: Wrong Answer

Solution code:
n = int(input())

T = 1
A = 1
for _ in range(n):
    t, a=map(int, input().split())
    if T * a == t * A:
        continue
    if T % t != 0:
        T += t - T % t
    if A < T * a // t:
        A = T * a // t
    else:
        A += a - A % a
        T = A * t // a

print(A + T)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[]
A=[]
for i in range(N):
    Ti,Ai=[int(i) for i in input().split()]
    T.append(Ti)
    A.append(Ai)
T_ans=1
A_ans=1
for i in range(N):
    if T_ans>T[i] or A_ans>A[i]:
        T_ans=T[i]*max(-(-T_ans//T[i]),-(-A_ans//A[i]))
        A_ans=A[i]*T_ans/T[i]
    else:
        T_ans=T[i]
        A_ans=A[i]
print(T_ans+A_ans)

Submission status: Wrong Answer

Solution code:
import math

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

now_t, now_a = t_a[0]
for t_i, a_i in t_a[1:]:
    if now_t/now_a < t_i/a_i:
        now_a = math.ceil(now_a/a_i) * a_i
        now_t = now_a // a_i * t_i
    elif now_t/now_a > t_i/a_i:
        now_t = math.ceil(now_t/t_i) * t_i
        now_a = now_t // t_i * a_i

print(now_t + now_a)

Submission status: Wrong Answer

Solution code:
import math

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

now_t, now_a = t_a[0]
for t_i, a_i in t_a[1:]:
    if now_t/now_a < t_i/a_i:
        now_a = math.ceil(now_a/a_i) * a_i
        now_t = now_a // a_i * t_i
    else:
        now_t = math.ceil(now_t/t_i) * t_i
        now_a = now_t // t_i * a_i

print(now_t + now_a)

Submission status: Wrong Answer

Solution code:
import math

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

now_t, now_a = t_a[0]
for t_i, a_i in t_a[1:]:
	if now_t/now_a < t_i/a_i:
		one = math.ceil(now_a/a_i)
	else:
		one = math.ceil(now_t/t_i)
	now_a = one * a_i
	now_t = one * t_i

print(now_t + now_a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    nit = math.ceil(tp/ti)
    nia = math.ceil(ap/ai)
    #nit = -(-tp//ti)
    #nia = -(-ap//ai)
    ni = max(nit, nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    nit = math.floor(tp/ti)
    nia = math.floor(ap/ai)
    ni = max(nit, nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    nit = math.ceil(tp/ti)
    nia = math.ceil(ap/ai)
    ni = max(nit, nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    nit = tp/ti
    nia = ap/ai
    ni = math.ceil(max(nit, nia))
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

Submission status: Wrong Answer

Solution code:
n = int(input())
x, y = [int(i) for i in input().split()]
print(y)
for i in range(n - 1):
    t, a = [int(i) for i in input().split()]
    c = max(-(-x//t), -(-y//a))
    x = t * c
    y = a * c
print(x + y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
Rate = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N-1):
    if Rate[i+1][0]>=Rate[i][0] and Rate[i+1][1]>=Rate[i][1]:
        ans = Rate[i+1][0]+Rate[i+1][1]
        Rate[i][0]
    elif Rate[i+1][0]<Rate[i][0] and Rate[i+1][1]>=Rate[i][1]:
        bai = math.ceil(Rate[i][0]/Rate[i+1][0])
        ans = bai*(Rate[i+1][0]+Rate[i+1][1])
        Rate[i+1][0] *= bai
        Rate[i+1][1] *= bai
    elif Rate[i+1][0]>=Rate[i][0] and Rate[i+1][1]<Rate[i][1]:
        bai = math.ceil(Rate[i][1]/Rate[i+1][1])
        ans = bai*(Rate[i+1][0]+Rate[i+1][1])
        Rate[i + 1][0] *= bai
        Rate[i + 1][1] *= bai
    elif Rate[i+1][0]<Rate[i][0] and Rate[i+1][1]<Rate[i][1]:
        if Rate[i][0]>Rate[i][1]:
            ans=Rate[i][0]//Rate[i+1][0]*(Rate[i+1][0]+Rate[i+1][1])
            Rate[i + 1][0] = Rate[i][0]
            Rate[i + 1][1] = Rate[i][0]//Rate[i+1][0]*Rate[i+1][1]
        else:
            ans=Rate[i][1]//Rate[i+1][1]*(Rate[i+1][0]+Rate[i+1][1])
            Rate[i + 1][0] = Rate[i][1]//Rate[i+1][1]*Rate[i+1][0]
            Rate[i + 1][1] = Rate[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for _ in range(N):
    tn,an = map(int,input().split())
    tmp = max(math.ceil(A/tn),math.ceil(B/an))
    A = tmp*tn
    B = tmp*an
print(A+B)

Submission status: Wrong Answer

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

""" 解説動画を参考にDPにしてみた版 """

import math

N = int(input())

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

# 比率を何倍したら実際の値なのかでDPを埋めてく
dp = [0] * (N)
# 始めの基準を1倍とする
dp [0] = 1

for i in range(1,N):
    # 今回 * 前回 の計算が終わったあとで整数未満を切り上げる
    dp[i] = math.ceil(max(T[i-1] / T[i], A[i-1] / A[i]) * dp[i-1])

print((T[-1]+A[-1]) * int(dp[-1]))

Submission status: Wrong Answer

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

""" 解説動画を参考にDPにしてみた版 """

N = int(input())

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

# 比率を何倍したら実際の値なのかでDPを埋めてく
dp = [0] * (N)
# 始めの基準を1倍とする
dp [0] = 1

for i in range(1,N):
    # 今回 * 前回 の計算が終わったあとで整数未満を切り上げる
    dp[i] = -(-(max(T[i-1] / T[i], A[i-1] / A[i]) * dp[i-1]) // 1)

print((T[-1]+A[-1]) * int(dp[-1]))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a=1
b=1

for i in range(n):
    c, d=map(int, input().split())
    n=math.ceil(max(a/c, b/d))
        
    a=n*c
    b=n*d

print(a+b)

Submission status: Wrong Answer

Solution code:

import math
n = int(input())
a, b=map(int, input().split())

for i in range(n-1):
    c, d=map(int, input().split())
    n1 = math.ceil(a/c)
    n2 = math.ceil(b/d)
    
    if n1<n2:
        n=n2
    else:
        n=n1
        
    a=n*c
    b=n*d

print(a+b)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

x = 1
y = 1
for i in range(N):
    t, a = map(int, input().split())

    m = math.ceil(x / t)
    n = math.ceil(y / a)
    k = max(m, n)
    x, y = (t * k, a * k)

print(x + y)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

dp = [0] * N
for i in range(N):
    a, t = map(int, input().split())

    if i == 0:
        dp[0] = (1, 1)
        continue

    m = math.ceil(dp[i - 1][0] / a)
    n = math.ceil(dp[i - 1][1] / t)
    k = max(m, n)
    dp[i] = (a * k, t * k)

print(dp[N-1][0] + dp[N-1][1])

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

dp = [0] * N
for i in range(N):
    a, t = map(int, input().split())

    if i == 0:
        dp[0] = (a, t)
        continue

    m = math.ceil(dp[i - 1][0] / a)
    n = math.ceil(dp[i - 1][1] / t)
    k = max(m, n)
    dp[i] = (a * k, t * k)

print(dp[N-1][0] + dp[N-1][1])