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 sys
import numpy as np
import random
import math
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	x, y = LI()
	for _ in range(n-1):
		t, a = LI()
		m = int(math.ceil(round(max(x/t,y/a),3)))
		x, y = m*t, m*a
	print(x+y)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import random
import math
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	x, y = LI()
	for _ in range(n-1):
		t, a = LI()
		if x <= t and y <= a:
			x, y = t, a
		else:
			m = int(math.ceil(max(x/t,y/a)))
			x, y = m*t, m*a
	print(x+y)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from math import ceil

res = [1, 1]
for i in range(n):
    t, a = TA[i]
    mx = max(ceil(res[0] / t), ceil(res[1] / a))
    # mx = max(-(-res[0] // t), -(-res[1] // a))
    res = [t * mx, a * mx]

print(sum(res))

Submission status: Wrong Answer

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

# from math import ceil

res = [1, 1]
for i in range(n):
    t, a = TA[i]
    # mx = max(ceil(res[0] / t), ceil(res[1] / a))
    mx = max(-(-res[0] // t), -(-res[1] // a))
    res = [t * mx, a * mx]
    print(res)

print(sum(res))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    t_pev, a_prev = TA[0]
    for i in range(1, n):
        t_now, a_now = TA[i]
        if t_pev <= t_now and a_prev <= a_now:
            t_pev, a_prev = t_now, a_now
        else:
            d = max(math.ceil(t_pev / t_now), math.ceil(a_prev / a_now))
            t_pev, a_prev = t_now * d, a_now * d
    print(t_pev + a_prev)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import math
#from fractions import Fraction
n = int(input())

x, y = map(int, input().split())
t, a = x, y

for _ in range(n - 1):
    tt, aa = map(int, input().split())

    #c = 1
    '''
    if (t >= a):
        c = math.ceil(tt / t)

    else:
        c = math.ceil(aa / a)
    '''
    c = math.ceil(max(t / tt, a / aa))

    t = tt * c
    a = aa * c


ans = t + a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

x, y = map(int, input().split())
t, a = x, y

for _ in range(n - 1):
    tt, aa = map(int, input().split())

    c = 1
    if (t >= a):
        while (tt * c < t):
            c += 1

    else:
        while (aa * c < a):
            c += 1

    t = tt * c
    a = aa * c


ans = t + a
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
'''def pair_revise(x,y,a,b):
    global p
    global q
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return p,q
u,v=1,1
for i in range(n):
    u,v=pair_revise(u,v,pairs[i][0],pairs[i][1])
    print(u,v)
print(u+v)'''
x,y=1,1
for i in range(n):
    a=pairs[i][0]
    b=pairs[i][1]
    k=max(ceil(x/a),ceil(y/b))
    x,y=a*k,b*k
print(x+y)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    #print(x,y,a,b)
    #for i in range(max(floor(x/a),floor(y/b)),max(floor(x/a),floor(y/b))+2):
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return [p,q]
    #return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
    #for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=1,1
for i in range(n):
    u,v=pair_revise(u,v,pairs[i][0],pairs[i][1])
print(u+v)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    #print(x,y,a,b)
    #for i in range(max(floor(x/a),floor(y/b)),max(floor(x/a),floor(y/b))+2):
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return [p,q]
    #return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
    #for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=pairs[0]
for i in range(n-1):
    u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print(u+v)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    #print(x,y,a,b)
    for i in range(max(floor(x/a),floor(y/b)),max(floor(x/a),floor(y/b))+2):
        p,q=a*i,b*i
        if p>=x and q>=y:
            break
    return [p,q]
    #return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
    #for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=pairs[0]
for i in range(n-1):
    u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print(u+v)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    #print(x,y,a,b)
    for i in range(max(1,max(floor(x/a),floor(y/b))),max(ceil(x/a),ceil(y/b))+1):
        p,q=a*i,b*i
        if p>=x and q>=y:
            break
    return [p,q]
    #return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
    #for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=pairs[0]
for i in range(n-1):
    u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print(u+v)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
lst = []
for _ in range(N):
    a, b = map(int, input().split())
    lst.append((a, b))

x = 1
a = lst[0][0]
b = lst[0][1]
for i in range(1, N):
    pre_a, pre_b = lst[i - 1]
    a, b = lst[i]
    x = max(math.ceil(pre_a * x / a), math.ceil(pre_b * x / b))

a, b = lst[-1]
print(a * x + b * x)

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())
x=1
y=1
for i in range(n):
  s,t=map(int,input().split())
  u=s
  v=t
  if s<x:
    if x/s == int(x/s):
      w=int(x/s)
    else:
      w=int(x/s)+1
    s*=w
    t*=w
  if t<y:
    s=u
    t=v
    if y/t == int(y/t):
      w=int(y/t)
    else:
      w=int(y/t)+1
    s*=w
    t*=w
  x=s
  y=t
print(x+y)

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())
x=1
y=1
for i in range(n):
  s,t=map(int,input().split())
  if s<x:
    if x/s == int(x/s):
      w=int(x/s)
    else:
      w=int(x/s)+1
    s*=w
    t*=w
  if t<y:
    if y/t == int(y/t):
      w=int(y/t)
    else:
      w=int(y/t)+1
    s*=w
    t*=w
  x=s
  y=t
