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:
def main():
    n = int(input())
    a, b = map(int, input().split())
    t = a + b
    for _ in range(n - 1):
        a, b = map(int, input().split())
        c = a + b
        p, q = divmod(t, c)
        if q:
            t += (c - q)

    print(t)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil
N=int(input())
ratio=[list(map(int,input().split())) for _ in range(N)]
ans=[ratio[0][0],ratio[0][1]]
#print(ans,ratio)
for i in range(1,N):
    ans1=[0,0]
    ans2=[0,0]
    #print(ans)
    rate1=ans[0]/ratio[i][0]
    rate2=ans[1]/ratio[i][1]
    g1=gcd(ans[0],ratio[i][0])
    mul1=(ans[0]*ratio[i][0])//g1
    ans1=[mul1,(mul1*ratio[i][1])/ratio[i][0]]

    g2=gcd(ans[1],ratio[i][1])
    mul2=(ans[1]*ratio[i][1])//g2
    ans2=[(mul2*ratio[i][0])/ratio[i][1],mul2]
    #print(ans1,ans2)
    if (rate1>1)and(rate2>1):
        if (ans1[0]<ans[0])or(ans1[1]<ans[1]):
            ans=ans2
        elif (ans2[0]<ans[0])or(ans2[1]<ans[1]):
            ans=ans1
        else:
            if ans1[0]<ans2[0]:
                ans=ans1
            else:
                ans=ans2
    else:
        ma=max(rate1,rate2)
        ma=ceil(ma)
        ans[0]=ratio[i][0]*ma
        ans[1]=ratio[i][1]*ma
    #input()
print(int(sum(ans)))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max(math.ceil(t/ti), math.ceil(a/ai))
    t = n*ti
    a = n*ai
print(int(t+a))

Submission status: Wrong Answer

Solution code:
n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max((t+ti-1)/ti, (a+ai-1)/ai)
    t = n*ti
    a = n*ai
