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: Runtime Error

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
else:
    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: Runtime Error

Solution code:
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(-(-t//nt), -(-a//na)
        nt *= r
        na *= r
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Runtime Error

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 = 1
    if nt<t:
        r *= ceil(t/nt)
    if na*r<a:
        r *= ceil(a/na)
    na = r*na
    nt = r*nt
    t,a = nt,na
    #print(t, a)
print(t+a)

Submission status: Runtime Error

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 = 1
    if nt<t:
        r *= ceil(t/nt)
    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: Runtime Error

Solution code:
n=int(input())
for i in range(n):
    if i==0:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        if t==1 and a==1:
            x=max(x,y)
            y=max(x,y)
        else:
            t=t*max(int(x/t),int(y/a))
            a=a*max(int(x/t),int(y/a))
            x=t
            y=a
print(x+y)

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(n):
    if i==1:
        x,y=map(int,input().split())
    else:
        t,a=map(int,input().split())
        v=t
        w=a
        while t<x or a<y:
            v+=t
            w+=a
        x=v
        y=w
print(x+y)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<ll> T(N);
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i) >> A.at(i);
  }
  ll t=1,a=1;

  for (int i = 0; i < N; i++) {
    ll x=t/T.at(i);
    ll y=a/A.at(i);
    if(t%T.at(i)!=0) x++;
    if(a%A.at(i)!=0) y++;
    int co=max(x,y);
    t=co*T.at(i);
    a=co*A.at(i);
  }
  cout << t+a << endl;
}

Submission status: Runtime Error

Solution code:
from math import *
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [int(x) for x in input().split()]
    T.append(ti)
    A.append(ai)
 
prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = int(ceil(prevT / T[i]))
    nextfacA = int(ceil(prevA / A[i]))
    nextfac = max(nextfacT, nextfacA)
    while(nextfac * T[i] < prevT and nextfac * A[i] < prevA):
        nextfac += 1
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]
 
print(prevA+prevT)
from math import *
N = int(input())
T = []
A = []
for i in range(0, N):
    ti, ai = [int(x) for x in input().split()]
    T.append(ti)
    A.append(ai)
 
prevT = T[0]
prevA = A[0]
for i in range(1, N):
    nextfacT = int(ceil(prevT / T[i]))
    nextfacA = int(ceil(prevA / A[i]))
    nextfac = max(nextfacT, nextfacA)
    while(nextfac * T[i] < prevT and nextfac * A[i] < prevA):
        nextfac += 1
    prevT = nextfac * T[i]
    prevA = nextfac * A[i]
 
print(prevA+prevT)

Submission status: Runtime Error

Solution code:
A = []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
    if curT > curA:
        if curT % T[i] != 0:
            curT += T[i] - curT % T[i]
        curA = curT // T[i] * A[i]
    else:
        if curA % A[i] != 0:
            curA += A[i] - curA % A[i]
        curT = curA // A[i] * T[i]
print(curT+curA)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>

typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  std::vector< ll > vb(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i] >> vb[i];
  }

  ll a = 1;
  ll b = 1;
  for (ll i = 0; i < N; i++) {
    ll n = std::max((a + va[i] - 1) / va[i], (b + vb[i] - 1) / vb[i]);
    a = n * va[i];
    b = n * vb[i];
    //std::cout << a << " " << b << std::endl;
  }

  std::cout << a + b << std::endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())

rates = [list(map(int, input().split())) for i in range(n)]

def nextgen(points, nextrate):
  pro = 0
  boolnow = True
  while(boolnow):
    pro += 1
    boolnow = not(poits[0] <= pro * nextrate[0] and points[1] <= pro * nextrate[1])
  return [nextrate[0] * pro, nextrate[1] * pro]

pointnow = [1, 1]
for i in range(n):
  pointnow = nextgen(pointnow, rates[i])
  
print(sum(pointnow))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    if sum(vote) > 10**10:
        t[1000000000] = 1
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])

Submission status: Runtime Error

Solution code:
from math import ceil

N = int(input())
ta, ao = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    if ta <= T and ao <= A:
        ta = T
        ao = A
    else:
        if ta % T == 0:
            n = ta//T
        else:
            n == ta//T + 1
        if ao % A == 0:
            m = ao//A
        else:
            m = ao//A + 1
        
        ta = max(n, m) * T
        ao = max(n, m) * A
        print(n)
