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: Time Limit Exceeded

Solution code:
N = int(input())
T, A = map(int, input().split())
num = T + A
for _ in range(N-1):
  t, a = map(int, input().split())
  while True:
    if num%(t+a) == 0 and (num*t)//(t+a) >= T and (num*a)//(t+a) >= A:
      T = (num*t)//(t+a)
      A = (num*a)//(t+a)
      break
    num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x,y = 1,1
for i in range(n):
    t,a = map(int,input().split())
    k = 0
    if x * a != y * t:
        while True:
            if t*k >= x and a*k >= y:
                break
            else:
                k += 1
        x = t * k
        y = a * k
print(x+y)

Submission status: Time Limit Exceeded

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

ans = [[arr[0][0], arr[0][1]]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    while ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
        ans[i+1][0] += arr[i+1][0]
        ans[i+1][1] += arr[i+1][1]
print(ans[num-1][0] + ans[num-1][1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num = 1
for _ in range(N):
  x, y = map(int, input().split())
  sum_xy = x+y
  while True:
    if num%sum_xy == 0:
      break
    else:
      num += num%sum_xy
print(num)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, T: "List[int]", A: "List[int]"):
    tmpT = T[0]
    tmpA = A[0]
    for i in range(1, N):
        d = 1
        while(T[i]*d<tmpT or A[i]*d<tmpA):
            d += 1
        tmpT = T[i] * d
        tmpA = A[i] * d
    print(tmpT+tmpA)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [int()] * (N)  # type: "List[int]" 
    A = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        T[i] = int(next(tokens))
        A[i] = int(next(tokens))
    solve(N, T, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
def func(T_pre, A_pre, T, A):
  for i in range(1, 10**10):
    if T_pre <= T and A_pre <= A:
      return T, A
    else:
      T = T*(i+1)/i
      A = A*(i+1)/i
for i in range(N):
  T, A = map(int, input().split())
  if i == 0:
    T_pre = T
    A_pre = A
  else:
    T_pre, A_pre = func(T_pre, A_pre, T, A)
print(int(T_pre+A_pre))

Submission status: Time Limit Exceeded

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

t_n = 1
a_n = 1

for ratio in l:
    while True:
        if t_n*ratio[1] < a_n*ratio[0]:
            t_n += 1
        
        elif t_n*ratio[1] > a_n*ratio[0]:
            a_n += 1
        
        else:
            break
        
print(a_n+t_n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,t,a,*u=map(int,open(0).read().split())
for u,b in zip(u[::2],u[1::2]):
    v,c=u,b
    while v<t or c<a:
        v+=u
        c+=b
    t,a=v,c
print(t+a)

Submission status: Time Limit Exceeded

Solution code:
n,t,a,*u=map(int,open(0).read().split())
for u,b in zip(u[::2],u[1::2]):
    while t*b!=a*u:
        if t*b<a*u:t+=1
        else:a+=1
print(t+a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = 1
y = 1
for i in range(n):
    t, a = [int(_) for _ in input().split()]
    tt = t
    aa = a
    while tt < x or aa < y:
        tt += t
        aa += a
    x = tt
    y = aa
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    t = []
    a = []
    for i in range(n):
        in_t,in_a = map(int,input().split(' '))
        t.append(in_t)
        a.append(in_a)
    if n == 1:
        return t[0]+a[0]
    tmp_t = t[0]
    tmp_a = a[0]
    for i in range(1,n):
        while True:
            if tmp_t/tmp_a == t[i]/a[i]:
                break
            elif tmp_t/tmp_a < t[i]/a[i]:
                tmp_t += 1
            else:
                tmp_a += 1
    return tmp_t+tmp_a

if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions

N=int(input())
t,a=1,1
for i in range(N):
    T,A=map(int,input().split())
    Te,Ae=T,A
    if t>T or a>A:
        T,A=T*math.ceil((t+a)/(T+A)),A*math.ceil((t+a)/(T+A))
        while t>T or a>A:
            T+=Te
            A+=Ae
    t,a=T,A

print(t+a)

Submission status: Time Limit Exceeded

Solution code:
import fractions

N=int(input())
t,a=1,1
for i in range(N):
    T,A=map(int,input().split())
    Te,Ae=T,A
    while t>T or a>A:
        T+=Te
        A+=Ae
    t,a=T,A

print(t+a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
pt = pa = 0
for _ in range(N):
    t,a = map(int,input().split())
    if pt == 0:pt,pa = t,a
    else:
        if (pt <= t) and (pa <= a):pt,pa = t,a
        else:
            i = 2
            while True:
                if (pt <= t*i) and (pa <= a*i):
                    pt,pa = t*i,a*i
                    break
                i += 1
print(pt+pa)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
q=[]
w=[]
S=[]
D=[]
for i in range(0,n):
    p=input().rstrip().split(' ')
    l.append(int(p[0]) / int(p[1]))
    q.append(p)
#print(l)
#print(q)
a=-1;
b=-1;
for i in range(0,len(l)):
    #print(a,b)
    if i==0:
        a=int(q[0][0])
        b=int(q[0][1])
    else:
        if int(q[i][0])>=a and int(q[i][1])>=b:
            a=int(q[i][0])
            b=int(q[i][1])
        else:
            #print(l[i-1])
            G=0;
            for j in range(a,10000000000):
                for k in range(b,1000000000):
                    if j/k == l[i]:
                        a=j;
                        b=k;
                        G=1;
                        break;
                    elif j/k < l[i-1]:
                        break;
                if G==1:
                    break;
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

T = 0
A = 0
for _ in range(N):
  count = 1
  next_T, next_A = [int(i) for i in input().split()]
  if next_T > T and next_A > A:
    T = int(next_T)
    A = int(next_A)
  else: 
    while next_T < T or next_A < A:
      next_T /= count-1 if count > 1 else 1
      next_A /= count-1 if count > 1 else 1
      next_T *= count 
      next_A *= count
      count += 1
    T = int(next_T)
    A = int(next_A)
print(int(sum([T, A])))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

N = int(sys.stdin.readline())
TA = []
for i in range(N):
    TA.append(list(map(int, sys.stdin.readline().split())))

current_T = 0
current_A = 0
for i in range(N):
    if i == 0:
        current_T = TA[i][0]
        current_A = TA[i][1]
        continue
    escape_flag = 0
    temp_T = math.floor(current_T / TA[i][0])
    temp_A = math.floor(current_A / TA[i][1])
    count = min([temp_T, temp_A])
    while escape_flag == 0:
        if TA[i][0] * count >= current_T and TA[i][1] * count >= current_A:
            escape_flag =1
        else:
            count += 1
    current_T = TA[i][0] * count
    current_A = TA[i][1] * count

print(current_T+ current_A)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

N = int(sys.stdin.readline())
TA = []
for i in range(N):
    TA.append(list(map(int, sys.stdin.readline().split())))

current_T = 0
current_A = 0
for i in range(N):
    if i == 0:
        current_T = TA[i][0]
        current_A = TA[i][1]
        continue
    escape_flag = 0
    count = 1
    while escape_flag == 0:
        if TA[i][0] * count >= current_T and TA[i][1] * count >= current_A:
            escape_flag =1
        else:
            count += 1
    current_T = TA[i][0] * count
    current_A = TA[i][1] * count

print(current_T+ current_A)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

lst_S = []
for i in range(N):
    lst_S.append(input().split())
    lst_S[i][0] = int(lst_S[i][0])
    lst_S[i][1] = int(lst_S[i][1])


bote_A = lst_S[0][0]
bote_B = lst_S[0][1]

for i in range(1, N):
    A_w = lst_S[i][0]
    B_w = lst_S[i][1]
    while 1:
        if (A_w >= bote_A) and (B_w >= bote_B):
            break
        else:
            A_w += lst_S[i][0]
            B_w += lst_S[i][1]
    bote_A = A_w
    bote_B = B_w

ans = bote_A + bote_B

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
re_t = 0
re_a = 0
for i in range(n):
    t, a = map(int, input().split(' '))
    n = 1
    while n*t < re_t or n*a < re_a:
        n += 1
    re_t = n * t
    re_a = n * a
print(re_t + re_a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a,b = map(int,input().split())
for i in range(N-1):
    aa,bb = map(int,input().split())
    taa,tbb = aa,bb
    while True:
        if aa >= a and bb >=b:
            break
        aa += taa
        bb += tbb
    a,b = aa,bb
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import math



N = int(input())
tn,an = [1,1]
for _ in range(N):
  t,a = map(int, input().split())
  idx = 1
  while t*idx < tn or a*idx < an:
    idx += 1
  tn,an = [t*idx,a*idx]
print(tn+an)

Submission status: Time Limit Exceeded

Solution code:
# C問題
N = int(input())
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1,  N+1):
    tmp_t = 0
    tmp_a = 0
    if i == N:
        flag = False        
    while flag:
        tmp_t += TA[i][0]
        tmp_a += TA[i][1]
        if tmp_t >= t and tmp_a >= a:
            t = tmp_t
            a = tmp_a
            break
    
print(t+a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
T = 1
A = 1
for _ in range(n):
    i = 1
    t, a = map(int, input().split())
    while i * t < T or i * a < A:
        i += 1
    T = i * t
    A = i * a
print(T + A)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
T, A = 0, 0
for i in range(N):
    Ti, Ai = map(int, input().split())
    t, a = Ti, Ai
    while t < T or a < A:
        t += Ti
        a += Ai
    T, A = t, a
print(T + A)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    tt, aa = ti, ai
    while tt < t or aa < a:
        tt += ti
        aa += ai

    t = tt
    a = aa

print(t + a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

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

l, r = 1, 1

for x, y in L:
    c = 1
    while True:
        xx = x * c
        yy = y * c
            
        if l <= xx and r <= yy:
            l, r = xx, yy
            break
        else:
            c += 1

print(l + r)

Submission status: Time Limit Exceeded

Solution code:

import math

def read_input():
    n = int(input())

    ratios = []
    for i in range(n):
        t, a = map(int, input().split())
        ratios.append((t, a))

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    # cand1
    cand1 = list(ex_votes)
    a = ex_votes[0] % ratio[0]
    if a != 0:
        cand1[0] += ratio[0] - a
    cand1 = (cand1[0], int(cand1[0] / ratio[0] * ratio[1]))

    while not check_votes(ex_votes, cand1):
        cand1 = (cand1[0] + ratio[0], cand1[1] + ratio[1])


    cand2 = list(ex_votes)
    b = ex_votes[1] % ratio[1]
    if b != 0:
        cand2[1] += ratio[1] - b
    cand2 = (int(cand2[1] / ratio[1] * ratio[0]), cand2[1])

    while not check_votes(ex_votes, cand2):
        cand2 = (cand2[0] + ratio[0], cand2[1] + ratio[1])

    if sum(cand1) < sum(cand2):
        return cand1
    else:
        return cand2


def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Time Limit Exceeded

Solution code:

import math

def read_input():
    n = int(input())

    ratios = []
    for i in range(n):
        t, a = map(int, input().split())
        ratios.append((t, a))

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.ceil(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            base += 1
            # diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            # if diff_votes[0] < diff_votes[1]:
            #     base += int(math.ceil(-diff_votes[0]/ratio[0]))
            # else:
            #     base += int(math.ceil(-diff_votes[1]/ratio[1]))

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Time Limit Exceeded

Solution code:
def read_input():
    n = int(input())

    ratios = []
    for i in range(n):
        t, a = map(int, input().split())
        ratios.append((t, a))

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = 1
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            base += 1

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

ratio_list=[]

for i in range(n):
    t,a=(int (x) for x in input().split())
    ratio_list.append([t,a])

t=ratio_list[0][0]
a=ratio_list[0][1]
ratio=0

for i in range(n-1):
    tr=ratio_list[i+1][0]
    ar=ratio_list[i+1][1]
    while tr/ar!=t/a:
        if tr/ar<t/a:
            a=a+1
        else:
            t=t+1

print(a+t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = y = 1
for i in range(n):
    t, a = map(int, input().split())
    k = 1
    while True:
        if t*k >= x and a*k >= y:
            x, y = t*k, a*k
            break
        k += 1
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = TA[0][0]
vote_A = TA[0][1]
if len(TA)>1:
	for Ti, Ai in TA[1:]:
		n = 1
		tmp_Ti = Ti * n
		tmp_Ai = Ai * n
		while tmp_Ti < vote_T or tmp_Ai < vote_A:
			n += 1
			tmp_Ti = Ti * n
			tmp_Ai = Ai * n
		vote_T = tmp_Ti
		vote_A = tmp_Ai
print(vote_A + vote_T)

Submission status: Time Limit Exceeded

Solution code:
n=int(input());a,b=1,1
for i in range(n):
  c,d=map(int,input().split())
  cc,dd=c,d
  while a>c or b>d:c+=cc;d+=dd
  a,b=c,d
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
import math

N=int(input())

def divceil(a,b):
  n=0
  while a>n*b:
    n+=1
  return n

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

Submission status: Time Limit Exceeded

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

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = 2
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

#比に対する掛け率
kake = 1
sum_tmp = 0
t_tmp = 0
a_tmp = 0

for i in range(n):
    kake = 1
    #i+1回目の合計がi回目の合計より大きくなる最小の掛け率を計算する
    while kake*(T[i]+A[i]) < sum_tmp or kake*T[i] < t_tmp or kake*A[i] < a_tmp:
        kake += 1
    
    sum_tmp = kake*(T[i]+A[i])
    t_tmp = kake*T[i]
    a_tmp = kake*A[i]

ans = kake * (T[n-1]+A[n-1])
print(ans)

Submission status: Time Limit Exceeded

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())
        v=t
        w=a
        while v<x or w<y:
            v+=t
            w+=a
        x=v
        y=w
print(x+y)

Submission status: Time Limit Exceeded

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())
        v=t
        w=a
        while t<x or a<y:
            v+=t
            w+=a
        x=v
        y=w
print(x+y)

Submission status: Time Limit Exceeded

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

tmp1 = 1
tmp2 = 1

res = 2
for l in L:
    i = 1
    while True:
        if i * l[0] >= tmp1 and i * l[1] >= tmp2:
            res += (i * l[0] - tmp1) + (i * l[1] - tmp2)
            tmp1 = i * l[0] 
            tmp2 = i * l[1] 
            break
        i += 1
            
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
B = []
for i in range(N) :
    in_a,in_b = map(int,input().split())
    A.append(in_a)
    B.append(in_b)
    
for i in range(1,N) :
    a = A[i]
    b = B[i]
    while ((A[i-1] > a) or (B[i-1] > b)) :
        a += A[i]
        b += B[i]
    A[i] = a
    B[i] = b
ans = A[-1] + B[-1]
print(ans)

Submission status: Time Limit Exceeded

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

for k in range(n):
    if k:
        for m in range(1,10**18):
            if a[k-1][0] <= m*a[k][0] and a[k-1][1] <= m*a[k][1]:
                a[k] = [m*a[k][0], m*a[k][1]]
                break
print(sum(a[n-1]))

Submission status: Time Limit Exceeded

Solution code:
n0 = [1, 1]
for i in range(int(input())):
    n = [int(_) for _ in input().split()]
    n1 = n
    while True:
        if all(i0 <= i1 for i0, i1 in zip(n0, n1)):
            break
        n1 = [j1 + j for j1, j in zip(n1, n)]
    n0 = n1
print(sum(n0))

Submission status: Time Limit Exceeded

Solution code:
def find_current_score(current_big_score, current_small_score, big_ratio, small_ratio):
    candidate_big_score = current_big_score
    candidate_small_score = 0
    while(True):
        candidate_small_score = candidate_big_score / big_ratio * small_ratio
        flag1 = candidate_small_score % 1 == 0.0
        flag2 = candidate_small_score >= current_small_score
        if(flag1 and flag2):
            break
        candidate_big_score += 1
    return int(candidate_big_score), int(candidate_small_score)

t_list = []
a_list = []

N = int(input())
for  n in range(N):
    t, a = list(map(int, input().strip().split()))
    t_list.append(t)
    a_list.append(a)
    
t_score = t_list[0]
a_score = a_list[0]

for n in range(1, N):
    t_ratio = t_list[n]
    a_ratio = a_list[n]
    t_score, a_score = find_current_score(t_score, a_score, t_ratio, a_ratio)
    
print(t_score + a_score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
t, a = 1, 1

for _ in range(N):
  _t, _a = map(int, input().strip().split())
  if _t > _a:
    i = t // _t
  else:
    i = a // _a
  while True:
    if _t*i>=t and _a*i>=a:
      break
    else:
      i += 1
  t = _t*i
  a = _a*i
print(t+a)

Submission status: Time Limit Exceeded

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

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N):
    j = 1
    while tak > TA[i][0]*j or aok > TA[i][1]*j:
        j += 1
    tak = TA[i][0] * j
    aok = TA[i][1] * j

print(tak+aok)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
    i = 1
    while True:
        if l2[0] * i >= l1[0] and l2[1] * i >= l1[1]:
            l2[0] *= i
            l2[1] *= i
            break
        i += 1
for i in range(N-1):
    modify(info[i],info[i+1])
ans = sum(info[-1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
    k1 = math.ceil(l1[0]/l2[0])
    k2 = math.ceil(l1[1]/l2[1])
    bigin = min(k1,k2)
    end = max(k1,k2)
    for i in range(bigin,end+1):
        if l2[0] * i >= l1[0] and l2[1] * i >= l1[1]:
            l2[0] *= i
            l2[1] *= i
            break
for i in range(N-1):
    modify(info[i],info[i+1])
ans = sum(info[-1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
Ratio = [list(map(int,input().split())) for _ in range(n)]
t,a = Ratio[0][0],Ratio[0][1]

for i in range(1,n):
    count = 1
    while True:
        if Ratio[i][0]*count >= t and Ratio[i][1]*count >= a:
            t,a = Ratio[i][0]*count,Ratio[i][1]*count
            break
        else:
            count += 1

print(t+a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

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

for i in range(1, n):
    if a[i][0] < a[i][1]:
        j = 1
        while True:
            if a[i][0]*j < s or a[i][1]*j < t:
                pass
            else:
                s = a[i][0]*j
                break
            j += 1

        t = j*a[i][1]

    elif a[i][0] > a[i][1]:
        j = 1
        while True:
            if a[i][1]*j < t or a[i][0]*j < s:
                pass
            else:
                t = a[i][1]*j
                break
            j += 1

        s = j*a[i][0]

    else:
        s, t = max(s, t), max(s,t)

print(s+t)

Submission status: Time Limit Exceeded

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

n_t, n_a = 1, 1
for t, a in TA:
    s, b = 0, 0
    while not (n_t <= s and n_a <= b):
        s += t
        b += a
    n_t, n_a = s, b

print(n_t+n_a)

Submission status: Time Limit Exceeded

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

# print("-")

s_t, s_a = 1, 1 
for t, a in TA:
    v_t, v_a = 0, 0
    while v_t < s_t or v_a < s_a:
        v_t += t
        v_a += a
    s_t, s_a = v_t, v_a
    # print(s_t, s_a)

print(s_t+s_a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
vote = [int(i) for i in input().split()]

# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n-1):
    # print(i)
    t, a = [int(i) for i in input().split()]
    # vote[0]<tk, vote[1]<akとなるkを算出(k<nなのでO(n))
    for k in range(1, 10000000):
        # print("k:{}".format(k))
        if t*k >= vote[0] and a*k >= vote[1]:
            vote = [t*k, a*k]
            break
    # print("vote:{}".format(vote))
print(sum(vote))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 2

for i in range(0, N):
    T_tmp = TA[i][0]
    A_tmp = TA[i][1]
    while T_tmp < T or A_tmp < A:
        T_tmp += TA[i][0]
        A_tmp += TA[i][1]
    T = T_tmp
    A = A_tmp
    ans = T + A

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
TA = []
for _ in range(N):
    TA.append(list(map(int, input().split())))

t0,a0 = 0,0
hyo = 0
for i in range(N):
    t,a = TA[i]
    if t0 == t and a0 == a:
        pass
    else:
        tmpt,tmpa = t,a
        if t0 > t or a0 > a:
            while t0 > tmpt or a0 > tmpa:
                tmpt += t
                tmpa += a
    t0,a0 = tmpt,tmpa
    # print(tmpt, tmpa)

print(t0+a0)

Submission status: Time Limit Exceeded

Solution code:
def solve(N, TAs):
    T, A = 1, 1
    for t, a in TAs:
        m = (t * A) % a
        y = 0
        while True:
            if (m + (y * t)) % a == 0 and (t * A + t * y) // a >= T:
                break
            y += 1
        x = (t * A + t * y) // a - T

        T += x
        A += y
    return T + A

#        T + x : A + y = t : a
#       <=> t * A + y * t = a * T + x * a
#       <=> x =  (t * A + y * t) / a -  T => 整数
# 　　　<=> y =  (a * T + x * a) / t -  A => 整数
# 以下二つが両方とも整数
# (a * T + x * a) / t
# (t * A + y * t) / a
#  t - (a * T mod t) = (x * a) mod t

if __name__ == "__main__":
    N = int(input())
    TAs = [(tuple)(map(int, input().split(" "))) for l in range(N)]
    print(solve(N, TAs))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

n=int(input())

x,y=map(int, input().split())
for i in range(n-1):
    t,a=map(int, input().split())
    if (x<=t and y<=a):
        x=t
        y=a
    else:
        tmp=1
        while 1:
            if x<=t*tmp and y<=a*tmp:
                x=t*tmp
                y=a*tmp
                break
            tmp+=1
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = input().split(" ")
n = int(b[0])
m = int(b[1])
for i in range(a-1):
    l = list(map(int,input().split(" ")))
    while l[0] / l[1] != n / m:
        if l[0] / l[1] > n / m:
            n += 1
        else:
            m += 1
print(n + m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
T = 1
A = 1


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

    if max(t,a)%min(t,a) == 0:
        if t > a:
            t = t//a
            a = a
        else:
            t = t
            a = a//t

    j = 0
    while T > t*j or A > a*j:
        j += 1

    T = t*j
    A = a*j

print(T+A)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
TA=[list(map(int, input().split())) for _ in range(N)]
ls=[[TA[0][0],TA[0][1]]]
for i in range(1,N):
    tmp=[TA[i][0],TA[i][1]]
    j=2
    while 1:
        if tmp[0]>=ls[-1][0] and tmp[1]>=ls[-1][1]:
            break
        tmp[0]=TA[i][0]*j
        tmp[1]=TA[i][1]*j
        j+=1
    ls.append([tmp[0],tmp[1]])
print(ls[-1][0]+ls[-1][1])

Submission status: Time Limit Exceeded

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

print(a + b)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=0,0
for i in range(n):
    x,y=ta[i]
    j,k=x,y
    t=0
    while(1):
        t+=1
        if j*t>=a and k*t>=b:
            break
    a,b=j*t,k*t
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t,a = 0,0
for i in range(n):
    tt,aa = map(int,input().split())
    p,q = tt,aa
    while p<t or q<a:
        p += tt
        q += aa
    t,a = p,q
print(t+a)

Submission status: Time Limit Exceeded

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

now_t, now_a = 1, 1
for t_i, a_i in t_a:
	count = 1
	while t_i*count < now_t or a_i*count < now_a:
		count += 1
	now_t = t_i*count
	now_a = a_i*count

print(now_t + now_a)

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    arry = [list(map(int, input().split())) for _ in range(n)]
    ans = [arry[0]]
    
    for i in range(1, n):
        a, b = arry[i]
        while True:
            if a >= ans[i-1][0] and b >= ans[i-1][1]:
                ans.append([a, b])
                break
            a += arry[i][0]
            b += arry[i][1]
            
    print(sum(ans[-1]))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

# initial
p_t, p_a = 1, 1

for i in range(N) :
    t, a = map(int, input().split())
    t_up, a_up = t, a
    
    if t >= p_t and a >= p_a : 
        p_t, p_a = t, a
    else :
        while t_up < p_t or a_up < p_a :
            t_up += t
            a_up += a
            # print("DBG2 : ", t, a)
            
        p_t, p_a = t_up, a_up
        
    # print(p_t, p_a)

print(p_t + p_a)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
t=1
a=1
for i in range(N):
    TA=input()
    TA=TA.rstrip().split(" ")
    T=int(TA[0])
    A=int(TA[1])
    if t<=T and a<=A:
        t=T
        a=A
    else:
        for j in range(10000000):
            if t<=T*j and a<=A*j:
                t=T*j
                a=A*j
                break
print(t+a)