Problem:


Score : 300 points

Problem Statement

AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.

Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

Constraints

1≦N≦1000

1≦T_i,A_i≦1000 (1≦i≦N)

T_i and A_i (1≦i≦N) are coprime.

It is guaranteed that the correct answer is at most 10^{18}.

Input

The input is given from Standard Input in the following format:

N
T_1 A_1
T_2 A_2
:
T_N A_N

Output

Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

Sample Input 1

3
2 3
1 1
3 2

Sample Output 1

10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Sample Input 2

4
1 1
1 1
1 5
1 100

Sample Output 2

101

It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.

Sample Input 3

5
3 10
48 17
31 199
231 23
3 2

Sample Output 3

6930



Sample input:
3
2 3
1 1
3 2


Sample output:
10

Submission status: Wrong Answer

Solution code:
n = int(input())
t = 1
a = 1
for i in range(n):
    next_t, next_a = map(int, input().split())
    if t != next_t or a != next_a:
        if t < next_t and a < next_a:
            t = next_t
            a = next_a
        elif t == next_t and a < next_a:
            a = next_a
        elif t < next_t and a == next_a:
            t = next_t
        elif t <= next_t and a > next_a:
            kake = a // next_a + 1
            t = next_t * kake
            a = next_a * kake
        elif t > next_t and a <= next_a:
            kake = t // next_t + 1
            t = next_t * kake
            a = next_a * kake
        elif t > next_t and a > next_a:
            kake = t / next_t
            if kake < a / next_a:
                kake = a / next_a
            if kake % 1 > 0:
                kake = kake // 1 + 1
            t = next_t * kake
            a = next_a * kake
print(int(a + t))

Submission status: Wrong Answer

Solution code:
n=int(input())
f=lambda:map(int,input().split())
a,b=f()
for _ in range(1,n):
  c,d=f()
  if c<a:
    if c>1: t=0--a//c; c*=t; d*=t
    else: c=a; d*=a
  if d<b:
    if d>1: t=0--b//d; c*=t; d*=t
    else: c=b; d*=b
  a,b=c,d
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
f=lambda:map(int,input().split())
a,b=f()
for _ in range(1,n):
  c,d=f(); x=y=0
  if c<a: t=0--a//c; c*=t; d*=t
  if d<b: t=0--b//d; c*=t; d*=t
  a,b=c,d
print(a+b)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
vote = [int(i) for i in input().split()]
for a in range(N-1):
    ti, ai = [int(i) for i in input().split()]
    if ti != ai:
        mt = ceil(vote[0]/ti)
        ma = ceil(vote[1]/ai)
        vote = [ti*max(mt, ma), ai*max(mt, ma)]
    else:
        vote = [max(vote[0], vote[1]), max(vote[0], vote[1])]
print(sum(vote))

Submission status: Wrong Answer

Solution code:
#046c
import math
N = int(input())
T,A = map(int, input().split())
#print(T,A)

for i in range(1,N):
    Ti,Ai = map(int, input().split())
    #Ti*n >= T　, Ai*n >= A (nは整数)
    #n >= T/Ti
    #n >= A/Ai
    #n = math.ceil(max(T/Ti,A/Ai))
    n = max(math.ceil(T/Ti),math.ceil(A/Ai))
    T = n*Ti
    A = n*Ai
    #print(T,A)
    
print(T+A)

Submission status: Wrong Answer

Solution code:
#046c
import math
N = int(input())
T,A = map(int, input().split())
#print(T,A)

for i in range(1,N):
    Ti,Ai = map(int, input().split())
    #Ti*n >= T　, Ai*n >= A (nは整数)
    #n >= T/Ti
    #n >= A/Ai
    n = math.ceil(max(T/Ti,A/Ai))
    T = n*Ti
    A = n*Ai
    #print(T,A)
    
print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

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

Submission status: Wrong Answer

Solution code:
from math import ceil

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

t_voted = a_voted = 1
for t, a in ratio:
    val = max(ceil(t_voted / t), ceil(a_voted / a))
    t_voted = t * val
    a_voted = a * val

print(t_voted + a_voted)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

t_voted, a_voted = ratio[0][0], ratio[0][1]
for t, a in ratio[1:]:
    if t > t_voted and a > a_voted:
        t_voted = t
        a_voted = a
    else:
        val = max(ceil(t_voted / t), ceil(a_voted / a))
        t_voted = t * val
        a_voted = a * val

