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,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    B = [LI() for _ in range(N)]

    # for i in range(1,N):
    #     if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
    #         r = max(math.ceil(b[i-1][0]/b[i][0]),math.ceil(b[i-1][1]/b[i][1]))
    #         b[i][0] *= r
    #         b[i][1] *= r
    # print(sum(b[-1]))

    a = 1
    b = 1
    for x,y in B:
        r = max(math.ceil(a/x),math.ceil(b/y))
        a = x*r
        b = y*r
    print(a+b)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    # for i in range(1,N):
    #     if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
    #         r = max(math.ceil(b[i-1][0]/b[i][0]),math.ceil(b[i-1][1]/b[i][1]))
    #         b[i][0] *= r
    #         b[i][1] *= r
    # print(sum(b[-1]))

    x = 1
    y = 1
    for i,j in b:
        r = max(math.ceil(x/i),math.ceil(y/j))
        x = i*r
        y = j*r
    print(x+y)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    for i in range(1,N):
        if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
            r = max(math.ceil(b[i-1][0]/b[i][0]),math.ceil(b[i-1][1]/b[i][1]))
            b[i][0] *= r
            b[i][1] *= r
    print(sum(b[-1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    for i in range(1,N):
        if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
            if b[i][0] == 0 or b[i][1] == 0:
                b[i][0] = b[i-1][0]
                b[i][1] = b[i-1][1]
            else:
                r = math.ceil(max(b[i-1][0]/b[i][0],b[i-1][1]/b[i][1]))
                b[i][0] *= r
                b[i][1] *= r
    print(sum(b[-1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    for i in range(1,N):
        if b[i][0] == 0 or b[i][1] == 0: continue
        if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
            if b[i][0] == 0 or b[i][1] == 0:
                b[i][0] = b[i-1][0]
                b[i][1] = b[i-1][1]
            else:
                r = math.ceil(max(b[i-1][0]/b[i][0],b[i-1][1]/b[i][1]))
                b[i][0] *= r
                b[i][1] *= r
    print(sum(b[-1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    for i in range(1,N):
        if b[i][0] == 0 or b[i][1] == 0: continue
        if b[i][0] < b[i-1][0] or b[i][1] < b[i-1][1]:
            r = math.ceil(max(b[i-1][0]/b[i][0],b[i-1][1]/b[i][1]))
            b[i][0] *= r
            b[i][1] *= r
    print(sum(b[-1]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    b = [LI() for _ in range(N)]

    for i in range(1,N):
        if b[i][0] < b[i-1][0]:
            r = math.ceil(b[i-1][0]/b[i][0])
            b[i][0] *= r
            b[i][1] *= r
        if b[i][1] < b[i-1][1]:
            r = math.ceil(b[i-1][1]/b[i][1])
            b[i][0] *= r
            b[i][1] *= r
    print(sum(b[-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

N = int(sys.stdin.readline().strip())

ratios = []
for _ in range(N):
    t, a = map(int, sys.stdin.readline().strip().split())
    ratios.append((t, a))

ans = 0
for i in range(N-1):
    t1, a1 = ratios[i]
    s1 = t1 + a1
    t2, a2 = ratios[i+1]
    s2 = t2 + a2

    # rate = max(math.ceil(t1 / t2), math.ceil(a1 / a2))
    rate = max(math.ceil(t1 / t2), math.ceil(a1 / a2),  math.ceil((a1 + t1) / (t2 + a2)))
    ratios[i+1] = (t2 * rate, a2 * rate)

print(sum(ratios[N-1]))

Submission status: Wrong Answer

Solution code:
import sys
import math

N = int(sys.stdin.readline().strip())

ratios = []
for _ in range(N):
    t, a = map(int, sys.stdin.readline().strip().split())
    ratios.append((t, a))

ans = 0
for i in range(N-1):
    t1, a1 = ratios[i]
    s1 = t1 + a1
    t2, a2 = ratios[i+1]
    s2 = t2 + a2

    rate = max(math.ceil(t1 / t2), math.ceil(a1 / a2))
    ratios[i+1] = (t2 * rate, a2 * rate)

print(sum(ratios[N-1]))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
T,A = 1,1
for i in range(n):
    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)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import ceil

n = int(readline())
ta = [list(map(int, readline().split())) for _ in range(n)]
t, a = ta.pop(0)
for tt, aa in ta:
    v = max(ceil(t / tt), ceil(a / aa))
    t = v * tt
    a = v * aa
print(t + a)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import ceil

n = int(readline())
ta = [list(map(int, readline().split())) for _ in range(n)]
t, a = 1, 1
for tt, aa in ta:
    v = max(ceil(t / tt), ceil(a / aa))
    t = v * tt
    a = v * aa
print(t + a)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import ceil

n = int(readline())
ta = [list(map(int, readline().split())) for _ in range(n)]
t, a = 1, 1
for tt, aa in ta:
    if tt == 1:
        if a % aa == 0 and a // aa >= t:
            t = a // aa
        else:
            a = t * aa
    elif aa == 1:
        if t % tt == 0 and t // tt >= a:
            a = t // tt
        else:
            t = a * tt
    else:
        v = max(ceil(t / tt), ceil(a / aa))
        t = v * tt
        a = v * aa
print(t + a)

Submission status: Wrong Answer

Solution code:
import math
def  results(a,b):
    return (a+b-1//b)
 
n=int(input())
t,a=map(int,input().split())
for i in range(1,n):
    ti,ai=map(int,input().split())
    if ti<=t or ai<=a:
        k=max(results(t,ti),results(a,ai))
        t=k*ti
        a=k*ai
    else:
        t=ti
        a=ai
    #print(t,a)
print(t+a)

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())
    p = max(math.ceil(a/c),math.ceil(b/d))
    a = c * p
    b = d * p
print(a+b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
def  results(a,b):
    return math.ceil(a/b)

n=int(input())
t,a=map(int,input().split())
for i in range(1,n):
    ti,ai=map(int,input().split())
    if ti<=t or ai<=a:
        k=max(results(t,ti),results(a,ai))
        t=k*ti
        a=k*ai
    else:
        t=ti
        a=ai
    #print(t,a)
print(t+a)

Submission status: Wrong Answer

Solution code:
import math
def  results(a,b):
    return math.ceil(a/b)

n=int(input())
t,a=map(int,input().split())
for i in range(1,n):
    ti,ai=map(int,input().split())
    if ti>=t and ai>=a:
        t=ti
        a=ai
    elif ti<t and ai>=a:
        k=results(t,ti)
        t=k*ti
        a=k*ai
    elif ti>=t and ai<a:
        k=results(a,ai)
        t=k*ti
        a=k*ai
    else:
        k=max(results(t,ti),results(a,ai))
        t=k*ti
        a=k*ai
    #print(t,a)
print(t+a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import ceil

def main():
  n = int(input())
  nt, na = 1, 1
  for i in range(n):
    t, a = map(int, input().split())
    r = max([ceil(nt/t), ceil(na/a)])
    nt, na = r*t, r*a
  print(nt + na)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import ceil

def main():
  n = int(input())
  for i in range(n):
    t, a = map(int, input().split())
    if i == 0:
      nt, na =  t, a
      continue
    r = max([ceil(nt/t), ceil(na/a)])
    nt, na = r*t, r*a
  print(nt + na)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [0]*N
A = [0]*N
ans = 0
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
t = T[0]
a = A[0]
for i in range(1, N):
    for j in range(max((t+T[i]-1)//T[i], (a+A[i]-1)//A[i]), 1000000):
        if(T[i]*j >= t and A[i]*j >= a):
            t = T[i]*j
            a = A[i]*j
            break
print(t+a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [0]*N
A = [0]*N
ans = 0
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
t = T[0]
a = A[0]
for i in range(1, N):
    for j in range(max(t//T[i]-1, a//A[i]-1, 0), 1000000):
        if(T[i]*j >= t and A[i]*j >= a):
            t = T[i]*j
            a = A[i]*j
            break
print(t+a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [0]*N
A = [0]*N
ans = 0
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
t = T[0]
a = A[0]
for i in range(1, N):
    for j in range(max(t//T[i]-1, a//A[i]-1, 0), 1000000):
        if(T[i]*j >= t and A[i]*j >= a):
            t = T[i]*j
            a = A[i]*j
            print(t, a)
            break
print(t+a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [0]*N
A = [0]*N
ans = 0
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
t = T[0]
a = A[0]
for i in range(1, N):
    for j in range(min(t//T[i], a//A[i]), 1000000):
        if(T[i]*j >= t and A[i]*j >= a):
            t = T[i]*j
            a = A[i]*j
            break
print(t+a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [0]*N
A = [0]*N
ans = 0
for i in range(N):
    T[i], A[i] = map(int, input().split())
    
t = T[0]
a = A[0]
for i in range(1, N):
    for j in range(max(t//T[i], a//A[i], 1), 1000000):
        if(T[i]*j >= t and A[i]*j >= a):
            t = T[i]*j
            a = A[i]*j
            break
print(t+a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

n = INT()
ans = [1, 1]
for i in range(n):
    t,a = MAP()
    k = max((ans[0] + t - 1) / t, (ans[1] + a - 1) / a)
    ans[0] = k * t
    ans[1] = k * a
    #print('a', t+a, ans)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

n = INT()
ans = [1, 1]
for i in range(n):
    t,a = MAP()
    k = max(ceil(ans[1] / a), ceil(ans[0] / t))
    ans[0] = k * t
    ans[1] = k * a
    #print('a', t+a, ans)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

n = INT()
ans = [0, 0]
for i in range(n):
    t,a = MAP()
    k = max(ceil(ans[1] / a), ceil(ans[0] / t))
    ans[0] = k * t
    ans[1] = k * a
    #print('a', t+a, ans)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N, = map(int, input().split())
r = 1
for _ in range(N):
    a, b = map(int, input().split())
    k=-(-r//(a+b))
    r=k*(a+b)
print(r)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N=int(input())
SUM=[]
for _ in range(N):
  T,A=map(int,input().split())
  SUM.append(T+A)
print(lcm_list(SUM))

Submission status: Wrong Answer

Solution code:
N = int(input())
TA = [[int(i) for i in input().split()] for _ in range(N)]

from math import ceil

taka = 1
aoki = 1

for i in range(N):
    T,A = TA[i]

    tmp = max(ceil(taka/T), ceil(aoki/A))
    taka = tmp * T
    aoki = tmp * A

print(taka + aoki)

Submission status: Wrong Answer

Solution code:
n = int(input())
ta = []
for i in range(n):
    tmp = list(map(int,input().split()))
    ta.append(tmp)
vote=ta[0]
import math
for v in ta[1:]:
    t_ratio=math.ceil(vote[0]/v[0])
    a_ratio=math.ceil(vote[1]/v[1])
    ratio = max(t_ratio,a_ratio)
    vote[0] = v[0] * ratio
    vote[1] = v[1] * ratio

print(sum(vote))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    N = cin.int()
    T = cin.intListList(N)
    a,b = 1,1
    for t in T:
        n = max(math.ceil(a / t[0]),math.ceil(b / t[1]))
        a,b = n * t[0],n * t[1]
    print(a + b)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [0,0]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = max(P[0]//t,P[1]//a)
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))

Submission status: Wrong Answer

Solution code:
N = int(input())
P = [0,0]

for i in range(N):
  Q = list(map(int,input().split()))
  t = Q[0]
  a = Q[1]
  m = max(P[0]/t,P[1]/a)
  while True:
    t = Q[0] * m
    a = Q[1] * m
    if t >= P[0] and a >= P[1]:
      P[0] = t
      P[1] = a
      break
    m += 1

print(sum(P))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

t0, a0 = map(int, input().split())

if N == 1:
    print(int(t0+a0))
    exit()

for i in range(N-1):
    T, A = map(int, input().split())
    t1 = math.ceil(t0/T)*T
    a1 = t1*A/T

    if a1 < a0:
        a1 = math.ceil(a0/A)*A
        t1 = a1*T/A

    t0, a0 = t1, a1
print(int(t0+a0))

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	lst = []
	for i in range(n):
		lst.append(list(map(int,input().split())))
	a = 1
	b = 1
	for i in lst:
		want = i[0]/i[1]
		while True:
			now = a/b
			if abs(now-want)<1e-8:
				break
			if want>now:
				a+=1
			else:
				b+=1
	print(a+b)
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ta = list(map(int, input().split()))
T, A = ta[0], ta[1]

# 繰り返し
for i in range(N - 1):
    tmp_ta = list(map(int, input().split()))
    t, a = tmp_ta[0], tmp_ta[1]
    # T,Aが各々t,aの倍数かつそのような比になればいい.
    # Tが最小 ->　Aも最小になる
    # ダメ.小さい方を揃えないと(3,3) -> (3,2)のような変化になる
    # (2,5) -> (2,4)でも死にそう
    # (2,5) -> (4,8)になるのが良さそう -> なっている
    # (1,2) -> (2,1) は？　(4,2)が答 -> なっている
    # intの範囲超えてintキャストしたら死ぬ,それはそう
    # どっちかを最小にすればいいんじゃないか？
    # まずt基準
    tmpTt = math.floor((T + t - 1) / t) * t
    tmpTa = tmpTt / t * a
    tmpAa = math.floor((A + a - 1) / a) * a
    tmpAt = tmpAa / a * t
    if tmpTa < A:
        T = tmpAt
        A = tmpAa
    elif tmpAt < T:
        A = tmpTa
        T = tmpTt
    elif (tmpTt + tmpTa) < (tmpAa + tmpAt):
        A = tmpTa
        T = tmpTt
    else:
        T = tmpAt
        A = tmpAa

print(math.floor(T + A))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
ta = list(map(int, input().split()))
T, A = ta[0], ta[1]

# 繰り返し
for i in range(N - 1):
    tmp_ta = list(map(int, input().split()))
    t, a = tmp_ta[0], tmp_ta[1]
    # T,Aが各々t,aの倍数かつそのような比になればいい.
    # Tが最小 ->　Aも最小になる
    # ダメ.小さい方を揃えないと(3,3) -> (3,2)のような変化になる
    # (2,5) -> (2,4)でも死にそう
    # (2,5) -> (4,8)になるのが良さそう -> なっている
    # (1,2) -> (2,1) は？　(4,2)が答 -> なっている
    # intの範囲超えてintキャストしたら死ぬ,それはそう
    # どっちかを最小にすればいいんじゃないか？
    # まずt基準
    tmpTt = math.floor((T + t - 1) / t) * t
    tmpTa = tmpTt / t * a
    tmpAa = math.floor((A + a - 1) / a) * a
    tmpAt = tmpAa / a * t
    if tmpTa < A:
        T = tmpAt
        A = tmpAa
    elif tmpAt < T:
        A = tmpTa
        T = tmpTt
    elif (tmpTt + tmpTa) < (tmpAa + tmpAt):
        A = tmpTa
        T = tmpTt
    else:
        T = tmpAt
        A = tmpAa

print(int(T + A))

Submission status: Wrong Answer

Solution code:
N = int(input())
ta = list(map(int, input().split()))
T, A = ta[0], ta[1]

# 繰り返し
for i in range(N - 1):
    tmp_ta = list(map(int, input().split()))
    t, a = tmp_ta[0], tmp_ta[1]
    # T,Aが各々t,aの倍数かつそのような比になればいい.
    # Tが最小 ->　Aも最小になる
    # ダメ.小さい方を揃えないと(3,3) -> (3,2)のような変化になる
    # (2,5) -> (2,4)でも死にそう
    # どっちかを最小にすればいいんじゃないか？
    # まずt基準
    tmpTt = int(int(T + t - 1) / t) * t
    tmpTa = tmpTt / t * a
    tmpAa = int(int(A + a - 1) / a) * a
    tmpAt = tmpAa / a * t
    if tmpTa < A:
        T = tmpAt
        A = tmpAa
    elif tmpAt < T:
        A = tmpTa
        T = tmpTt
    elif (tmpTt + tmpTa) < (tmpAa + tmpAt):
        A = tmpTa
        T = tmpTt
    else:
        T = tmpAt
        A = tmpAa

print(int(T + A))

Submission status: Wrong Answer

Solution code:
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際の二人の得票数を数える
N = ri()
T_cnt = 1
A_cnt = 1
for _ in range(N):
    t, a = rl()
    n = max(math.ceil(T_cnt/t), math.ceil(A_cnt/a))
    T_cnt, A_cnt = t * n, a * n

answer = T_cnt + A_cnt
print(int(answer))
#24

Submission status: Wrong Answer

Solution code:
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際の二人の得票数を数える
N = ri()
T_cnt = 1
A_cnt = 1
for _ in range(N):
    t, a = rl()
    n = max(math.ceil(T_cnt/t), math.ceil(A_cnt/a))
    T_cnt, A_cnt = t * n, a * n

answer = T_cnt + A_cnt
print(answer)
#24

Submission status: Wrong Answer

Solution code:
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際の二人の得票数を数える
N = ri()
T_cnt = 1
A_cnt = 1
for _ in range(N):
    t, a = rl()
    
    if T_cnt / t >= A_cnt / a:
        #Tを基準にふやす
        if T_cnt%t != 0:
            T_cnt = math.ceil(T_cnt/t) * t
        A_cnt = T_cnt // t * a
    else:
        if A_cnt%a != 0:
            A_cnt = math.ceil(A_cnt/a) * a
        T_cnt = A_cnt // a * t

answer = T_cnt + A_cnt
print(answer)
#24

Submission status: Wrong Answer

Solution code:
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際の二人の得票数を数える
N = ri()
T_cnt = 1
A_cnt = 1
for _ in range(N):
    t, a = rl()
    
    if T_cnt * a >= A_cnt * t:
        #Tを基準にふやす
        if T_cnt%t != 0:
            T_cnt = math.ceil(T_cnt/t) * t
        A_cnt = T_cnt // t * a
    else:
        if A_cnt%a != 0:
            A_cnt = math.ceil(A_cnt/a) * a
        T_cnt = A_cnt // a * t

answer = T_cnt + A_cnt
print(answer)
#24

Submission status: Wrong Answer

Solution code:
import sys
import math

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際の二人の得票数を数える
N = ri()
T_cnt = 1
A_cnt = 1
for _ in range(N):
    t, a = rl()
    
    if t / T_cnt <= a / A_cnt:
        #Tを基準にふやす
        if T_cnt%t != 0:
            T_cnt = math.ceil(T_cnt/t) * t
        A_cnt = T_cnt // t * a
    else:
        if A_cnt%a != 0:
            A_cnt = math.ceil(A_cnt/a) * a
        T_cnt = A_cnt // a * t

answer = T_cnt + A_cnt
print(answer)
#24

Submission status: Wrong Answer

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

ma = 1
mb = 1
for a, b in AB:
  i = math.ceil(ma /a)
  j = math.ceil(mb /b)
  k = max(i, j)
  
  ma = k*a
  mb = k*b
  
print(ma + mb)

Submission status: Wrong Answer

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

ma,mb = AB[0]
for a, b in AB[1:]:
  i = math.ceil(ma /a)
  j = math.ceil(mb /b)
  k = max(i, j)
  
  ma = k*a
  mb = k*b
  
print(ma + mb)

Submission status: Wrong Answer

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

ma,mb = AB[0]
for a, b in AB:
  i = math.ceil(ma /a)
  j = math.ceil(mb /b)
  k = max(i, j)
  
  ma = k*a
  mb = k*b
  
print(ma + mb)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
x,y=1,1
for i in l:
    t=i[0]
    a=i[1]
    z=max(x/t,y/a)
    if z!=int(z):
        z=int(z)+1
    x=int(z)*t
    y=int(z)*a
print(x+y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

def main():
    N = int(input())
    T = A = 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)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# n(n>0) 以上で一番小さい m の倍数を返す
import math
def f(n, m):
    return int(m * math.ceil(n/m))

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# n(n>0) 以上で一番小さい m の倍数を返す
import math
def f(n, m):
    return int(m * math.ceil(n/m))

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math

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

for i in range(1,N):
    times = max(math.ceil(T[i-1]/T[i]),math.ceil(A[i-1]/A[i]))
    if T[i] < T[i-1] or A[i] < A[i-1]:
        T[i] = T[i]*times
        A[i] = A[i]*times
print(T[N-1]+A[N-1])

Submission status: Wrong Answer

Solution code:
import sys
import os
import math

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

t = 1
a = 1
for i in range(N):
    times = max(math.ceil(t/T[i]),math.ceil(a/A[i]))
    T[i] = T[i]*times
    A[i] = A[i]*times
    t = T[i]
    a = A[i]
print(T[N-1]+A[N-1])

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
N = int(input())
T = [0 for _ in range(N)]
A = [0 for _ in range(N)]
for i in range(N):
    t,a = list(map(int,input().split()))
    T[i] = t
    A[i] = a

points = T[0] + A[0]
for i in range(1,N):
    times = max(math.ceil(T[i-1]/T[i]),math.ceil(A[i-1]/A[i]))
    T[i] = T[i]*times
    A[i] = A[i]*times
    points = T[i] + A[i]
print(points)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
lis = [[] for _ in range(N)]
for n in range(N):
    lis[n] = list(map(int, input().split()))
a = 1
b = 1

for n in range(N):
    x = max(math.ceil(a / lis[n][0]), math.ceil(b / lis[n][1]))
    a = x * lis[n][0]
    b = x * lis[n][1]
print(a + b)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
import sys
N = int(input())
T = []
A = []
for n in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)

a = 1
t = 1
for n in range(N):
    tmp_t = math.ceil(t / T[n])
    tmp_a = math.ceil(a / A[n])
    x = max(tmp_t, tmp_a)
    t = x * T[n]
    a = x * A[n]
print(a + t)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
import sys
N = int(input())
T = []
A = []
for n in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
a, t = 1, 1
for n in range(N):
    tmp_a = math.ceil(a / A[n])
    tmp_t = math.ceil(t / T[n])
    x = max(tmp_a, tmp_t)
    a = x * A[n]
    t = x * T[n]
print(a + t)