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:
#from pprint import pprint
import collections
import itertools

def get_ltru(f, b):
    return [(b[2], b[1], f[0], f[3]),
            (b[1], b[0], f[1], f[0]),
            (b[0], b[3], f[2], f[1]),
            (b[3], b[2], f[3], f[2])]

def rotations(c):
    return set(tuple(c[i:] + c[:i]) for i in range(4))

def count_distict(s_list):
    sl = s_list
    if len(s_list) == 0:
        return 1
    if len(s_list) == 1:
        return len(s_list[0])
    if len(s_list) == 2:
        return len(s_list[0])*len(s_list[1]) - len(s_list[0]&s_list[1])
    if len(s_list) == 3:
        return len(s_list[0])*len(s_list[1])*len(s_list[2]) - len(s_list[0]&s_list[1])*len(sl[2]) - len(s_list[0]&s_list[2])*len(sl[1]) -len(s_list[1]&s_list[2])*len(sl[0])\
                + len(s_list[0]&s_list[1]&s_list[2])
    if len(sl) == 4:
        a,b,c,d = sl[0], sl[1], sl[2], sl[3]
        return len(a)*len(b)*len(c)*len(d)\
                - len(a&b)*len(c)*len(d)\
                - len(a&c)*len(b)*len(d)\
                - len(a&d)*len(b)*len(c)\
                - len(b&c)*len(a)*len(d)\
                - len(b&d)*len(a)*len(b)\
                - len(c&d)*len(a)*len(b)\
                + 2*len(a&b&c)*len(d)\
                + 2*len(a&b&d)*len(c)\
                + 2*len(a&c&d)*len(b)\
                + 2*len(b&c&d)*len(a)\
                + len(a&b)*len(c&d)\
                + len(a&c)*len(b&d)\
                + len(b&c)*len(a&d)\
                - 6*len(a&b&c&d)

N = int(raw_input())

C = [[int(s) for s in raw_input().split()] for i in range(N)]

r_to_c = {}

r_to_c = collections.defaultdict(set)


for i in range(N):
    for r in rotations(C[i]):
        r_to_c[r].add(i)
#pprint(dict(r_to_c))