print(ta+ao)

Submission status: Runtime Error

Solution code:
N = int(input())
T, A = 1, 1
for i in range(N):
    t, a = map(int, input().split())
    if T % t == 0:
        n1 = T // t
    else:
        n1 = T // t + 1
    if A % a == 0:
        n2 = A // a
    else:
        n2 = T // a + 1
    n = max(n1, n2)
    #print(T,A)
    T = n*t
    A = n*a
    
print(sum(T+A))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
ratio = [list(map(int, input().split())) for i in range(n)]

k = 1
for i in range(n-1):
  k1 = math.ceil(ratio[i][0] * k / ratio[i+1][0])
  k2 = math.ceil(ratio[i][1] * k / ratio[i+1][1])
  k3 = math.ceil(sum(ratio[i]) * k / sum(ratio[i+1])
  k = max(k1, k2, k3)

print(sum(ratio[n-1]) * k)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

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

# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

ans = 1
for i in range(N):
    if TA[i][0] + TA[i][1] >= ans:
        ans = TA[i][0] + TA[i][1]
    else:
        ans = lcm_base(ans, TA[i][0] + TA[i][1])

print(ans)

Submission status: Runtime Error

Solution code:
import math
from Decimal import *

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

    for i in range(N - 1):
        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            mul = Decimal(max(math.ceil(T[i] / T[i + 1]), math.ceil(A[i] / A[i + 1])))
            A[i + 1] *= mul
            T[i + 1] *= mul
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math


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

    for i in range(N):
        if math.gcd(A[i], T[i]) != 1:
            A[i] = A[i] // math.gcd(A[i], T[i])
            T[i] = T[i] // math.gcd(A[i], T[i])

    for i in range(N - 1):

        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            if T[i] / T[i + 1] >= A[i] / A[i + 1]:
                A[i + 1] = math.ceil(T[i] / T[i + 1]) * A[i + 1]
                T[i + 1] = math.ceil(T[i] / T[i + 1]) * T[i + 1]
            else:
                T[i + 1] = math.ceil(A[i] / A[i + 1]) * T[i + 1]
                A[i + 1] = math.ceil(A[i] / A[i + 1]) * A[i + 1]
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def ceil(x, y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

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

Submission status: Runtime Error

Solution code:
def ceil(x,y):
    if x%y == 0:
        return x//y
    if x%y == 1:
        return x//y + 1

n = int(input())
x,y = 1,1

for _ in range(n):
    t,a  = map(int,input().split())
    temp = max(ceil(x,t),ceil(y,a))
    x = t*temp
    y = a*temp

print(x+y)

Submission status: Runtime Error

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 a // a_rate * t_rate >= t:
                t = a // a_rate * t_rate
            else:
                pre_t = t
                t = 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 t // t_rate * a_rate >= a:
                a = t // t_rate * a_rate
            else:
                pre_a = a
                a = t // t_rate * a_rate

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

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

    print(a + t)


main()

Submission status: Runtime Error

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):
    t, a = list(map(int, input().split()))
    if ti == t and ai == a:
        continue
    ti = t
    ai = a
    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: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
    t, a = list(map(int, input().split()))
    if ti == t and ai == a:
        continue
    ti = t
    ai = a
    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: Runtime Error

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

print(vi)

Submission status: Runtime Error

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

print(vi)

Submission status: Runtime Error

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

print(vi)

Submission status: Runtime Error

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

print(vi)

Submission status: Runtime Error

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

print(vi)

Submission status: Runtime Error

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

print(vi)

Submission status: Runtime Error

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

print(vi)

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

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

print(x + y)

Submission status: Runtime Error

Solution code:
def c_atcodeer_and_election_report(N, R):
    t, a = 1, 1  # 高橋, 青木の票数
    for x, y in R:
        # t<=nx ∧ a<=ny を満たす最小のnを求める
        n = max(t // x, a // y)
        if t > n * x or a > n * y:
            n += 1
        t = n * x
        a = n * y
    return t + a

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_AtCoDeer_and_ElectionReport(N, R))

Submission status: Runtime Error

Solution code:
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = m.flo-or((max((tt/t),(aa/a))))
    tt = t * n
    aa = a * n
    vote = tt + aa
print(vote)

Submission status: Runtime Error

Solution code:
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = max(m.cail(tt/t),m.ceil(aa/a))
    vote = vote * n
print(vote)

Submission status: Runtime Error

Solution code:
n = int(input())
vote = 0
tt = 0
aa = 0
for i in range(n):
    t, a = map(int,input().split())
    if (tt < t and aa = a) or (tt = t and aa < a) or (tt< t and aa <a):
        tt = t
        aa = a
        vote = t + a
    else:
        count = 1
        s = t + a
        while vote > s:
            count = count + 1
            s = s * count
            
        vote = s
        tt = count * t
        ss = count * a
            
print(vote)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    before_t = A[0][0]
    before_a = A[0][1]
    for t, a in A[1:]:
        n1 = -(-before_t // t)
        n2 = -(-before_a // a)
        n = max(n1, n2)
        taka, aoki = t * n, a * n
        before_t, before_a = taka, aoki

    print(taka + aoki)

main()

Submission status: Runtime Error

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

ans = 0
pre_t = 0
pre_a = 0

for t, a in TA:
    gcd = gcd(t, a)

    t = t * gcd
    a = a * gcd

    first_t = t
    first_a = a

    while (pre_t > t) or(pre_a > a):
        t += first_t
        a += first_a

    pre_t = t
    pre_a = a
    
print(t + a)

Submission status: Runtime Error

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

ans = 0
pre_t = 0
pre_a = 0

for t, a in TA:
    gcd = _gcd(t, a)

    t = t * gcd
    a = a * gcd

    first_t = t
    first_a = a

    while (pre_t > t) or(pre_a > a):
        t += first_t
        a += first_a

    pre_t = t
    pre_a = a
    
print(t + a)

Submission status: Runtime Error

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):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

Submission status: Runtime Error

Solution code:
 = 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):
    tt = ta[i][0]
    aa = ta[i][1]
    while t > tt or a > aa:
        tt += ta[i][0]
        aa += ta[i][1]
    t = tt
    a = aa

print(t+a)

Submission status: Runtime Error

Solution code:
t = int(raw_input())
A, B = 1, 1
for _ in range(t):
    a, b = tuple(map(int, raw_input().split()))
    c, d = int(ceil(float(A) / float(a))), int(ceil(float(B) / float(b)))
    e = max(c, d)
    A, B = a * e, b * e

print sum((A, B))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
T = []
A = []
Nb = 0
for i in range(N):
    a, b = map(int,input().split())
    T.append(a)
    A.append(b)
Tn = 1
An = 1
for i in range(N):
        tmp = max(math.ceil(Tn / T[i]), math.ceil(An / A[i]))
        Tn = T[i] * tmp
        An = A[i] * tmp
print(Tn + An)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=input()
T=[]
A=[]
for i in range(N):
    Ti,Ai=map(int,raw_input().split())
    T.append(Ti)
    A.append(Ai)
 
Tn=1
An=1
dp = np.zeros(N)
dp[0] = 1
 
for i in range(1,N):
    dp[i] = math.ceil(max(A[i]/A[i-1],T[i]/T[i-1])*dp[i-1])
 
print (T[N]+A[N])*dp[N]

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=input()
T=[]
A=[]
for i in range(N):
    Ti,Ai=map(int,raw_input().split())
    T.append(Ti)
    A.append(Ai)

Tn=1
An=1
dp = np.zeros(N)
dp[0] = 1

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

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x)),math.ceil(ah/y)))
     th = m*x
     ah = m*y
     h += 1
