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:
N = int(input())
t, a = 0, 0
for _ in range(N):
    T, A = map(int, input().split())

    if t == 0 and a == 0:   # T1, A1のときの処理
        t = T
        a = T
    
    for i in range(10 ** 20):
        if T == A:
            t += 0
            a += 0
            break
        elif T > A:
            Y = A * t + A * i - T * a
            if Y % T == 0 and Y >= 0:
                t += i
                a += Y / T
                break
        else:
            X = T * a + T * i - A * t
            if X % A == 0 and X >= 0:
                t += X / A
                a += i
                break
print(int(t + a))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a, b = map(int, input().split())
c, d = a, b
for i in range(n-1):
    a, b = map(int, input().split())
    if a >= c and b >= d:
        c, d = a, b
    else:
        aa = math.ceil(c/a)*a
        ba = aa * b // a
        if ba < d:
            ba = math.ceil(d/ba)*ba
            aa = ba * a // b 
        bb = math.ceil(d/b)*b
        ab = bb * a // b
        if ab < c:
            ab = math.ceil(c/ab)*ab
            bb = ab * b // a
        if aa+ba < ab+bb:
            c, d = aa, ba
        else:
            c, d = ab, bb
print(c+d)

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = 0, 0
for _ in range(N):
    T, A = map(int, input().split())

    if t == 0 and a == 0:   # T1, A1のときの処理
        t = T
        a = T
    
    for i in range(10 ** 10):
        if T == A:
            t += 0
            a += 0
            break
        elif T > A:
            Y = A * t + A * i - T * a
            if Y % T == 0 and Y >= 0:
                t += i
                a += Y // T
                break
        else:
            X = T * a + T * i - A * t
            if X % A == 0 and X >= 0:
                t += X // A
                a += i
                break
print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = 0, 0
for _ in range(N):
    T, A = map(int, input().split())

    if t == 0 and a == 0:   # T1, A1のときの処理
        t = T
        a = T
    
    for i in range(10 ** 18):
        if T == A:
            t += 0
            a += 0
            break
        elif T > A:
            Y = A * t + A * i - T * a
            if Y % T == 0 and Y >= 0:
                t += i
                a += Y // T
                break
        else:
            X = T * a + T * i - A * t
            if X % A == 0 and X >= 0:
                t += X // A
                a += i
                break
print(t + a)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [None]*N
A = [None]*N
for i in range(N):
    T[i], A[i] = (int(i) for i in input().split())

voted_num = T[0] + A[0]
now_T = T[0]
now_A = A[0]

for i in range(1, N):
    _sum = T[i] + A[i]
    if voted_num % _sum == 0: continue
    j = 1
    while _sum < voted_num or T[i]*j < now_T or A[i]*j < now_A:
        _sum = T[i]*j+A[i]*j
        j += 1
    now_T = T[i]*j
    now_A = A[i]*j
    voted_num = now_T + now_A

print(voted_num)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
for i in range(1,n):
    if li[i][0] >= li[i-1][0] and li[i][1] >= li[i-1][1]:
        continue
    elif li[i][0] >= li[i-1][0] and li[i][1] < li[i-1][1]:
        bai = math.ceil(li[i-1][1]/li[i][1])
        li[i][0] *= bai
        li[i][1] *= bai
    elif li[i][0] < li[i-1][0] and li[i][1] >= li[i-1][1]:
        bai = math.ceil(li[i-1][0]/li[i][0])
        li[i][0] *= bai
        li[i][1] *= bai
    else:
        bai = max(math.ceil(li[i-1][0]/li[i][0]),math.ceil(li[i-1][1]/li[i][1]))
        li[i][0] *= bai
        li[i][1] *= bai
print(sum(li[-1]))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
for i in range(1,n):
    if li[i][0] >= li[i-1][0] and li[i][1] >= li[i-1][1]:
        continue
    elif li[i][0] >= li[i-1][0] and li[i][1] < li[i-1][1]:
        bai = math.ceil(li[i-1][1]/li[i][1])
        li[i][0] *= bai
        li[i][1] *= bai
    elif li[i][0] < li[i-1][0] and li[i][1] >= li[i-1][1]:
        bai = math.ceil(li[i-1][0]/li[i][0])
        li[i][0] *= bai
        li[i][1] *= bai
    else:
        bai = max(math.ceil(li[i-1][0]/li[i][0]),math.ceil(li[i-1][1]/li[i][1]))
        li[i][0] *= bai
        li[i][1] *= bai
