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:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

def reduce(p, q):
    common = fractions.gcd(p, q)
    return [p // common, q // common]

N = _I()
TA = [LI() for _ in range(N)]
new_TA = []
for t, a in TA:
    new_TA.append(reduce(t, a))
TA = new_TA
"""
まず割合を求める
割合が違ったら数字を変更する必要がある
2:1にしないといけないのに
10-20
だったら、
答えは40-20であるが、
2:1をまず10-20より大きくする
まず割る
10/2=5
20/1=20
だからまず20倍する
40:20
これが答えであればok
逆ならどうか
17:25
2-3
なら
そもそも17:25が正解
じゃあ一方だけこえてたら？
17:25
21-3
これなら
まず小さい方は25にする
21-25
そこから割合を求める
21/17=1....
25/25 = 1
2倍する
34:50
満たしている
"""

vals = [1,1]
for t, a in TA:
    #  # まず同じ大きさにする
    #  if vals[0] < t:
    #      vals[0] = t
    #  if vals[1] < a:
    #      vals[1] = a

    xt = math.ceil(vals[0] / t)
    xa = math.ceil(vals[1] / a)

    max_x = max(xt, xa)
    #  t *= max_x
    #  a *= max_x
    vals[0] = t * max_x
    vals[1] = a * max_x

print(sum(vals))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

def reduce(p, q):
    common = fractions.gcd(p, q)
    return [p // common, q // common]

N = _I()
TA = [LI() for _ in range(N)]
new_TA = []
for t, a in TA:
    new_TA.append(reduce(t, a))
TA = new_TA
"""
まず割合を求める
割合が違ったら数字を変更する必要がある
2:1にしないといけないのに
10-20
だったら、
答えは40-20であるが、
2:1をまず10-20より大きくする
まず割る
10/2=5
20/1=20
だからまず20倍する
40:20
これが答えであればok
逆ならどうか
17:25
2-3
なら
そもそも17:25が正解
じゃあ一方だけこえてたら？
17:25
21-3
これなら
まず小さい方は25にする
21-25
そこから割合を求める
21/17=1....
25/25 = 1
2倍する
34:50
満たしている
"""

vals = [1,1]
for t, a in TA:
    original_ratio = [t/(t+a), a/(t+a)]
    # まず同じ大きさにする
    if vals[0] < t:
        vals[0] = t
    if vals[1] < a:
        vals[1] = a

    xt = math.ceil(vals[0] / t)
    xa = math.ceil(vals[1] / a)

    max_x = max(xt, xa)
    t *= max_x
    a *= max_x
    idx = 2
    vals[0] = t
    vals[1] = a

print(sum(vals))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

def reduce(p, q):
    common = fractions.gcd(p, q)
    return [p // common, q // common]

N = _I()
TA = [LI() for _ in range(N)]
new_TA = []
for t, a in TA:
    new_TA.append(reduce(t, a))
TA = new_TA
"""
まず割合を求める
割合が違ったら数字を変更する必要がある
2:1にしないといけないのに
10-20
だったら、
答えは40-20であるが、
2:1をまず10-20より大きくする
まず割る
10/2=5
20/1=20
だからまず20倍する
40:20
これが答えであればok
逆ならどうか
17:25
2-3
なら
そもそも17:25が正解
じゃあ一方だけこえてたら？
17:25
21-3
これなら
まず小さい方は25にする
21-25
そこから割合を求める
21/17=1....
25/25 = 1
2倍する
34:50
満たしている
"""

vals = TA[0]
for t, a in TA[1:]:
    original_ratio = [t/(t+a), a/(t+a)]
    # まず同じ大きさにする
    if vals[0] < t:
        vals[0] = t
    if vals[1] < a:
        vals[1] = a

    xt = math.ceil(vals[0] / t)
    xa = math.ceil(vals[1] / a)

    max_x = max(xt, xa)
    t *= max_x
    a *= max_x
    idx = 2
    vals[0] = t
    vals[1] = a

print(sum(vals))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

N = _I()
TA = [LI() for _ in range(N)]
"""
まず割合を求める
割合が違ったら数字を変更する必要がある
2:1にしないといけないのに
10-20
だったら、
答えは40-20であるが、
2:1をまず10-20より大きくする
まず割る
10/2=5
20/1=20
だからまず20倍する
40:20
これが答えであればok
逆ならどうか
17:25
2-3
なら
そもそも17:25が正解
じゃあ一方だけこえてたら？
17:25
21-3
これなら
まず小さい方は25にする
21-25
そこから割合を求める
21/17=1....
25/25 = 1
2倍する
34:50
満たしている

"""

vals = TA[0]
for t, a in TA[1:]:
    original_ratio = [t/(t+a), a/(t+a)]
    # まず同じ大きさにする
    if vals[0] < t:
        vals[0] = t
    if vals[1] < a:
        vals[1] = a

    xt = math.ceil(vals[0] / t)
    xa = math.ceil(vals[1] / a)

    max_x = max(xt, xa)
    t *= max_x
    a *= max_x
    idx = 2
    vals[0] = t
    vals[1] = a

print(sum(vals))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

N = _I()
TA = [LI() for _ in range(N)]
"""
まず割合を求める
割合が違ったら数字を変更する必要がある
2:1にしないといけないのに
10-20
だったら、
答えは40-20であるが、
2:1をまず10-20より大きくする
まず割る
10/2=5
20/1=20
だからまず20倍する
40:20
これが答えであればok
逆ならどうか
17:25
2-3
なら
そもそも17:25が正解
じゃあ一方だけこえてたら？
17:25
21-3
これなら
まず小さい方は25にする
21-25
そこから割合を求める
21/17=1....
25/25 = 1
2倍する
34:50
満たしている

"""

vals = TA[0]
for t, a in TA[1:]:
    # まず同じ大きさにする
    if vals[0] < t:
        vals[0] = t
    if vals[1] < a:
        vals[1] = a

    xt = math.ceil(vals[0] / t)
    xa = math.ceil(vals[1] / a)

    max_x = max(xt, xa)
    t *= max_x
    a *= max_x
    vals = [t,a]

print(sum(vals))

Submission status: Wrong Answer

Solution code:

# https://atcoder.jp/contests/abc046/tasks/arc062_a

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math


def main():
    n = int(input())
    t, a = 1, 1
    for _ in range(n):
        tt, at = map(int, input().split())

        temp_t = math.ceil(t/tt)
        temp_a = math.ceil(a/at)
        co = max(temp_t, temp_a)

        t = co * tt
        a = co * at

    print(t + a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())

ta = [0] * N
ao = [0] * N

for i in range(N):
    t, a = map(int, input().split())
    if i == 0:
        ta[i] = t
        ao[i] = a
    else:
        tmp = max(math.ceil(ta[i-1]/t), math.ceil(ao[i-1]/a))
        ta[i] = t*tmp
        ao[i] = a*tmp

print(ta[-1]+ao[-1])

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)

N = _I()
TA = [LI() for _ in range(N)]

vals = TA[0]
for t, a in TA[1:]:
    #  print('ta', t, a)
    #  print('vals', vals)
    t_p = math.ceil(vals[0] / t)
    a_p = math.ceil(vals[1] / a)
    max_p = max(t_p, a_p)
    #  print('max_p', max_p)
    vals[0] = t*max_p
    vals[1] = a * max_p

print(sum(vals))

Submission status: Wrong Answer

Solution code:
N=int(input())

tiai=[list(map(float,input().split())) for i in range(N)]
n1n2=[1,1]
for i in range(0,N):
  nn=max(n1n2[0]/tiai[i][0], n1n2[1]/tiai[i][1])
  nn=(int(nn) if int(nn)==nn else int(nn)+1)
  n1n2=[int(nn*tiai[i][0]),int(nn*tiai[i][1])]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

tiai=[list(map(int,input().split())) for i in range(N)]
n1n2=[1,1]
for i in range(0,len(tiai)):
  nn=max(n1n2[0]/tiai[i][0], n1n2[1]/tiai[i][1])
  nn=(int(nn) if int(nn)==nn else int(nn)+1)
  n1n2=[nn*tiai[i][0],nn*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

n1n2=[1,1]
for i in range(0,len(tiai)):
  nn=max(n1n2[0]/tiai[i][0], n1n2[1]/tiai[i][1])
  nn=(int(nn) if int(nn)==nn else int(nn)+1)
  n1n2=[nn*tiai[i][0],nn*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

n1n2=tiai[0]
for i in range(1,len(tiai)):
  nn=max(n1n2[0]/tiai[i][0], n1n2[1]/tiai[i][1])
  nn=(int(nn) if int(nn)==nn else int(nn)+1)
  n1n2=[nn*tiai[i][0],nn*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

n1n2=tiai[0]
for i in range(1,N):
  nn=max(n1n2[0]/tiai[i][0], n1n2[1]/tiai[i][1])
  nn=(int(nn) if int(nn)==nn else int(nn)+1)
  n1n2=[nn*tiai[i][0],nn*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

n1n2=tiai[0]
ceil=(lambda x:x if isinstance(x,int) else int(x) if x.is_integer() else int(x)+1)

for i in range(1,N):
  nn=max(n1n2[0]/tiai[i][0], n1n2[1]/tiai[i][1])
  nn=(int(nn) if nn.is_integer() else int(nn)+1)
  n1n2=[nn*tiai[i][0],nn*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

n1n2=tiai[0]
ceil=(lambda x:x if isinstance(x,int) else int(x) if x.is_integer() else int(x)+1)

for i in range(1,N):
  if ceil(n1n2[0]/tiai[i][0])>ceil(n1n2[1]/tiai[i][1]):
    n1n2=[ceil(n1n2[0]/tiai[i][0])*tiai[i][0],ceil(n1n2[0]/tiai[i][0])*tiai[i][1]]
  else:
    n1n2=[ceil(n1n2[1]/tiai[i][1])*tiai[i][0],ceil(n1n2[1]/tiai[i][1])*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

n1n2=tiai[0]
ceil=(lambda x:x if isinstance(x,int) else int(x) if x.is_integer() else int(x)+1)

for i in range(1,N):
  if ceil(n1n2[0]/tiai[i][0])*tiai[i][1]>n1n2[1]:
    n1n2=[ceil(n1n2[0]/tiai[i][0])*tiai[i][0],ceil(n1n2[0]/tiai[i][0])*tiai[i][1]]
  else:
    n1n2=[ceil(n1n2[1]/tiai[i][1])*tiai[i][0],ceil(n1n2[1]/tiai[i][1])*tiai[i][1]]

print(sum(n1n2))

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]

# エントリーポイント
def main():
    N = input(int)
    TA = input([int, int, N])

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

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
t = 1
a = 1
for i in range(n):
    ti, ai = input().split(" ")
    ti = int(ti)
    ai = int(ai)
    tir = t/ti
    air = a/ai
    koef = max(tir, air)
    if koef % 1 == 0:
        koef = int(koef)
    else:
        koef = int(koef) + 1
    t = ti*koef
    a = ai*koef
print(t + a)

Submission status: Wrong Answer

Solution code:
n = int(input())
t = 1
a = 1
for i in range(n):
    ti, ai = input().split(" ")
    ti = int(ti)
    ai = int(ai)
    tir = t/ti
    air = a/ai
    if tir>1 or air>1:
        koef = max(tir, air)
        if koef % 1 == 0:
            koef = int(koef)
        else:
            koef = int(koef) + 1
        t = ti*koef
        a = ai*koef
    else:
        t = ti
        a = ai
print(t + a)

Submission status: Wrong Answer

Solution code:
n = int(input())
t = 1
a = 1
for i in range(n):
    ti, ai = input().split(" ")
    ti = int(ti)
    ai = int(ai)
    tir = t/ti
    air = a/ai
    if tir>=1 or air>=1:
        koef = max(tir, air)
        if koef % 1 == 0:
            koef = int(koef)
        else:
            koef = int(koef) + 1
        t = ti*koef
        a = ai*koef
    else:
        t = ti
        a = ai
print(t + a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

a,b = map(int,input().split())
for _ in range(1,n):
    ai ,bi =[int(x) for x in input().split()]
    n = math.ceil(max(a/ai, b/bi))
    a = n * ai
    b = n * bi
print(a+b)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

a, b = 1, 1

for _ in range(N):
    x, y = map(int, input().split())
    n = max(ceil(a / x), ceil(b / y))
    a, b = n * x, n * y

print(a + b)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
t = a = 1
for i in range(N):
  T, A = map(int, input().split())
  qT = math.ceil(t/T)
  qA = math.ceil(a/A)
  q = max(qT, qA)
  t = T*q
  a = A*q
r = t+a
print(r)

Submission status: Wrong Answer

Solution code:
import math
from sys import exit, stdin

N = int(stdin.readline().rstrip())
TA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
min = []
min.append(TA[0][0]+TA[0][1])#min0

for i in range(1,N):
    min.append(TA[i][0]+TA[i][1])
    tmp = min[i]
    #print("before:min",i,min[i])
    n = 2
    while min[i-1]>min[i]:
        min[i] = tmp*n
        n+=1
        #print("after:min",i,min[i])

print(min[N-1])

Submission status: Wrong Answer

Solution code:
import math
n = int (input())
a,b = map(int,input().split())
for i in range(n-1):
    c,d = map(int,input().split())
    if (c>=a and d>=b):
        a=c
        b=d
    else:
        left = int(math.ceil((1.0*a)/c))
        right = int(math.ceil((1.0 * b) / d))
        mx = max(left,right)
        a= c*mx
        b=d*mx
print(a+b)

Submission status: Wrong Answer

Solution code:
#%%
import fractions
import math


def lcm(x, y):
    tmp = x * y // fractions.gcd(x, y)
    return tmp

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

#print('----------')

tmp1 = A[0][0]
tmp2 = A[0][1]

for i in range(1, N):
    a = math.ceil(tmp1/A[i][0])
    b = math.ceil(tmp2/A[i][1])
    c = max(a, b)    
    tmp1 = A[i][0] * c
    tmp2 = A[i][1] * c
    #print(tmp1, tmp2)

ans = (tmp1 + tmp2)
print(ans)












#%%

Submission status: Wrong Answer

Solution code:
import math
from sys import exit, stdin

N = int(stdin.readline().rstrip())
TA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

n, x, y = 1, 1, 1

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

print(x+y)

Submission status: Wrong Answer

Solution code:
import math
from sys import exit, stdin

N = int(stdin.readline().rstrip())
TA = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

n, x, y = 1, 1, 1

for i in range(N):
    if i == 0:
        n = 1
    else:
        n = max(math.ceil(x / TA[i][0]), math.ceil(y / TA[i][1]))
    x = TA[i][0]*n
    y = TA[i][1]*n

print(x+y)

Submission status: Wrong Answer

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

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())
    if y * a != x * b:
        k = max(math.ceil(a/x),math.ceil(b/y))
        a = x * k
        b = y * k
print(a+b)

Submission status: Wrong Answer

Solution code:
import math
 
num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
ans = [[arr[0][0], arr[0][1]]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    if ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
        # ceil by int
        r = max([int((ans[i][0]-1)/arr[i+1][0])+1, int((ans[i][1]-1)/arr[i+1][1])+1])
        ans[i+1][0] = arr[i+1][0] * r
        ans[i+1][1] = arr[i+1][1] * r

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

Submission status: Wrong Answer

Solution code:
import math
 
num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
ans = [[arr[0][0], arr[0][1]]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    if ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
        r = max([math.ceil((ans[i][0])/arr[i+1][0]), math.ceil((ans[i][1])/arr[i+1][1])])
        ans[i+1][0] = arr[i+1][0] * r
        ans[i+1][1] = arr[i+1][1] * r

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

Submission status: Wrong Answer

Solution code:
import math
 
num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
t = 1
a = 1
for i in range(num):
    if t > arr[i][0] or a > arr[i][1]:
        r = max(math.ceil((t-arr[i][0])/arr[i][0]+1), math.ceil((a-arr[i][1])/arr[i][1]+1))
        t = arr[i][0] * r
        a = arr[i][1] * r
    else:
        t = arr[i][0]
        a = arr[i][1]
print(t + a)

Submission status: Wrong Answer

Solution code:
import math
 
num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
ans = [[arr[0][0], arr[0][1]]]
if num != 1:
    for i in range(num-1):
        ans.append([arr[i+1][0], arr[i+1][1]])
        if ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
            r = max([math.ceil((ans[i][0])/arr[i+1][0]), math.ceil((ans[i][1])/arr[i+1][1])])
            ans[i+1][0] = arr[i+1][0] * r
            ans[i+1][1] = arr[i+1][1] * r
                
print(ans[num-1][0] + ans[num-1][1])

Submission status: Wrong Answer

Solution code:
import math
 
num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
ans = [[arr[0][0], arr[0][1]]]
if num != 1:
    for i in range(num-1):
        ans.append([arr[i+1][0], arr[i+1][1]])
        if ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
            r = max([math.ceil((ans[i][0]-ans[i+1][0])/arr[i+1][0]), math.ceil((ans[i][1]-ans[i+1][1])/arr[i+1][1])])
            ans[i+1][0] += arr[i+1][0] * r
            ans[i+1][1] += arr[i+1][1] * r

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

Submission status: Wrong Answer

Solution code:
import math

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

ans = [[arr[0][0], arr[0][1]]]
if num != 1:
    for i in range(num-1):
        ans.append([arr[i+1][0], arr[i+1][1]])
        if ans[i][0] > ans[i+1][0]:
            r = math.ceil((ans[i][0]-ans[i+1][0])/arr[i+1][0])
            ans[i+1][0] += arr[i+1][0] * r
            ans[i+1][1] += arr[i+1][1] * r
        if ans[i][1] > ans[i+1][1]:
            s = math.ceil((ans[i][1]-ans[i+1][1])/arr[i+1][1])
            ans[i+1][0] += arr[i+1][0] * s
            ans[i+1][1] += arr[i+1][1] * s

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

Submission status: Wrong Answer

Solution code:
import math

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

ans = [[arr[0][0], arr[0][1]]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    if ans[i][0] > ans[i+1][0]:
        r = math.ceil((ans[i][0]-ans[i+1][0])/arr[i+1][0])
        ans[i+1][0] += arr[i+1][0] * r
        ans[i+1][1] += arr[i+1][1] * r
    if ans[i][1] > ans[i+1][1]:
        r = math.ceil((ans[i][1]-ans[i+1][1])/arr[i+1][1])
        ans[i+1][0] += arr[i+1][0] * r
        ans[i+1][1] += arr[i+1][1] * r

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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())
    x=max(ceil(T/t),ceil(A/a))
    if x==0:x=1
    T,A=t*x,a*x
print(T+A)

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())
    if t>=T and a>=A:
        x=1
    elif t>=T and a<A:
        x=ceil(A/a)
    elif t<T and a>=A:
        x=ceil(T/t)
    else:
        x=max(ceil(T/t),ceil(A/a))
    T,A=t*x,a*x
print(T+A)

Submission status: Wrong Answer

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


def solve(N: int, T: "List[int]", A: "List[int]"):
    tmpT = 1
    tmpA = 1
    for i in range(N):
        d = max(math.ceil(tmpT/T[i]), math.ceil(tmpA/A[i]))
        tmpT = T[i] * d
        tmpA = A[i] * d
    print(tmpT+tmpA)
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def solve(N: int, T: "List[int]", A: "List[int]"):
    tmpT = T[0]
    tmpA = A[0]
    for i in range(1, N):
        d = max(math.ceil(tmpT/T[i]), math.ceil(tmpA/A[i]))
        tmpT = T[i] * d
        tmpA = A[i] * d
    print(tmpT+tmpA)
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

t_n = 1
a_n = 1

for ratio in l:
    n = max(math.ceil(t_n / ratio[0]),math.ceil(a_n / ratio[1]))
    
    t_n = n*ratio[0]
    a_n = n*ratio[1]
        
print(a_n+t_n)

Submission status: Wrong Answer

Solution code:

import math
n = int(input())
taka = [0] * n
ao = [0] * n

for i in range(n):
    t, a = map(int, input().split())
    if i == 0:
        taka[i] = t
        ao[i] = a
    else:
        tmp = math.ceil(max(taka[i-1]/t, ao[i-1]/a))
        taka[i] = tmp*t
        ao[i] = tmp*a

print(taka[-1]+ao[-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import bisect
import math



def main():
    num = int(input())
    vote_a, vote_b = 1, 1
    for i in range(num):
        a, b = map(int, input().split())
        aaa = math.ceil(vote_a / a)
        bbb = math.ceil(vote_b / b)
        ccc = max(aaa, bbb)
        vote_a, vote_b = a * ccc, b * ccc

    print(vote_a + vote_b)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil

if __name__ =="__main__":
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]

    now_t,now_a = ls[0]

    for i in range(1,n):
        x = max([ceil(now_t/ls[i][0]),ceil(now_a/ls[i][1])])
        now_t,now_a = x*ls[i][0],x*ls[i][1]
    print(now_t+now_a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def play():
	
	s, e = 0,1e18
	
	while s!=e:
		
		mid = (s + (e - s) // 2)
		if mid * x >= a and mid * y >= b:
			e = mid
		else : s = mid + 1
	return int(s)
	
t = int(input())

a,b  = map(int,input().split())

for i in range(0,t - 1):
	x, y = map(int,input().split())
	n = play()
	a, b = n * x, n * y
print(a+b)

Submission status: Wrong Answer

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

def solve():
    N = int(input())
    #T, A = [], []
    is_first = True
    for i in range(N):
        t, a = list(map(int, input().split()))
        if is_first:
            T, A = t, a
            is_first = False
            continue
        
        n = max(math.ceil(A/a), math.ceil(T/t))
        T, A = n*t, n*a
    print(T+A)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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