print(long(th+ah))

Submission status: Runtime Error

Solution code:
# C
from math import ceil
#N = int(input())
#T = [[int(i) for i in input().split()] for n in range(N)]
m = T[0]
for n in range(1, N):
    a = ceil(max(m[0]/T[n][0], m[1]/T[n][1]))
    m = [T[n][0] * a, T[n][1] * a]
print(sum(m))

Submission status: Runtime Error

Solution code:
import math                                                             
                                                                        
N = input()                                                             
t = []                                                                  
a = []                                                                  
for i in range(int(N)):                                                 
    t_n, a_n = input().split()                                          
    t.append(int(t_n))                                                  
    a.append(int(a_n))                                                  
                                                                        
ma = 0                                                                  
t_prev = 0                                                              
a_prev = 0                                                              
t_ans = 0                                                               
a_ans = 0                                                               
for t_n, a_n in zip(t, a):                                              
    summ = t_n + a_n                                                    
    summ_cp = summ                                                      
    #i = 0                                                              
    #while 1:                                                           
    #    i += 1                                                         
    #    summ = summ_cp * i                                             
    #    if summ >= ma and ((t_n*i) >= t_prev) and ((a_n*i) >= a_prev): 
    #        ma = summ                                                  
    #        break                                                      
        #summ = summ_cp * i                                             
    k = max(math.ceil(t_ans/t_n), math.ceil(a_ans/a_n))                 
    if not k:                                                           
        k = 1                                                           
    t_ans = k*t_n                                                       
    a_ans = k*a_n                                                       
