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())
Ratio = [list(map(int,input().split())) for _ in range(n)]
t,a = Ratio[0][0],Ratio[0][1]

for i in range(1,n):
    if t/Ratio[i][0] == t//Ratio[i][0]:
        x = t//Ratio[i][0]
    else:
        x = t//Ratio[i][0]+1
    if a/Ratio[i][1] == a//Ratio[i][1]:
        y = a//Ratio[i][1]
    else:
        y = a//Ratio[i][1]+1
    z = max(x,y)
    t,a = Ratio[i][0]*z,Ratio[i][1]*z

print(t+a)

Submission status: Wrong Answer

Solution code:
import math
from decimal import *

n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]

def newT(t, ratio):
    if t[0] <= ratio[0] and t[1] <= ratio[1]:
        return ratio
    else:
        #切り上げ (x+p-1)//p * p
        c = max(((t[0]+ratio[0]-1)//ratio[0])*ratio[0], ((t[1]+ratio[1]-1)//ratio[1])*ratio[1])
        return [i*c for i in ratio]

to = l[0]
for li in l[1:]:
    to = newT(to, li)

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]

def newT(t, ratio):
    a = t[0] / ratio[0]
    b = t[1] / ratio[1]
    if a <= 1 and b <= 1:
        return ratio
    else:
        c = math.ceil(max([a, b]))
        return [i*c for i in ratio]

to = l[0]
for li in l[1:]:
    to = newT(to, li)

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

Submission status: Wrong Answer

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

t_num = t_list[0]
a_num = a_list[0]
for i in range(1, n):
    t, a = t_list[i], a_list[i]
    for m in range(100000):
        if m * t >= t_num and m * a >= a_num:
            t_num = m * t
            a_num = m * a
            break
print(t_num + a_num)

Submission status: Wrong Answer

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

t_num = t_list[0]
a_num = a_list[0]
for i in range(1, n):
    t, a = t_list[i], a_list[i]
    for m in range(10000):
        if m * t >= t_num and m * a >= a_num:
            t_num = m * t
            a_num = m * a
            break
print(t_num + a_num)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = []
d = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])
    d.append([])
d[0].append(c[0][0])
d[0].append(c[0][1])

def f(x,y):
    return x//y + (1 if x%y > 0 else 0)

for i in range(1, n):
    #zz = max(math.ceil(d[i - 1][0] / c[i][0]), math.ceil(d[i - 1][1] / c[i][1]))
    zz = max(f(d[i - 1][0], c[i][0]),f(d[i - 1][1], c[i][1]))
    d[i].append(c[i][0] * zz)
    d[i].append(c[i][1] * zz)

    print(d[i][0], d[i][1])
print(d[n - 1][0] + d[n - 1][1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = []
d = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])
    d.append([])
d[0].append(c[0][0])
d[0].append(c[0][1])


for i in range(1, n):
    zz = max(math.ceil(d[i - 1][0] / c[i][0]), math.ceil(d[i - 1][1] / c[i][1]))
    d[i].append(c[i][0] * zz)
    d[i].append(c[i][1] * zz)

print(d[n - 1][0] + d[n - 1][1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = []
d = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])
    d.append([])
d[0].append(c[0][0])
d[0].append(c[0][1])

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

for i in range(1, n):
    if d[i - 1][0] <= c[i][0] and d[i - 1][1] <= c[i][1]:
        d[i].append(c[i][0])
        d[i].append(c[i][1])
    elif d[i - 1][0] <= c[i][0] and d[i - 1][1] > c[i][1]:
        d[i].append(math.ceil(d[i - 1][1] / c[i][1]) * c[i][0])
        d[i].append(math.ceil(d[i - 1][1] / c[i][1]) * c[i][1])
    elif d[i - 1][0] > c[i][0] and d[i - 1][1] <= c[i][1]:
        d[i].append(math.ceil(d[i - 1][0] / c[i][0]) * c[i][0])
        d[i].append(math.ceil(d[i - 1][0] / c[i][0]) * c[i][1])
    else:
        zz = max(math.ceil(d[i - 1][0] / c[i][0]), math.ceil(d[i - 1][1] / c[i][1]))
        d[i].append(c[i][0] * zz)
        d[i].append(c[i][1] * zz)

