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())
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)
print(TT+AA)

Submission status: Wrong Answer

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

nowt,nowa=TA[0]
for t,a in TA[1:]:
  c=max(nowt//t,nowa//a)
  if max(nowt/t,nowa/a)!=c: c+=1
  nowt,nowa=c*t,c*a
print(nowt+nowa)

Submission status: Wrong Answer

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

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

for i in range(N):
	t_r = T[i]
	a_r = A[i]
	c = max(math.ceil(t_v / t_r), math.ceil(a_v / a_r))
	t_v = c * t_r
	a_v = c * a_r
			
print(int(t_v + a_v))

Submission status: Wrong Answer

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

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

for i in range(N):
	t_r = T[i]
	a_r = A[i]
	c = int(max(math.ceil(t_v / t_r), math.ceil(a_v / a_r)))
	t_v = c * t_r
	a_v = c * a_r
			
print(t_v + a_v)

Submission status: Wrong Answer

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

for _ in range(N):
	t, a = map(int, input().split())
	T.append(t)
	A.append(a)
	
t_v = T[0]
a_v = A[0]
	
for i in range(1, N):
	t_r = T[i]
	a_r = A[i]
	c = int(max(math.ceil(t_v / t_r), math.ceil(a_v / a_r)))
	t_v = c * t_r
	a_v = c * a_r
			
print(t_v + a_v)

Submission status: Wrong Answer

Solution code:
import math 

n=int(input())
list=[list(map(int,input().split())) for i in range(n)]
ans=[0,0]
for i in range(n):
	if ans[0]<=list[i][0] and ans[1]<=list[i][1] :
		ans[0]=list[i][0]
		ans[1]=list[i][1]
		continue
	if ans[0]-list[i][0]>=ans[1]-list[i][1] :
		val=math.ceil(ans[0]/list[i][0])
	else: 
		val=math.ceil(ans[1]/list[i][1])

	ans[0]=list[i][0]*val
	ans[1]=list[i][1]*val

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

Submission status: Wrong Answer

Solution code:
a = int(input())
b,c = map(int,input().split())

min = b + c

for i in range(a - 1):
  next1 , next2 = map(int,input().split())
  sums = next1 + next2
  new_one = min 
  t = True
  while t == True: 
    if sums > min:
      min = sums
      t = False
    elif (new_one >= min) and (new_one % sums == 0) :
      min = new_one
      t = False
    else:
      new_one += 1
print(min)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
t, a = map(int, input().split())
x = gcd(t,a)
pT = t//x
pA = a//x
for i in range(1,N):
  t, a = map(int, input().split())
  mt = pT//t+1 if pT%t!=0 else pT//t
  ma = pA//a+1 if pA%a!=0 else pA//a
  m = max(mt,ma)
  pT = t*m
  pA = a*m
  print(pT,pA)

print(pT+pA)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
t, a = map(int, input().split())
x = gcd(t,a)
pT = t//x
pA = t//x

for i in range(1,N):
  t, a = map(int, input().split())
  mt = pT//t+1 if pT%t!=0 else pT//t
  ma = pA//a+1 if pA%a!=0 else pA//a
  m = max(mt,ma)
  pT = t*m
  pA = a*m

print(pT+pA)

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)])

    a = x*s
    b = x*t

print(a+b)

Submission status: Wrong Answer

Solution code:
import math

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

y = [a[0][0], a[0][1]]
for i in range(1, n):
    if a[i][1] >= y[1] and a[i][0] >= y[0]:
        y[0] = a[i][0]
        y[1] = a[i][1]
    else:
        p = math.ceil(max(y[0]/a[i][0], y[1]/a[i][1]))
        y[0] = p * a[i][0]
        y[1] = p * a[i][1]
