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:
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 = max(math.ceil(t/T),math.ceil(a/A))
    t = n*T
    a = n*A
    
print(t+a)

Submission status: Wrong Answer

Solution code:
n=int(input())
TA=[list(map(int,input().split())) for _ in range(n)]
l=1
from math import ceil,floor
r=1
for i , j  in TA:
    p=ceil(l/i)
    q=ceil(r/j)
    w=max(p,q)
    l=i*w
    r=j*w
print(l+r)

Submission status: Wrong Answer

Solution code:
n=int(input())
TA=[list(map(int,input().split())) for _ in range(n)]
l=TA[0][0]
from math import ceil,floor
r=TA[0][1]
for i , j  in TA[1:]:
    p=ceil(l/i)
    q=ceil(r/j)
    w=max(p,q)
    l=i*w
    r=j*w
print(l+r)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
import math

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


"""

・Ti, Ai を i回目の二人の得票数の比
・Pti, Pai をi回目の二人の得票数とすると、

Pti : Pai = Ti : Ai なので、　Pti = M * Ti, Pai = M * Ai (M=1,2,3,...)と表せる。

とあらわせる。ここで、
Pti-1 <= Pti
Pai-1 <= Pai
なので、Mは
M >= Pti-1 / Ti
M >= Pai-1 / Ai
の両方を満たすものになり、得票数を最小に保つにはMもなるべく小さくとる
"""
t,a = 0,0
for i in range(N):
    if i == 0:
        t,a = TA[i][0], TA[i][1]

    else:
        M = math.ceil(max(t / TA[i][0], a / TA[i][1]))
        t = M * TA[i][0]
        a = M * TA[i][1]


