Problem:


Score : 300 points

Problem Statement

AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.

Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

Constraints

1≦N≦1000

1≦T_i,A_i≦1000 (1≦i≦N)

T_i and A_i (1≦i≦N) are coprime.

It is guaranteed that the correct answer is at most 10^{18}.

Input

The input is given from Standard Input in the following format:

N
T_1 A_1
T_2 A_2
:
T_N A_N

Output

Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

Sample Input 1

3
2 3
1 1
3 2

Sample Output 1

10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Sample Input 2

4
1 1
1 1
1 5
1 100

Sample Output 2

101

It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.

Sample Input 3

5
3 10
48 17
31 199
231 23
3 2

Sample Output 3

6930



Sample input:
3
2 3
1 1
3 2


Sample output:
10

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
A=B=1
for i in range(n):
    x,y=[int(i) for i in input().split()]
    n=max(math.ceil(A/x),math.ceil(B/y))
    A=n*x
    B=n*y
print(A+B)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
prv_t, prv_a = 1, 1
for _ in range(N):
  t,a = map(int,input().split())
  x = max(ceil(prv_t/t), ceil(prv_a/a))
  prv_t, prv_a = t*x, a*x
print(prv_t+prv_a)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
prv_t, prv_a = 1, 1
for _ in range(N):
  t,a = map(int,input().split())
  
  x = max([ceil(prv_t/t), ceil(prv_a/a)])
  ans = (t+a)*x
  prv_t, prv_a = t*x, a*x
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
prv_t, prv_a = map(int,input().split())
ans = prv_t + prv_a
x = 1
for _ in range(N-1):
  t,a = map(int,input().split())
  
  x = max([ceil(prv_t/t), ceil(prv_a/a)])
  ans = (t+a)*x
  prv_t, prv_a = t*x, a*x
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
prv_t, prv_a = map(int,input().split())
ans = prv_t + prv_a
for _ in range(N-1):
  t,a = map(int,input().split())
  
  x = max([ceil(prv_t/t), ceil(prv_a/a)])
  ans = (t+a)*x
  prv_t, prv_a = t*x, a*x
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
prv_t, prv_a = map(int,input().split())
ans = prv_t + prv_a
for _ in range(N-1):
  t,a = map(int,input().split())
  
  x = max([ceil(ans/(t+a)),ceil(prv_t/t), ceil(prv_a/a)])
  ans = (t+a)*x
  prv_t, prv_a = t*x, a*x
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int, input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T,A=1,1

for i in range(N):
	n = max(math.ceil(A/a[i]), math.ceil(T/t[i]))
	A = a[i] * n
	T = t[i] * n

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int, input().split())
	t.append(a_tmp)
	a.append(t_tmp)

T,A=1,1

for i in range(N):
	n = max(math.ceil(A/a[i]), math.ceil(T/t[i]))
	A = a[i] * n
	T = t[i] * n

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
a,t = [],[]
for _ in range(N):
	a_tmp, t_tmp = map(int, input().split())
	a.append(a_tmp)
	t.append(t_tmp)

A,T=1,1

for i in range(N):
	n = max(math.ceil(A/a[i]), math.ceil(T/t[i]))
	A = a[i] * n
	T = t[i] * n

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int,input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T, A = t[0], a[0]