print(li)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = [[1,1]]+li
for i in range(1,n+1):
    if li[i][0] >= li[i-1][0] and li[i][1] >= li[i-1][1]:
        continue
    elif li[i][0] >= li[i-1][0] and li[i][1] < li[i-1][1]:
        bai = math.ceil(li[i-1][1]/li[i][1])
        li[i][0] *= bai
        li[i][1] *= bai
    elif li[i][0] < li[i-1][0] and li[i][1] >= li[i-1][1]:
        bai = math.ceil(li[i-1][0]/li[i][0])
        li[i][0] *= bai
        li[i][1] *= bai
    else:
        bai = max(math.ceil(li[i-1][0]/li[i][0]),math.ceil(li[i-1][1]/li[i][1]))
        li[i][0] *= bai
        li[i][1] *= bai
print(sum(li[-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[]
A=[]

for i in range(N):
    p,q=map(int,input().split())
    T.append(p)
    A.append(q)

s=T[0]
t=A[0]
for i in range(1,N):
    if s%T[i]==0 and t%A[i]==0:
        cv=min(s//T[i],t//A[i])
    elif s%T[i]==0 and t%A[i]!=0 and s%T[i]>t%A[i]:
        cv=min(s//T[i],t//A[i])
    elif s%T[i]<t%A[i] and t%A[i]==0 and s%T[i]!=0:
        cv=t//A[i]
    else:
        cv=min(s//T[i],t//A[i])+1
    s=cv*T[i]
    t=cv*A[i]

print(s+t)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[]
A=[]

for i in range(N):
    p,q=map(int,input().split())
    T.append(p)
    A.append(q)

s=T[0]
t=A[0]
for i in range(1,N):
    if s%T[i]==0 and t%A[i]==0:
        cv=max(s//T[i],t//A[i])
    else:
        cv=max(s//T[i],t//A[i])+1
    s=cv*T[i]
    t=cv*A[i]

print(s+t)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[]
A=[]
for i in range(N):
    p,q=map(int,input().split())
    T.append(p)
    A.append(q)

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

cnt=lcm(T)

ans=cnt//T[N-1]*(T[N-1]+A[N-1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
x,y = a[0][0],a[0][1]
for i in range(1,n):
  xr=(a[i-1][0]+a[i][0]-1)//a[i][0]
  yr=(a[i-1][1]+a[i][1]-1)//a[i][1]
  r=max(xr,yr)
  x*=r
  y*=r
print(x+y)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = []
A = []
for _ in range(N):
    t , a =map(int,input().split())
    T.append(t)
    A.append(a)
sum_val = T[0] + A[0]
now_t , now_a = T[0] , A[0]
#print(now_t , now_a)
for next in range(1 , N):
    # 値と割合が同じ時はcontinue
    if T[next] == A[next] == 1:
    #if T[next] == now_t and A[next] == now_a:
        continue
    elif T[next] >= now_t and A[next] >= now_a:
        now_t ,now_a = T[next] , A[next]
    elif T[next] >= now_t and A[next] < now_a:
        mul = math.ceil(now_a / A[next])
        now_t = mul * T[next]
        now_a = mul * A[next]
    elif T[next] < now_t and A[next] >= now_a:
        mul = math.ceil(now_t / T[next])
        now_t = mul * T[next]
        now_a = mul * A[next]
    else:
        add = 0
        if now_t > now_a:
            if now_t % T[next] != 0:
                add = T[next] - (now_t % T[next])
            now_t += add
            now_a = (now_t // T[next]) * A[next]
        else:
            if now_a % A[next] != 0:
                add = A[next] - (now_a % A[next])
            now_a += add
            now_t = (now_a // A[next]) * T[next]
    #print(now_t , now_a)
print(now_t + now_a)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T = []
A = []
for _ in range(N):
    t , a =map(int,input().split())
    T.append(t)
    A.append(a)
sum_val = T[0] + A[0]
now_t , now_a = T[0] , A[0]
for next in range(1 , N):
    if T[next] == now_t and A[next] == now_a:
        continue
    elif T[next] >= now_t and A[next] >= now_a:
        now_t ,now_a = T[next] , A[next]
    elif T[next] >= now_t and A[next] < now_a:
        mul = math.ceil(now_a / A[next])
        now_t = mul * T[next]
        now_a = mul * A[next]
    elif T[next] < now_t and A[next] >= now_a:
        mul = math.ceil(now_t / T[next])
        now_t = mul * T[next]
        now_a = mul * A[next]
    else:
        add = 0
        if now_t > now_a:
            if now_t % T[next] != 0:
                add = T[next] - (now_t % T[next])
            now_t += add
            now_a = (now_t // T[next]) * A[next]
        else:
            if now_a % A[next] != 0:
                add = A[next] - (now_a % A[next])
            now_a += add
            now_t = (now_a // A[next]) * T[next]
print(now_t + now_a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = (max(int(ceil(C/t)),int(ceil(D/a))))
        C,D = n*t,n*a
    ans = C+D
    print(int(ans))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = (max(int(ceil(C/t)),int(ceil(D/a))))
        C,D = n*t,n*a
    ans = C+D
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = int(max(ceil(C/t),ceil(D/a)))
        C,D = n*t,n*a
    ans = C+D
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = max(ceil(C/t), ceil(D/a))
        C,D = n*t,n*a
    ans = C+D
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = max(ceil(C/t), ceil(D/a))
        C,D = n*t,n*a
    ans = C+D
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        old_D = D
        if C%t != 0 :
            C=t*ceil(C/t)
        D=C//t * a
        if D<old_D:
            ratio = ceil(old_D/D)
            D*=ratio
            C*=ratio
    ans = C+D
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = map(int, input().split())

ans = t + a

for _ in range(N - 1):
    T, A = map(int, input().split())

    n = max(t // T + (1 if t % T else 0), a // A + (1 if a % A else 0))

    if ((T + A) * n == ans):n += 1
    ans = (T + A) * n

    t, a = T * n, A * n

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = map(int, input().split())
ans = t + a
for _ in range(N - 1):
    T, A = map(int, input().split())
    # T_old+A_old<=ans
    # t<=ans*T/(T+A) <=> t*(T+A)/T<=ans
    # a<=ans*T/(T+A) <=> a*(T+A)/A<=ans
    # T+Aの倍数
    x = int(round(max(ans, t * (T + A) / T, a * (T + A) / A)))
    # ans = (T + A) // x * x + (T + A if (T + A) % x > 0 else 0)
    ans = x // (T + A) * (T + A) + (T + A if x % (T + A) > 0 else 0)
    t, a = ans*T//(T+A), ans*A//(T+A)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n=int(input())
    x,y=1,1
    for _ in range(n):
        a,b=map(int,input().split())
        k=(max(ceil(x/a),ceil(y/b)))
        x,y=k*a,k*b
    print(x+y)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n=int(input())
    x,y=1,1
    for _ in range(n):
        a,b=map(int,input().split())
        k=ceil(max(x/a,y/b))
        x,y=k*a,k*b
    print(x+y)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n=int(input())
    x,y=1,1
    for _ in range(n):
        a,b=map(int,input().split())
        s=ceil(x/a)
        t=ceil(y/b)
        m=max(s,t)
        x,y=m*a,m*b
    print(x+y)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
import math
n = int(input())
ls = []
for i in range(n):
    t, a = [int(i) for i in sys.stdin.readline().split()]
    ls.append((t, a))
_min = 1e-10
_min_a = 1
_min_t = 1
res = []
for l in ls:
    t, a = l
    _sum = t + a
    cnt = max(math.ceil(_min_a / a), math.ceil(_min_t / t))
    _min_a = cnt * a
    _min_t = cnt * t
    _min = cnt * _sum
    res.append(_min)
print(res[-1])

Submission status: Wrong Answer

Solution code:
import sys
import math
n = int(input())
ls = []
for i in range(n):
    t, a = [int(i) for i in sys.stdin.readline().split()]
    ls.append((t, a))
_min = 1e-10
_min_a = 1e-10
_min_t = 1e-10
res = []
for l in ls:
    t, a = l
    _sum = t + a
    cnt = max(math.ceil(_min_a / a), math.ceil(_min_t / t))
    _min_a = cnt * a
    _min_t = cnt * t
    _min = cnt * _sum
    res.append(_min)
print(res[-1])

Submission status: Wrong Answer

Solution code:
import sys
import math
n = int(input())
ls = []
for i in range(n):
    t, a = [int(i) for i in sys.stdin.readline().split()]
    ls.append((t, a))
_min = 1e-10
_min_a = 1e-10
_min_t = 1e-10
res = []
for l in ls:
    t, a = l
    _sum = t + a
    cnt = math.ceil(max(_min / _sum, _min_a / a, _min_t / t))
    _min_a = cnt * a
    _min_t = cnt * t
    _min = cnt * _sum
    res.append(_min)
print(res[-1])

Submission status: Wrong Answer

Solution code:
import sys
import math
n = int(input())
ls = []
for i in range(n):
    t, a = [int(i) for i in sys.stdin.readline().split()]
    ls.append((t, a))
_min = 1e-10
_min_a = 1e-10
_min_t = 1e-10
res = []
for l in ls:
    t, a = l
    _sum = t + a
    _min = math.ceil(max(_min / _sum, _min_a / a, _min_t / t))
    _min_a = _min * a
    _min_t = _min * t
    _min = _min * _sum
    res.append(_min)
print(res[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1

def UP(V1,V2,R1,R2):
    n=max(-(-V1//R1),-(-V2//R2))
    return(n*R1,n*R2)

for i in range(N):
    up=UP(Taka,Aoki,TA[i][0],TA[i][1])
    print(up)
    Taka=up[0]
    Aoki=up[1]

print(Taka+Aoki)

Submission status: Wrong Answer

Solution code:
from math import ceil

N=int(input())
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1

def UP(V1,V2,R1,R2):
    n=max(ceil(V1/R1),ceil(V2/R2))
    return(n*R1,n*R2)

for i in range(N):
    up=UP(Taka,Aoki,TA[i][0],TA[i][1])
    Taka=up[0]
    Aoki=up[1]

print(Taka+Aoki)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = 1,1
for t,a in ta:
  mul = max(1,max(math.ceil(T/t),math.ceil(A/a)))
  T,A = t * mul,a * mul
print(T+A)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = 1,1
for t,a in ta:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  T,A = t * mul,a * mul
print(T+A)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = ta[0][0],ta[0][1]
for t,a in ta[1:]:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  T,A = max(t,t * mul), max(a,a * mul)
print(T+A)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = ta[0][0],ta[0][1]
for t,a in ta[1:]:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  T,A = max(T,t * mul), max(A,a * mul)
print(T+A)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = ta[0][0],ta[0][1]
for t,a in ta[1:]:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  if mul == 1:
    T,A = t,a
  else:
    T,A = t * mul, a * mul
print(T+A)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = ta[0][0],ta[0][1]
for t,a in ta[1:]:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  T,A = t * mul, a * mul
print(T+A)

Submission status: Wrong Answer

Solution code:
import math

def flg(a,b):
    if a>b:
        return 1
    elif a==b:
        return 0
    else:
        return -1

def main():
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]
    t,a = ls[0]
    flg_now = flg(t,a)
    for i in range(1,n):
        nex = ls[i]
        flg_nex = flg(nex[0],nex[1])
        if flg_nex==0:
            t = max(a,t)
            a = max(a,t)
        else:
            if flg_now==flg_nex:
                if flg_now==1:
                    t = math.ceil(t/nex[0])*nex[0]
                    a = math.ceil(t/nex[0])*nex[1]
                elif flg_now==-1:
                    a = math.ceil(t/nex[1])*nex[1]
                    t = math.ceil(t/nex[1])*nex[0]         
            else:
                if flg_now==1:
                    t = math.ceil(t/nex[0])*nex[0]
                    a = t*nex[1]//nex[0]
                elif flg_now==0:
                    if flg_nex==1:
                            a = math.ceil(a/nex[1])*nex[1]
                            t = math.ceil(a/nex[1])*nex[0]
                    else:
                        t = math.ceil(t/nex[0])*nex[0]
                        a = math.ceil(t/nex[0])*nex[1]
                else:
                    a = math.ceil(a/nex[1])*nex[1]
                    t = a*nex[0]//nex[1]
        flg_now = flg(nex[0],nex[1])
    print(a+t)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

def flg(a,b):
    if a>b:
        return 1
    elif a==b:
        return 0
    else:
        return -1

def main():
    n = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(n)]
    t,a = ls[0]
    flg_now = flg(t,a)
    for i in range(1,n):
        nex = ls[i]
        flg_nex = flg(nex[0],nex[1])
        print(t,a,"now",flg_now,"nex",flg_nex)
        if flg_nex==0:
            t = max(a,t)
            a = max(a,t)
        else:
            if flg_now==flg_nex:
                if flg_now==1:
                    t = math.ceil(t/nex[0])*nex[0]
                    a = math.ceil(t/nex[0])*nex[1]
                elif flg_now==-1:
                    a = math.ceil(t/nex[1])*nex[1]
                    t = math.ceil(t/nex[1])*nex[0]         
            else:
                if flg_now==1:
                    t = math.ceil(t/nex[0])*nex[0]
                    a = t*nex[1]//nex[0]
                elif flg_now==0:
                    if flg_nex==1:
                            a = math.ceil(a/nex[1])*nex[1]
                            t = math.ceil(a/nex[1])*nex[0]
                    else:
                        t = math.ceil(t/nex[0])*nex[0]
                        a = math.ceil(t/nex[0])*nex[1]
                else:
                    a = math.ceil(a/nex[1])*nex[1]
                    t = a*nex[0]//nex[1]
        flg_now = flg(nex[0],nex[1])
    print(a+t)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#C
import math
N = int(input())
TA = [list(map(int,input().split())) for i in range(N)]

t,a = 1,1
for i in range(N):
    ti,ai = TA[i]
    n = max(math.ceil(t/ti),math.ceil(a/ai))
    t = n*ti
    a = n*ai
        
    #print(t,a)
    
print(t+a)

Submission status: Wrong Answer

Solution code:
#C
import math
N = int(input())
TA = [list(map(int,input().split())) for i in range(N)]

t,a = 0,0
for i in range(N):
    if i == 0:
        t,a = TA[i]
    else:
        ti,ai = TA[i]
        n = max(math.ceil(t/ti),math.ceil(a/ai))
        t = n*ti
        a = n*ai
        
    #print(t,a)
    
print(t+a)

Submission status: Wrong Answer

Solution code:
#C
import math
N = int(input())
TA = [list(map(int,input().split())) for i in range(N)]

t,a = 0,0
for i in range(N):
    if i == 0:
        t,a = TA[i]
    else:
        ti,ai = TA[i]
        if t/ti <= a/ai:
            t = ti*math.ceil(a/ai)
            a = ai*math.ceil(a/ai)
        else:
            t = ti*math.ceil(t/ti)
            a = ai*math.ceil(t/ti)
    #print(t,a)
    
print(t+a)

Submission status: Wrong Answer

Solution code:
a, b = 1, 1
n = int(input())
vote = [ [ int(v) for v in input().split() ] for i in range(n) ]

def voting(p,q):
    global a, b
    if a*q != p*b:
        if p >= q:
            b = max( q, q * ( (b+q-1) // q ) )
            if a <= (b // q) * p:
                a = (b // q) * p
            else:
                a = p * ( (a+p-1) // p )
                print(a)
                b = (a // p) * q
        else:
            a = max( p, p * ( (a+p-1) // p ) )
            if b <= (a // p) * q:
                b = (a // p) * q
            else:
                b = q * ( (b+q-1) // q )
                print(b)
                a = (b // q) * p
         

a, b = vote[0]
for p, q in vote[1:]:
    voting(p,q)
print(a+b)

Submission status: Wrong Answer

Solution code:
a, b = 1, 1
n = int(input())
vote = [ [ int(v) for v in input().split() ] for i in range(n) ]

def voting(p,q):
    global a, b
    if a*q != p*b:
        if p >= q:
            b = max( q, q * ( (b+q-1) // q ) )
            if a <= (b // q) * p:
                a = (b // q) * p
            else:
                a = p * ( (a+p-1) // p )
                print(a)
                b = (a // p) * q
        else:
            a = max( p, p * ( (a+p-1) // p ) )
            if b <= (a // p) * q:
                b = (a // p) * q
            else:
                b = q * ( (b+q-1) // q )
                print(b)
                a = (b // q) * p
         

for p, q in vote:
    voting(p,q)
print(a+b)