ans = 0
for i,j in itertools.product(range(N), repeat=2):
    if i == j: continue
    f = C[i]
    multiplier = 4//len(rotations(C[j]))
    for b in rotations(C[j]):
        l,t,r,u = get_ltru(f,b)
        sym = {i:list() for i in [1,2,4]}
        for face in (l,t,r,u):
            sym[len(rotations(face))].append(face)
        #print(dict(sym))
        this_num = 1
        for n in [1,2,4]:
            this_num *= (4//n)**(len(sym[n]))*count_distict([r_to_c[face]-{i,j} for face in sym[n]])
        ans += this_num*multiplier
print(ans//6)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
curA=1
curT=1
sum=2
lim=2**64
for i in range(0,n):
	T,A=map(int,input().split())
	x=0
	#x=max(x,math.ceil(float(curA)/A))
	#x=max(x,math.ceil(float(curT)/T))
	x=max((curT-1)/T+1 ,(curA-1)/A+1)
	sum=x*(A+T)
	curA=x*A
	curT=x*T
ans=int(sum)
print(ans)

Submission status: Wrong Answer

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

TA.reverse()
(voteA, voteB) = TA.pop()
while TA:
	(Ti, Ai) = TA.pop()
	tmp = max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
	voteA = Ti * tmp
	voteB = Ai * tmp
print(voteA + voteB)

Submission status: Wrong Answer

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

TA.reverse()
(voteA, voteB) = TA.pop()
while TA:
	(Ti, Ai) = TA.pop()
	tmp = max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
	voteA = Ti * tmp
	voteB = Ti * tmp
print(voteA + voteB)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
curA=1
curT=1
sum=2
lim=2**64
for i in range(0,n):
	T,A=map(int,input().split())
	x=0
	#x=max(x,math.ceil(float(curA)/A))
	#x=max(x,math.ceil(float(curT)/T))
	step=lim
	k=0
	while(step>=1):
		while (k+step)*A<curA:
			k+=step
		step=step/2
	x=k	
	step=lim
	k=0
	while(step>=1):
		while (k+step)*T<curT:
			k+=step
		step=step/2

	x=max(x,k)
	x+=1
	sum=x*(A+T)
	curA=x*A
	curT=x*T
ans=int(sum)
print(ans)

Submission status: Wrong Answer

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

TA.reverse()
(voteA, voteB) = TA.pop()
while TA:
	(Ti, Ai) = TA.pop()
	voteA = Ti * max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
	voteB = Ai * max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
print(voteA + voteB)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
curA=1
curT=1
sum=2
for i in range(0,n):
	T,A=map(int,input().split())
	x=0
	x=max(x,math.ceil(float(curA)/A))
	x=max(x,math.ceil(float(curT)/T))
	sum=x*(A+T)
	curA=x*A
	curT=x*T
ans=int(sum)
print(ans)

Submission status: Wrong Answer

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

TA.reverse()
(voteA, voteB) = TA.pop()
while TA:
	(Ti, Ai) = TA.pop()
	if Ti < voteA:
		if Ai < voteB:
			voteA = Ti * max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
			voteB = Ai * max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
		else:
			voteA = Ti * int((voteA + Ti -1) / Ti)
			voteB = Ai * int((voteA + Ti -1) / Ti)
	elif Ai < voteB:
		voteB = Ai * int((voteB + Ai -1) / Ai)
		voteA = Ti * int((voteB + Ai -1) / Ai)
	else:
		(voteA, voteB) = (Ti, Ai)

print(voteA + voteB)

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())
t = []
a = []
for i in xrange(n):
    mem = map(int, raw_input().split())
    t.append(mem[0])
    a.append(mem[1])

for i in xrange(n):
    if i == 0:
        tn = t[0]
        an = a[0]
    else:
        mt = int(math.ceil(float(tn) / t[i]))
        ma = int(math.ceil(float(an) / a[i]))
        if mt > ma:
            tn = mt * t[i]
            an = mt * a[i]
        else:
            tn = ma * t[i]
            an = ma * a[i]
print tn + an

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())
t = []
a = []
for i in xrange(n):
    mem = map(int, raw_input().split())
    t.append(mem[0])
    a.append(mem[1])

for i in xrange(n):
    if i == 0:
        tn = t[0]
        an = a[0]
    else:
        mt = int(math.ceil(float(tn) / t[i]))
        ma = int(math.ceil(float(an) / a[i]))
        print mt, ma
        if mt > ma:
            tn = mt * t[i]
            an = mt * a[i]
        else:
            tn = ma * t[i]
            an = ma * a[i]
print tn + an

Submission status: Wrong Answer

Solution code:
import math
n = int(raw_input())
t = []
a = []
for i in xrange(n):
    mem = map(int, raw_input().split())
    t.append(mem[0])
    a.append(mem[1])

for i in xrange(n):
    if i == 0:
        tn = t[0]
        an = a[0]
    else:
        mt = int(math.ceil(float(tn) / t[i]))
        ma = int(math.ceil(float(an) / a[i]))
        print mt, ma
        if mt > ma:
            tn = mt * t[i]
            an = mt * a[i]
        else:
            tn = ma * t[i]
            an = ma * a[i]
    print tn, an
print tn + an

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X, Y = map(int, input().split())
for i in range(N - 1):
    T, A = map(int, input().split())
    if T >= X and A >= Y:
        X = T
        Y = A
    else:
        t = math.ceil(X / T)
        a = math.ceil(Y / A)
        X = T * max(a, t)
        Y = A * max(a, t)
print(X + Y)

Submission status: Wrong Answer

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

TA.reverse()
(voteA, voteB) = TA.pop()
for i in range(1,N):
	(Ti, Ai) = TA.pop()
	if Ti < voteA:
		if Ai < voteB:
			voteA = Ti * max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
			voteB = Ai * max(int((voteA + Ti -1) / Ti), int((voteB + Ai -1) / Ai))
		else:
			voteA = Ti * int((voteA + Ti -1) / Ti)
			voteB = Ai * int((voteA + Ti -1) / Ti)
	elif Ai < voteB:
		voteB = Ai * int((voteB + Ai -1) / Ai)
		voteA = Ti * int((voteB + Ai -1) / Ai)
	else:
		(voteA, voteB) = (Ti, Ai)