for i in range(1,N):
	if T <= t[i] and A <= a[i]:
		T = t[i]
		A = a[i]
	elif T > t[i] and A <= a[i]:
		T = math.ceil(T/t[i]) * t[i]
		A = (T//t[i]) * a[i]
	elif T <= t[i] and A > a[i]:
		A = math.ceil(A/a[i]) * a[i]
		T = (A//a[i]) * t[i]
	elif T > t[i] and A > a[i]:
		#Tに合わせる
		T_t = math.ceil(T/t[i]) * t[i]
		A_t = (T_t//t[i]) * a[i]

		#Aに合わせる
		A_a = math.ceil(A/a[i]) * a[i]
		T_a = (A_a//a[i]) * t[i]

		if A_t < A and T_a >= T:
			T = T_a
			A = A_a
		elif T_a < T and A_t >= A:
			T = T_t
			A = A_t
		elif T_a >= T and A_t >= A:
			if T_t + A_t <= T_a + A_a:
				T = T_t
				A = A_t
			else:
				T = T_a
				A = A_a
		else:
			if T_t + A_t <= T_a + A_a:
				T = T_t * 2
				A = A_t * 2
			else:
				T = T_a * 2
				A = A_a * 2
			

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int,input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T, A = t[0], a[0]

for i in range(1,N):
	if T <= t[i] and A <= a[i]:
		T = t[i]
		A = a[i]
	elif T > t[i] and A <= a[i]:
		T = math.ceil(T/t[i]) * t[i]
		A = (T//t[i]) * a[i]
	elif T <= t[i] and A > a[i]:
		A = math.ceil(A/a[i]) * a[i]
		T = (A//a[i]) * t[i]
	elif T > t[i] and A > a[i]:
		#Tに合わせる
		T_t = math.ceil(T/t[i]) * t[i]
		A_t = (T_t//t[i]) * a[i]

		#Aに合わせる
		A_a = math.ceil(A/a[i]) * a[i]
		T_a = (A_a//a[i]) * t[i]

		if A_t < A:
			T = T_a
			A = A_a
		elif T_a < T:
			T = T_t
			A = A_t
		elif T_a == T and A_t == A:
			if T_t + A_t <= T_a + A_a:
				T = T_t
				A = A_t
			else:
				T = T_a
				A = A_a


print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int,input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T, A = t[0], a[0]

for i in range(1,N):
	if T <= t[i] and A <= a[i]:
		T = t[i]
		A = a[i]
	elif T > t[i] and A <= a[i]:
		T = math.ceil(T/t[i]) * t[i]
		A = (T//t[i]) * a[i]
	elif T <= t[i] and A > a[i]:
		A = math.ceil(A/a[i]) * a[i]
		T = (A//a[i]) * t[i]
	elif T > t[i] and A > a[i]:
		#Tに合わせる
		T_t = math.ceil(T/t[i]) * t[i]
		A_t = (T_t//t[i]) * a[i]

		#Aに合わせる
		A_a = math.ceil(A/a[i]) * a[i]
		T_a = (A_a//a[i]) * t[i]

		if A_t < A:
			T = T_a
			A = A_a
		elif T_a < T:
			T = T_t
			A = A_t

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int,input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T, A = t[0], a[0]

for i in range(1,N):
	if T <= t[i] and A <= a[i]:
		T = t[i]
		A = a[i]
	elif T > t[i] and A <= a[i]:
		T = math.ceil(T/t[i]) * t[i]
		A = (T//t[i]) * a[i]
	elif T <= t[i] and A > a[i]:
		A = math.ceil(A/a[i]) * a[i]
		T = (A//a[i]) * t[i]
	elif T > t[i] and A > a[i]:
		#Tに合わせる
		T_t = math.ceil(T/t[i]) * t[i]
		A_t = (T_t//t[i]) * a[i]

		#Aに合わせる
		A_a = math.ceil(A/a[i]) * a[i]
		T_a = (A_a//a[i]) * t[i]

		if A_t < A:
			T = T_a
			A = A_a
		else:
			T = T_t
			A = A_t

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int,input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T, A = t[0], a[0]

for i in range(1,N):
	if T <= t[i] and A <= a[i]:
		T = t[i]
		A = a[i]
	elif T > t[i] and A <= a[i]:
		T = math.ceil(T/t[i]) * t[i]
		A = (T//t[i]) * a[i]
	elif T <= t[i] and A > a[i]:
		A = math.ceil(A/a[i]) * a[i]
		T = (A//a[i]) * t[i]
	elif T > t[i] and A > a[i]:
		#Tに合わせる
		T_t = math.ceil(T/t[i]) * t[i]
		A_t = (T_t//t[i]) * a[i]

		#Aに合わせる
		A_a = math.ceil(A/a[i]) * a[i]
		T_a = (A_a//a[i]) * t[i]

		if A_t < A:
			T = T_a
			A = A_a
		elif T_a < T:
			T = T_t
			A = A_t
		else:
			if T_t + A_t <= T_a + A_a:
				T = T_t
				A = A_t
			else:
				T = T_a
				A = A_a

print(A+T)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
t,a = [],[]
for _ in range(N):
	t_tmp, a_tmp = map(int,input().split())
	t.append(t_tmp)
	a.append(a_tmp)

T, A = t[0], a[0]

for i in range(1,N):
	if T <= t[i] and A <= a[i]:
		T = t[i]
		A = a[i]
	elif T > t[i] and A <= a[i]:
		T = math.ceil(T/t[i]) * t[i]
		A = (T//t[i]) * a[i]
	elif T <= t[i] and A > a[i]:
		A = math.ceil(A/a[i]) * a[i]
		T = (A//a[i]) * t[i]
	elif T > a[i] and A > a[i]:
		#Tに合わせる
		T_t = math.ceil(T/t[i]) * t[i]
		A_t = (T_t//t[i]) * a[i]

		#Aに合わせる
		A_a = math.ceil(A/a[i]) * a[i]
		T_a = (A_a//a[i]) * t[i]

		if A_t < A:
			T = T_a
			A = A_a
		elif T_a < T:
			T = T_t
			A = A_t
		else:
			if T_t + A_t <= T_a + A_a:
				T = T_t
				A = A_t
			else:
				T = T_a
				A = A_a

print(A+T)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
import math
ans = 1
for i in range(N):
    T,A = map(int,input().split())
    s = T + A
    g = math.ceil(ans/s)
    ans = g*s
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
from decimal import Decimal

N = int(input())

t, a = 1, 1
for T, A in [tuple(map(int, input().split())) for _ in range(N)]:
    n = ceil(max(Decimal(t / T), Decimal(a / A)))
    t, a = n * T, n * A
print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil
from decimal import Decimal

N = int(input())

t, a = 1, 1
for T, A in [tuple(map(int, input().split())) for _ in range(N)]:
    n = max(ceil(Decimal(t / T)), ceil(Decimal(a / A)))
    t, a = n * T, n * A
print(t + a)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

t, a = 1, 1
for T, A in [tuple(map(int, input().split())) for _ in range(N)]:
    n = max(ceil(t / T), ceil(a / A))
    t, a = n * T, n * A
print(t + a)

Submission status: Wrong Answer

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from math import ceil
from decimal import *
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]

t = TA[0][0]
a = TA[0][1]

for i in range(1,N):
    n = Decimal(max(ceil(t/TA[i][0]), ceil(a/TA[i][1])))
    t = n*TA[i][0]
    a = n*TA[i][1]
    print(i,t,a)

print(t+a)

Submission status: Wrong Answer

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from math import ceil
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]

t = TA[0][0]
a = TA[0][1]

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

print(t+a)

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve():
    N = int(input())

    LIS = []
    for _ in range(N):
        LIS.append(tuple(map(int, input().split())))
    # print(LIS)

    A, B = 1, 1
    for (x, y) in LIS:
        div = max(ceil(A / x), ceil(B / y))
        A = x * div
        B = y * div

    return A + B


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve():
    N = int(input())

    LIS = []
    for _ in range(N):
        LIS.append(tuple(map(int, input().split())))
    # print(LIS)

    A, B = LIS[0]
    for (x, y) in LIS[1:]:
        # print("current:", A, B)
        # print("ratio  :", x, y, "\n")
        div = max(ceil(A / x), ceil(B / y))
        A = x * div
        B = y * div

    return A + B


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve():
    N = int(input())

    LIS = []
    for _ in range(N):
        LIS.append(tuple(map(int, input().split())))
    # print(LIS)

    A, B = LIS[0]
    for (x, y) in LIS[1:]:
        # print("current:", A, B)
        # print("ratio  :", x, y, "\n")
        if x == y:
            m = max(max(x, y), max(A, B))
            A, B = m, m
        elif A < x and B < y:
            A, B = x, y
        else:
            div = max(ceil(A / x), ceil(B / y))
            A = x * div
            B = y * div

    return A + B


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve():
    N = int(input())

    LIS = []
    for _ in range(N):
        LIS.append(tuple(map(int, input().split())))
    # print(LIS)

    A, B = LIS[0]
    for (x, y) in LIS[1:]:
        # print("current:", A, B)
        # print("ratio  :", x, y, "\n")
        if x == y:
            m = max(max(x, y), max(A, B))
            A, B = m, m
        elif A <= x and B <= y:
            A, B = x, y
        else:
            div = max(ceil(A / x), ceil(B / y))
            A = x * div
            B = y * div

    return A + B


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

Solution code:
from math import ceil


def solve():
    N = int(input())

    LIS = []
    for _ in range(N):
        LIS.append(tuple(map(int, input().split())))
    # print(LIS)

    A, B = LIS[0]
    for (x, y) in LIS[1:]:
        # print("current:", A, B)
        # print("ratio  :", x, y, "\n")
        if x == y:
            m = max(A, B)
            A, B = m, m
        elif A <= x and B <= y:
            A, B = x, y
        else:
            div = max(ceil(A / x), ceil(B / y))
            A = x * div
            B = y * div

    return A + B


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
num = [list(map(int,input().split())) for i in range(N)]
A = 1
B = 1
n = 1
for i in range(N):
  x = num[i][0]
  y = num[i][1]
  n = max(math.ceil(A/x),math.ceil(B/y),1)
  A = n*x
  B = n*y
  
print(A + B)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
num = [list(map(int,input().split())) for i in range(N)]
A = num[0][0]
B = num[0][1]
n = 1
for i in range(1,N):
  x = num[i][0]
  y = num[i][1]
  n = max(math.ceil(A/x),math.ceil(B/y),1)
  A = n*x
  B = n*y
  
print(A + B)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
T = [0]*n
A = [0]*n

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

votes = [T[0],A[0]]

for i in range(1,n):
    m = max(math.ceil(votes[0]/T[i]),math.ceil(votes[1]/A[i]))
    votes[0] = m*T[i]
    votes[1] = m*A[i]
    
print(votes[0]+votes[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
t,a = map(int,input().split())
for _ in range(N-1):
    T,A = map(int,input().split())
    b = 1
    if t>T:
        if t%T==0:
            b = t//T
        else:
            b = t//T+1
    T0 = T*b
    A0 = A*b
    c = 1
    if a>A0:
        if a%A0==0:
            c = a//A0
        else:
            c = a//A0+1
    t = T0*c
    a = A0*c
print(t+a)

Submission status: Wrong Answer

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

def solve(N: int, T: "List[int]", A: "List[int]"):
    current = [T[0],A[0]]
    for i in range(1,N):
        t = T[i]
        a = A[i]
        if current[0]>t or current[1]>a:
            multi = max(math.ceil(current[0]/t),math.ceil(current[1]/a))
            t = t*multi
            a = a*multi
        
        current[0]=t
        current[1]=a
    print(sum(current))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [int()] * (N)  # type: "List[int]"
    A = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        T[i] = int(next(tokens))
        A[i] = int(next(tokens))
    solve(N, T, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x = 0
y = 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
    else:
        tmp = max(math.ceil(x/t), math.ceil(y/a))
        x = tmp * t
        y = tmp * a


print(x+y)

Submission status: Wrong Answer

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

x = 0
y = 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
    else:
        if (x >= t and y < a) or (x > t and y <= a):
            x = math.ceil(x / t) * t
            y = a * math.ceil(x/t)
        elif (x <= t and y > a) or (x < t and y >= a):
            y = math.ceil(y/a)*a
            x = t * math.ceil(y/a)
        else:
            tmp = max(math.ceil(x/t), math.ceil(y/a))
            x = tmp * t
            y = tmp * a


print(x+y)

Submission status: Wrong Answer

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

x = 0
y = 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
    else:
        if x >= t and y < a:
            x = math.ceil(x / t) * t
            y = a * math.ceil(x/t)
        elif x < t and y >= a:
            y = math.ceil(y/a)*a
            x = t * math.ceil(y/a)
        else:
            tmp = max(math.ceil(x/t), math.ceil(y/a))
            x = tmp * t
            y = tmp * a


print(x+y)

Submission status: Wrong Answer

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

x = 0
y = 0
for t, a in TA:
    if x <= t and y <= a:
        x = t
        y = a
    else:
        if x > t and y < a:
            x = math.ceil(x / t) * t
            y = a * math.ceil(x/t)
        elif x < t and y > a:
            y = math.ceil(y/a)*a
            x = t * math.ceil(y/a)
        else:
            tmp = max(math.ceil(x/t), math.ceil(y/a))
            x = tmp * t
            y = tmp * a


print(x+y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=[]
import math
for i in range(n):
    a,t=map(int,input().split())
    lists.append((a,t))
x=1
y=1
for i in range(n):
    j=max(math.ceil(x/lists[i][0]),math.ceil(y/lists[i][1]))
    x=lists[i][0]*j
    y=lists[i][1]*j
    if i==n-1:
        print(x+y)

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=[]
import math
for i in range(n):
    a,t=map(int,input().split())
    lists.append((a,t))
anslist=[0 for i in range(n)]
anslist[0]=(lists[0][0],lists[0][1])
for i in range(n-1):
    a=math.ceil(anslist[i][0]/lists[i+1][0])
    b=math.ceil(anslist[i][1]/lists[i+1][1])
    j=max(a,b)
    anslist[i+1]=(j*lists[i+1][0],j*lists[i+1][1])
print(sum(anslist[-1])  )

Submission status: Wrong Answer

Solution code:
import sys


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    na = 1
    nb = 1
    for i in range(n):
        t, a = list(map(int, input().rstrip('\n').split()))
        r = max((na + t - 1) // t, (nb + a - 1) // a)
        na = r * t
        nb = r * a
        print(na, nb, r)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
ans_a = 0
ans_b = 0
for i in range(n):
    a, b = map(int, input().split())
    if a >= ans_a and b >= ans_b:
        ans_a = a
        ans_b = b
    else:
        if a < ans_a and b >= ans_b:
            ans_a = ceil(ans_a / a) * a
            ans_b = ceil(ans_a / a) * b
        elif a >= ans_a and b < ans_b:
            ans_a = ceil(ans_b / b) * a
            ans_b = ceil(ans_b / b) * b
        else:
            tmp_a = ceil(ans_a / a) * a
            tmp_b = ceil(ans_a / a) * b
            if tmp_a >= ans_a and tmp_b >= ans_b:
                tmp_diff = tmp_a - a + tmp_b - b
            else:
                tmp_diff = float("inf")

            tmp_a2 = ceil(ans_b / b) * a
            tmp_b2 = ceil(ans_b / b) * b
            if tmp_a2 >= ans_a and tmp_b2 >= ans_b:
                tmp_diff2 = tmp_a2 - a + tmp_b2 - b
            else:
                tmp_diff2 = float("inf")

            if tmp_diff < tmp_diff2:
                ans_a = tmp_a
                ans_b = tmp_b
            else:
                ans_a = tmp_a2
                ans_b = tmp_b2
print(ans_a + ans_b)

Submission status: Wrong Answer

Solution code:
#vote n times each time t:a 
#print(199*2)
#62 398 


# 231 23  
from math import ceil 
#print(ceil(398/23))
#print(231*18,23*18)
#4158 414 

#print(ceil(4158/3))
#print(4158*2/3 )
#print(4158+2772)
n=int(input())
a,b=map(int,input().split())
for i in range(1,n):
    x,y=map(int,input().split())
    if x>=a and y>=b:
        a=x 
        b=y 
        continue 
    if x<a:
        a1=ceil(a/x)
        x=a1*x 
        y=a1*y 
        a=x 
        b=y 
    elif y<b: 
        b1=ceil(b/y )
        y=b1*y  
        x=x*b1  
        a=x 
        b=y 
   # print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
#vote n times each time t:a 
#print(199*2)
#62 398 


# 231 23  
from math import ceil 
#print(ceil(398/23))
#print(231*18,23*18)
#4158 414 

#print(ceil(4158/3))
#print(4158*2/3 )
#print(4158+2772)
n=int(input())
a,b=map(int,input().split())
for i in range(1,n):
    x,y=map(int,input().split())
    if x>=a and y>=b:
        a=x 
        b=y 
        continue 
    if x<a:
        a1=ceil(a/x)
        x=a1*x 
        y=a1*y 
        a=x 
        b=y 
    if y<b: 
        b1=ceil(b/y )
        y=b1*y  
        x=x*b1  
        a=x 
        b=y 
   # print(a,b)
print(a+b)

Submission status: Wrong Answer

Solution code:
# C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

# 比がa:bとなる合計最小の票分布はa,b
# 次にc:dになったとき、a<=cかつb<=dとなるようにc,dに同じ数をかける

import math

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

a, b = TA[0]
c, d = a, b

for idx in range(1,N):
    c, d = TA[idx]
    multi = max(math.ceil(a/c), math.ceil(b/d))
    c *= multi
    d *= multi
    a,b = c,d
    
print(c+d)

Submission status: Wrong Answer

Solution code:
# C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

# 比がa:bとなる合計最小の票分布はa,b
# 次にc:dになったとき、a<=cかつb<=dとなるようにc,dに同じ数をかける

import math

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

a, b = TA[0]
ans = a + b

for idx in range(1,N):
    c, d = TA[idx]
    multi = max(math.ceil(a/c), math.ceil(b/d))
    c *= multi
    d *= multi
    ans = c+d
    a,b = c,d
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
for i in range(n):
    a,b=map(int,input().split())
    c=a+b
    if ans>c:
        k=ans//c
        if ans%c!=0:
            k+=1
        ans=c*k
    else:
        ans=c
print(ans)

Submission status: Wrong Answer

Solution code:
from math import *

n = int(input())

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

for i in range(n-1):
    tr,ar = map(int,input().split())
    k = max(ceil(t/tr),ceil(a/ar))
    t = k*tr
    a = k*ar
    
print(t+a)

Submission status: Wrong Answer

Solution code:
from math import *

n = int(input())

t = 1 
a = 1 

for i in range(n):
    tr,ar = map(int,input().split())
    k = max(ceil(t/tr),ceil(a/ar))
    t = k*tr
    a = k*ar
    
print(t+a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

t_num,a_num = 1,1

for i in range(n):
    t,a = map(int,input().split())

    k = max(math.ceil(t_num/t),math.ceil(a_num/a))		
    #その比に票を合わせる
    t_num = k*t
    a_num = k*a
    #print([t_num,a_num])    

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

t_num,a_num = 1,1

for i in range(n):
    t,a = map(int,input().split())

    k = max(t_num/t,a_num/a)
    #切り上げ
    k = int(math.ceil(k))
    #その比に票を合わせる
    t_num = k*t
    a_num = k*a
    #print([t_num,a_num])    

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

t_num,a_num = 1,1

for i in range(n):
    t,a = map(int,input().split())

    k = max(t_num/t,a_num/a)
    #切り上げ
    k = math.ceil(k)
    #その比に票を合わせる
    t_num = k*t
    a_num = k*a
    #print([t_num,a_num])    

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

t = [0 for i in range(n)]
a = [0 for i in range(n)]

for i in range(n):
    t[i],a[i] = map(int,input().split())

t_num,a_num = 1,1

for i in range(n):
    k = max(t_num/t[i],a_num/a[i])
    #切り上げ
    k = math.ceil(k)
    #その比に票を合わせる
    t_num,a_num = k*t[i],k*a[i]
    #print([t_num,a_num])    

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

t = [0 for i in range(n)]
a = [0 for i in range(n)]

for i in range(n):
    t[i],a[i] = map(int,input().split())

t_num = t[0]
a_num = a[0]

for i in range(1,n):
    k = max(t_num/t[i],a_num/a[i])
    #切り上げ
    k = math.ceil(k)
    #その比に票を合わせる
    t_num,a_num = k*t[i],k*a[i]

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

t = [0 for i in range(n)]
a = [0 for i in range(n)]

for i in range(n):
    t[i],a[i] = map(int,input().split())

t_num = t[0]
a_num = a[0]

for i in range(1,n):
    k = max(t_num/t[i],a_num/a[i],1)
    #切り上げ
    k = math.ceil(k)
    #その比に票を合わせる
    t_num,a_num = k*t[i],k*a[i]

print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]
t = 1
a = 1
for i in range(N):
  x = max(math.ceil(t / TA[i][0]),math.ceil(a / TA[i][1]))
  t = TA[i][0] * x
  a = TA[i][1] * x
print(t + a)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]
t = TA[0][0]
a = TA[0][1]
for i in range(1,N):
  x = max(math.ceil(t / TA[i][0]),math.ceil(a / TA[i][1]))
  t = TA[i][0] * x
  a = TA[i][1] * x
print(t + a)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]
t = TA[0][0]
a = TA[0][1]
for i in range(1,N):
  if TA[i][0] < t or TA[i][1] < a:
    x = max(math.ceil(t / TA[i][0]),math.ceil(a / TA[i][1]))
    t = TA[i][0] * x
    a = TA[i][1] * x
  else:
    t = TA[i][0]
    a = TA[i][1]
print(t + a)

Submission status: Wrong Answer

Solution code:
n=int(input())
suji=[]
for i in range (n):
	suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
	if i%2==0:
		tlist.append(suji[i])
	else:
		alist.append(suji[i])

for i in range(n-1):
	k=max(alist[i]//alist[i+1],tlist[i]//tlist[i+1])+1
	tlist[i+1]=tlist[i+1]*k
	alist[i+1]=alist[i+1]*k

print(int(tlist[n-1]+alist[n-1]))

Submission status: Wrong Answer

Solution code:
import math

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

tmp_tuple = t_a[0]
for i in range(1, n):
    if (tmp_tuple[0] / t_a[i][0]) == (tmp_tuple[1] / t_a[i][1]):
        continue
    else:
        factor = max(math.ceil(tmp_tuple[0] / t_a[i][0]), math.ceil(tmp_tuple[1] / t_a[i][1]))

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))

print(sum(tmp_tuple))

Submission status: Wrong Answer

Solution code:
import math

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

tmp_tuple = t_a[0]
for i in range(1, n):
    if (tmp_tuple[0] / t_a[i][0]) == (tmp_tuple[1] / t_a[i][0]):
        continue
    else:
        factor = max(math.ceil(tmp_tuple[0] / t_a[i][0]), math.ceil(tmp_tuple[1] / t_a[i][1]))

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))

print(sum(tmp_tuple))

Submission status: Wrong Answer

Solution code:
import math

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

tmp_tuple = t_a[0]
for i in range(1, n):
    factor = max(math.ceil(tmp_tuple[0] / t_a[i][0]), math.ceil(tmp_tuple[1] / t_a[i][1]))

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))

print(sum(tmp_tuple))

Submission status: Wrong Answer

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

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

tka, aok = 1, 1

for ta in TA:
    t, a = ta
    time = max(ceil(tka / t), ceil(aok / a))

    # if tka / t == tka // t:
    #     time1 = tka // t
    # else:
    #     time1 = tka // t + 1

    # if aok / a == aok // a:
    #     time2 = aok // a
    # else:
    #     time2 = aok // a + 1
    # time = max(time1, time2)

    tka, aok = time * t, time * a

print(tka+aok)

Submission status: Wrong Answer

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

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

tka, aok = 0, 0

for ta in TA:
    t, a = ta
    if tka == aok == 0:
        tka, aok = t, a
        continue
    # time = max(ceil(tka / t), ceil(aok / a))

    if tka / t == tka // t:
        time1 = tka // t
    else:
        time1 = tka // t + 1

    if aok / a == aok // a:
        time2 = aok // a
    else:
        time2 = aok // a + 1
    time = max(time1, time2)

    tka, aok = time * t, time * a

    print()
print(tka+aok)

Submission status: Wrong Answer

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

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

tka, aok = 0, 0

for ta in TA:
    t, a = ta
    if tka == aok == 0:
        tka, aok = t, a
        continue
    time = max(ceil(tka / t), ceil(aok / a))
    tka, aok = time * t, time * a
print(tka+aok)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
T, A = [], []
for _ in range(N):
    t, a = tuple(map(int, input().split()))
    T.append(t)
    A.append(a)
x, y = 1, 1
for t, a in zip(T, A):
    n = max(math.ceil(x / t), math.ceil(y / a))
    x = n * t
    y = n * a
print(x + y)