print(t_voted + a_voted)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

t_voted, a_voted = ratio[0][0], ratio[0][1]
for t, a in ratio[1:]:
    if t < t_voted and a < a_voted:
        t_voted = t
        a_voted = a
    else:
        val = max(ceil(t_voted / t), ceil(a_voted / a))
        t_voted = t * val
        a_voted = a * val

print(t_voted + a_voted)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

t_voted, a_voted = ratio[0][0], ratio[0][1]
for t, a in ratio[1:]:
    val = max(ceil(t_voted / t), ceil(a_voted / a))
    t_voted = t * val
    a_voted = a * val

print(t_voted + a_voted)

Submission status: Wrong Answer

Solution code:
import fractions
N=int(input())
T,A=map(int,input().split())
for i in range(1,N):
    nT,nA=map(int,input().split())
    m,p=nT,nA
    if(nT>=T and nA>=A):
        T,A=nT,nA
        continue
    pT,pA=T//nT,A//nA
    if(T%nT!=0):
        pT+=1
    if(A%nT!=0):
        pA+=1
    T,A=nT*max(pT,pA),nA*max(pT,pA)
print(T+A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

N = int(stdin.readline().rstrip())

ans = [1,1]

for i in range(N):
    x,y = [int(n) for n in stdin.readline().rstrip().split()]
    # print(math.ceil(ans[0]/x),math.ceil(ans[1]/y))
    go = max(math.ceil(ans[0]/x),math.ceil(ans[1]/y))
    ans = [go*x,go*y]
    # print(ans)

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = []
A = []
for i in range(N):
    x,y=[int(i) for i in input().split()]
    T.append(x)
    A.append(y)

for j in range (N -1):
    if T[j]>T[j+1] and A[j]>A[j+1]:
        H = math.ceil(T[j] / T[j + 1])
        K = math.ceil(A[j] / A[j+1])
        p = max(H,K)
        
        T[j+1] = T[j+1]*p
        A[j+1] = A[j+1]*p
    elif T[j]>T[j+1] and A[j] <= A[j+1]:
        p = math.ceil(T[j] / T[j+1])
        T[j+1] = T[j+1]*p
        A[j+1] = A[j+1]*p
    elif A[j]>A[j+1] and T[j] <= T[j+1]:
        p = math.ceil(A[j] / A[j+1])
        T[j+1] = T[j+1]*p
        A[j+1] = A[j+1]*p
print(T[N-1]+A[N-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

N = int(stdin.readline().rstrip())

ans = [1,1]

for i in range(N):
    x,y = [int(n) for n in stdin.readline().rstrip().split()]
    print(math.ceil(ans[0]/x),math.ceil(ans[1]/y))
    go = max(math.ceil(ans[0]/x),math.ceil(ans[1]/y))
    ans = [go*x,go*y]
    print(ans)

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = []
A = []
for i in range(N):
    x,y=[int(i) for i in input().split()]
    T.append(x)
    A.append(y)

for j in range (N -1):
    if T[j]>T[j+1] and A[j]>A[j+1]:
        H = T[j]/T[j + 1]
        K = A[j] / A[j+1]
        if H >= K:
            p = math.floor(H)
            if p != H:
                p += 1
        else:
            p = math.floor(K)
            if p != K:
                p += 1
        
        T[j+1] = T[j+1]*p
        A[j+1] = A[j+1]*p
    elif T[j]>T[j+1] and A[j] <= A[j+1]:
        p = math.floor(T[j] / T[j+1])
        if p != (T[j] / T[j+1]):
            p += 1
        T[j+1] = T[j+1]*p
        A[j+1] = A[j+1]*p
    elif A[j]>A[j+1] and T[j] <= T[j+1]:
        p = math.floor(A[j] / A[j+1])
        if p != (A[j] / A[j+1]):
            p += 1
        T[j+1] = T[j+1]*p
        A[j+1] = A[j+1]*p
print(T[N-1]+A[N-1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
from operator import itemgetter
import math
#stdin = open("sample.txt")

N = int(stdin.readline().rstrip())
hyo = [0,0]
ans = [0,0]

for i in range(N):
    hyo[0],hyo[1] = [int(x) for x in stdin.readline().rstrip().split()]

    if ans[0]<=hyo[0] and ans[1]<=hyo[1]:
        ans[0] = hyo[0]
        ans[1] = hyo[1]
    elif ans[0]>hyo[0] and ans[1]>hyo[1]:
        which = ans[0]//hyo[0]
        if which < ans[1]//hyo[1]:
            which = ans[1]//hyo[1]
        ans[0] = hyo[0] * which
        ans[1] = hyo[1] * which
    elif ans[0]>hyo[0]:
        left = ans[0]//hyo[0]
        if ans[0]%hyo[0] == 0:
            ans[0] = hyo[0]*left
            ans[1] = hyo[1]*left
        else:
            ans[0] = hyo[0]*(left+1)
            ans[1] = hyo[1]*(left+1)
    elif ans[1]>hyo[1]:
        right = ans[1]//hyo[1]
        if ans[1]%hyo[1] == 0:
            ans[0] = hyo[0]*right
            ans[1] = hyo[1]*right
        else:
            ans[0] = hyo[0]*(right+1)
            ans[1] = hyo[1]*(right+1)
    #print(ans)

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

Submission status: Wrong Answer

Solution code:
import math

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

x = l[0]
for i in range(1,n):
    y = math.ceil(x[0] / l[i][0])
    z = math.ceil(x[1] / l[i][1])
    x = [max(y, z) * j for j in l[i]]

print(sum(x))

Submission status: Wrong Answer

Solution code:
import math

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

x = l[0]
for i in range(1,n):
    if l[i][0] >= x[0] and l[i][1] >= x[1]:
        x = l[i]
    else:
        y = math.ceil(x[0] / l[i][0])
        z = math.ceil(x[1] / l[i][1])
        x = [max(y, z) * j for j in l[i]]
print(sum(x))

Submission status: Wrong Answer

Solution code:
import math

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

x = l[0]
for i in range(1,n):
    if l[i][0] > x[0] and l[i][1] > x[1]:
        x = l[i]
    else:
        y = math.ceil(x[0] / l[i][0])
        z = math.ceil(x[1] / l[i][1])
        x = [max(y, z) * j for j in l[i]]
        
print(sum(x))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int,input().split())) for _ in range(n)]
ans = [ta[0][0],ta[0][1]]
for i in range(1,n):
  if ans[0] / ta[i][0] <= 1 and ans[1] / ta[i][1] <= 1:
    ans[0] = ta[i][0]
    ans[1] = ta[i][1]
  else:
    x = max(math.ceil(ans[0]/ta[i][0]),math.ceil(ans[1]/ta[i][1]))
    ans[0] = ta[i][0]*x
    ans[1] = ta[i][1]*x
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int,input().split())) for _ in range(n)]
ans = [ta[0][0],ta[0][1]]
for i in range(1,n):
  if ta[i][0] >= ans[0] and ta[i][1] >= ans[1]:
    ans[0] = ta[i][0]
    ans[1] = ta[i][1]
  else:
    x = max(math.ceil(ans[0]/ta[i][0]),math.ceil(ans[1]/ta[i][1]))
    ans[0] = ta[i][0]*x
    ans[1] = ta[i][1]*x
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
a=A[0][0]
b=A[0][1]
import fractions
for i in range(1,N):
  if a<=A[i][0] and b<=A[i][1]:
    a=A[i][0] 
    b=A[i][1]
  else:
    aa=1
    bb=1
    if a>A[i][0]:
      aa=a//(A[i][0]+0.001)+1
    if b>A[i][1]:
      bb=b//(A[i][1]+0.001)+1
    c=max(aa,bb)
    a=c*A[i][0]
    b=c*A[i][1]