print(float((t_ans+a_ans))

Submission status: Runtime Error

Solution code:
import math
from decimal import Decimal

N = int(input())
T, A = [Decimal(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [Decimal(x) for x in input().split()]
        n = max(math.ceil(T/T2),math.ceil(A/A2)
        T = T2*n
        A = A2*n

print(T + A)

Submission status: Runtime Error

Solution code:
import math
from decimal import Decimal

N = int(input())
T, A = [int(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [int(x) for x in input().split()]
        n = max(math.ceil(Decimal(T)/Decimal(T2)),math.ceil(Decimal(A)/Decimal(A2))
        T = T2*n
        A = A2*n

print(T + A)

Submission status: Runtime Error

Solution code:
import math
from decimal import Decimal

N = int(input())
T, A = [int(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [int(x) for x in input().split()]
        print('i= ',i)
        n = max(math.ceil(Decimal(T)/Decimal(T2)),math.ceil(Decimal(A)/Decimal(A2))
        print('n= ',n)
        T = T2*n
        A = A2*n
        print('T= ',T)
        print('A= ',A)

print(T + A)

Submission status: Runtime Error

Solution code:
import math

N  = int(raw_input())

T, A = map(float, raw_input().split())

for i in range(N - 1):
    t, a = map(float, raw_input().split())

    s1 = math.ceil(T / t)

    s2 = math.ceil(A / a)

    s = max(s1, s2)

    T = s * t
    A = s * a

print "%d" % T + A

Submission status: Runtime Error

Solution code:
time=input()

aok=1
tak=1

for i in time:
	l=map(int, raw_input().split())
	if l[0]>=l[1]:
		tak=(tak/l[1]+1)*l[1]
		aok=tak/l[1]*l[0]
	else:
		aok=(aok/l[0]+1)*l[0]
		tak=aok/l[0]*l[1]

print aok+tak

Submission status: Runtime Error

Solution code:
import fractions

n = int(input())

t = 1
a = 1

for i in range(n):
	x,y = map(int, input().split())
	t = fractions.gcd(x)
	a = fractions.gcd(y)
	
print(t + a)

Submission status: Runtime Error

Solution code:
import math

N  = int(raw_input())

ans = [0, 0]

T, A = [0] * 1001, [0] * 1001

for i in range(N):

    T[i], A[i] = map(float, raw_input().split())

    if i != 0 and T[i - 1] - T[i] >= 0 or A[i - 1] - A[i] >= 0:

        if (math.ceil(T[i  - 1] / T[i]) >= (math.ceil(A[i - 1] / A[i])):
            m  = math.ceil(T[i  - 1] / T[i]) 

        else:
            m = math.ceil(A[i - 1] / A[i])

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

print "%d" % sum(ans)

Submission status: Runtime Error

Solution code:
import math

N  = int(raw_input())

ans = [0, 0]
T, A = [0] * 1001, [0] * 1001

for i in range(N):
    T[i], A[i] = map(float, raw_input().split())

    if (i != 0) and ((T[i - 1] - T[i] > 0) or (A[i - 1] - A[i] > 0)):

        if (T[i  - 1] / T[i]) > (A[i - 1] / A[i]):
            m  = math.ceil(T[i  - 1] / T[i]) 

        else:
            m = math.ceil(A[i - 1] / A[i])

        T[i] *= m
        A[i] *= m

    ans = [T[i], A[i]]

    T[i] /= m
    A[i] /= m

print "%d" % sum(ans)