print(t+a)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ta = [tuple(map(int,input().split())) for _ in range(N)]
left = ta[0][0]
right = ta[0][1]
res = left+right
for t,a in ta[1:]:
    tmp1 = math.ceil(left//t)
    tmp2 = math.ceil(right//a)
    buff = max(tmp1,tmp2)
    right = buff*a
    left = buff*t
print(int(right+left))

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ta = [tuple(map(int,input().split())) for _ in range(N)]
left = ta[0][0]
right = ta[0][1]
res = left+right
for t,a in ta[1:]:
    tmp1 = math.ceil(left/t)
    tmp2 = math.ceil(right/a)
    buff = max(tmp1,tmp2)
    right = buff*a
    left = buff*t
print(int(right+left))

Submission status: Wrong Answer

Solution code:
import math
from itertools import product
N=int(input())
ta = [tuple(map(int,input().split())) for _ in range(N)]
left = ta[0][0]
right = ta[0][1]
res = left+right
for t,a in ta[1:]:
    if t>=left and a>=right:
        left=t
        right=a
        res = t+a
        continue
    tmp1 = math.ceil(left/t)
    tmp2 = math.ceil(right/a)
    if tmp1 < tmp2:
        buff = math.ceil(right/a)
        right = buff*a
        left = buff*t
    else:
        buff = math.ceil(left/t)
        left = buff*t
        right = buff*a
print(right+left)

Submission status: Wrong Answer

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

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        # multiply_rate = max(math.ceil(a / s), math.ceil(b / t))
        multiply_rate = max(a + s - 1 // s, b + t - 1 // t)
        return (s * multiply_rate, t * multiply_rate)
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 1, 1
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        # print(a, b)
    
    # print('')
    print(a + b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        multiply_rate = max(math.ceil(a / s), math.ceil(b / t))
        return (s * multiply_rate, t * multiply_rate)
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 1, 1
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        # print(a, b)
    
    # print('')
    print(a + b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        multiply_rate = max(math.ceil(a / s), math.ceil(b / t))
        return tuple(map(lambda x: x * multiply_rate, (s, t)))
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 1, 1
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        # print(a, b)
    
    # print('')
    print(a + b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        if s >= a and t >= b:
            return (s, t)
        else:
            multiply_rate = max(math.ceil(a / s), math.ceil(b / t))
            return tuple(map(lambda x: x * multiply_rate, (s, t)))
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 1, 1
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        # print(a, b)
    
    # print('')
    print(a + b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def calc_minimum_card_pair(a, b, s, t):
        """
        現在 a, b 枚であるとする
        カードを増やす操作を行い比を s : t にするとき、変化後のカード枚数を返す
        """
        if s >= a and t >= b:
            return (s, t)
        else:
            multiply_rate = max(math.ceil(a / s), math.ceil(b / t))
            return tuple(map(lambda x: x * multiply_rate, (s, t)))
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    a, b = 0, 0
    for s, t in L:
        a, b = calc_minimum_card_pair(a, b, s, t)
        # print(a, b)
    
    # print('')
    print(a + b)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  t_rate = math.ceil(ary[0] / tmp_ary[0])
  a_rate = math.ceil(ary[1] / tmp_ary[1])
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))
print(int(ary[0] + ary[1]))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  t_rate = math.ceil(ary[0] / tmp_ary[0])
  a_rate = math.ceil(ary[1] / tmp_ary[1])
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))
print(ary[0] + ary[1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ary = list(map(int, input().split()))
for i in range(n - 1):
  tmp_ary = list(map(int, input().split()))
  t_rate = math.ceil(ary[0] / tmp_ary[0])
  a_rate = math.ceil(ary[1] / tmp_ary[1])
  rate = max([t_rate, a_rate])
  ary = list(map(lambda x: x * rate, tmp_ary))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ary = []
for i in range(n):
  tmp_ary = list(map(int, input().split()))
  if len(ary) == 0:
    ary = tmp_ary[:]
  else:
    #t_rate = math.ceil(ary[0] / tmp_ary[0])
    t_rate = 0
    #a_rate = math.ceil(ary[1] / tmp_ary[1])
    a_rate = 0
    rate = max([t_rate, a_rate])
    ary = list(map(lambda x: x * rate, tmp_ary))
print(ary[0] + ary[1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ary = []
for i in range(n):
  tmp_ary = list(map(int, input().split()))
  if len(ary) == 0:
    ary = tmp_ary[:]
  else:
    t_rate = math.ceil(ary[0] / tmp_ary[0])
    a_rate = math.ceil(ary[1] / tmp_ary[1])
    rate = max([t_rate, a_rate])
    ary = list(map(lambda x: x * rate, tmp_ary))
print(ary[0] + ary[1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
ary = []
for i in range(n):
  tmp_ary = list(map(int, input().split()))
  if len(ary) == 0:
    ary = tmp_ary[:]
  else:
    if tmp_ary[0] >= ary[0]:
      t_rate = 1
    else:
      t_rate = math.ceil(ary[0] / tmp_ary[0])
    if tmp_ary[1] >= ary[1]:
      a_rate = 1
    else:
      a_rate = math.ceil(ary[1] / tmp_ary[1])
    if t_rate >= a_rate:
      rate = t_rate
    else:
      rate = a_rate
    ary = list(map(lambda x: x * rate, tmp_ary))

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

Submission status: Wrong Answer

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #a,b,c=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    for i in range(n):
        x,y=map(int, readline().rstrip().split())
        if i==0:
            a,b=x,y
            continue
        if x==1 and y==1:
            continue
        start=max(a//x,b//y)
        zz=start-1
        for z in range(start,start+1000):
            if x*z>=a and y*z>=b:
                zz=z
                break
        a,b=x*z,y*z
    print(a+b)
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Wrong Answer

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #a,b,c=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    for i in range(n):
        x,y=map(int, readline().rstrip().split())
        if i==0:
            a,b=x,y
            continue
        if x==1 and y==1:
            continue
        start=max(a//x,b//y)
        zz=start
        for z in range(start,start+1000):
            if x*z>=a and y*z>=b:
                zz=z
                break
        a,b=x*z,y*z
    print(a+b)
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
TA = [[int(i) for i in input().split()] for i in range(N)]
Takahashi, Aoki = TA[0][0], TA[0][1]

for ta, ao in TA:
    if Takahashi <= ta and Aoki <= ao:
        Takahashi, Aoki = ta, ao
    else:
        num = max(math.ceil(Takahashi / ta), math.ceil(Aoki / ao))
        Takahashi, Aoki = num * ta, num * ao


print(Takahashi + Aoki)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
TA = [[int(i) for i in input().split()] for i in range(N)]
Takahashi, Aoki = TA[0][0], TA[0][1]
i = 0
for ta, ao in TA:
    if Takahashi <= ta and Aoki <= ao:
        Takahashi, Aoki = ta, ao
    else:
        num = math.ceil(max(Takahashi / ta, Aoki / ao))
        Takahashi, Aoki = num * ta, num * ao
        i += 1

print(Takahashi + Aoki)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    n = int(input())
    a, b = map(int, input().split())
    for _ in range(n - 1):
        i, j = map(int, input().split())
        x = max(ceil(a / i), ceil(b / j))
        a, b = x * i, x * j
    print(a + b)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()