print(y[0] + y[1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
now = [1,1]
data = []
#def search_n(a,b):

for i in range(n):
    data.append(list(map(int, input().split())))
for i in range(n):
    t,a = data[i]
    mul = max(math.ceil(now[0]/t), math.ceil(now[1]/a))
    now = list(map(lambda x:x*mul, data[i]))
print(sum(now))

Submission status: Wrong Answer

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = 1, 1
    for i in range(N):
        newT, newA = LI()
        # if newT >= curT and newA >= curA:
        #     curT, curA = newT, newA
        #     continue
        r1 = math.ceil(curT/newT)
        r2 = math.ceil(curA/newA)
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()

Submission status: Wrong Answer

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = 1, 1
    for i in range(N):
        newT, newA = LI()
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        r1 = math.ceil(curT/newT)
        r2 = math.ceil(curA/newA)
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()

Submission status: Wrong Answer

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = -1, -1
    for i in range(N):
        newT, newA = LI()
        n = fractions.gcd(newT, newA)
        newT, newA = newT // n, newA // n
        if curT == -1 and curA == -1:
            curT, curA = newT, newA
            continue
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        # pattern1
        r1 = math.ceil(curT/newT) # <= 1
        r2 = math.ceil(curA/newA) # <= 1
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()

Submission status: Wrong Answer

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = -1, -1
    for i in range(N):
        newT, newA = LI()
        if curT == -1 and curA == -1:
            curT, curA = newT, newA
            continue
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        # pattern1
        r1 = math.ceil(curT/newT) # <= 1
        r2 = math.ceil(curA/newA) # <= 1
        curT = newT * max(r1, r2)
        curA = newA * max(r1, r2)
    print(curT + curA)
main()

Submission status: Wrong Answer

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = -1, -1
    for i in range(N):
        newT, newA = LI()
        if curT == -1 and curA == -1:
            curT, curA = newT, newA
            continue
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        # pattern1
        r1 = math.ceil(curT/newT)
        r2 = math.ceil(curA/newA)
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        elif newT >= curT and newA < curA:
            curT = newT * r2
            curA = newA * r2
        elif newT < curT and newA >= curA:
            curT = newT * r1
            curA = newA * r1
        elif newT < curT and newA < curA:
            tmpT = newT * max(r1, r2)
            tmpA = newA * max(r1, r2)
            curT, curA = tmpT, tmpA
        else:
            pass
    print(curT + curA)
main()

Submission status: Wrong Answer

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def lcm(a, b):
    n = fractions.gcd(a, b)
    return a * b // n

def main():
    N = I()
    curT, curA = -1, -1
    for i in range(N):
        newT, newA = LI()
        if curT == -1 and curA == -1:
            curT, curA = newT, newA
            continue
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        # pattern1
        r1 = math.ceil(curT/newT)
        r2 = math.ceil(curA/newA)
        if newT >= curT and newA >= curA:
            curT, curA = newT, newA
            continue
        elif newT >= curT and newA < curA:
            curT = newT * r2
            curA = newA * r2
        elif newT < curT and newA >= curA:
            curT = newT * r1
            curA = newA * r1
        elif newT < curT and newA < curA:
            tmpT = newT * min(r1, r2)
            tmpA = newA * min(r1, r2)
            if not (tmpT >= curT and tmpA >= curA):
                tmpT = newT * max(r1, r2)
                tmpA = newA * max(r1, r2)
            curT, curA = tmpT, tmpA
        else:
            pass
    print(curT + curA)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
x,y=map(int,input().split())

import math
for i in range(n-1):
  t,a=map(int,input().split())
  tbai=(x-1//t+1)
  abai=y-1//a+1
  bai=max(tbai,abai)
  x=t*bai
  y=a*bai
  #print(x,y)
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
x,y=map(int,input().split())

import math
for i in range(n-1):
  t,a=map(int,input().split())
  tbai=(x-1/t+1)
  abai=y-1/a+1
  bai=max(tbai,abai)
  x=t*bai
  y=a*bai
  #print(x,y)
print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
x,y=map(int,input().split())

import math
for i in range(n-1):
  t,a=map(int,input().split())
  tbai=math.ceil(x/t)
  abai=math.ceil(y/a)
  bai=max(tbai,abai)
  x=t*bai
  y=a*bai
  #print(x,y)
print(x+y)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
now = [1,1]
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
for i in range(n):
    t,a = data[i]
    mul = max(math.ceil(now[0]/t), math.ceil(now[1]/a))
    now = list(map(lambda x:x*mul, data[i]))
print(sum(now))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
now = [1,1]
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
for i in range(n):
    t,a = data[i]
    mul = max(math.ceil(now[0]/t), math.ceil(now[1]/a),1)
    now = list(map(lambda x:x*mul, data[i]))
print(sum(now))

Submission status: Wrong Answer

Solution code:
N = int(input())
ansT = 1
ansA = 1
for i in range(N):
    T, A = map(int,input().split())
    if int(ansT / T) > int(ansA / A):
        ansT = T * int((ansT + T - 1) / T)
        ansA = A * int((ansT + T - 1) / T)
    else:
        ansT = T * int((ansA + A - 1) / A)
        ansA = A * int((ansA + A - 1) / A)

print(int(ansT + ansA))

Submission status: Wrong Answer

Solution code:

N = int(input())
ansT = 1
ansA = 1
for i in range(N):
    T, A = map(int,input().split())
    if ansT / T > ansA / A:
        ansT = T * int((ansT + T - 1) / T)
        ansA = A * int((ansT + T - 1) / T)
    else:
        ansT = T * int((ansA + A - 1) / A)
        ansA = A * int((ansA + A - 1) / A)

print(int(ansT + ansA))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
max_t = 0
max_a = 0
for _ in range(n):
    t, a = map(int, input().split())
    x = 1
    while 1:
        if ans < (t + a) * x and max_t <= t*x and max_a <= a*x:
            ans = (t + a) * x
            max_t = t * x
            max_a = a * x
            break
        else:
            x += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

TA = [[int(_) for _ in input().split()] for _ in range(N)]


def ceil(a, b):
    return a // b + (a % b > 0)


x, y = 0, 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
        continue

    tv = ceil(x, t)
    av = ceil(y, a)
    if tv > av:
        nx = tv * t
        y = nx * a // t
    else:
        y = av * a
        x = y * t // a
print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

TA = [[int(_) for _ in input().split()] for _ in range(N)]

x, y = 1, 1
for t, a in TA:
    tv = ceil(x / t)
    av = ceil(y / a)
    n = max(tv, av)
    x = n * t
    y = n * a
print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

TA = [[int(_) for _ in input().split()] for _ in range(N)]

x, y = 1, 1
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
        continue

    tv = ceil(x / t)
    av = ceil(y / a)
    n = max(tv, av)
    x = n * t
    y = n * a
print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

TA = [[int(_) for _ in input().split()] for _ in range(N)]

x, y = 0, 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
        continue

    tv = ceil(x / t)
    av = ceil(y / a)
    n = max(tv, av)
    x = n * t
    y = n * a
print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

TA = [[int(_) for _ in input().split()] for _ in range(N)]

x, y = 0, 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
        continue

    tv = ceil(x / t)
    av = ceil(y / a)


    def f1():
        nx = tv * t
        ny = nx * a // t
        return nx, ny


    def f2():
        ny = av * a
        nx = ny * t // a
        return nx, ny


    f1x, f1y = f1()
    f2x, f2y = f2()
    if f1x < x or f1y < y:
        x = f2x
        y = f2y
    elif f2x < x or f2y < y:
        x = f1x
        y = f1y
    else:
        if f1x + f1y < f2x + f2y:
            x = f1x
            y = f1y
        else:
            x = f2x
            y = f2y

print(x + y)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

TA = [[int(_) for _ in input().split()] for _ in range(N)]

x, y = 0, 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
        continue

    tv = ceil(x / t)
    av = ceil(y / a)
    if tv > av:
        x = tv * t
        y = x * a // t
    else:
        y = av * a
        x = y * t // a
print(x+y)

Submission status: Wrong Answer

Solution code:
n = int(input())

#a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

#a,bの最小公倍数
def lcm(a, b):
   return a * b // gcd (a, b)
import math
ans = (1, 1)
for _ in range(n):
   t,a = map(int,input().split())
   b = max(math.ceil(ans[0] / t), math.ceil(ans[1] / a))
   ans = [b*t, b*a]

print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
takahashi = 1
aoki = 1
for _ in range(N):
  t, a = map(int, input().split())
  X = -(-takahashi + t-1)//t # 切り上げ
  Y = -(-aoki + a-1)//a      # 切り上げ
  n = max(X, Y)
  takahashi = t*n
  aoki = a*n
  
print(int(takahashi+aoki))

Submission status: Wrong Answer

Solution code:
n = int(input())
from math import ceil
from fractions import gcd

tkhs = 1
aoki = 1

for _ in range(n):
    t, a = map(int, input().split())
    t, a = t // gcd(t,a), a // gcd(t,a)
    k = max(ceil(tkhs/t), ceil(aoki/a))
    tkhs = k*t
    aoki = k*a

print(tkhs+aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
from math import ceil

tkhs = 1
aoki = 1

for _ in range(n):
    t, a = map(int, input().split())
    k = max(ceil(tkhs/t),ceil(aoki/a))
    tkhs = k*t
    aoki = k*a

print(tkhs+aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
t_ = [0]*n
a_ = [0]*n

for i in range(n):
  t, a = map(int, input().split())
  t_[i] = t
  a_[i] = a
  
tpred = [0]*(n)
apred = [0]*(n)

import math
for i in range(n):
  if i == 0:
    tpred[i] = t_[i]
    apred[i] = a_[i]
  else:
    tpred[i] = t_[i]*max(math.ceil(tpred[i-1]/t_[i]), math.ceil(apred[i-1]/a_[i]))
    apred[i] = a_[i]*max(math.ceil(tpred[i-1]/t_[i]), math.ceil(apred[i-1]/a_[i]))
print(tpred[-1]+apred[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
t_ = [0]*n
a_ = [0]*n

for i in range(n):
  t, a = map(int, input().split())
  t_[i] = t
  a_[i] = a
  
tpred = [0]*(n+1)
apred = [0]*(n+1)

import math
for i in range(n):
  tpred[i+1] = t_[i]*max([1, math.ceil(tpred[i]/t_[i]), math.ceil(apred[i]/a_[i])])
  apred[i+1] = a_[i]*max([1, math.ceil(tpred[i]/t_[i]), math.ceil(apred[i]/a_[i])])
  
print(tpred[-1]+apred[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N = int(input())
ans1 = 1
ans2 = 1
for _ in range(N):
  i1, i2 = list(map(int, input().split()))
  n = max(np.ceil(ans1/i1), np.ceil(ans2/i2))
  ans1 = i1 * n
  ans2 = i2 * n
print(int(ans1+ans2))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x, y = 1, 1
for i in range(N):
  a, b = map(int, input().split())
  mul = max(math.ceil(x/a), math.ceil(y/b))
  x = mul*a
  y = mul*b
print(x+y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
l = [[int(i) for i in input().split()] for i in range(N)]
a = l[0][0]
b = l[0][1]
for i in range(1,N):
  if l[i][0] >= a and l[i][1] >= b:
    a = l[i][0]
    b = l[i][1]
  elif l[i][0] < a and l[i][1] >= b:
    c = math.ceil(a/l[i][0])
    a = l[i][0]*c
    b = l[i][1]*c
  elif l[i][0] >= a and l[i][1] < b:
    c = math.ceil(b/l[i][1])
    a = l[i][0]*c
    b = l[i][1]*c
  else:
    c1 = math.ceil(a/l[i][0])*l[i][1]
    c2 = math.ceil(b/l[i][1])*l[i][0]
    if c1 < a and c2 >= b:
      a = math.ceil(a/l[i][0])*l[i][0]
      b = c1
    elif c1 >= a and c2 < b:
      b = math.ceil(b/l[i][1])*l[i][1]
      a = c2
print(a+b)

Submission status: Wrong Answer

Solution code:
from math import ceil
# def ceil(x,y):
#   return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
  rate = max(ceil(t/ T), ceil(a/ A))
  t = T * rate
  a = A * rate
print(t + a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

def gcd(a, b):
    r = a % b
    while(r != 0):
        a,b = b,r
        r = a % b
    return b
def lcm(m,n):
    return (m*n)//gcd(m,n)

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

Submission status: Wrong Answer

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

import math
dp = ta[0]
for i in range(1, n):
    t = ta[i][0]
    a = ta[i][1]

    k = max(dp[0] / t, dp[1] / a)
    k = math.ceil(k)
    dp = [k * t, k * a]
print(sum(dp))

Submission status: Wrong Answer

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

import math
dp = ta[0]
for i in range(1, n):
    t = ta[i][0]
    a = ta[i][1]

    k  = max(math.ceil(dp[0] / t), math.ceil(dp[1] / a))
    dp = [k * t, k * a]
    # print(dp)
print(sum(dp))

Submission status: Wrong Answer

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

import math
dp = [1, 1]
for i in range(n):
    t = ta[i][0]
    a = ta[i][1]

    k = max(math.ceil(dp[0] / t), math.ceil(dp[1] / a))
    dp = [t * k, a * k]
print(sum(dp))

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def gcd(a, b):
	while b:
		a, b = b, a % b
		return a
#a,bの最小公倍数
def lcm(a, b):
	return a * b // gcd (a, b)

N = INT()
A = [MAP() for _ in range(N)]

ans = 1
B = [None] * N

for i, a in enumerate(A):
	num = sum(a)
	mod = ans % num
	if mod: ans += num-mod
	x = int(ans*(a[0]/(a[0]+a[1])))
	y = ans - x
	if i != 0:
		while True:
			# print(a, ans, x, y)
			if x>=B[i-1][0] and y>=B[i-1][1]:
				break
			else:
				px, py = B[i-1][0], B[i-1][1]
				if px%a[0] == 0 or py%a[1] == 0 and ans < max(sum(a)*(px//a[0]), sum(a)*(py//a[1])):
					ans =  max(sum(a)*(px//a[0]), sum(a)*(py//a[1]))
				else:
					bai = max(px//x, py//y) + 1
					ans *= bai
				x = int(ans*(a[0]/(a[0]+a[1])))
				y = ans - x
	B[i] = [x, y]
	# print(a, ans, x, y)

# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def gcd(a, b):
	while b:
		a, b = b, a % b
		return a
#a,bの最小公倍数
def lcm(a, b):
	return a * b // gcd (a, b)

N = INT()
A = [MAP() for _ in range(N)]

ans = 1
B = [None] * N

for i, a in enumerate(A):
	num = sum(a)
	mod = ans % num
	if mod: ans += num-mod
	x = int(ans*(a[0]/(a[0]+a[1])))
	y = ans - x
	if i != 0:
		while True:
			# print(a, ans, x, y)
			if x>=B[i-1][0] and y>=B[i-1][1]:
				break
			else:
				px, py = B[i-1][0], B[i-1][1]
				if px%a[0] == 0 or py%a[1] == 0:
					if ans < max(sum(a)*(px//a[0]), sum(a)*(py//a[1])):
						ans =  max(sum(a)*(px//a[0]), sum(a)*(py//a[1]))
				else:
					bai = max(px//x, py//y) + 1
					ans *= bai
				x = int(ans*(a[0]/(a[0]+a[1])))
				y = ans - x
	B[i] = [x, y]
	# print(a, ans, x, y)

# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def gcd(a, b):
	while b:
		a, b = b, a % b
		return a
#a,bの最小公倍数
def lcm(a, b):
	return a * b // gcd (a, b)

N = INT()
A = [MAP() for _ in range(N)]

ans = 1
B = [None] * N

for i, a in enumerate(A):
	num = sum(a)
	mod = ans % num
	if mod: ans += num-mod
	x = int(ans*(a[0]/(a[0]+a[1])))
	y = ans - x
	if i != 0:
		while True:
			# print(a, ans, x, y)
			if x>=B[i-1][0] and y>=B[i-1][1]:
				break
			else:
				px, py = B[i-1][0], B[i-1][1]
				if px%a[0] == 0 or py%a[1] == 0:
					ans = max(sum(a)*(px//a[0]), sum(a)*(py//a[1]))
				else:
					bai = max(px//x, py//y) + 1
					ans *= bai
				x = int(ans*(a[0]/(a[0]+a[1])))
				y = ans - x
	B[i] = [x, y]
	# print(a, ans, x, y)

# print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def gcd(a, b):
	while b:
		a, b = b, a % b
		return a
#a,bの最小公倍数
def lcm(a, b):
	return a * b // gcd (a, b)

N = INT()
A = [MAP() for _ in range(N)]

ans = 1
B = [None] * N

for i, a in enumerate(A):
	num = sum(a)
	mod = ans % num
	if mod: ans += num-mod
	x = int(ans*(a[0]/(a[0]+a[1])))
	y = ans - x
	if i != 0:
		while True:
			# print(a, ans, x, y)
			if x>=B[i-1][0] and y>=B[i-1][1]:
				break
			else:
				px, py = B[i-1][0], B[i-1][1]
				if px>py and px%a[0] == 0:
					ans = sum(a)*(px//a[0])
				elif px<py and py%a[1] == 0:
					ans = sum(a)*(py//a[1])
				else:
					bai = max(px//x, py//y) + 1
					ans *= bai
				x = int(ans*(a[0]/(a[0]+a[1])))
				y = ans - x
	B[i] = [x, y]
	# print(a, ans, x, y)

# print(B)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    for n in range(1, 10 ** 5):
        if t <= n * T and a <= n * A:
            t = n * T
            a = n * A
            break
    # if t == 0 and a == 0:   # T1, A1のときの処理
    #     t = T
    #     a = T
    
    # for i in range(10 ** 20):
    #     if T == A:
    #         t += 0
    #         a += 0
    #         break
    #     elif T > A:
    #         Y = A * t + A * i - T * a
    #         if Y % T == 0 and Y >= 0:
    #             t += i
    #             a += Y / T
    #             break
    #     else:
    #         X = T * a + T * i - A * t
    #         if X % A == 0 and X >= 0:
    #             t += X / A
    #             a += i
    #             break
print(int(t + a))

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [None]*N
A = [None]*N
for i in range(N):
    T[i], A[i] = (int(i) for i in input().split())

voted_num = T[0] + A[0]
now_T = T[0]
now_A = A[0]

for i in range(1, N):
    _sum = T[i] + A[i]
    if voted_num % _sum == 0: continue
    j = 1
    while _sum < voted_num or T[i]*j < now_T or A[i]*j < now_A:
        j += 1
        _sum = T[i]*j+A[i]*j

        
    now_T = T[i]*j
    now_A = A[i]*j
    voted_num = now_T + now_A
    
print(voted_num)