print(x+y)

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())
x,y=map(int,input().split())
gcd=fractions.gcd(x,y)
x=int(x/gcd)
y=int(y/gcd)
for i in range(n-1):
  s,t=map(int,input().split())
  if s<x:
    if x/s == int(x/s):
      w=int(x/s)
    else:
      w=int(x/s)+1
    s*=w
    t*=w
  if t<y:
    if y/t == int(y/t):
      w=int(y/t)
    else:
      w=int(y/t)+1
    s*=w
    t*=w
  x=s
  y=t
print(x+y)

Submission status: Wrong Answer

Solution code:
import fractions

n=int(input())
x,y=map(int,input().split())
gcd=fractions.gcd(x,y)
x=int(x/gcd)
y=int(y/gcd)
for i in range(n-1):
  s,t=map(int,input().split())
  if s<x:
    w=int(x/s)+1
    s*=w
    t*=w
  if t<y:
    w=int(y/t)+1
    s*=w
    t*=w
  x=s
  y=t
print(x+y)

Submission status: Wrong Answer

Solution code:
import sys
def v():
    N=int(sys.stdin.readline())
    P=[]
    pt,pa=tuple(map(int,sys.stdin.readline().split()))
    res=pt+pa
    print(res)
    for _ in [0]*(N-1):
        xt,xa=tuple(map(int,sys.stdin.readline().split()))
        xs=xt+xa
        kt=pt//xt if pt%xt ==0 else pt//xt+1
        ka=pa//xa if pa%xa ==0 else pa//xa+1
        k=max([kt,ka])
        pt,pa=k*xt,k*xa
        res=pt+pa
    print(res)
if __name__=='__main__':v()

Submission status: Wrong Answer

