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

N = int(input())

T, A = map(int, input().split())

for i in range(1, N):
    t, a = map(int, input().split())
    td = math.ceil(T / t)
    ad = math.ceil(A / a)

    if td < ad:
        T = t * ad
        A = a * ad
    else:
        T = t * td
        A = a * td

print(T + A)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
t= 1
a= 1

for _ in range(N):
    t1,a1 = map(int,input().split())
    nt = math.ceil(t/t1)
    na = math.ceil(a/a1)
    t = max(nt,na)*t1
    a = max(nt,na)*a1

print(t+a)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
t= 1
a= 1

def t_small(t,a,t1,a1):
    gain = math.ceil(t/t1)
    t = gain*t1
    a_tmp=gain*a1
    if a_tmp<a:
        gain_a = math.ceil(a/a_tmp)
        t *= gain_a
        a = a_tmp*gain_a
    else:
        a = a_tmp
    return t,a,t+a

def a_small(t,a,t1,a1):
    gain = math.ceil(a/a1)
    a = gain*a1
    t_tmp=gain*t1
    if t_tmp<t:
        gain_t = math.ceil(t/t_tmp)
        a *= gain_t
        t = t_tmp*gain_t
    else:
        t = t_tmp
    return t,a,t+a

ans = 0
for _ in range(N):
    t1,a1 = map(int,input().split())
    tt1,aa1,sta1 = t_small(t,a,t1,a1)
    tt2,aa2,sta2 = a_small(t,a,t1,a1)
    if sta1<=sta2:
        t=tt1;a=aa1;ans = sta1
    else:
        t=tt2;a=aa2;ans=sta2
print(ans)

Submission status: Wrong Answer

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

for i in range(1,N):
    T,A = TA[i]
    if T < t_cunt or A < a_cunt:
        nt = int(t_cunt/T) + 1 if 0<t_cunt%T else int(t_cunt/T)
        na = int(a_cunt/A) + 1 if 0<a_cunt%A else int(a_cunt/A)
        n = max(nt, na)
        t_cunt = n*T
        a_cunt = n*A
    else:
        t_cunt = T
        a_cunt = A
    #print(t_cunt, a_cunt)
print(t_cunt+a_cunt)

Submission status: Wrong Answer

Solution code:
N = int(input())

t_cunt = a_cunt = 1

for _ in range(N):
    T,A = map(int,input().split())
    if T < t_cunt or A < a_cunt:
        nt = int(t_cunt/T) + 1 if 0<t_cunt%T else int(t_cunt/T)
        na = int(a_cunt/A) + 1 if 0<a_cunt%A else int(a_cunt/A)
        n = max(nt, na)
        t_cunt = n*T
        a_cunt = n*A
    else:
        t_cunt = T
        a_cunt = A
    #print(t_cunt, a_cunt)
print(t_cunt+a_cunt)

Submission status: Wrong Answer

Solution code:
N = int(input())

t_cunt = a_cunt = 1

for _ in range(N):
    T,A = map(int,input().split())
    nt = int(t_cunt/T) + 1 if 0<t_cunt%T else int(t_cunt/T)
    na = int(a_cunt/A) + 1 if 0<a_cunt%A else int(a_cunt/A)
    n = max(nt, na)
    t_cunt = n*T
    a_cunt = n*A
    #print(t_cunt, a_cunt)
print(t_cunt+a_cunt)

Submission status: Wrong Answer

Solution code:
N = int(input())

t_cunt = a_cunt = 1

for _ in range(N):
    T,A = map(int,input().split())
    nt = int(t_cunt/T) + 1 if t_cunt%T else int(t_cunt/T)
    na = int(a_cunt/A) + 1 if a_cunt%A else int(a_cunt/A)
    n = max(nt, na)
    t_cunt = n*T
    a_cunt = n*A