print(t+a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max(math.ceil(t/ti), math.ceil(a/ai))
    t = n*ti
    a = n*ai
print(t+a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max(math.ceil(t/ti), math.ceil(a/ai))
    t, a = n*ti, n*ai
print(t+a)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 1, 1
    for t, a in inp:
        n = max(ceil(scr_t/t), ceil(scr_a/a))
        scr_t = n * t
        scr_a = n * a

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = -1, -1
    for t, a in inp:
        if t >= scr_t and a >= scr_a:
            scr_t = t
            scr_a = a
            continue
        if t < scr_t and a >= scr_a:
            scr_t = t * ceil(scr_t/t)
            scr_a = scr_t * a // t
        elif a < scr_a and t >= scr_t:
            scr_a = a * ceil(scr_a/a)
            scr_t = scr_a * t // a
        else:
            if t / a >= scr_t / scr_a:
                scr_a = a * ceil(scr_a/a)
                scr_t = scr_a * t // a
            else:
                scr_t = t * ceil(scr_t/t)
                scr_a = scr_t * a // t

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 0, 0
    for t, a in inp:
        if t >= scr_t and a >= scr_a:
            scr_t = t
            scr_a = a
            continue
        if t < scr_t and a >= scr_a:
            scr_t = t * ceil(scr_t/t)
            scr_a = scr_t * a / t
        elif a < scr_a and t >= scr_t:
            scr_a = a * ceil(scr_a/a)
            scr_t = scr_a * t / a
        else:
            if t / a >= scr_t / scr_a:
                scr_a = a * ceil(scr_a/a)
                scr_t = scr_a * t / a
            else:
                scr_t = t * ceil(scr_t/t)
                scr_a = scr_t * a / t

    print(int(scr_t + scr_a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 0, 0
    for t, a in inp:
        if t >= scr_t and a >= scr_a:
            scr_t = t
            scr_a = a
        else:
            scr_t1 = t * ceil(scr_t/t)
            scr_a1 = scr_t1 * a // t
            scr_a2 = a * ceil(scr_a/a)
            scr_t2 = scr_a2 * t // a
            if scr_t1 < scr_t or scr_a1 < scr_a:
                scr_t = scr_t2
                scr_a = scr_a2
            elif scr_t2 < scr_t or scr_a2 < scr_a:
                scr_t = scr_t1
                scr_a = scr_a1
            else:
                if scr_t1 + scr_a1 <= scr_t2 + scr_a2:
                    scr_t = scr_t1
                    scr_a = scr_a1
                else:
                    scr_t = scr_t2
                    scr_a = scr_a2

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    N = int(readline())
    inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    scr_t, scr_a = 0, 0
    for t, a in inp:
        if t >= scr_t and a >= scr_a:
            scr_t = t
            scr_a = a
            continue
        if t < scr_t and a >= scr_a:
            scr_t = t * ceil(scr_t/t)
            scr_a = scr_t * a // t
        elif a < scr_a and t >= scr_t:
            scr_a = a * ceil(scr_a/a)
            scr_t = scr_a * t // a
        else:
            if t / a >= scr_t / scr_a:
                scr_a = a * ceil(scr_a/a)
                scr_t = scr_a * t // a
            else:
                scr_t = t * ceil(scr_t/t)
                scr_a = scr_t * a // t

    print(scr_t + scr_a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
mt = 0
ma = 0
for i in range(n):
    t , a = map(int, input().split())
    if t>=mt and a>=ma:
        mt = t
        ma = a
    elif t<mt or a<ma:
        k1 = math.ceil(mt/t)
        k2 = math.ceil(ma/a)
        k=max(k1,k2)
        mt=t*k
        ma=a*k
print(mt+ma)

Submission status: Wrong Answer

Solution code:
import math
def resolve():
    N = int(input())
    TA = [list(map(int, input().split())) for i in range(N)]
    t, a = TA[0]
    for i in range(1, len(TA)):
        t_next, a_next = TA[i]
        div = max(math.ceil(t/t_next), math.ceil(a/a_next))
        t = t_next*div
        a = a_next*div
    print(t+a)


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
import math

def resolve():
	n = int(input())
	v = []
	for _ in range(n):
		v.append(list(map(int, input().split())))
	t, a = 1, 1
	for i in range(n):
		tv, av = v[i]
		c = max(math.ceil(t/tv), math.ceil(a/av))
		t, a = c*tv, c*av
	print(t+a)
resolve()

Submission status: Wrong Answer

Solution code:
import math

def resolve():
	n = int(input())
	v = []
	for _ in range(n):
		v.append(list(map(int, input().split())))
	t, a = v[0][0], v[0][1]
	for i in range(1, n):
		tv, av = v[i]
		c = max(math.ceil(t/tv), math.ceil(a/av))
		t, a = c*tv, c*av
	print(t+a)
resolve()

Submission status: Wrong Answer

Solution code:
import math
def resolve():
    N = int(input())
    T = []
    A = []
    for _ in range(N):
        x, y = map(int, input().split())
        T.append(x)
        A.append(y)
    t, a = T[0], A[0]
    for i in range(1, N):
        m = max(math.ceil(t/T[i]), math.ceil(a/A[i]))
        t, a = T[i]*m, A[i]*m
    print(t+a)
resolve()

Submission status: Wrong Answer

Solution code:
ma = lambda : map(int,input().split())
ni = lambda :int(input())
import math
ceil = math.ceil
n = ni()
pt,pa = ma()
for i in range(n-1):
    t,a = ma()
    l = max(ceil(pt/t),ceil(pa/a))
    pt = t*l
    pa = a*l
print(pt+pa)

Submission status: Wrong Answer

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

tx = ab[0][0]
ty = ab[0][1]
for i in range(1,N):
    rate_t = tx/ty
    rate_n = ab[i][0]/ab[i][1]
    if rate_t == rate_n :
        continue
    if rate_t > rate_n:
        ty = tx/rate_n
        if int(ty) != ty:
            for j in range(int(tx),10**18):
                if j % ab[i][0] ==0:
                    tx = j
                    ty = tx/rate_n
#                    print(f"tx={tx},ty={ty}")
                    break
    else:
        tx = ty*rate_n
        if int(tx) != tx:
            for k in range(int(ty),10**18):
                if k % ab[i][1] ==0:
                    ty = k
                    tx = ty*rate_n
#                    print(f"tx={tx},ty={ty}")
                    break

print(int(tx+ty))

Submission status: Wrong Answer

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

tx = ab[0][0]
ty = ab[0][1]
for i in range(1,N):
    rate_t = tx/ty
    rate_n = ab[i][0]/ab[i][1]
    if rate_t == rate_n :
        continue
    elif rate_t > rate_n:
        ty = tx/rate_n
        if int(ty) != ty:
            for j in range(int(tx),10**18):
                if j % ab[i][0] ==0:
                    tx = j
                    ty = tx/rate_n
#                    print(f"tx={tx},ty={ty}")
                    break
    else:
        tx = ty*rate_n
        if int(tx) != tx:
            for k in range(int(ty),10**18):
                if k % ab[i][1] ==0:
                    ty = k
                    tx = ty*rate_n
#                    print(f"tx={tx},ty={ty}")
                    break

print(int(tx+ty))

Submission status: Wrong Answer

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

tx = ab[0][0]
ty = ab[0][1]
for i in range(1,N):
    rate_t = tx/ty
    rate_n = ab[i][0]/ab[i][1]
    if rate_t == rate_n :
        pass
    elif rate_t > rate_n:
        ty = tx/rate_n
        if int(ty) != ty:
            for j in range(int(tx),10**18):
                if j % ab[i][0] ==0:
                    tx = j
                    ty = tx/rate_n
#                    print(f"tx={tx},ty={ty}")
                    break
    else:
        tx = ty*rate_n
        if int(tx) != tx:
            for k in range(int(ty),10**18):
                if k % ab[i][1] ==0:
                    ty = k
                    tx = ty*rate_n
#                    print(f"tx={tx},ty={ty}")
                    break

print(int(tx+ty))

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
T, A = 1, 1
for _ in range(N):
    t, a = map(int,input().split())
    k = max(ceil(T / t), ceil(A / a))
    T = t * k
    A = a * k
if A + T == 0:
    print(C)
print(A + T)

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
T, A = 1, 1
for _ in range(N):
    t, a = map(int,input().split())
    k = max(ceil(T / t), ceil(A / a))
    T = t * k
    A = a * k
    if k == 0:
        print(B)
print(A + T)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

tv = 1
av = 1
for i in range(n):
    ti, ai = map(int, input().split())
    n = max(math.ceil(tv/ti),  math.ceil(av/ai))
    tv = ti*n
    av = ai*n
    
print(tv+av)

Submission status: Wrong Answer

Solution code:
import math

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

tv = 1
av = 1
for i in range(n):
    n = max(math.ceil(tv/t[i]),  math.ceil(av/a[i]))
    tv = t[i]*n
    av = a[i]*n
    
print(tv+av)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil
N = int(input())
T, A = map(int,input().split())
for _ in range(N-1):
    t, a = map(int,input().split())
    k = max(ceil(T / t), ceil(A / a))
    T = t * k
    A = a * k
print(A + T)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

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

A, B = 1, 1
for x,y in L:
    n = max(math.ceil(A/x), math.ceil(B/y))
    A, B = n*x, n*y

print(A+B)

Submission status: Wrong Answer

Solution code:
from math import ceil


n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        if a == b:
            x = max(votes)
            votes = [x, x]
        else:
            num = max(ceil(votes[0]/a), ceil(votes[1]/b))
            x = a * num
            y = b * num
            votes = [x, y]

print(sum(votes))

Submission status: Wrong Answer

Solution code:
from math import ceil


n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        if a == b:
            x = max(votes)
            votes = [x, x]
        else:
            num = max(ceil(votes[0]/a), ceil(votes[1]/b))
            for i in range(num, 10000000):
                x = a * i
                y = b * i
                if x >= votes[0] and y >= votes[1]:
                    votes = [x, y]
                    break

print(sum(votes))

Submission status: Wrong Answer

Solution code:
from math import ceil


n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        if a == b:
            x = max(votes)
            votes = [x, x]
        else:
            num = min(ceil(votes[0]/a), ceil(votes[1]/b))
            for i in range(num, 10000):
                x = a * i
                y = b * i
                if x >= votes[0] and y >= votes[1]:
                    votes = [x, y]
                    break

print(sum(votes))

Submission status: Wrong Answer

Solution code:
N=int(input())
table=[[int(i) for i in input().split()] for j in range(0,N)]

for i in range(0,N-1):
    a=table[i][0]//table[i+1][0]
    A=table[i][0]%table[i+1][0]
    b=table[i][1]//table[i+1][1]
    B=table[i][1]%table[i+1][1]
    if a>b and A==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a>b and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a<b and B==0:
        table[i+1][0]=b*table[i+1][0]
        table[i+1][1]=b*table[i+1][1]
    elif a<b and not B==0:
        table[i+1][0]=(b+1)*table[i+1][0]
        table[i+1][1]=(b+1)*table[i+1][1]
    elif a==b and A==0 and B==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a==b and not A==0 and B==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==b and not B==0 and A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==0 and not B==0 and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]

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

Submission status: Wrong Answer

Solution code:
N=int(input())
table=[[int(i) for i in input().split()] for j in range(0,N)]

for i in range(0,N-1):
    a=table[i][0]//table[i+1][0]
    A=table[i][0]%table[i+1][0]
    b=table[i][1]//table[i+1][1]
    B=table[i][1]%table[i+1][0]
    if a>b and A==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a>b and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a<b and B==0:
        table[i+1][0]=b*table[i+1][0]
        table[i+1][1]=b*table[i+1][1]
    elif a<b and not B==0:
        table[i+1][0]=(b+1)*table[i+1][0]
        table[i+1][1]=(b+1)*table[i+1][1]
    elif a==b and A==0 and B==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a==b and not A==0 and B==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==b and not B==0 and A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==0 and not B==0 and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]

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

Submission status: Wrong Answer

Solution code:
N=int(input())
table=[[int(i) for i in input().split()] for j in range(0,N)]

for i in range(0,N-1):
    for j in range(0,10**9):
        if table[i][0]<=j*table[i+1][0]:
            for l in range(j,10**9):
                if table[i][1]<=l*table[i+1][1]:
                    table[i+1][1]=j*table[i+1][1]
                    table[i+1][0]=l*table[i+1][0]
                    break
                else:
                    pass
            break
        else:
            pass

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

Submission status: Wrong Answer

Solution code:
import math

def solve(ratio_list):
  a = 0
  b = 0
  for p, q in ratio_list:
    if a == 0 and b == 0:
      a = p
      b = q
    else:
      factor = int(max(math.ceil(a/p), math.ceil(b/q)))
      a = factor*p
      b = factor*q
  return a,b


if __name__ == "__main__":
  n = int(input())
  ratio = [tuple(map(int, input().split())) for _ in range(n)]
  a,b = solve(ratio)
  print(a+b)

Submission status: Wrong Answer

Solution code:
import math

def solve(ratio_list):
  a = 0
  b = 0
  for p, q in ratio_list:
    if a == 0 and b == 0:
      a = p
      b = q
    factor = int(max(math.ceil(a/p), math.ceil(b/q)))
    a = factor*p
    b = factor*q
  return a,b


if __name__ == "__main__":
  n = int(input())
  ratio = [tuple(map(int, input().split())) for _ in range(n)]
  a,b = solve(ratio)
  print(a+b)

Submission status: Wrong Answer

Solution code:
import fractions
import math

def solve(ratio_list):
  a = 0
  b = 0
  for p, q in ratio_list:
    if a == 0 and b == 0:
      a = p
      b = q
    factor = max(math.ceil(a/p), math.ceil(b/q))
    a = factor*p
    b = factor*q
  return a,b


if __name__ == "__main__":
  n = int(input())
  ratio = [tuple(map(int, input().split())) for _ in range(n)]
  a,b = solve(ratio)
  print(a+b)

Submission status: Wrong Answer

Solution code:
ls = list()
lt = list()
la = list()
LS = list()
LT = list()
LA = list()
N = int(input())
for i in range(1, N+1):
    T, A = map(int, input().split())
    X = T + A
    ls.append(X)
    lt.append(T)
    la.append(A)
    LS.append(X)
    LT.append(T)
    LA.append(A)
print(lt, la, LT, LA)
for j in range(1, N):
    while ls[j] < ls[j-1]:
        ls[j] += LS[j]
    while lt[j] < lt[j-1] or la[j] < la[j-1]:
        lt[j] += LT[j]
        la[j] += LA[j]
    print(lt[j], la[j], LT[j], LA[j])
print(lt[N-1] + la[N-1])

Submission status: Wrong Answer

Solution code:
def total(t, a):
  if ans[0] + ans[1] == 0:
    ans[0] = t
    ans[1] = a
  elif t == a:
    big = max(ans[0], ans[1])
    ans[0] = big
    ans[1] = big
  elif (ans[0] >= ans[1] and t < a) or (ans[0] < ans[1] and t < a):
    while ans[0]%t != 0 or ans[1]%1 != 0:
      ans[0] += 1
      ans[1] = ans[0]*a//t
    if ans[1] < a:
      ans[1] = a
  elif (ans[0] <= ans[1] and t > a) or (ans[0] > ans[1] and t > a):
    while ans[1]%a != 0 or ans[0]%1 != 0:
      ans[1] += 1
      ans[0] = ans[1]*t//a
    if ans[0] < t:
      ans[0] = t
    
  return [ans[0], ans[1]]
    
n = int(input())
ans = [0, 0]
for _ in range(n):
  t, a = list(map(int, input().split()))
  ans = total(t, a)

print(ans[0]+ans[1] )

Submission status: Wrong Answer

Solution code:
def total(t, a):
  if ans[0] + ans[1] == 0:
    ans[0] = t
    ans[1] = a
  elif t == a:
    big = max(ans[0], ans[1])
    ans[0] = big
    ans[1] = big
  elif (ans[0] >= ans[1] and t < a) or (ans[0] < ans[1] and t < a):
    while ans[0]%t != 0 or ans[1]%1 != 0:
      ans[0] += 1
      ans[1] = ans[0]*a//t
    if ans[1] < a:
      ans[1] = a
  elif (ans[0] <= ans[1] and t > a) or (ans[0] > ans[1] and t > a):
    while ans[1]%a != 0 or ans[0]%1 != 0:
      ans[1] += 1
      ans[0] = ans[1]*t//a
    if ans[0] < t:
      ans[0] = t
    
  return [ans[0], ans[1]]
    
n = int(input())
ans = [0, 0]
for _ in range(n):
  t, a = list(map(int, input().split()))
  ans = total(t, a)
  print(ans)

print(ans[0]+ans[1] )

Submission status: Wrong Answer

Solution code:
icase=0
if icase==0:
    n=int(input())
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=map(int,input().split())
elif icase==1:
    n=5
    t=[3,48,31,231,3]
    a=[10,17,199,23,2]
    ans=6930

ti=t[0]
ai=a[0]
dt=0.1
for i in range(n-1):
    if ti/t[i+1]>ai/a[i+1]:
        ii=max(int((ti-dt)/t[i+1])+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max(int((ai-dt)/a[i+1])+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print(ai+ti)

Submission status: Wrong Answer

Solution code:
icase=0
if icase==0:
    n=int(input())
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=map(int,input().split())
elif icase==1:
    n=5
    t=[3,48,31,231,3]
    a=[10,17,199,23,2]
    ans=6930

ti=t[0]
ai=a[0]
dt=0.1**5
for i in range(n-1):
    if ti/t[i+1]>ai/a[i+1]:
        ii=max(int((ti-dt)/t[i+1])+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max(int((ai-dt)/a[i+1])+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print(ai+ti)

Submission status: Wrong Answer

Solution code:
icase=0
if icase==0:
    n=int(input())
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=map(int,input().split())
elif icase==1:
    n=5
    t=[3,48,31,231,3]
    a=[10,17,199,23,2]
    ans=6930

ti=t[0]
ai=a[0]
dt=0.1**12
for i in range(n-1):
    if ti/t[i+1]>ai/a[i+1]:
        ii=max(int((ti-dt)/t[i+1])+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max(int((ai-dt)/a[i+1])+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print(ai+ti)

Submission status: Wrong Answer

Solution code:
n=int(input())
t=[0]*n
a=[0]*n

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

ti=t[0]
ai=a[0]

for i in range(n-1):
    if int(ti/t[i+1])>int(ai/a[i+1]):
        ii=max(int(ti/t[i+1]-0.0001)+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max(int(ai/a[i+1]-0.0001)+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print(ai+ti)

Submission status: Wrong Answer

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


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


n = int(input())
cur_t = 1
cur_a = 1
for i in range(n):
    t, a = map(int, input().split())
    times = max(math.ceil(cur_t / t), math.ceil(cur_a / a))
    cur_t = t * times
    cur_a = a * times
    #print(cur_t, cur_a)
print(cur_t + cur_a)

Submission status: Wrong Answer

Solution code:
import math

#in1 = '5'
#in2 = ['1 2','2 1','1 1','3 1','1 1']
#n = int(in1)
n = int(input())

tall = 1
aall = 1
for idx1 in range(n):
    t, a = map(int, input().split())
    #t, a = map(int, in2[idx1].split())
    mul = max(math.ceil(tall / t), math.ceil(aall / a))
    tall, aall = t * mul, a * mul
    #print(tall, aall)

print(tall + aall)

Submission status: Wrong Answer

Solution code:
import math

#in1 = '5'
#in2 = ['1 2','2 1','1 1','3 1','1 1']
#n = int(in1)
n = int(input())

tall = 1
aall = 1
for idx1 in range(n):
    t, a = map(int, input().split())
    #t, a = map(int, in2[idx1].split())
    mul = max(math.ceil(tall / t), math.ceil(aall / a))
    tall, aall = t * mul, a * mul
    print(tall, aall)

print(tall + aall)

Submission status: Wrong Answer

Solution code:
import math

#in1 = '4'
#in2 = ['1 1','1 1','1 5','1 100']
#n = int(in1)
n = int(input())

idx1 = 0
ta = [[0 for i in range(2)] for j in range(n)]

if n != 0:
    while idx1 < n:
        x = input().split()
        #x = in2[idx1].split()
        ta[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

vote_cnt = [1, 1]

for idx1 in range(len(ta)):
    mul = max(math.ceil(vote_cnt[0] / ta[idx1][0]), math.ceil(vote_cnt[1] / ta[idx1][1]))
    vote_cnt[0] = ta[idx1][0] * mul
    vote_cnt[1] = ta[idx1][1] * mul

print(sum(vote_cnt))

Submission status: Wrong Answer

Solution code:
import math

#in1 = '5'
#in2 = ['3 10','48 17','31 199','231 23','3 2']
#n = int(in1)
n = int(input())

idx1 = 0
ta = [[0 for i in range(2)] for j in range(n)]

if n != 0:
    while idx1 < n:
        x = input().split()
        #x = in2[idx1].split()
        ta[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

vote_cnt = ta[0]

for idx1 in range(1, len(ta)):
    mul = max(math.ceil(vote_cnt[0] / ta[idx1][0]), math.ceil(vote_cnt[1] / ta[idx1][1]))
    vote_cnt[0] = ta[idx1][0] * mul
    vote_cnt[1] = ta[idx1][1] * mul

print(sum(vote_cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(max(t[i-1]//t[i], a[i-1]//a[i]), 10**9+7):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
print(t[n-1]+a[n-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(max(t[i-1]//t[i], a[i-1]//a[i]), 10**9+7):
            print(' ', j)
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
print(t[n-1]+a[n-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(1, 10**5+1):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
    print(t[n-1]+a[n-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(1, 10**6+1):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
print(t[n-1]+a[n-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(1, 10**5+1):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
print(t[n-1]+a[n-1])

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
import sys
n = int(input())
T = [0 for i in range(n)]
A = [0 for i in range(n)]
for i in range(n):
    T[i],A[i] = map(int,input().split())
t = 1
a = 1
for i in range(n):
    t = T[i]*max(ceil(t/T[i]), ceil(a/A[i]))
    a = A[i]*max(ceil(t/T[i]), ceil(a/A[i]))

print(t+a)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
import sys
n = int(input())
T = [0 for i in range(n)]
A = [0 for i in range(n)]
for i in range(n):
    T[i],A[i] = map(int,input().split())
t = 1
a = 1
for i in range(n):
    t = T[i]*max(ceil(t/T[i]), ceil(a/A[i]))
    a = A[i]*max(ceil(t/T[i]), ceil(a/A[i]))
    print(t,a)

print(t+a)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
import sys

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

print(t+a)

Submission status: Wrong Answer

Solution code:
N = int(input())

l = [0, 0]
for _ in range(N):
    t, a = map(int, input().split())
    if t >= l[0] and a >= l[1]:
        l = [t, a]
    else:
        print(t, a)
        temp = max((l[0] - 1) // t + 1, (l[1] - 1) // a + 1)
        l = [t * temp, a * temp]
    
print(sum(l))

Submission status: Wrong Answer

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

a = 1
b = 1
for ti, ai in zip(T,A):
    n = max(math.ceil(a/ti),math.ceil(b/ai))
    a = n*ti
    b = n*ai
    #print(a,b)
print(a+b)