print(int(a+b))

Submission status: Wrong Answer

Solution code:
from math import *

n = int(input())
suma = 0
sumb = 0
for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    suma = t
    sumb = a
  else:
    multi = max(ceil(suma / t), ceil(sumb / a))
    suma = t * multi
    sumb = a * multi

print(str(suma + sumb))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=1
def retsmlst(s,n):
  tmp=s
  while tmp<n:
    tmp+=s
  return tmp
  
  
for _ in range(N):
  a,b=map(int,input().split())
  s=a+b
  ans=retsmlst(s,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=1
def retsmlst(s,n):
  tmp=s
  while s+tmp<n:
    tmp+=s
  return tmp
  
  
for _ in range(N):
  a,b=map(int,input().split())
  s=a+b
  ans=retsmlst(s,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# C - AtCoDeerくんと選挙速報
from math import ceil
n=int(input())
t,a=1,1
for i in range(n):
    tt,aa=map(int,input().split())
    min_num=max(ceil(t/tt),ceil(a/aa))
    t=min_num*tt
    a=min_num*aa
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
T = [0]*n
A = [0]*n
Tvote = [0]*n
Avote = [0]*n

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

for k in range(n):
    if k == 0:
        Tvote[k] = T[k]
        Avote[k] = A[k]
    else:
        '''
        j = math.ceil(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        print(Tvote[k-1]/T[k])
        print(Avote[k-1]/A[k])
        print(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        print(j)
        print(Avote[k-1], A[k]*j)
        print(bool(Avote[k-1]<A[k]*j))
        print(bool(j>Avote[k-1]/A[k]))
        '''
        j = int(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))+1
#        j = 1
#        while Tvote[k-1]>j*T[k] or Avote[k-1]>j*A[k]:
#            j += 1
        Tvote[k] = j*T[k]
        Avote[k] = j*A[k]
#    print("---input:{}:{}--vote{}:{}--diff{}".format(T[k],A[k],Tvote[k],Avote[k],bool(T[k]/A[k]==Tvote[k]/Avote[k])))   

#print("---Tvote:{}".format(Tvote))
#print("---Avote:{}".format(Avote))
#print('hoge')
#for i in range(n):
#    print(Tvote[i],Avote[i])
print(Tvote[n-1]+Avote[n-1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
T = [0]*n
A = [0]*n
Tvote = [0]*n
Avote = [0]*n

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

for k in range(n):
    if k == 0:
        Tvote[k] = T[k]
        Avote[k] = A[k]
    else:
        j = math.ceil(max(Tvote[k-1]/T[k],Avote[k-1]/A[k]))
        Tvote[k] = j*T[k]
        Avote[k] = j*A[k]

#print("---Tvote:{}".format(Tvote))
#print("---Avote:{}".format(Avote))
print(Tvote[n-1]+Avote[n-1])

Submission status: Wrong Answer

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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x // X + x % X != 0, y // Y + y % Y)
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    # print(x, y)

print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil
 
n = int(input())
a = 1
b = 1
 
for i in range(n):
    s,t = map(int,input().split())
    #x = max([ceil(a/s), ceil(b/t)])
    x = max((a+s-1)//s, (b+t-1)//t)
    if x*s==a and x*t==b and i!=0:
        x+=1
 
    a = x*s
    b = x*t
print(a+b)

Submission status: Wrong Answer

Solution code:
from math import ceil
 
n = int(input())
a = 1
b = 1
 
for i in range(n):
    s,t = map(int,input().split())
    #x = max([ceil(a/s), ceil(b/t)])
    x = max((a+s-1)//s, (b+t-1)//t)
    if x*s==a and x*t==b and i!=0:
        x+=1
 
    a = x*s
    b = x*t
    print(x,a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[0]*N
b=[0]*N
for i in range(N):
    a[i],b[i]=map(int,input().split())
array=[[0]*2]*(N+1)
for i in range(N):
    count=1
    while True:
        A=a[i]*count
        B=b[i]*count
        if A<array[i][0]:
            count+=1
        elif  B<array[i][1]:
            count+=1
        elif A==array[i][0] and B==array[i][1]:
            count+=1
        else:
            array[i+1]=[A,B]
            break
print(array[-1][0]+array[-1][1])

Submission status: Wrong Answer

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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

from math import ceil

for i in range(1, N):
    X, Y = TA[i]
    for i in range(1, 10000):
        X2, Y2 = X * i, Y * i
        if X2 >= x and Y2 >= y:
            x, y = X2, Y2
            break
    #print(x, y)

print(x + y)

Submission status: Wrong Answer

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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

from math import ceil

for i in range(1, N):
    X, Y = TA[i]
    if X <= x or Y <= y:
        mul = max(ceil(x / X), ceil(y / Y))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    #print(x, y)

print(x + y)

Submission status: Wrong Answer

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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

from math import ceil

for i in range(1, N):
    X, Y = TA[i]
    if X <= x or Y <= y:
        mul = max(ceil(x / X), ceil(y / Y))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    print(x, y)

print(x + y)

Submission status: Wrong Answer

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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

from math import ceil

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(ceil(x / X), ceil(y / Y))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    # print(x, y)

print(x + y)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
cur = list(map(int,input().split()))
mini = cur[0:]
cur = np.array(cur)
mini = np.array(mini)
for i in range(N - 1):
    cur = list(map(int,input().split()))
    cur = np.array(cur)
    po = mini / cur
    poo = np.max(po)
    if poo > int(poo):
        mini = cur * (int(poo) + 1)
    else:
        mini = cur * int(poo)       
print(int(np.sum(mini)))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
cur = list(map(int,input().split()))
mini = cur[0:]
cur = np.array(cur)
mini = np.array(mini)
for i in range(N - 1):
    cur = list(map(int,input().split()))
    cur = np.array(cur)
    po = mini / cur
    poo = np.max(po)
    if poo - int(poo):
        mini = cur * (int(poo) + 1)
    else:
        mini = cur * int(poo)       
print(int(np.sum(mini)))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
cur = list(map(int,input().split()))
mini = cur[0:]
cur = np.array(cur)
mini = np.array(mini)
for i in range(N - 1):
    cur = list(map(int,input().split()))
    cur = np.array(cur)
    po = mini / cur
    poo = np.max(po)
    if poo - int(poo):
        mini = cur * (int(poo) + 1)
    else:
        mini = cur * poo       
print(int(np.sum(mini)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s, t = map(int, input().split())
for _ in range(n - 1):
    u, v = map(int, input().split())
    p = 1
    if s / u < t / v and t > v:
        p = (t - 1) // v + 1
    elif s / u > t / v and s > u:
        p = (s - 1) // u + 1
    s = u * p
    t = v * p
print(int(s + t))

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    a=taka[n]/taka[n+1]
    b=aoki[n]/aoki[n+1]
    large=math.ceil(max(a,b))
    taka[n+1]*=large
    aoki[n+1]*=large

print(taka[N-1]+aoki[N-1])

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    a=taka[n]/taka[n+1]
    b=aoki[n]/aoki[n+1]
    large=math.ceil(max(a,b))
    taka[n+1]=taka[n+1]*large
    aoki[n+1]=aoki[n+1]*large
print(taka[N-1]+aoki[N-1])

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    a=taka[n]/taka[n+1]
    b=aoki[n]/aoki[n+1]
    large=math.ceil(max(a,b))
    taka[n+1]=taka[n+1]*large
    aoki[n+1]=aoki[n+1]*large
    print(taka)
    print(aoki)
print(taka[N-1]+aoki[N-1])

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    a=math.ceil(taka[n]/taka[n+1])
    b=math.ceil(aoki[n]/aoki[n+1])
    large=max(a,b)
    taka[n+1]=taka[n+1]*large
    aoki[n+1]=aoki[n+1]*large
print(taka[N-1]+aoki[N-1])

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    if taka[n]<=taka[n+1] and aoki[n]<=aoki[n+1]:
        pass
    else:
        a=math.ceil(taka[n]/taka[n+1])
        b=math.ceil(aoki[n]/aoki[n+1])
        large=max(a,b)
        taka[n+1]=taka[n+1]*large
        aoki[n+1]=aoki[n+1]*large
print(taka[N-1]+aoki[N-1])

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    if taka[n]<=taka[n+1] and aoki[n]<=aoki[n+1]:
        continue
    else:
        a=math.ceil(taka[n]/taka[n+1])
        b=math.ceil(aoki[n]/aoki[n+1])
        large=max(a,b)
        taka[n+1]=taka[n+1]*large
        aoki[n+1]=aoki[n+1]*large
print(taka[N-1]+aoki[N-1])

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    if taka[n]<=taka[n+1] and aoki[n]<=aoki[n+1]:
        continue
    else:
        a=math.ceil(taka[n]/taka[n+1])
        b=math.ceil(aoki[n]/aoki[n+1])
        large=max(a,b)
        taka[n+1]=taka[n+1]*large
        aoki[n+1]=aoki[n+1]*large
print(int(taka[N-1]+aoki[N-1]))

Submission status: Wrong Answer

Solution code:
import math
taka=[]
aoki=[]
N=int(input())
for a in range(N):
    T,A=map(int,input().split())
    taka.append(T)
    aoki.append(A)
for n in range(N-1):
    if taka[n]<=taka[n+1] and aoki[n]<=aoki[n+1]:
        continue
    else:
        a=math.ceil(taka[n]/taka[n+1])
        b=math.ceil(aoki[n]/aoki[n+1])
        large=max(a,b)
        taka[n+1]=taka[n+1]*large
        aoki[n+1]=aoki[n+1]*large
print(str(taka[N-1]+aoki[N-1]))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = 0
t_1, a_1 = map(int, input().split())
pret = t_1
prea = a_1
for x in range(n - 1):
    t, a = map(int, input().split())
    m = max(math.ceil(pret / t), math.ceil(prea / a))
    pret = m * t
    prea = m * a
print(pret + prea)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = 0
pret = 0
prea = 0
for x in range(n):
    t, a = map(int, input().split())
    if ans == 0 : 
        ans = t + a 
        pret = t
        prea = a
    else:
        sum = t + a
        ans = max(math.ceil(pret / t), math.ceil(prea / a)) * sum
        pret = ans * t // sum
        prea = ans * a // sum
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

T = np.ones(N)

A = np.ones(N)

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

for i in range(N):
  if i ==0:
    t[0] = T[0]
    a[0] = A[0]
  else:
    # xt, xa
    xt = int(np.ceil(t[i-1]/T[i]))
    xa = int(np.ceil(a[i-1]/A[i]))
    t[i] =int(T[i]*max(xt,xa))
    a[i] = int(A[i]*max(xt,xa))
    
ans = t[-1] +a[-1]
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
T,A = map(int,input().split())
import math
if n == 1:
    print(T+A)
for _ in range(n-1):
    t,a = map(int,input().split())
    if t>=T and a>=A:
        T,A = t,a
    else:
        i = max(math.ceil(T/t),math.ceil(A/a))
        T,A = t*i,a*i 
if n!= 1:
    print(T+A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math as m

N = int(input())
# 初回は単純に人数として加算
T, A = map(int, input().split())

for _ in range(N - 1):
    t_i, a_i = map(int, input().split())

    # 比率を考えると総人数は T, A = n*t_i, n*a_i の形になる
    # 必ず現在のT, A以上となるnの値を考える
    n = max(m.ceil(T / t_i), m.ceil(A / a_i))

    # 更新
    T, A = n * t_i, n * a_i

print(T + A)

Submission status: Wrong Answer

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

XY = [TA[0]]

for i in range(1, n):
    x0, y0 = XY[i-1]
    x1, y1 = TA[i]
    xq, xr = divmod(x0, x1)
    yq, yr = divmod(y0, y1)
    if xr != 0:
        xq += 1
    if yr != 0:
        yq += 1
    q = max(xq, yq)
    x1, y1 = x1*q, y1*q
    print(x1, y1)
    print(xq, yq)
    print()
    XY.append([x1, y1])
    
print(sum(XY[-1]))

Submission status: Wrong Answer

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

XY = [TA[0]]

for i in range(1, n):
    x0, y0 = XY[i-1]
    x1, y1 = TA[i]
    xq, xr = divmod(x0, x1)
    yq, yr = divmod(y0, y1)
    if xr != 0:
        xq += 1
    elif yr != 0:
        yq += 1
    q = max(xq, yq)
    x1, y1 = x1*q, y1*q
    XY.append([x1, y1])
    
print(sum(XY[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a,b = map(int,input().split())
for _ in range(n-1):
    c,d = map(int,input().split())
    deltaA = 0
    deltaB = d/c * (a + deltaA) - b 
    #print(deltaA,deltaB)
    while deltaB < 0 or int(deltaB) != deltaB:
        deltaA += 1
        deltaB = d/c * (a + deltaA) - b 
        #print(deltaA,deltaB)
    a += int(deltaA)
    b += int(deltaB)
#print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
import math

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

a, b = ta[0]
for i in range(n):
    x, y = ta[i]
    z = max(-(-a/x), -(-b/y))
    a = x * z
    b = y * z

ans = a + b
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

a, b = ta[0]
for i in range(n):
    x, y = ta[i]
    z = max(math.ceil(a / x), math.ceil((b / y)))
    a = x * z
    b = y * z

ans = a + b
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
nt,na=map(int,input().split())
for i in range(n-1):
    t,a=map(int,input().split())
    x=max(math.ceil(nt/t),math.ceil(na/a))
    nt,na=x*t,x*a
print(nt+na)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
nt,na=map(int,input().split())
for i in range(n-1):
    t,a=map(int,input().split())
    if t<nt or a<na:
        x=max(math.ceil(nt/t),math.ceil(na/a))
    else:
        x=1
    nt,na=x*t,x*a
print(nt+na)

Submission status: Wrong Answer

Solution code:
N = int(input())
TT,AA = map(int,input().split())
for k in range(1,N):
    T,A = map(int,input().split())
    j = max(int(TT/T),int(AA/A))
    for n in range(2):
        if T*j>=TT and A*j>=AA:
            TT=T*j 
            AA=A*j
            break
        else:
            j+=1
print(TT+AA)

Submission status: Wrong Answer

Solution code:
N = int(input())
TT,AA= map(int,input().split())
for k in range(1,N):
    T,A = map(int,input().split())
    j=max(int(TT/T),int(AA/A))
    for  n in range(2):
        if T*j>=TT and A*j>=AA:
            TT=T*j 
            AA=A*j
            break
        else:
            j+=1
print(TT+AA)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 参考記録
N = int(input())
x, y = 1, 1
for i in range(N):
    a, b = map(int, input().split())
    # 前回の得票数+今回の得票数が今回のやつよりはるかに多い➡その倍数分あればいい？？
    mul = max((x+a-1)//a, (y+b-1)//b)
    x = mul*a
    y = mul*b
    print(mul)
print(x+y)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0] * N
A = [0] * N
total = []
for i in range(N):
    t[i], A[i] = map(int, input().split())
    total.append(t[i]+A[i])
total_sort =  sorted(total)

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
    
def multiple(a, b):
    return a*b // euclid(a, b)

result = 1
for i in total:
    result = multiple(result, i)
    
if (len(set(t)) == 1)|(len(set(A)) == 1):
    result = t[-1]+A[-1]
    
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [0] * N
A = [0] * N
total = []
for i in range(N):
    t[i], A[i] = map(int, input().split())
    total.append(t[i]+A[i])
total_sort =  sorted(total)

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
    
def multiple(a, b):
    return a*b // euclid(a, b)

result = 1
for i in total:
    result = multiple(result, i)

Submission status: Wrong Answer

Solution code:
n = int(input())
votelist = [input().split() for i in range(n)]
for j in range(n) :
    votelist[j] = [int(k) for k in votelist[j]]
for l in range(n-1):
    if votelist[l][0] > votelist[l+1][0] or votelist[l][1] > votelist[l+1][1] :
        x = max(votelist[l][0]//votelist[l+1][0], votelist[l][1]//votelist[l+1][1])
        if x != max(votelist[l][0]/votelist[l+1][0], votelist[l][1]/votelist[l+1][1]) :
            x += 1
    else :
        x = 1
    votelist[l+1] = [m*x for m in votelist[l+1]]
print(sum(votelist[n-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
votelist = [input().split() for i in range(n)]
for j in range(n) :
    votelist[j] = [int(k) for k in votelist[j]]
for l in range(n-1):
    if votelist[l][0] > votelist[l+1][0] or votelist[l][1] > votelist[l+1][1] :
        x = max(votelist[l][0]//votelist[l+1][0], votelist[l][1]//votelist[l+1][1])
        if x != max(votelist[l][0]/votelist[l+1][0], votelist[l][1]/votelist[l+1][1]) :
            x += 1
    elif votelist[l][0]==votelist[l+1][0] or votelist[l][1]==votelist[l+1][1] :
        x = 1
    else :
        x = min(votelist[l+1][0]//votelist[l][0], votelist[l+1][1]//votelist[l][1])
    votelist[l+1] = [m*x for m in votelist[l+1]]
print(sum(votelist[n-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
TT,AA= map(int,input().split())
for k in range(1,N):
    T,A = map(int,input().split())
    j=max(int(TT/T+0.999999),int(AA/A+0.999999))
    TT=T*j 
    AA=A*j
print(TT+AA)