print(t_cunt+a_cunt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A, B = 1, 1
for t, a in TA:
    k = max(math.ceil(A/t), math.ceil(B/a))
    A = k*t
    B = k*a

print(A+B)

Submission status: Wrong Answer

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

A, B = 1, 1
for t, a in TA:
    n = max(math.ceil(A/t), math.ceil(B/a))
    A = n*t
    B = n*a

print(A+B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=1,1
from math import ceil
ans=0
for i in range(n):
    q,w=map(int,input().split())
    base= max(ceil(b/w),ceil(a/q))
    a= base*q ; b=base*w 
    # print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=map(int,input().split())
from math import ceil
ans=0
for i in range(n-1):
    q,w=map(int,input().split())
    base= max(ceil(b/w),ceil(a/q))
    a= base*q ; b=base*w 
    # print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=map(int,input().split())
from math import ceil
ans=0
for i in range(n-1):
    q,w=map(int,input().split())
    base= ceil(a/q)
    if base*w>= b:
        a=base*q ; b=base*w 
        # print(a,b)
        continue
    base= ceil(b/w)
    a= base*q ; b=base*w 
    # print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a,b=map(int,input().split())
from math import ceil
ans=0
for i in range(n-1):
    q,w=map(int,input().split())
    base= ceil(a/q)
    if base*w>= b:
        a=base*q ; b=base*w ;#print(a,b)
        continue
    base= ceil(b/w)
    a= base*q ; b=base*w 
    #print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    TA = [NLI() for _ in range(N)]
    nt, na = 0, 0
    for t, a in TA:
        if t >= nt and a >= na:
            nt = t
            na = a
        elif t >= nt and a < na:
            k = math.ceil(na/a)
            nt = k*t
            na = k*a
        elif t < nt and a >= na:
            k = math.ceil(nt/t)
            nt = k*t
            na = k*a
        else:
            kt = math.ceil(nt / t)
            ka = math.ceil(na / a)
            k = max(kt, ka)
            nt = k * t
            na = k * a
    print(nt+na)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    TA = [NLI() for _ in range(N)]
    nt, na = 0, 0
    for t, a in TA:
        if t >= nt and a >= na:
            nt = t
            na = a
            continue
        elif t >= nt and a < na:
            k = math.ceil(na/a)
            nt = k*t
            na = k*a
            continue
        elif t < nt and a >= na:
            k = math.ceil(nt/t)
            nt = k*t
            na = k*a
            continue
        else:
            kt = math.ceil(nt / t)
            ka = math.ceil(na / a)
            k = max(kt, ka)
            nt = k * t
            na = k * a
    print(nt+na)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        x = int(math.ceil(t / ti))
        y = int(math.ceil(a / ai))

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        x = math.ceil(t / ti)
        y = math.ceil(a / ai)

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        x = math.ceil(t / ti)
        y = math.ceil(a//ai)

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()

        if ti == ai:
            t = max(t, a)
            a = max(t, a)

        x = t // ti
        x += 1 if t % ti else 0
        y = int(math.ceil(a / ai))
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = 1, 1

    for _ in range(n):
        ti, ai = ns()
        x = t // ti
        x += 1 if t % ti else 0
        y = int(math.ceil(a / ai))
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = ns()

    for _ in range(n - 1):
        ti, ai = ns()
        x = t // ti
        x += 1 if t % ti else 0
        y = int(math.ceil(a / ai))
        y += 1 if a % ai else 0

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = ns()

    for _ in range(n - 1):
        ti, ai = ns()
        x = int(math.ceil(t / ti))
        y = int(math.ceil(a / ai))

        nxt = max(x, y)

        t, a = ti * nxt, ai * nxt

    print(t + a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = ns()

    for _ in range(n - 1):
        ti, ai = ns()
        t1 = int(ti * math.ceil(t / ti))
        a1 = int(t1 // ti * ai)
        a1 = INF if a1 < a else a1

        a2 = int(ai * math.ceil(a / ai))
        t2 = int(a2 // ai * ti)
        t2 = INF if t2 < t else t2

        t, a = [t1, a1] if t1 + a1 < t2 + a2 else [t2, a2]

    print(int(t + a))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
# 最小公倍数
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n = ni()
    t, a = ns()

    for _ in range(n - 1):
        ti, ai = ns()
        t1 = ti * math.ceil(t / ti)
        a1 = t1 // ti * ai
        a1 = INF if a1 < a else a1

        a2 = ai * math.ceil(a / ai)
        t2 = a2 // ai * ti
        t2 = INF if t2 < t else t2

        t, a = [t1, a1] if t1 + a1 < t2 + a2 else [t2, a2]

    print(int(t + a))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = 1
B = 1
for _ in range(N):
    a, b = map(int, input().split())
    if a == b:
        A = max(A, B)
        B = max(A, B)
    else:
        if A%a == 0:
            aa = A//a
        else:
            aa = A//a + 1
        if B//b == 0:
            bb = B//b
        else:
            bb = B//b + 1
        tmp = max(aa, bb)
        A = tmp*a
        B = tmp*b

print(A+B)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
t,a = [list(i) for i in zip(*l)]
takahasi = 1
aoki = 1
for i in range(n):
    m = max(1,t[i] // takahasi , a[i] // aoki)
    takahasi = m * t[i]
    aoki = m * a[i]
print(takahasi + aoki)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(n-1):
    if ta[i+1][0]<ta[i][0] or ta[i+1][1]<ta[i][1]:
        k=max(math.ceil(ta[i][0]/ta[i+1][0]), math.ceil(ta[i][1]/ta[i+1][1]))
        ta[i+1][0]*=k
        ta[i+1][1]*=k

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

Submission status: Wrong Answer

Solution code:

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

for i in range(n-1):
    if ta[i+1][0]<ta[i][0] or ta[i+1][1]<ta[i][1]:
        k=max(int((ta[i][0]-0.5)/ta[i+1][0])+1, int((ta[i][1]-0.5)/ta[i+1][1])+1)
        ta[i+1][0]*=k
        ta[i+1][1]*=k
print(ta[-1][0]+ta[-1][1])

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    TA = in_nl2(N)

    t_score, a_score = 1, 1
    for i in range(N):

        t, a = TA[i]
        # print(t, a, '------------------')

        if t == a:
            t_score = max(t_score, a_score)
            a_score = t_score
        else:
            t_s = -(-t_score // t) * t
            a_s = (t_s // t) * a
            if t_s >= t_score and a_s >= a_score:
                t_score = t_s
                a_score = a_s
                print(t_score, a_score)
                continue
            # else:
                # print('dame1', t_s, a_s)

            a_s = -(-a_score // a) * a
            t_s = (a_s // a) * t
            if t_s >= t_score and a_s >= a_score:
                t_score = t_s
                a_score = a_s
                print(t_score, a_score)
            # else:
                # print('dame2', t_s, a_s)

                # print(t_score, a_score)

    print(t_score + a_score)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
cura,curb = 1,1

for i in range(n):
    t,a = map(int,input().split())
    
    xa,xb = cura/t,curb/a
    x = math.ceil(max(xa,xb))
    
    cura,curb = t*x,a*x
    
print(cura+curb)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
cura,curb = 1,1

for i in range(n):
    t,a = map(int,input().split())
    
    xa,xb = cura/t,curb/a
    x = math.ceil(max(xa,xb))
    
    cura,curb = t*x,a*x
    print(cura,curb)
    
print(cura+curb)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
cura,curb = map(int,input().split())
for i in range(n-1):
    t,a = map(int,input().split())
    
    xa,xb = cura/t,curb/a
    x = math.ceil(max(xa,xb))
    
    cura,curb = t*x,a*x
    
print(cura+curb)

Submission status: Wrong Answer

Solution code:
def ceil(X, Y):  # 天井関数 ceil(X/Y) Y>10**(-10)?
    return int((X + Y - pow(10, -10)) // Y)


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

t, a = 1, 1
for ti, ai in ta:
    tmp = max(ceil(t, ti), ceil(a, ai))
    t, a = ti * tmp, ai * tmp
print(t + a)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

Submission status: Wrong Answer

Solution code:
import math
def f(x1,y1,x2,y2,z):
    z = max(z,math.ceil((x2+y2)*x1/x2))
    x = x2+y2
    n = z//x
    k = z%x
    if k==0:
        z = n*x
        x1 = (z*x2)//x
        y1 = (z*y2)//x
        return z,x1,y1
    else:
        z = (n+1)*x
        x1 = (z*x2)//x
        y1 = (z*y2)//x
        return z,x1,y1
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
x1,y1 = A[0]
s = x1+y1
for i in range(1,N):
    t,a = A[i]
    s,x1,y1 = f(x1,y1,t,a,s)
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def f(x,y):
    n = y//x
    k = y%x
    if k==0:
        return n*x
    else:
        return (n+1)*x
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
s = A[0][0]+A[0][1]
for i in range(1,N):
    t,a = A[i]
    b = t+a
    s = f(b,s)
print(s)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc062/tasks/arc062_a
# C - AtCoDeerくんと選挙速報

from math import ceil
N=int(input())
T=[0]*N
A=[0]*N
p=1
q=1
for i in range(N):
    T[i],A[i]=map(int,input().split())
   
    s = ceil(p/T[i])
    t = ceil(q/A[i])
    r = max(s,t)
    p = T[i]*r
    q = A[i]*r 
    #print(p,q)
    
print(p+q)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc062/tasks/arc062_a
# C - AtCoDeerくんと選挙速報

from math import ceil
N=int(input())
T=[0]*N
A=[0]*N
p=1
q=1
for i in range(N):
    T[i],A[i]=map(int,input().split())
   
    s = ceil(p/T[i])
    t = ceil(q/A[i])
    r = max(s,t)
    p = int(T[i]*r)
    q = int(A[i]*r)
      
    #print(p,q)
    
print(int(p+q))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc062/tasks/arc062_a
# C - AtCoDeerくんと選挙速報

from math import ceil
N=int(input())
T=[0]*N
A=[0]*N
p=1
q=1
for i in range(N):
    T[i],A[i]=map(int,input().split())
   
    s = ceil(p/T[i])
    t = ceil(q/A[i])
    r = max(s,t)
    p = T[i]*r
    q = A[i]*r
      
    #print(p,q)
    
print(p+q)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc062/tasks/arc062_a
# C - AtCoDeerくんと選挙速報

def lcm(x,y):
    tmp=gcd(x,y)
    return x*y//tmp
   
from math import gcd,ceil
N=int(input())
T=[0]*N
A=[0]*N
p=1
q=1
for i in range(N):
    T[i],A[i]=map(int,input().split())
   
    if p<=T[i] and q<=A[i]:
        p,q = T[i],A[i]
    else:
        s = ceil(p/T[i])
        t = ceil(q/A[i])
        r = max(s,t)
        p = T[i]*r
        q = A[i]*r
       
    #print(p,q)
else:
    print(p+q)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
def main():
    n = int(input())
    a, b = 1, 1
    for _ in range(n):
        c, d = list(map(int, input().split()))
        if a * d == b * c:
            continue
        else:
            if a <= c and b <= d:
                a += c - a
                b += d - b
            else:
                x = math.ceil(a / c)
                y = math.ceil(b / d)
                c *= max(x, y)
                d *= max(x, y)
                a += c - a
                b += d - b
    print(a + b)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
chokudai, aoki = 0, 0
for i in range(n):
	t, a = map(int,input().split())
	if i == 0:
		chokudai, aoki = t, a
		continue
	bairitsu = max(math.ceil(chokudai/t), math.ceil(aoki/a))
	t *= bairitsu
	a *= bairitsu
	#print(t, a)
	chokudai, aoki = t, a
print(chokudai + aoki)

Submission status: Wrong Answer

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

chokudai = 0
aoki = 0
for i in range(n):
	t, a = map(int,input().split())
	if i == 0:
		chokudai = t
		aoki = a
		continue
	tmpt, tmpa = t, a
	bairitsu = max(math.ceil(chokudai/t), math.ceil(aoki/a))
	tmpt *= bairitsu
	tmpa *= bairitsu
	#print(tmpt, tmpa)
	chokudai = tmpt
	aoki = tmpa
print(chokudai + aoki)

Submission status: Wrong Answer

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

chokudai = 0
aoki = 0
ans = 0
for i in range(n):
	t, a = map(int,input().split())
	if i == 0:
		chokudai = t
		aoki = a
		continue
	tmpt, tmpa = t, a
	bairitsu = max(math.ceil(chokudai/t), math.ceil(aoki/a))
	tmpt *= bairitsu
	tmpa *= bairitsu
	ans += (tmpt-chokudai) + (tmpa-aoki)
	chokudai = tmpt
	aoki = tmpa
print(chokudai + aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print(T+A)

Submission status: Wrong Answer

Solution code:
n = int(input())


def check(i):
    return T <= t*i and A <= a*i and T+A <= (t+a)*i


T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    L = 1
    R = 10**15
    cnt = 0
    while True:
        M = (L+R)//2
        if check(M):
            R = M
        else:
            L = M
        cnt += 1
        if 10**4 < cnt:
            break
    T = t*R
    A = a*R


print(T+A)

Submission status: Wrong Answer

Solution code:
n = int(input())
T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    x = -(-T//t) * t
    for i in range(1, 100000):
        y = x//t * a * i
        if A <= y:
            T = x*i
            A = y
            break

print(T+A)

Submission status: Wrong Answer

Solution code:
n = int(input())
T = A = 1
for _ in range(n):
    t, a = map(int, input().split())
    x = -(-T//t) * t
    for i in range(1, 1000):
        y = x//t * a * i
        if A <= y:
            T = x*i
            A = y
            break

print(T+A)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
T = []
A = []

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

t_num = T[0]
a_num = A[0]
for i in range(1, N):
    tn = ceil(t_num / T[i])
    an = ceil(a_num / A[i])
    n = max(tn, an)
    t_num = T[i] * n
    a_num = A[i] * n

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
T = []
A = []

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

t_num = 1
a_num = 1
for i in range(N):
    tn = ceil(t_num / T[i])
    an = ceil(a_num / A[i])
    n = max(tn, an)
    t_num = T[i] * n
    a_num = A[i] * n

print(t_num + a_num)

Submission status: Wrong Answer

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

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

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

print(T + A)

Submission status: Wrong Answer

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

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

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

print(T + A)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
c = []
for i in range(n):
  t,a = map(int,input().split())
  c.append((t,a))
  
al = c[0][0]
ar = c[0][1]
for i in range(n):
  if i == 0:
    continue
  b = max(ceil(al/c[i][0]),ceil(ar/c[i][1]))
  al = c[i][0]*b
  ar = c[i][1]*b
  
print(al+ar)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t,a = map(int,input().split())
mi = [t,a,t+a]
for i in range(1,n):
    t,a = map(int,input().split())
    ts = max(math.ceil(mi[0]/t),math.ceil(mi[1]/a),math.ceil(mi[2]/(a+t)))
    mi = [t*ts,a*ts,(t+a)*ts]

print(mi[2])

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    from math import ceil

    t_cur, a_cur = list(map(int, readline().split()))

    for _ in range(n-1):
        t, a = list(map(int, readline().split()))
        i_t = ceil(t_cur / t)
        i_a = ceil(a_cur / a)
        x = max(i_t, i_a)
        t_cur, a_cur = t * x, a * x

    print(t_cur + a_cur)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ans = 2
for i in range(n):
    t,a=map(int,input().split())
    ans = (ans + t+a-1)//(t+a)*(t+a)
print(ans)