print(d[n - 1][0] + d[n - 1][1])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = []
d = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])
    d.append([])
d[0].append(c[0][0])
d[0].append(c[0][1])

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

for i in range(1, n):
    if d[i - 1][0] <= c[i][0] and d[i - 1][1] <= c[i][1]:
        d[i].append(c[i][0])
        d[i].append(c[i][1])
    elif d[i - 1][0] <= c[i][0] and d[i - 1][1] > c[i][1]:
        d[i].append(math.ceil(d[i - 1][1] / c[i][1]) * c[i][0])
        d[i].append(math.ceil(d[i - 1][1] / c[i][1]) * c[i][1])
    elif d[i - 1][0] > c[i][0] and d[i - 1][1] <= c[i][1]:
        d[i].append(math.ceil(d[i - 1][0] / c[i][0]) * c[i][0])
        d[i].append(math.ceil(d[i - 1][0] / c[i][0]) * c[i][1])
    else:
        p1 = lcm_base(d[i - 1][0], c[i][0])
        xx = p1 // c[i][0]
        p2 = c[i][1] * xx
        p1 = math.ceil(d[i - 1][1] / p2) * p1
        p2 = math.ceil(d[i - 1][1] / p2) * p2

        q2 = lcm_base(d[i - 1][1], c[i][1])
        yy = q2 // c[i][1]
        q1 = c[i][0] * yy
        q2 = math.ceil(d[i - 1][0] / q1) * q2
        q1 = math.ceil(d[i - 1][0] / q1) * q1

        if p1 + p2 >= q1 + q2:
            d[i].append(q1)
            d[i].append(q2)
        else:
            d[i].append(p1)
            d[i].append(p2)

print(d[n - 1][0] + d[n - 1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
d = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])
    d.append([])
d[0].append(c[0][0])
d[0].append(c[0][1])

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

