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())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    mt = math.ceil(t / ti)
    ma = math.ceil(a / ai)
    m = max(mt, ma)

    t = m * ti
    a = m * ai

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    m = int(max(math.ceil(t / ti), math.ceil(a / ai)))

    t = m * ti
    a = m * ai

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    n = int(max(math.ceil(t / ti), math.ceil(a / ai)))

    t = n * ti
    a = n * ai

print(t + a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    n = max(math.ceil(t / ti), math.ceil(a / ai))

    t = n * ti
    a = n * ai

print(t + a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
ta_array = [[int(x) for x in input().split()] for y in range(n)]
res = 1
prev_t, prev_a = ta_array.pop(0)
for t, a in ta_array:
    res_a = int(ceil(prev_a*res/a))
    res_t = int(ceil(prev_t*res/t))
    res = max(res_a, res_t)
    prev_t = t
    prev_a = a
print(prev_t*res+prev_a*res)

Submission status: Wrong Answer

Solution code:
from math import ceil

n = int(input())
ta_array = [[int(x) for x in input().split()] for y in range(n)]
res = 1
prev_t, prev_a = ta_array.pop(0)
for t, a in ta_array:
    res_a = ceil(prev_a*res/a)
    res_t = ceil(prev_t*res/t)
    res = max(res_a, res_t)
    prev_t = t
    prev_a = a
print(prev_t*res+prev_a*res)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
T, A = 1, 1
for t, a in [map(int, input().split()) for _ in range(N)]:
    n = int(max(ceil(T / t), ceil(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 [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:
from math import ceil

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

T, A = 1, 1
for t, a in TA:
    n = max(ceil(T / t), ceil(A / a))
    T, A = n * t, n * a

print(T + A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
https://abc046.contest.atcoder.jp/tasks/arc062_a

"""
import sys

from math import ceil

def solve(N, ratios):
    T, A = 1, 1
    for t, a in ratios:
        n = max(ceil(T/t), ceil(A/a))
        T, A = t*n, a*n
    return T+A


def main(args):
    N = int(input())
    ratios = [[int(x) for x in input().split()] for _ in range(N)]
    ans = solve(N, ratios)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
https://abc046.contest.atcoder.jp/tasks/arc062_a

"""
import sys

from math import ceil

def solve(N, ratios):
    T, A = 1, 1
    for t, a in ratios:
        n = ceil(max(T/t, A/a))
        T, A = t*n, a*n
    return T+A


def main(args):
    N = int(input())
    ratios = [[int(x) for x in input().split()] for _ in range(N)]
    ans = solve(N, ratios)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
N = int(input())

L = []
for i in range(N):
    t,a = map(int, input().split())
    L.append((t,a))
# print(L)

import math

check1 = (1, 1)
for i in range(N):
    check2 = L[i]
    
    x1 = check1[0]
    y1 = check1[1]
    
    x2 = check2[0]
    y2 = check2[1]
    check2 = L[i]
    
#     print('11', x1, y1)
#     print('22', x2, y2)
    
    a1 = math.floor(x1 / x2) + 1
    a2 = math.floor(y1 / y2) + 1
    
#     print('aa', a1, a2)
        
    a = max(a1, a2)
        
    check1 = (x2*a, y2*a) 
    
#     print(check1)
#     print('~~~~~~~~~~~~~~~~~~~~')

# print(check1)

print(sum(check1))

Submission status: Wrong Answer

Solution code:
N = int(input())

L = []
for i in range(N):
    t,a = map(int, input().split())
    L.append((t,a))
# print(L)

import math

check1 = (1, 1)
for i in range(N):
    check2 = L[i]
    
    x1 = check1[0]
    y1 = check1[1]
    
    x2 = check2[0]
    y2 = check2[1]
    check2 = L[i]
    
#     print(x1, y1)
#     print(x2, y2)
    
    a1 = math.ceil(x1 / x2)
    a2 = math.ceil(y1 / y2)
    
#     print(a1, a2)
        
    a = max(a1, a2)
        
    check1 = (x2*a, y2*a) 
    
#     print(check1)

# print(check1)

print(sum(check1))

Submission status: Wrong Answer

Solution code:
N = int(input())

L = []
for i in range(N):
    t,a = map(int, input().split())
    L.append((t,a))
# print(L)

import math

check1 = (0, 0)
for i in range(N):
    check2 = L[i]
    
    x1 = check1[0]
    y1 = check1[1]
    
    x2 = check2[0]
    y2 = check2[1]
    check2 = L[i]
    
    if  x1 <= x2 and y1 <= y2:
        check1 = (x2, y2)
    
    if x1 > x2 and y1 <= y2:
        a = math.ceil(x1 / x2)
        check1 = (x2*a, y2*a)
    
    if x1 <= x2 and y1 > y2:
        a = math.ceil(y1 / y2)
        check1 = (x2*a, y2*a)
        
    if x1 > x2 and y1 > y2:
        a1 = math.ceil(x1 / x2)
        a2 = math.ceil(y1 / y2)
        
        a = max(a1, a2)
        
        check1 = (x2*a, y2*a)        

# print(check1)


print(sum(check1))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

    m = max(math.ceil(t_/t), math.ceil(a_/a))
    t_, a_ = t * m, a * m
ans = t_ + a_
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

    if t >= t_ and a >= a_:
        t_, a_ = t, a
    else:
        m = max(math.ceil(t_/t), math.ceil(a_/a))
        t_, a_ = t * m, a * m
ans = t_ + a_
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
T = R[0][0]
A = R[0][1]
for r in R[1:]:
    diff = (T+A) % (r[0]+r[1])
    if diff != 0:
        if T < r[0] and A < r[1]:
            T = r[0]
            A = r[1]
        elif T > r[0] and A < r[1]:
            i = T // r[0]
            if T % r[0] != 0:
                i += 1
            T = r[0] * i
            A = r[1] * i
        elif T < r[0] and A > r[1]:
            i = A // r[1]
            if A % r[1] != 0:
                i += 1
            T = r[0] * i
            A = r[1] * i
        else:
            i = T // r[0]
            if T % r[0] != 0:
                i += 1
            j = A // r[1]
            if A % r[1] != 0:
                j += 1
            T = r[0] * max(i, j)
            A = r[1] * max(i, j)
print(T+A)

Submission status: Wrong Answer

Solution code:
import math


def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.ceil(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0] * base, ratio[1] * base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < diff_votes[1]:
                base += int(math.ceil(-diff_votes[0] / ratio[0]))
            else:
                base += int(math.ceil(-diff_votes[1] / ratio[1]))


def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:
import math


def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    base = int(max(math.ceil(ex_votes[0]/ratio[0]), math.ceil(ex_votes[1]/ratio[1])))
    test_votes = (ratio[0] * base, ratio[1] * base)
    return test_votes


def submit():
    n, ratios = read_input()

    votes = ratios[0]
    for ratio in ratios[1:]:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:
import math


def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.ceil(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0] * base, ratio[1] * base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0]/ratio[0] < diff_votes[1]/ratio[1]:
                base += int(math.ceil(-diff_votes[0] / ratio[0]))
            else:
                base += int(math.ceil(-diff_votes[1] / ratio[1]))


def submit():
    n, ratios = read_input()

    votes = ratios[0]
    for ratio in ratios[1:]:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:
import math


def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.ceil(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0] * base, ratio[1] * base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < diff_votes[1]:
                base += int(math.ceil(-diff_votes[0] / ratio[0]))
            else:
                base += int(math.ceil(-diff_votes[1] / ratio[1]))


def submit():
    n, ratios = read_input()

    votes = ratios[0]
    for ratio in ratios[1:]:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    base = max(math.ceil(ex_votes[0]/ratio[0]), math.ceil(ex_votes[1]/ratio[1]))
    return (base * ratio[0], base * ratio[1])


def submit():
    n, ratios = read_input()

    votes = ratios[0]
    for ratio in ratios[1:]:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    base = max(math.ceil(ex_votes[0]/ratio[0]), math.ceil(ex_votes[1]/ratio[1]))
    return (base * ratio[0], base * ratio[1])


def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.floor(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < 0 and diff_votes[1] < 0:
                base0 = int(math.ceil((-1 * diff_votes[0]) / ratio[0]))
                base1 = int(math.ceil((-1 * diff_votes[1]) / ratio[1]))
                base += max(base0, base1)
            elif diff_votes[0] < 0:
                base += int(math.ceil((-1 * diff_votes[0]) / ratio[0]))
            else:
                base += int(math.ceil((-1 * diff_votes[1]) / ratio[1]))

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.floor(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < 0 and diff_votes[1] < 0:
                base0 = int(math.ceil((-1 * diff_votes[0]) / ratio[0]))
                base1 = int(math.ceil((-1 * diff_votes[1]) / ratio[1]))
                base += min(base0, base1)
            elif diff_votes[0] < 0:
                base += int(math.ceil((-1 * diff_votes[0]) / ratio[0]))
            else:
                base += int(math.ceil((-1 * diff_votes[1]) / ratio[1]))

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.floor(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < diff_votes[1]:
                base += int(math.ceil((-1 * diff_votes[0]) / ratio[0]))
            else:
                base += int(math.ceil((-1 * diff_votes[1]) / ratio[1]))

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.ceil(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < diff_votes[1]:
                base += int(math.ceil(-diff_votes[0]/ratio[0]))
            else:
                base += int(math.ceil(-diff_votes[1]/ratio[1]))

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

import math

def read_input():
    n = int(input())

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

    return n, ratios


def get_votes(ex_votes, ratio):
    def check_votes(a, b):
        return a[0] <= b[0] and a[1] <= b[1]

    base = int(math.ceil(sum(ex_votes) / (ratio[0] + ratio[1])))
    while True:
        test_votes = (ratio[0]*base, ratio[1]*base)
        if check_votes(ex_votes, test_votes):
            return test_votes
        else:
            diff_votes = (test_votes[0] - ex_votes[0], test_votes[1] - ex_votes[1])
            if diff_votes[0] < 0:
                base += int(math.ceil(-diff_votes[0]/ratio[0]))
            else:
                base += int(math.ceil(-diff_votes[1]/ratio[1]))

def submit():
    n, ratios = read_input()

    votes = (1, 1)
    for ratio in ratios:
        votes = get_votes(votes, ratio)

    print(sum(votes))


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

for i in range(N):
    T, K = map(int, input().split())
    if i == 0:
        a, b = T, K
    else:
        if a <= T and b <= K:
            a, b = T, K
        elif a <= T and b > K:
            b = K * math.ceil(b / K)
            a = T * math.ceil(b / K)
        elif a > T and b <= K:
            b = K * math.ceil(a / T)
            a = T * math.ceil(a / T)
        else:
            tmp = max(math.ceil(a/T), math.ceil(b/K))
            a, b = tmp*T, tmp*K

print(a + b)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

def solve(N):
    t_now = a_now = 1
    for i in range(N):
        t, a = map(int, input().split())
        ratio = math.ceil(max(t_now/t, a_now/a)) 
        t_now, a_now = t*ratio, a*ratio
        
    print(t_now + a_now)
                
if __name__ == '__main__':
    N = int(input())
    
    solve(N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math

def solve(N):
    t_now = a_now = 1
    for i in range(N):
        t, a = map(int, input().split())
        ratio = max(math.ceil(t_now/t), math.ceil(a_now/a)) 
        t_now, a_now = t*ratio, a*ratio
        
    print(t_now + a_now)
                
if __name__ == '__main__':
    N = int(input())
    
    solve(N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = y = 1
for i in range(n):
    t, a = map(int,input().split())    
    b = 1
    if t < a:
        if x % t == 0:
            b = 0
        if y <= (x//t + b)*a:
            x = (x//t + b)*t
            y = x//t * a
        else:
            if y % a == 0:
                b = 0
            y = (y//a + b)*a
            x = y//a * t
    else:
        if y % a == 0:
            b = 0
        if x <= (y//a + b)*t:
            y = (y//a + b)*a
            x = y//a * t
        else:
            if y % a == 0:
                b = 0
            x = (x//t + b)*t
            y = x//t * a
print(x+y)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = y = 1
for i in range(n):
    t, a = map(int,input().split())
    b = 1
    if x <= y:
        if y % a == 0:
            b = 0
        y = (y//a + b)*a
        x = y//a * t
    else:
        if x % t == 0:
            b = 0
        x = (x//t + b)*t
        y = x//t * a
print(x+y)

Submission status: Wrong Answer

Solution code:
N = int(input())
tans = 1
aans = 1
for i in range(N):
    t, a = map(int, input().split())
    n = max(-(-tans // t), -(-aans / a))
    tans = n * t
    aans = n * a
print(aans + tans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# python で確認
import math
n = int(input())
t = a = 1
for _ in range(n):
    rT, rA = map(int, input().split())
    k = math.ceil(max(t / rT, a / rA))
    t, a = rT * k, rA * k
print(t + a)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import math


trial_num = int(input())
vote_rate_list = [ 0 for i in range(trial_num)]
vote_num_list = [ 0 for i in range(trial_num)]


for i in range(trial_num):
    n,k = map(int,input().split())
    vote_rate_list[i] = [n,k]

    if(i == 0):
        vote_num_list[i] = [n,k]
    else:
        x = max(math.ceil(vote_num_list[i-1][0]/vote_rate_list[i][0]) , math.ceil(vote_num_list[i-1][1]/ vote_rate_list[i][1]))

        vote_num_list[i] = [n*x, k*x]

print(vote_num_list[trial_num-1][0] + vote_num_list[trial_num-1][1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import math
trial_num = int(input())
vote_rate_list = [ 0 for i in range(trial_num)]
vote_num_list = [ 0 for i in range(trial_num)]

for i in range(trial_num):
    n,k=map(int,input().split())
    vote_rate_list[i] = [n,k]

    if(i==0):
        vote_num_list[i] = [n,k]
    else:
        x = max(math.ceil(vote_num_list[i-1][0]/vote_rate_list[i][0]) , math.ceil(vote_num_list[i-1][1]/ vote_rate_list[i][1]))

        vote_num_list[i] = [n * x, k*x]

print(vote_num_list[trial_num-1][0] + vote_num_list[trial_num-1][1])

Submission status: Wrong Answer

Solution code:
def c_atcodeer_and_election_report(N, R):
    from math import ceil
    vote_takahashi, vote_aoki = 1, 1
    for x, y in R:
        # v_t<=nx ∧ v_a<=ny を満たす最小のnを求める
        n = ceil(max(vote_takahashi / x, vote_aoki / y))
        vote_takahashi = n * x
        vote_aoki = n * y
    return vote_takahashi + vote_aoki

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_atcodeer_and_election_report(N, R))

Submission status: Wrong Answer

Solution code:
import math


def atcodeer_and_election_report(N: int, ratios: list) -> int:
    t, a = ratios[0]

    for nt, na in ratios[1:]:
        # t <= nt * k and a <= na * k
        # を満たす最小の k を求めたい
        k = max(math.ceil(t / nt), math.ceil(a / na))
        t, a = nt * k, na * k

    return t + a


if __name__ == "__main__":
    N = int(input())
    ratios = [tuple(int(s) for s in input().split()) for _ in range(N)]
    ans = atcodeer_and_election_report(N, ratios)
    print(ans)

Submission status: Wrong Answer

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = 1
vote_A = 1
for Ti, Ai in TA:
	n = max(ceil(vote_T/Ti),ceil(vote_A/Ai))
	vote_T = Ti * n
	vote_A = Ai * n
print(vote_A + vote_T)

Submission status: Wrong Answer

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = TA[0][0]
vote_A = TA[0][1]
if len(TA)>1:
	for Ti, Ai in TA[1:]:
		n = max(ceil(vote_T/Ti),ceil(vote_A/Ai))
		vote_T = Ti * n
		vote_A = Ai * n
print(vote_A + vote_T)

Submission status: Wrong Answer

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

my_round_int = lambda x: int((x * 2 + 1) // 2)

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = TA[0][0]
vote_A = TA[0][1]
if len(TA)>1:
	for Ti, Ai in TA[1:]:
		high = 10 ** 18
		low = 0
		t = (high + low)/2
		for _ in range(80):
			# print(t,"倍")
			if Ti * t > vote_T and Ai * t > vote_A:
				high = (high+low)/2
			else:
				low = (high+low)/2
			t = (low+high)/2
		tmp = int(t)
		if abs(tmp - t) >= 0.1:
			t = tmp + 1
		else:
			t = my_round_int(t)
		vote_T = t * Ti
		vote_A = t * Ai

print(vote_A + vote_T)

Submission status: Wrong Answer

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

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
TA = [LIST() for _ in range(N)]
vote_T = TA[0][0]
vote_A = TA[0][1]
if len(TA)>1:
	for Ti, Ai in TA[1:]:
		high = 10 ** 18
		low = 0
		t = (high + low)/2
		for _ in range(70):
			# print(t,"倍")
			if Ti * t > vote_T and Ai * t > vote_A:
				high = (high+low)/2
			else:
				low = (high+low)/2
			t = (low+high)/2
		n = ceil(t) 
		vote_T = n * Ti
		vote_A = n * Ai

print(vote_A + vote_T)

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(pt[i-1]/t, pa[i-1]/a))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max(pt[i-1]/t*1.0, pa[i-1]/a*1.0))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max([pt[i-1]/t*1.0, pa[i-1]/a*1.0]))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = math.ceil(max([pt[i-1]/float(t), pa[i-1]/float(a)]))
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    tmp = max([math.ceil(pt[i-1]*1.0/t), math.ceil(pa[i-1]*1.0/a)])
    pt[i]=tmp*t
    pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    if t == 1 and a == 1:
      pt[i] = max(pt[i-1], pa[i-1])
      pa[i] = max(pt[i-1], pa[i-1])
    elif t == 1:
      pt[i] = pt[i-1]
      pa[i] = pt[i-1] * a
    elif a == 1:
      pt[i] = pa[i-1] * t
      pa[i] = pa[i-1]
    else:
      tmp = max([math.ceil(pt[i-1]*1.0/t), math.ceil(pa[i-1]*1.0/a)])
      pt[i]=tmp*t
      pa[i]=tmp*a

print(int(pt[-1] + pa[-1]))

Submission status: Wrong Answer

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

pt = [0] * n
pa = [0] * n

for i in range(n):
  t, a = map(int, input().split())
  if i == 0:
    pt[0] = t
    pa[0] = a
  else:
    if t == 1 and a == 1:
      pt[i] = max(pt[i-1], pa[i-1])
      pa[i] = max(pt[i-1], pa[i-1])
    elif t == 1:
      pt[i] = pt[i-1]
      pa[i] = pt[i-1] * a
    elif a == 1:
      pt[i] = pa[i-1] * t
      pa[i] = pa[i-1]
    else:
      tmp = max([math.ceil(pt[i-1]*1.0/t), math.ceil(pa[i-1]*1.0/a)])
      pt[i]=tmp*t
      pa[i]=tmp*a

print(pt[-1] + pa[-1])