print(voteA + voteB)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
ta=[map(int,raw_input().split()) for _ in xrange(n)]
for i in xrange(1,n):
    if ta[i-1][0]>ta[i][0]:
        ta[i][1]=ta[i][1]*((ta[i-1][0]-1)/ta[i][0]+1)
        ta[i][0]=ta[i][0]*((ta[i-1][0]-1)/ta[i][0]+1)
    if ta[i-1][1]>ta[i][1]:
        ta[i][0]=ta[i][0]*((ta[i-1][1]-1)/ta[i][1]+1)
        ta[i][1]=ta[i][1]*((ta[i-1][1]-1)/ta[i][1]+1)
print(ta[n-1][0]+ta[n-1][1])

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n = int(input())
    a,b = 0,0
    t = 0
    for _ in range(n):
        l,r = list(map(int, input().split()))
        ll = l
        rr = r
        if ll < a:
            s = a - ll
            ss = (s // l)
            if ss * l + ll < a:
                ss += 1
            ll += l*ss
            rr += r*ss
        if rr < b:
            s = b - rr
            ss = (s // r)
            if ss * r + r < b:
                ss += 1
            ll += l*ss
            rr += r*ss
        a = ll
        b = rr
        t = ll + rr
    return t

print(f())

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
X, Y = map(int, input().split())
for i in range(N - 1):
    T, A = map(int, input().split())
    if T >= X and A >= Y:
        X = T
        Y = A
    elif T < X and A >= Y:
        t = math.ceil(X / T)
        X = T * t
        Y = A * t
    elif T >= X and A < Y:
        a = math.ceil(Y / A)
        X = T * a
        Y = A * a
    else:
        t = math.ceil(X / T)
        a = math.ceil(Y / A)
        X = T * max(a, t)
        Y = A * max(a, t)
print(X + Y)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n = int(input())
    a,b = 0,0
    t = 0
    for _ in range(n):
        l,r = list(map(int, input().split()))
        k = l+r
        c = t//k + k
        ll = c//k * l
        rr = c//k * r
        if ll < a:
            s = a - ll
            ss = (s // l)
            if ss * l + ll < a:
                ss += 1
            ll += l*ss
            rr += r*ss
        if rr < b:
            s = b - rr
            ss = (s // r)
            if ss * r + r < b:
                ss += 1
            ll += l*ss
            rr += r*ss
        a = ll
        b = rr
        t = ll + rr
    return t

print(f())

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
from math import gcd
a,b=map(int,input().split())
temp=a+b
for i in range(1,n):
    c,d=map(int,input().split())
    i=c+d
    j=i
    c1=c
    d1=d
    while i<temp or c<a or d<b:

        i+=j
        c+=c1
        d+=d1
        
        
        
    temp=i
    a=c
    b=d
    
print(temp)

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)

Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow

for i in range(1,N):
    t=T[i]
    a=A[i]
    tempans=(t+a+ans-1)//(t+a)*(t+a)
    while True:
        tempT=tempans*t//(t+a)
        tempA=tempans*a//(t+a)
        if tempT>=Tnow and tempA>=Anow:
            ans=tempans
            Tnow=tempT
            Anow=tempA
            break
        else:
            tempans+=t+a
print(ans)

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)

Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow

for i in range(1,N):
    tempans=(T[i]+A[i]+ans-1)//(T[i]+A[i])*(T[i]+A[i])
    while True:
        tempT=tempans*T[i]//(T[i]+A[i])
        tempA=tempans*A[i]//(T[i]+A[i])
        if tempT>=Tnow and tempA>=Anow:
            ans=tempans
            Tnow=tempT
            Anow=tempA
            break
        else:
            tempans+=T[i]+A[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x,y=1,1
for _ in range(n):
  t,a=map(int,input().split())
  if t>a:
    for i in range(x-x%t,x*1000+1,t):
      if i>=x and i//t*a>=y:break
    x,y=i,i//t*a
  else:
    for i in range(y-y%a,y*1000+1,a):
      if i>=y and i//a*t>=x:break
    x,y=i//a*t,i
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x,y=1,1
for _ in range(n):
  t,a=map(int,input().split())
  for i in range(x-x%t,x*1000+1,t):
    if i>=x and i//t*a>=y:break
  x,y=i,i//t*a
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = 1
B = 1
for _ in range(N):
    a, b = map(int, input().split())
    if a == b:
        A = max(A, B)
        B = max(A, B)
    elif a < b:
        if A%a == 0:
            pass
        else:
            A = (A//a+1)*a
        while (A//a)*b < B:
            A += a
        B = (A//a)*b
    else:
        if B%b == 0:
            pass
        else:
            B = (B//b+1)*b
        while (B//b)*a < A:
            B += b
        A = (B//b)*a
print(A+B)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

x = ab[0][0]
y = ab[0][1]
j = 1
flg = True
for i in range(1,n):
    xx = ab[i][0]
    yy = ab[i][1]
    while flg:
        if x> j*xx or y > j*yy:
            j +=1
        else:
            x = xx *j
            y = yy *j
            break
    j = 1

print(x+y)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

x = ab[0][0]
y = ab[0][1]
j = 1
for i in range(1,n):
    flg = True
    xx = ab[i][0]
    yy = ab[i][1]
    while flg:
        if x> j*xx or y > j*yy:
            j +=1
        else:
            x = xx *j
            y = yy *j
            flg =False
    j = 1

print(x+y)

Submission status: Time Limit Exceeded

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

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ta = [list(map(int, input().split())) for _ in range(n)]
    ans = sum(ta[0])
    for i in range(1, n):
        si1 = sum(ta[i - 1])
        si = sum(ta[i])
        tmp = si
        while tmp * ta[i][0] // si < ans * ta[i - 1][0] // si1 or tmp * ta[i][1] // si < ans * ta[i - 1][1] // si1:
            tmp += si
        ans = tmp
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
n=int(input())
INF=10**18
x,y=map(int,input().split())
for _ in range(n-1):
  t,a=map(int,input().split())
  if x*a>y*t:
    i=1
    while t*i<x:
      i+=1
    x=t*i
    y=x*a//t
  else:
    i=1
    while a*i<y:
      i+=1
    y=a*i
    x=y*t//a
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

T,A = map(int, input().split())
rlt = T+A
for _ in range(N-1):
  t,a = map(int, input().split())
  i = math.ceil(rlt/(t+a))
  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 = map(int,input().split())
nowt = t
nowa = a
for i in range(n-1):
    t , a = map(int,input().split())
    kou = 1
    while True:
        if t*kou >= nowt and a*kou >= nowa:
            break
        else:
            kou += 1
    nowt = t*kou
    nowa = a*kou
print(nowt+nowa)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

chokudai = 0
aoki = 0
ans = 0
for i in range(n):
	t, a = map(int,input().split())
	if i == 0:
		chokudai = t
		aoki = a
		continue
	tmpt, tmpa = t, a
	while tmpt < chokudai or tmpa < aoki:
		tmpt += t
		tmpa += a
	ans += (tmpt-chokudai) + (tmpa-aoki)
	chokudai = tmpt
	aoki = tmpa
print(chokudai + aoki)

Submission status: Time Limit Exceeded

Solution code:
import sys
from fractions import gcd

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print(*a, **dict(file=sys.stderr, **kw))

N = ini()


def solve():
    p = q = 1
    for i in range(N):
        x, y = inm()
        k = 1
        while True:
            if x * k >= p and y * k >= q:
                p = x * k
                q = y * k
                break
            k += 1
    return p + q


print(solve())

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    total = T+A
    x = -(-total//(a+t))
    for x in range(x, 10**15):
        if T <= t*x and A <= a*x:
            T = t*x
            A = a*x
            break

print(T+A)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
T = []
A = []

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

t_num = 1
a_num = 1
for i in range(N):
    # TAは常にn倍ずつ増加していく
    n = 1
    while T[i] * n < t_num or A[i] * n < a_num:
        n += 1
    t_num = T[i] * n
    a_num = A[i] * n

print(t_num + a_num)

Submission status: Time Limit Exceeded

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

N = int(readline())
T, A = map(int,readline().split())

import math
for i in range(N - 1):
  t,a = map(int,readline().split())
  i = 1
  while True:
    if t * i >= T and a * i >= A:
      T,A = t * i,a * i
      break
    i += 1

print(T + A)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    TTAA = [list(map(int, input().split())) for _ in range(N)]
    t, a = 1, 1
    for T, A in TTAA:
        while t / a != T / A:
            if t / a > T / A:
                a += 1
            else:
                t += 1
    print(t + a)


resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    x, y = TA[0]
    for i in range(1, N):
        t, a = TA[i]

        tmp_x = t
        tmp_y = a
        while tmp_x < x or tmp_y < y:
            tmp_x += t
            tmp_y += a

        x = tmp_x
        y = tmp_y

    ans = x + y
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
T = [0]*N
A = [0]*N
ans = 0
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
t = T[0]
a = A[0]
for i in range(1, N):
    for j in range(1, 1000000):
        if(T[i]*j >= t and A[i]*j >= a):
            t = T[i]*j
            a = A[i]*j
            break
print(t+a)

Submission status: Time Limit Exceeded

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

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

n = INT()
ans = [0, 0]
for i in range(n):
    t,a = MAP()
    k = 1
    while True:
        if ans[0] <= k * t and ans[1] <= k * a:
            break
        k += 1
    ans[0] = k * t
    ans[1] = k * a
    #print('a', t+a, ans)
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
t = a = 0
for i in range(N):
    T,A = map(int, input().split())
    for n in range(1,10**18):
        if t <= T*n and a <= A*n:
            t = T*n
            a = A*n
            break
print(t+a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
P = [0,0]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = 1
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))

Submission status: Time Limit Exceeded

Solution code:
def main():
	n = int(input())
	lst = []
	for i in range(n):
		lst.append(list(map(int,input().split())))
	a = 1
	b = 1
	for i in lst:
		want = i[0]/i[1]
		while True:
			now = a/b
			if abs(now-want)<1e-12:
				break
			if want>now:
				a+=1
			else:
				b+=1
	print(a+b)
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

ma,mb = AB[0]
for a, b in AB:
  i = 0
  while i*a < ma:
    i += 1
  j = 0
  while j*b < mb:
    j += 1
  k = max(i, j)
  
  ma = k*a
  mb = k*b
  
print(ma + mb)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
x,y=1,1
for i in l:
    t=i[0]
    a=i[1]
    i=1
    while x>(t*i) or y>(a*i):
        i+=1
    x=t*i
    y=a*i
print(x+y)

Submission status: Time Limit Exceeded

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

def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    n=int(input())
    a=1
    b=1
    for _ in range(n):
        x,y = map(int,input().split())
        x1=x
        y1=y
        while x1<a or y1<b:
            x1+=x
            y1+=y
        a=x1
        b=y1
    print(a+b)
        

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os

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

points = T[0] + A[0]
for i in range(1,N):
    t, a = T[i], A[i]
    t0, a0 = T[i-1], A[i-1]
    while T[i] + A[i] < points or T[i] < t0 or A[i] < a0:
        T[i] += t
        A[i] += a
    points = T[i] + A[i]
print(points)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
    tmpT = L[i][0]
    tmpA = L[i][1]
    mul = 2
    while not(tmpT >= nowT and tmpA >= nowA):
        tmpT = L[i][0] * mul
        tmpA = L[i][1] * mul
        mul += 1
    nowT = tmpT
    nowA = tmpA

print(nowT + nowA)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
t,a=ta[0][0],ta[0][1]
for i in range(n-1):
    wa=sum(ta[i+1])
    j=(t+a)//wa
    while wa*j<t+a or t>j*ta[i+1][0] or a>j*ta[i+1][1]:
        j+=1
    t,a=j*ta[i+1][0],j*ta[i+1][1]
    # print([t,a])
print(t+a)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
t,a=ta[0][0],ta[0][1]
for i in range(n-1):
    wa=sum(ta[i+1])
    j=1
    while wa*j<t+a or t>j*ta[i+1][0] or a>j*ta[i+1][1]:
        j+=1
    t,a=j*ta[i+1][0],j*ta[i+1][1]
    # print([t,a])
print(t+a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x=0
t=0
n=0
pre_t=0
pre_n=0
for i in range(N):
    now_t,now_n = map(int,input().split())
    t = now_t
    n = now_n
    while(pre_t > t or pre_n > n):
        t += now_t
        n += now_n
    pre_t = t
    pre_n = n
    x = t+n
print(x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

tNow = 1
aNow = 1

for i in range(N) :
    t, a = map(int, input().split())
    n = 1
    while n * t < tNow or n * a < aNow :
        n += 1
    tNow = n * t
    aNow = n * a

print(tNow + aNow)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ta=[]
t=0
a=0
ans=[[0,0]]
for i in range(n):
    p=[int(j) for j in input().split()]
    t=max(t,p[0])
    a=max(a,p[1])
    i,j=1,1
    while True:
        if p[0]*i>=t and p[1]*j>=a and p[0]*i>=ans[-1][0] and p[1]*j>=ans[-1][1]:
            ans.append([p[0]*i,p[1]*j])
            break
        i+=1
        j+=1
 
print(sum(ans[-1]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ta=[]
t=0
a=0
ans=[[0,0]]
for i in range(n):
    p=[int(j) for j in input().split()]
    t=max(t,p[0])
    a=max(a,p[1])
    i,j=1,1
    while True:
        if p[0]*i>=t and p[1]*j>=a and p[0]*i>=ans[-1][0] and p[1]*j>=ans[-1][1]:
            ans.append([p[0]*i,p[1]*j])
            break
        i+=1
        j+=1

print(sum(ans[-1]))

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
L = [[int(i) for i in input().split()] for _ in range(N)]
T = 1
A = 1
for l in L:
    t, a = l[0], l[1]
    while(T > t or A > a):
        t += l[0]
        a += l[1]
    else:
        T, A = t, a
print(T+A)

Submission status: Time Limit Exceeded

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

for i in range(1,N+1):
    cnt=2
    t=num[i][0]
    a=num[i][1]
    while 1:
        if num[i][0]<num[i-1][0] or num[i][1]<num[i-1][1]:
            num[i][0]=cnt*t
            num[i][1]=cnt*a
            cnt+=1
        else:
            break
print(sum(num[-1]))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if i == 0:
        d = b
        e = c
    else:
        f = b
        g = c
        while True:
            if d <= f and e <= g:
                d = f
                e = g
                break
            else:
                f += b
                g += c
print(d + e)

Submission status: Time Limit Exceeded

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

ct = T[0]
ca = A[0]
for i in range(1, N):
    t = T[i]
    a = A[i]
    m = 1
    while (t + a) * m < (ct + ca) or m * t < ct or m * a < ca:
        m += 1
    ct = m * t
    ca = m * a

print(ct+ca)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = [list(map(int, input().split()))for _ in range(a)]
c = []
for i in range(len(b)):
    c.append(b[i].copy())
    if len(c) != 1:
        while True:
            if c[i][0] < c[i-1][0] or c[i][1] < c[i-1][1]:
                c[i][0] = c[i][0] + b[i][0]
                c[i][1] = c[i][1] + b[i][1]
            else:
                break
print(c[len(c)-1][0] + c[len(c)-1][1])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=ceil(a/c)*d-b
  else:
    y=ceil(a/c)*d-b

  while y<0:
    y+=d


  x=c*(b+y)//d-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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


import math

a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=math.ceil(a/c)*d-b
  else:
    y=math.ceil(a/c)*d-b

  while y<0:
    y+=d


  x=c*(b+y)//d-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0; total_t = 0; total_a = 0;
for t, a in ratio:
    i = 1
    while total_t > t*i or total_a > a*i:
        i += 1
    total_t = t*i
    total_a = a*i
    ans = total_t + total_a
print(ans)

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)
    
v1 = T[0]
v2 = A[0]

for i in range(1, N):
    n = 1
    if v1<=T[i] and v2<=A[i]:
        v1 = T[i]
        v2 = A[i]
    else:
        while v1>n*T[i] or v2>n*A[i]:
            n += 1
        v1 = T[i]*n
        v2 = A[i]*n

print(v1+v2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
TA = [[int(x) for x in input().split()]for _ in range(N)]
t = 1
a = 1

for i in TA:
    j = 1
    while(t>i[0]*j or a>i[1]*j):
        j+=1
    t = i[0]*j
    a = i[1]*j

print(t+a)