for i in range(1, n):
    if d[i - 1][0] <= c[i][0] and d[i - 1][1] <= c[i][1]:
        d[i].append(c[i][0])
        d[i].append(c[i][1])
    elif d[i - 1][0] <= c[i][0] and d[i - 1][1] > c[i][1]:
        d[i].append((d[i - 1][1] // c[i][1] + 1) * c[i][0])
        d[i].append((d[i - 1][1] // c[i][1] + 1) * c[i][1])
    elif d[i - 1][0] > c[i][0] and d[i - 1][1] <= c[i][1]:
        d[i].append((d[i - 1][0] // c[i][0] + 1) * c[i][0])
        d[i].append((d[i - 1][0] // c[i][0] + 1) * c[i][1])
    else:
        p1 = lcm_base(d[i - 1][0], c[i][0])
        xx = p1 // c[i][0]
        p2 = c[i][1] * xx
        p1 = (d[i - 1][1] // p2 + 1) * p1
        p2 = (d[i - 1][1] // p2 + 1) * p2

        q2 = lcm_base(d[i - 1][1], c[i][1])
        yy = q2 // c[i][1]
        q1 = c[i][0] * yy
        q2 = (d[i - 1][0] // q1 + 1) * q2
        q1 = (d[i - 1][0] // q1 + 1) * q1

        if p1 + p2 >= q1 + q2:
            d[i].append(q1)
            d[i].append(q2)
        else:
            d[i].append(p1)
            d[i].append(p2)

print(d[n - 1][0] + d[n - 1][1])

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    t0, a0 = 1, 1
    for _ in range(n):
        t, a = map(int, input().split())
        if t >= t0 and a >= a0:
            t0, a0 = t, a
            continue
        if t >= t0:
            mult = math.ceil(a0 / a)
        elif a >= a0:
            mult = math.ceil(t0 / t)
        else:
            mult = max(math.ceil(t0 / t), math.ceil(a0 / a))
        t0 = t * mult
        a0 = a * mult
    print(t0 + a0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    t0, a0 = 1, 1
    for _ in range(n):
        t, a = map(int, input().split())
        mult = max(math.ceil(t0 / t), math.ceil(a0 / a))
        t0 = t * mult
        a0 = a * mult
    print(t0 + a0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
t = [0 for _ in range(n)]
a = [0 for _ in range(n)]
for i in range(n):
    t[i], a[i] = [int(i) for i in input().split()]
for i in range(n):
    k = max(math.ceil(vote[0] / t[i]),
            math.ceil(vote[1] / a[i]))
    vote = [t[i] * k, a[i] * k]
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if i == 0:
        vote = [t, a]
        continue
    """
    k = max(vote[0] // t, vote[1] // a)
    if t * k < vote[0] or a * k < vote[1]:
        # print("miss")
        k = max(math.ceil(vote[0] / t),
                math.ceil(vote[1] / a))
    """
    k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # print(vote)
    # print("[{},{}] k:{}".format(t, a, k))
    # print("vote:{}".format(vote))
print(vote[0] + vote[1])

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
ta, ao = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    if ta <= T and ao <= A:
        ta = T
        ao = A
    else:
        if ta % T == 0:
            n = ta//T
        else:
            n = ta//T + 1
        if ao % A == 0:
            m = ao//A
        else:
            m = ao//A + 1
        
        ta = max(n, m) * T
        ao = max(n, m) * A
        print(n)
print(ta+ao)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
ta, ao = 1, 1
for i in range(N):
    T, A = map(int, input().split())
    if ta <= T and ao <= A:
        ta = T
        ao = A
    else:
        n = ceil(max(ta/T, ao/A))
        ta = n * T
        ao = n * A
        
print(ta+ao)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

s, t = 1, 1

for i in range(0, n):

    j = max(ceil(s/a[i][0]), ceil(t/a[i][1]))
    s, t = a[i][0]*j, a[i][1]*j


print(s+t)

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

s, t = a[0][0], a[0][1]

for i in range(1, n):

    j = max(ceil(s/a[i][0]), ceil(t/a[i][1]))
    s, t = a[i][0]*j, a[i][1]*j

print(s+t)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]

s, t = a[0][0], a[0][1]

for i in range(1, n):
    if a[i][0] < a[i][1]:
        j = 1
        while True:
            if a[i][0]*j < s or a[i][1]*j < t:
                pass
            else:
                s = a[i][0]*j
                break
            j += 1

        t = j*a[i][1]

    elif a[i][0] > a[i][1]:
        j = 1
        while True:
            if a[i][1]*j < t or a[i][0]*j < s:
                pass
            else:
                t = a[i][1]*j
                break
            j += 1

        s = j*a[i][0]

    else:
        s, t = max(s, t), max(s,t)

    print(s, t)
print(s+t)

Submission status: Wrong Answer

Solution code:
import math

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

n_t, n_a = 1, 1
for t, a in TA:
    # print(n_t/t, n_a/a)
    v = max(math.ceil(n_t/t), math.ceil(n_a/a))
    n_t, n_a = t*v, a*v

print(n_t+n_a)

Submission status: Wrong Answer

Solution code:
import math

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

n_t, n_a = 1, 1
for t, a in TA:
    # print(n_t/t, n_a/a)
    v = max(math.ceil(n_t//t), math.ceil(n_a//a))
    n_t, n_a = t*v, a*v

print(n_t+n_a)

Submission status: Wrong Answer

Solution code:
import math

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

n_t, n_a = 1, 1
for t, a in TA:
    # print(n_t/t, n_a/a)
    v = math.ceil(max(n_t/t, n_a/a))
    n_t, n_a = t*v, a*v
    # print(v, n_t, n_a)
    # s, b = 0, 0
    # while not (n_t <= s and n_a <= b):
    #     s += t
    #     b += a
    # n_t, n_a = s, b

print(n_t+n_a)

Submission status: Wrong Answer

Solution code:
import math

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

n_t, n_a = 1, 1
for t, a in TA:
    v = max(math.ceil(n_t/t), math.ceil(n_a/a))
    n_t, n_a = t*v, a*v
    # s, b = 0, 0
    # while not (n_t <= s and n_a <= b):
    #     s += t
    #     b += a
    # n_t, n_a = s, b

print(n_t+n_a)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
array = [[int(x) for x in input().split()] for y in range(n)]
takahashi, aoki = array[0]
for t, a in array[1:]:
    if takahashi/aoki == t/a:
        continue
    else:
        if t == a:
            takahashi, aoki = max(takahashi, aoki), max(takahashi, aoki)
        else:
            kakerukazu = max(int(math.ceil(takahashi/t)), int(math.ceil(aoki/a)))
            takahashi = t*kakerukazu
            aoki = a*kakerukazu
print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
array = [[int(x) for x in input().split()] for y in range(n)]
takahashi, aoki = array[0]
for t, a in array[1:]:
    if takahashi/aoki == t/a:
        continue
    else:
        if t == a:
            takahashi, aoki = max(takahashi, aoki), max(takahashi, aoki)
        else:
            kakerukazu = max(math.ceil(takahashi/t), math.ceil(aoki/a))
            takahashi = t*kakerukazu
            aoki = a*kakerukazu
print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
array = [[int(x) for x in input().split()] for y in range(n)]
takahashi, aoki = array[0]
for t, a in array[1:]:
    if takahashi/aoki == t/a:
        continue
    else:
        if t == a:
            takahashi, aoki = max(takahashi, aoki), max(takahashi, aoki)
        else:
            tmp_takahashi = int(t*math.ceil(takahashi/t))
            tmp_aoki = int(tmp_takahashi/t*a)

            tmp2_aoki = int(a*math.ceil(aoki/a))
            tmp2_takahashi = int(tmp2_aoki/a*t)

            if tmp2_aoki < aoki or tmp2_takahashi < takahashi:
                takahashi, aoki = tmp_takahashi, tmp_aoki
                continue
            elif tmp_aoki < aoki or tmp_takahashi < takahashi:
                takahashi, aoki = tmp2_takahashi, tmp2_aoki
                continue

            if (tmp_takahashi+tmp_takahashi) > (tmp2_takahashi+tmp2_aoki):
                takahashi, aoki = tmp2_takahashi, tmp2_aoki
            else:
                takahashi, aoki = tmp_takahashi, tmp_aoki
print(int(takahashi+aoki))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
array = [[int(x) for x in input().split()] for y in range(n)]
takahashi, aoki = array[0]
for t, a in array[1:]:
    if takahashi/aoki == t/a:
        continue
    else:
        if t == a:
            takahashi, aoki = max(takahashi, aoki), max(takahashi, aoki)
        else:
            tmp_takahashi = int(t*math.ceil(takahashi/t))
            tmp_aoki = int(tmp_takahashi/t*a)

            tmp2_aoki = int(a*math.ceil(aoki/a))
            tmp2_takahashi = int(tmp2_aoki/a*t)

            if tmp2_aoki < aoki or tmp2_takahashi < takahashi:
                takahashi, aoki = tmp_takahashi, tmp_aoki
                continue
            elif tmp_aoki < aoki or tmp_takahashi < takahashi:
                takahashi, aoki = tmp2_takahashi, tmp2_aoki
                continue

            if (tmp_takahashi+tmp_takahashi) > (tmp2_takahashi+tmp2_aoki):
                takahashi, aoki = tmp2_takahashi, tmp2_aoki
            else:
                takahashi, aoki = tmp_takahashi, tmp_aoki
print(takahashi+aoki)

Submission status: Wrong Answer

Solution code:
import math

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

# print("-")

s_t, s_a = 1, 1 
for t, a in TA:
    v = max(math.ceil(s_t/t), math.ceil(s_a/a))
    s_t, s_a = t*v, a*v
    # print(s_t, s_a)

print(s_t+s_a)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, = map(int, raw_input().split())
t = 1
a = 1
for i in range(N):
  ti, ai = map(int, raw_input().split())
  tx = ceil(1.0*t/ti)
  ax = ceil(1.0*a/ai)
  mx = max(tx,ax)
  t  = mx * ti
  a  = mx * ai
print int(t+a)

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = list(map(int, input().split())) # first time
# print("%d : %d"%(t, a))
for i in range(N-1):
    t_i, a_i = list(map(int, input().split()))
    if t/a < t_i/a_i: # a基準に増やす
        if a % a_i  != 0:
            a += a_i - a % a_i
        t = a * t_i / a_i
    else: # t基準に増やす
        if t % t_i != 0:
            t += t_i - t % t_i
        a = t * a_i / t_i
    # print("%d : %d"%(t, a))
print(int(t+a))

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = list(map(int, input().split())) # first time

for i in range(N-1):
    t_i, a_i = list(map(int, input().split()))
    if t/a < t_i/a_i: # a基準に増やす
        while a % a_i != 0:
            a += 1
        t = a * t_i / a_i
    else: # t基準に増やす
        while t % t_i != 0:
            t += 1
        a = t * a_i / t_i
print(int(t+a))

Submission status: Wrong Answer

Solution code:
N = int( input())
bridge, blue = map( int, input().split())
for _ in range(N-1):
    t, a = map( int, input().split())
    if (( bridge - 0.5)//t + 1)*a >= blue:
        if bridge%t == 0:
            bridge = ( ( bridge - 0.5)//t + 1)*t
            blue = ( ( bridge - 0.5)//t + 1)*a
    else:
        blue = ( ( blue - 0.5)//a + 1)*a
        bridge = ( ( blue - 0.5)//a + 1)*t
print( int(bridge + blue))

Submission status: Wrong Answer

Solution code:
N = int( input())
bridge, blue = map( int, input().split())
for _ in range(N-1):
    t, a = map( int, input().split())
    if (( bridge - 0.5)//t + 1)*a >= blue:
        bridge = ( int( bridge - 0.5)//t + 1)*t
        blue = ( int( bridge - 0.5)//t + 1)*a
    else:
        blue = ( int( blue - 0.5)//a + 1)*a
        bridge = ( int( blue - 0.5)//a + 1)*t
print( bridge + blue)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if i == 0:
        vote = [t, a]
        continue
    k = max(int(vote[0] / t),
            int(vote[1] / a))
    if t*k < vote[0] or a*k < vote[1]:
        # print("miss")
        k = max(math.ceil(vote[0] / t),
                math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # print("[{},{}] k:{}".format(t, a, k))
    # print("vote:{}".format(vote))
print(vote[0] + vote[1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
vote =[0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n):
    # print(i)
    t, a = [int(i) for i in input().split()]
    if i == 0:
        vote = [t, a]
        continue
    k = max(math.ceil(vote[0] / t),
            math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # print("[{},{}] k:{}".format(t, a, k))
    # print("vote:{}".format(vote))
print(vote[0] + vote[1])

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n):
    # print(i)
    t, a = [int(i) for i in input().split()]
    if i == 0:
        vote = [t, a]
        continue
    k = max(math.ceil(vote[0] / t),
            math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    print("[{},{}] k:{}".format(t, a, k))
    print("vote:{}".format(vote))
print(vote[0] + vote[1])

Submission status: Wrong Answer

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

# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
vote = [int(i) for i in input().split()]

# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n-1):
    # print(i)
    t, a = [int(i) for i in input().split()]
    # vote[0]<tk, vote[1]<akとなるkを算出(k<nなのでO(n))
    k = max(math.ceil(vote[0]/t), math.ceil((vote[1]/a)))
    # for k in range(1, 10000000):
        # print("k:{}".format(k))
        # if t*k >= vote[0] and a*k >= vote[1]:
    vote = [t*k, a*k]
            # break
    # print("vote:{}".format(vote))
print(sum(vote))

Submission status: Wrong Answer

Solution code:
n = int(input())

# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
vote = [int(i) for i in input().split()]

# 各入力に対し、vote[0]<tk, vote[1]<akとなる
# 最小のtk,akでvoteを更新
for i in range(n-1):
    # print(i)
    t, a = [int(i) for i in input().split()]
    # vote[0]<tk, vote[1]<akとなるkを算出(k<nなのでO(n))
    for k in range(1, 10000):
        # print("k:{}".format(k))
        if t*k >= vote[0] and a*k >= vote[1]:
            vote = [t*k, a*k]
            break
    # print("vote:{}".format(vote))
print(sum(vote))

Submission status: Wrong Answer

Solution code:
N = int(input())
T, A = 1, 1
for i in range(N):
    t, a = map(int, input().split())
    if T % t == 0:
        n1 = T // t
    else:
        n1 = T // t + 1
    if A % a == 0:
        n2 = A // a
    else:
        n2 = T // a + 1
    n = max(n1, n2)
    T = n*t
    A = n*a
    
print(T+A)

Submission status: Wrong Answer

Solution code:
import math


class Point:
    def __init__(self, t, a):
        self.t = t
        self.a = a


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

T = 1
A = 1

for p in points:
    n = int(max((math.ceil(T/p.t)), (math.ceil(A/p.a))))
    T = n*p.t
    A = n*p.a
print(T+A)

Submission status: Wrong Answer

Solution code:
import math


class Point:
    def __init__(self, t, a):
        self.t = t
        self.a = a


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

T = 1
A = 1

for p in points:
    n = max((math.ceil(T/p.t)), (math.ceil(A/p.a)))
    T = n*p.t
    A = n*p.a
print(T+A)

Submission status: Wrong Answer

Solution code:
import math

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

k = 1
for i in range(n-1):
  k1 = math.ceil(ratio[i][0] * k / ratio[i+1][0])
  k2 = math.ceil(ratio[i][1] * k / ratio[i+1][1])
  k3 = math.ceil(sum(ratio[i]) * k / sum(ratio[i+1]))
  k = max(k1, k2, k3)

print(sum(ratio[n-1]) * k)

Submission status: Wrong Answer

Solution code:
import math

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

k = 1
for i in range(n-1):
  k1 = math.ceil(ratio[i][0] * k / ratio[i+1][0])
  k2 = math.ceil(ratio[i][1] * k / ratio[i+1][1])
  k = max(k1, k2)

print(sum(ratio[n-1]) * k)

Submission status: Wrong Answer

Solution code:
import math

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 2

for i in range(0, N):
    m = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
    T = TA[i][0] * m
    A = TA[i][1] * m
    ans = T + A

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 0

for i in range(0, N):
    m = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
    T = TA[i][0] * m
    A = TA[i][1] * m
    ans = T + A

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 0

for i in range(0, N):
    g = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
    T = TA[i][0] * g
    A = TA[i][1] * g
    ans = T + A

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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


T = 1 # 高橋くんの最小得票数
A = 1 # 青木くんの最小得票数
ans = 2

for i in range(0, N):
    g = max(math.ceil(T / TA[i][0]), math.ceil(A / TA[i][1]))
    T = TA[i][0] * g
    A = TA[i][1] * g
    ans = T + A

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
t, a = [int(x) for x in input().split()]
for i in range(N - 1):
    T, A = [int(x) for x in input().split()]
    T_A = T / A
    while True:
        t_a = t / a
        if abs(t_a - T_A) < 10 ** (-5):
            break
        elif t_a > T_A:
            a += 1
        elif t_a < T_A:
            t += 1
print(t + a)

Submission status: Wrong Answer

Solution code:
N=int(input())
T=1
A=1
for i in range(N):
    t,a=map(int,input().split())
    if t>=T and a>=A:
        T1=t
        A1=a
    elif t>=T and A>=a:
        if A%a==0:
            A1=a
            T1=t*(int(A/a))
            
        else:
            A1=a*(int(A/a)+1)
            T1=t*(int(A/a)+1)
    elif T>=t and a>=A:
        if T%t==0:
            T1=t
            A1=a*(int(T/t))
        else:
            T1=t*(int(T/t)+1)
            A1=a*(int(T/t)+1)
    else:
        if T/t>=A/a:
            if T%t==0:
                T1=t*(int(T/t))
                A1=a*(int(T/t))
            else:
                T1=t*(int(T/t)+1)
                A1=a*(int(T/t)+1)
        else:
            if A%a==0:
                A1=a*(int(A/a))
                T1=t*(int(A/a))
            else:
                A1=a*(int(A/a)+1)
                T1=t*(int(A/a)+1)
    T=T1
    A=A1
    #print(T,A)
print(A+T)

Submission status: Wrong Answer

Solution code:
N=int(input())
t=1
a=1
import numpy as np
for i in range(1,N+1):
    tk,ao=input().split()
    T=int(tk)
    A=int(ao)
    n=max(np.ceil(t/T),np.ceil(a/A))
    a=n*A
    t=n*T
print(int(a+t))

Submission status: Wrong Answer

Solution code:
N=int(input())
t=1
a=1
import numpy as np
for i in range(1,N+1):
    tk,ao=input().split()
    T=int(tk)
    A=int(ao)
    n=int(max(np.ceil(t/T),np.ceil(a/A)))
    a=n*A
    t=n*T
print(a+t)

Submission status: Wrong Answer

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


def main():
    from math import ceil

    n = int(input())
    count_t, count_a = 1, 1

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

        if (t >= count_t) and (a >= count_a):
            count_t = t
            count_a = a
        else:
            ratio = max(ceil(count_t / t), ceil(count_a / a))
            count_t = t * ratio
            count_a = a * ratio

    print(count_t + count_a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

nowa = 1
nowt = 1
for i in range(n):
    (t, a) = list(map(int, input().split()))
    bai = max(math.ceil(nowa / a), math.ceil(nowt / t))
    nowa = a * bai
    nowt = t * bai

print(nowa + nowt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=0
for i in range(1,n+1):
  b,m=map(int,input().split())
  if l!=b+m or l==0:
    l=(l//(b+m)+1)*(b+m)
  else:
    pass
print(l)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=0
p=0
for i in range(1,n+1):
  b,m=map(int,input().split())
  if l!=b+m:
    l=(l//(b+m)+1)*(b+m)
  else:
    pass
print(l)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=0
p=0
for i in range(1,n+1):
  b,m=map(int,input().split())
  l=(l//(b+m)+1)*(b+m)
print(l)

Submission status: Wrong Answer

Solution code:
from fractions import math


def main():
    N = int(input())
    T = []
    A = []
    for _ in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


def main():
    N = int(input())
    T = []
    A = []
    for i in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

    for i in range(N - 1):

        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            mul = max(math.ceil(T[i] / T[i + 1]), math.ceil(A[i] / A[i + 1]))
            A[i + 1] *= mul
            T[i + 1] *= mul
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


def main():
    N = int(input())
    T = []
    A = []
    for i in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

    for i in range(N - 1):

        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            mul = max(math.ceil(T[i] / T[i + 1]), math.ceil(A[i] / A[i + 1]))
            A[i + 1] *= mul
            T[i + 1] *= mul
            '''
            if T[i] / T[i + 1] >= A[i] / A[i + 1]:
                A[i + 1] = math.ceil(T[i] / T[i + 1]) * A[i + 1]
                T[i + 1] = math.ceil(T[i] / T[i + 1]) * T[i + 1]
            else:
                T[i + 1] = math.ceil(A[i] / A[i + 1]) * T[i + 1]
                A[i + 1] = math.ceil(A[i] / A[i + 1]) * A[i + 1]
            '''
        print(T)
        print(A)
        print("---------")
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


def main():
    N = int(input())
    T = []
    A = []
    for i in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

    for i in range(N - 1):

        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            if T[i] / T[i + 1] >= A[i] / A[i + 1]:
                A[i + 1] = math.ceil(T[i] / T[i + 1]) * A[i + 1]
                T[i + 1] = math.ceil(T[i] / T[i + 1]) * T[i + 1]
            else:
                T[i + 1] = math.ceil(A[i] / A[i + 1]) * T[i + 1]
                A[i + 1] = math.ceil(A[i] / A[i + 1]) * A[i + 1]
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()