Solution code:
from math import ceil 
N = int(input())
votes = [1,1]
rate = 1
for i in range(N):
    t,a = map(int,input().split())
    rate = max(votes[0] - 1 // t, votes[1] - 1 // a) + 1
    # if t * rate >= votes[0] and a * rate >= votes[1]:
    votes = [t * rate, a * rate]

print(sum(votes))

Submission status: Wrong Answer

Solution code:
from math import ceil 
N = int(input())
votes = [1,1]
rate = 1
for i in range(N):
    t,a = map(int,input().split())
    rate = max(ceil(votes[0] / min(t,votes[0])),ceil(votes[1] / min(a,votes[1])))
    # if t * rate >= votes[0] and a * rate >= votes[1]:
    votes = [t * rate, a * rate]

print(sum(votes))

Submission status: Wrong Answer

Solution code:
from math import ceil
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    n = int(read())
    a, b = 1, 1
    for _ in range(n):
        x, y = map(int, read().split())
        m = ceil(max(a / x, b / y))
        a = m * x
        b = m * y
    print(a + b)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    n = int(read())
    t, a = map(int, read().split())
    at, aa = t, a
    for _ in range(n - 1):
        t, a = map(int, read().split())
        if t / at < a / aa:
            at = t * ceil(at / t)
            aa = at * a // t
        else:
            aa = a * ceil(aa / a)
            at = aa * t // a
    print(at + aa)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    N = int(input())
    T, A = map(int, input().split())
    for _ in range(N-1):
        t, a = map(int, input().split())
        x = sorted([math.ceil(T/t), math.ceil(A/a)])
        # y = list(filter(lambda i: i > 1, [math.ceil(T/t), math.ceil(A/a)]))
        # print(x,y)
        x.sort()
        T = t*x[-1]
        A = a*x[-1]
        # print(T,A)
    print(T+A)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    N = int(input())
    T, A = map(int, input().split())
    for _ in range(N-1):
        t, a = map(int, input().split())
        if T <= t and A <= a:
            T,A = t,a
        else:
            # x = sorted([math.ceil(T/t), math.ceil(A/a)],reverse=True)
            y = list(filter(lambda i: i > 1, [math.ceil(T/t), math.ceil(A/a)]))
            # print(x,y)
            y.sort()
            T = t*y[-1]
            A = a*y[-1]
        # print(T,A)
    print(T+A)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    N = int(input())
    T, A = map(int, input().split())
    for _ in range(N-1):
        t, a = map(int, input().split())
        if T <= t and A <= a:
            T,A = t, a
        else:
            x = sorted([math.ceil(T/t), math.ceil(A/a)],reverse=True)
            y = list(filter(lambda i: i > 1, x))
            # print(x,y)
            T = t*y[0]
            A = a*y[0]
        # print(T,A)
    print(T+A)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

n = int(input())
tv = av = 1
t = [0]*n; a = [0]*n
for i in range(n):
    t[i], a[i] = imap()
for i in range(n):
    tmp = max(int(tv/t[i])+bool(tv%t[i]!=0), int(av/a[i])+bool(av%a[i]!=0))
    tv = t[i]*tmp; av=a[i]*tmp
print(tv+av)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

n = int(input())
tv = av = 1
t = [0]*n; a = [0]*n
for i in range(n):
    t[i], a[i] = imap()
for i in range(n):
    tmp = max(int(tv/t[i])+(tv%t[i]!=0), int(av/a[i])+(av%a[i]!=0))
    tv = t[i]*tmp; av=a[i]*tmp
print(tv+av)

Submission status: Wrong Answer

Solution code:
import math

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

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

print(x + y)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# t0, a0 = map(int, input().split())
anst = 1
ansa = 1
for _ in range(n):
    ti, ai = map(int, input().split())
    anst = ti * math.ceil(max(anst/ti, ansa/ai))
    ansa = ai * math.ceil(max(anst/ti, ansa/ai))
    # p
    # if math.ceil(anst/ti) < math.ceil(ansa/ai):
    #     # if math.ceil(anst/ti)*ai >= ansa:
    #     #     anst = ti * math.ceil(anst/ti)
    #     #     ansa = ai * math.ceil(anst/ti)
    #     # else:
    #     ansa = ai * math.ceil(ansa/ai)
    #     anst = ti * math.ceil(ansa/ai)
    # else:
    #     # if math.ceil(ansa/ai)*ti >= anst:
    #     #     ansa = ai * math.ceil(ansa/ai)
    #     #     anst = ti * math.ceil(ansa/ai)
    #     # else:
    #     ansa = ai * math.ceil(anst/ti)
    #     anst = ti * math.ceil(anst/ti)
    # # print("anst", anst,"ansa = ", ansa)
        
print(int(anst + ansa))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# t0, a0 = map(int, input().split())
anst = 1
ansa = 1
for _ in range(n):
    ti, ai = map(int, input().split())
    anst = ti * max(math.ceil(anst/ti), math.ceil(ansa/ai))
    ansa = ai * max(math.ceil(anst/ti), math.ceil(ansa/ai))
    # p
    # if math.ceil(anst/ti) < math.ceil(ansa/ai):
    #     # if math.ceil(anst/ti)*ai >= ansa:
    #     #     anst = ti * math.ceil(anst/ti)
    #     #     ansa = ai * math.ceil(anst/ti)
    #     # else:
    #     ansa = ai * math.ceil(ansa/ai)
    #     anst = ti * math.ceil(ansa/ai)
    # else:
    #     # if math.ceil(ansa/ai)*ti >= anst:
    #     #     ansa = ai * math.ceil(ansa/ai)
    #     #     anst = ti * math.ceil(ansa/ai)
    #     # else:
    #     ansa = ai * math.ceil(anst/ti)
    #     anst = ti * math.ceil(anst/ti)
    # # print("anst", anst,"ansa = ", ansa)
        
print(int(anst + ansa))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# t0, a0 = map(int, input().split())
anst = 1
ansa = 1
for _ in range(n):
    ti, ai = map(int, input().split())
    if math.ceil(anst/ti) < math.ceil(ansa/ai):
        # if math.ceil(anst/ti)*ai >= ansa:
        #     anst = ti * math.ceil(anst/ti)
        #     ansa = ai * math.ceil(anst/ti)
        # else:
        ansa = ai * math.ceil(ansa/ai)
        anst = ti * math.ceil(ansa/ai)
    else:
        # if math.ceil(ansa/ai)*ti >= anst:
        #     ansa = ai * math.ceil(ansa/ai)
        #     anst = ti * math.ceil(ansa/ai)
        # else:
        ansa = ai * math.ceil(anst/ti)
        anst = ti * math.ceil(anst/ti)
    # print("anst", anst,"ansa = ", ansa)
        
print(int(anst + ansa))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# t0, a0 = map(int, input().split())
anst = 1
ansa = 1
for _ in range(n):
    ti, ai = map(int, input().split())
    if math.ceil(anst/ti) < math.ceil(ansa/ai):
        # if math.ceil(anst/ti)*ai >= ansa:
        #     anst = ti * math.ceil(anst/ti)
        #     ansa = ai * math.ceil(anst/ti)
        # else:
        ansa = ai * math.ceil(ansa/ai)
        anst = ti * math.ceil(ansa/ai)
    else:
        # if math.ceil(ansa/ai)*ti >= anst:
        #     ansa = ai * math.ceil(ansa/ai)
        #     anst = ti * math.ceil(ansa/ai)
        # else:
        ansa = ai * math.ceil(anst/ti)
        anst = ti * math.ceil(anst/ti)
    # print("anst", anst,"ansa = ", ansa)
        
print(anst + ansa)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# t0, a0 = map(int, input().split())
anst = 1
ansa = 1
for _ in range(n):
    ti, ai = map(int, input().split())
    if math.ceil(anst/ti) <= math.ceil(ansa/ai):
        # if math.ceil(anst/ti)*ai >= ansa:
        #     anst = ti * math.ceil(anst/ti)
        #     ansa = ai * math.ceil(anst/ti)
        # else:
        ansa = ai * math.ceil(ansa/ai)
        anst = ti * math.ceil(ansa/ai)
    else:
        # if math.ceil(ansa/ai)*ti >= anst:
        #     ansa = ai * math.ceil(ansa/ai)
        #     anst = ti * math.ceil(ansa/ai)
        # else:
        ansa = ai * math.ceil(anst/ti)
        anst = ti * math.ceil(anst/ti)
    # print("anst", anst,"ansa = ", ansa)
        
print(anst + ansa)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t0, a0 = map(int, input().split())
anst = t0
ansa = a0
for _ in range(1,n):
    ti, ai = map(int, input().split())
    if math.ceil(anst/ti) <= math.ceil(ansa/ai):
        # if math.ceil(anst/ti)*ai >= ansa:
        #     anst = ti * math.ceil(anst/ti)
        #     ansa = ai * math.ceil(anst/ti)
        # else:
        ansa = ai * math.ceil(ansa/ai)
        anst = ti * math.ceil(ansa/ai)
    else:
        # if math.ceil(ansa/ai)*ti >= anst:
        #     ansa = ai * math.ceil(ansa/ai)
        #     anst = ti * math.ceil(ansa/ai)
        # else:
        ansa = ai * math.ceil(anst/ti)
        anst = ti * math.ceil(anst/ti)
    # print("anst", anst,"ansa = ", ansa)
        
print(anst + ansa)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t0, a0 = map(int, input().split())
anst = t0
ansa = a0
for _ in range(1,n):
    ti, ai = map(int, input().split())
    if ti * math.ceil(anst/ti) + math.ceil(anst/ti)*ai <= ai * math.ceil(ansa/ai) + ti*math.ceil(ansa/ai):
        if math.ceil(anst/ti)*ai >= ansa:
            anst = ti * math.ceil(anst/ti)
            ansa = ai * math.ceil(anst/ti)
        else:
            ansa = ai * math.ceil(ansa/ai)
            anst = ti * math.ceil(ansa/ai)
    else:
        if math.ceil(ansa/ai)*ti >= anst:
            ansa = ai * math.ceil(ansa/ai)
            anst = ti * math.ceil(ansa/ai)
        else:
            ansa = ai * math.ceil(anst/ti)
            anst = ti * math.ceil(anst/ti)
    # print("anst", anst,"ansa = ", ansa)
        
print(anst + ansa)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
t0, a0 = map(int, input().split())
anst = t0
ansa = a0
for _ in range(1,n):
    ti, ai = map(int, input().split())
    if ti * math.ceil(anst/ti) + math.ceil(anst/ti)*ai <= ai * math.ceil(ansa/ai) + ti*math.ceil(ansa/ai):
        if math.ceil(anst/ti)*ai >= ansa:
            anst = ti * math.ceil(anst/ti)
            ansa = math.ceil(anst/ti)*ai
        else:
            ansa = ai*math.ceil(ansa/ai)
            anst = ti*math.ceil(ansa/ai)
    else:
        if math.ceil(ansa/ai)*ti >= anst:
            ansa = ai*math.ceil(ansa/ai)
            anst = ti*math.ceil(ansa/ai)
        else:
            ansa = ai*math.ceil(anst/ti)
            anst = ti*math.ceil(anst/ti)
        
print(anst + ansa)

Submission status: Wrong Answer

Solution code:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    A, B = [0] * N, [0] * N

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

    x = 1

    for i in range(N-1):
        x = max(math.ceil(A[i]*x/A[i+1]), math.ceil(B[i]*x/B[i+1]))

    print(x*(A[N-1]+B[N-1]))


resolve()

Submission status: Wrong Answer

Solution code:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    x = [1]+[0]*(N-1)
    for i in range(N-1):
        x[i+1] = max(math.ceil(A[i]*x[i]/A[i+1]), math.ceil(B[i]*x[i]/B[i+1]))
    print(x[N-1]*(A[N-1]+B[N-1]))


resolve()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
pairs = (map(int, input().split()) for _ in range(N))

t, a = 1, 1
for ti, ai in pairs:
    mul = max(int(math.ceil(t / ti)), int(math.ceil(a / ai)))
    t = ti * mul
    a = ai * mul

print(t + a)

Submission status: Wrong Answer

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

print(t + a)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000000
N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(takahashi/a)),ceil(Decimal(aoki/b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(takahashi/a)),ceil(Decimal(aoki/b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
from math import ceil

N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(takahashi/a)),ceil(Decimal(aoki/b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(takahashi/a),ceil(aoki/b))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
##ディオファントス方程式を解こうとして断念.

from math import ceil

N = int(input())

takahashi,aoki = 0.1,0.1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(takahashi/a),ceil(aoki/b))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
##ディオファントス方程式を解こうとして断念

from math import ceil

N = int(input())

takahashi,aoki = map(int,input().split())

for _ in range(N-1):
    a,b = map(int,input().split())
    c = max(ceil(takahashi/a),ceil(aoki/b))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = [int(x) for x in stdin.readline().rstrip().split()]
 
for _ in range(N-1):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = int(max(math.ceil(t/T),math.ceil(a/A)))
    t = n*T
    a = n*A
    
print(t+a)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = 1,1

for _ in range(N):
    T,A = [int(x) for x in stdin.readline().rstrip().split()]
    n = max(math.ceil(t/T),math.ceil(a/A))
    t = n*T
    a = n*A
    
print(t+a)