Problem:


Score : 300 points

Problem Statement

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

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

Constraints

1≦N≦1000

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

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

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

Input

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

N
T_1 A_1
T_2 A_2
:
T_N A_N

Output

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

Sample Input 1

3
2 3
1 1
3 2

Sample Output 1

10

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

Sample Input 2

4
1 1
1 1
1 5
1 100

Sample Output 2

101

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

Sample Input 3

5
3 10
48 17
31 199
231 23
3 2

Sample Output 3

6930



Sample input:
3
2 3
1 1
3 2


Sample output:
10

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
import sys
N = int(input())
T = []
A = []
for n in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)

if N == 1:
    ans = T[N - 1] + A[N - 1]
    print(ans)
    sys.exit()

for n in range(1, N):
    if A[n - 1] <= A[n] and T[n - 1] <= T[n]:
        continue
    elif A[n - 1] > A[n] and T[n - 1] <= T[n]:
        tmp = math.ceil(A[n - 1] / A[n])
        A[n] = tmp * A[n]
        T[n] = tmp * T[n]
    elif A[n - 1] <= A[n] and T[n - 1] > T[n]:
        tmp = math.ceil(T[n - 1] / T[n])
        A[n] = tmp * A[n]
        T[n] = tmp * T[n]
    elif A[n - 1] > A[n] and T[n - 1] > T[n]:
        tmp_div_a = math.ceil(A[n - 1] / A[n])
        tmp_div_t = math.ceil(T[n - 1] / T[n])
        if tmp_div_a * T[n] >= T[n - 1]:
            T[n] = tmp_div_a * T[n]
            A[n] = tmp_div_a * A[n]
        elif tmp_div_t * A[n] >= A[n - 1]:
            T[n] = tmp_div_t * T[n]
            A[n] = tmp_div_t * A[n]
print(T[N - 1] + A[N - 1])

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
import sys
N = int(input())
T = []
A = []
for n in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)

if N == 1:
    ans = T[N - 1] + A[N - 1]
    print(ans)
    sys.exit()

for n in range(1, N):
    if A[n - 1] <= A[n] and T[n - 1] <= T[n]:
        continue
    elif A[n - 1] > A[n] and T[n - 1] <= T[n]:
        tmp = math.ceil(A[n - 1] / A[n])
        A[n] = tmp * A[n]
        T[n] = tmp * T[n]
    elif A[n - 1] <= A[n] and T[n - 1] > T[n]:
        tmp = math.ceil(T[n - 1] / T[n])
        A[n] = tmp * A[n]
        T[n] = tmp * A[n]
    elif A[n - 1] > A[n] and T[n - 1] > T[n]:
        tmp_div_a = math.ceil(A[n - 1] / A[n])
        tmp_div_t = math.ceil(T[n - 1] / T[n])
        if tmp_div_a * T[n] >= T[n - 1]:
            T[n] = tmp_div_a * T[n]
            A[n] = tmp_div_a * A[n]
        else:
            T[n] = tmp_div_t * T[n]
            A[n] = tmp_div_t * A[n]
print(T[N - 1] + A[N - 1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil

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

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
A = 1
B = 1
ans = 1
for i in range(0, N):
    x, y = map(int, input().split())
    ans = ceil(max(A/x, B/y))
    A = ans*x
    B = ans*y
print(A+B)

Submission status: Wrong Answer

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

takahasi, aoki = ratio[0]
for i in range(1, N):
    t_ratio, a_ratio = ratio[i]
    n = max(math.ceil(takahasi/t_ratio), math.ceil(aoki/a_ratio))
    takahasi = n * t_ratio
    aoki = n * a_ratio

print(takahasi+aoki)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
input = sys.stdin.readline

def main():
    N = int(input())
    ta = [list(map(int, input().split())) for i in range(N)]

    a, b = 1, 1
    for i in range(N):
        x, y = ta[i]
        n = max(ceil(a/x), ceil(b/y))
        a = x * n
        b = y * n
        # print(i, a, b, n, n*x, n*y)
    print(a+b)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
input = sys.stdin.readline

def main():
    N = int(input())
    ta = [list(map(int, input().split())) for i in range(N)]

    a, b = 1, 1
    for i in range(N):
        x, y = ta[i]
        n = max(ceil(a/y), ceil(b/y))
        a = x * n
        b = y * n
        # print(i, a, b, n, n*x, n*y)
    print(a+b)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())

t0,a0=map(int,input().split())

for i in range(1,N):
    T,A=map(int,input().split())
    if T>A:
        if a0%A!=0:
            a0=a0+(A-a0%A)
        else:
            a0=a0
        if t0<=(a0*T)//A:
            t0=(a0*T)//A
        else:
            if t0%T!=0:
                t0=t0+(T-t0%T)
            else:
                t0=t0
            a0=(t0*A)//T

    elif T<A:
        if t0%T!=0:
            t0=t0+(T-t0%T)
        else:
            t0=t0
        if a0<=(t0*A)//T:
            a0=(t0*A)//T
        else:
            if a0%A!=0:
                a0=a0+(A-a0&A)
            else:
                a0=a0
            t0=(a0*T)//A
    else:
        if a0>t0:
            t0=a0
        else:
            a0=t0

print(t0+a0)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

nowT = 1
nowA = 1
for i in range(N):
    nextT, nextA = map(int, input().split())

    mul = max(ceil(nowT / nextT), ceil(nowA / nextA))
    nowT = nextT * mul
    nowA = nextA * mul

print(nowT + nowA)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

L = []
for i in range(N):
    L.append(list(map(int, input().split())))

nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
    nextT = L[i][0]
    nextA = L[i][1]

    mul = max(ceil(nowT / nextT), ceil(nowA / nextA))
    nowT = nextT * mul
    nowA = nextA * mul

print(nowT + nowA)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

L = []
for i in range(N):
    L.append(list(map(int, input().split())))

nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
    nextT = L[i][0]
    nextA = L[i][1]

    if nextT >= nowT and nextA >= nowA:
        nowT = nextT
        nowA = nextA
        continue

    mul = max(ceil(nowT / nextT), ceil(nowA / nextA))
    nowT = nextT * mul
    nowA = nextA * mul

print(nowT + nowA)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())

L = []
for i in range(N):
    L.append(tuple(map(int, input().split())))

nowT = L[0][0]
nowA = L[0][1]
for i in range(1, N):
    tmpT = L[i][0]
    tmpA = L[i][1]

    if tmpT >= nowT and tmpA >= nowA:
        nowT = tmpT
        nowA = tmpA
        continue

    mul = max(ceil(nowT / tmpT), ceil(nowA / tmpA))
    nowT = tmpT * mul
    nowA = tmpA * mul

print(nowT + nowA)

Submission status: Wrong Answer

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


def main():
    from math import ceil

    n = int(input())
    vote_t, vote_a = 1, 1

    # See:
    # http://arc062.contest.atcoder.jp/data/arc/062/editorial.pdf
    # KeyInsight：各状態で，できるだけ得票数が少ないほうがよい
    # 高橋君にA票，青木君にB票あるとき，満たすべき比率がx：yだとすると，
    # A <= m * x ^ B <= m * yとなるような最小の自然数mを取ればよい
    for i in range(n):
        ti, ai = map(int, input().split())
        m = int(max(ceil(vote_t / ti), ceil(vote_a / ai)))
        vote_t = ti * m
        vote_a = ai * m

    print(vote_t + vote_a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    from math import ceil

    n = int(input())
    vote_t, vote_a = 1, 1

    # See:
    # http://arc062.contest.atcoder.jp/data/arc/062/editorial.pdf
    # KeyInsight：各状態で，できるだけ得票数が少ないほうがよい
    # 高橋君にA票，青木君にB票あるとき，満たすべき比率がx：yだとすると，
    # A <= m * x ^ B <= m * yとなるような最小の自然数mを取ればよい
    for i in range(n):
        ti, ai = map(int, input().split())
        m = max(ceil(vote_t / ti), ceil(vote_a / ai))
        vote_t = ti * m
        vote_a = ai * m

    print(vote_t + vote_a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x=0
t=0
n=0
pre_t=1
pre_n=1
for i in range(N):
    t,n = map(int,input().split())
    if(pre_t >= t or pre_n >= n):
        mul = max(math.ceil(pre_t/t),math.ceil(pre_n/n))
        t *= mul
        n *= mul
    pre_t = t
    pre_n = n
    x = t+n
print(x)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x=0
t=0
n=0
pre_t=1
pre_n=1
for i in range(N):
    t,n = map(int,input().split())
    if(pre_t > t or pre_n > n):
        mul = max(math.ceil(pre_t/t),math.ceil(pre_n/n))
        t *= mul
        n *= mul
    pre_t = t
    pre_n = n
    x = t+n
print(x)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x=0
t=0
n=0
pre_t=0
pre_n=0
for i in range(N):
    t,n = map(int,input().split())
    mul = max(math.ceil(pre_t/t),math.ceil(pre_n/n))
    t *= mul
    n *= mul
    pre_t = t
    pre_n = n
    x = t+n
print(x)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
x=0
t=0
n=0
pre_t=0
pre_n=0
for i in range(N):
    t,n = map(int,input().split())
    if(pre_t > t or pre_n > n):
        mul = max(math.ceil(pre_t/t),math.ceil(pre_n/n))
        t *= mul
        n *= mul
    pre_t = t
    pre_n = n
    x = t+n
print(x)

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())
    if i != 0:
        t = math.ceil(T[i-1]/T[i])
        a = math.ceil(A[i-1]/A[i])
        T[i] *= max(t, a)
        A[i] *= max(t, a)

#print(T,A)
print(T[-1]+A[-1])

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())
    if i != 0:
        if T[i] > T[i-1] and A[i] > A[i-1]:
            pass
        else:
            t = math.ceil(T[i-1]/T[i])
            a = math.ceil(A[i-1]/A[i])
            T[i] *= max(t, a)
            A[i] *= max(t, a)

print(T[-1]+A[-1])

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = [[int(i) for i in input().split()] for _ in range(N)]
T = 1
A = 1
for l in L:
    k = max(math.ceil(T/l[0]), math.ceil(A/l[1]))
    T, A = k*l[0], k*l[1]
print(T+A)

Submission status: Wrong Answer

Solution code:
import math

N=int(input())
num=[[1,1]]
for _ in range(N):
    num.append(list(map(int,input().split())))

for i in range(1,N+1):
    t=num[i][0]
    a=num[i][1]
    cnt_t=math.ceil(num[i-1][0]/t)
    cnt_a=math.ceil(num[i-1][1]/a)
    num[i][0]=max(cnt_t,cnt_a)*t
    num[i][1]=max(cnt_t,cnt_a)*a
    #print(i,t,a,cnt_t,cnt_a,num[i])
print(sum(num[-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
x, y = 0, 0
for i in range(N):
  a, b = map(int, input().split())
  mul = max((x-1)//a+1, (y-1)//b+1)
  x = mul*a
  y = mul*b
print(x+y)

Submission status: Wrong Answer

Solution code:
A, B = 1, 1
for _ in range(int(input())):
    x, y = map(int, input().split())
    n = max(-(-A // x), -(-B // y))
    A, B = n * x, n * y

    print(A, B)

print(A + B)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A, B = 1, 1

for _ 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:
import math

N = int(input())
p = 1
q = 1

for _ in range(N):
    t, a = map(int, input().split())
    n = max(math.ceil(p / t), math.ceil(q / a))
    p, q = n * t, n * a

print(p + q)

Submission status: Wrong Answer

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

print(A+T)

Submission status: Wrong Answer

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

print(A+T)

Submission status: Wrong Answer

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

print(A+T)

Submission status: Wrong Answer

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

print(A+T)

Submission status: Wrong Answer

Solution code:
N=int(input())
 
X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
 
 
def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)
 
 
a=X[0][0]
b=X[0][1]
 
for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
 

  x=ceil(a/c)
  y=ceil(b/d)
  
  a1=1000000000000000000
  b1=1000000000000000000
  a2=1000000000000000000
  b2=1000000000000000000
  if d*x-b>=0:
    a1=c*x
    b1=d*x
 
  
  if c*y-a>=0:
    a2=c*y
    b2=d*y
  if (a1+b1)<(a2+b2):
    a=a1
    b=b1
  else:
    a=a2
    b=b2
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" a1 = "+str(a1)+" b1 = "+str(b1)+" a2 = "+str(a2)+" b2 = "+str(b2)+" c = "+str(c)+" d = "+str(d))
  
 
 
 
 
  
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())
 
X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
 
 
def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)
 
 
a=X[0][0]
b=X[0][1]
 
for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
 

  x=ceil(a/c)
  y=ceil(b/d)
  
  a1=100000000000
  b1=100000000000
  a2=100000000000
  b2=100000000000
  if d*x-b>=0:
    a1=c*x
    b1=d*x
 
  
  if c*y-a>=0:
    a2=c*y
    b2=d*y
  if (a1+b1)<(a2+b2):
    a=a1
    b=b1
  else:
    a=a2
    b=b2
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" a1 = "+str(a1)+" b1 = "+str(b1)+" a2 = "+str(a2)+" b2 = "+str(b2)+" c = "+str(c)+" d = "+str(d))
  
 
 
 
 
  
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())
 
X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
 
 
def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)
 
 
a=X[0][0]
b=X[0][1]
 
for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
 
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d))
  x=ceil(a/c)
  y=ceil(b/d)
  
  a1=100000000000
  b1=100000000000
  if d*x-b>=0:
    a1=c*x
    b1=d*x
 
  
  if c*y-a>=0:
    a2=c*y
    b2=d*y
    if (a1+b1)<(a2+b2):
      a=a1
      b=b1
    else:
      a=a2
      b=b2

  
 
 
 
 
  
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())
 
X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
 
 
def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)
 
 
a=X[0][0]
b=X[0][1]
 
for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=ceil(a/c)*d-b
  else:
    y=ceil(a/c)*d-b
 
  if y<0:
    y=y%d
 
 
  x=c*(b+y)//d-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]

 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d))
  x=ceil(a/c)
  y=ceil(b/d)
  

  if d*x-b>=0:
    a=c*x
    b=d*x

  
  elif c*y-a>=0:
    a=c*y
    b=d*y
  




  
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]

 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d))

  a=max(ceil(a/c),ceil(b/d))*c
  b=max(ceil(a/c),ceil(b/d))*d
  
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  y=ceil(max(b/d,a/c))*d-b
  
  x=ceil(max(b/d,a/c))*c-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  y=ceil(b/d)*d-b
  
  x=ceil(a/c)*c-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


def ceil(x):
  if int(x)==x:
    return int(x)
  else:
    return int(x//1+1)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  y=ceil(max(b/d,a/c))*d-b
  
  x=c*(b+y)//d-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


import math

a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=-b%d
  else:
    y=math.ceil(a/c)*d-b%d

  while y<0:
    y+=d


  x=c*(b+y)//d-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


import math

a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=-b%d
  else:
    y=math.ceil(a/c)*d-b

  while y<0:
    y+=d


  x=c*(b+y)//d-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


import math

a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=-b%d
  else:
    y=math.ceil(a/c)*d-b

  x=int(c/d*(b+y))-a
 
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])


import math

a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  a1=a*d/c
  if a1<b:
    y=-b%d
  else:
    y=math.ceil(a/c)*d-b

  x=c*(b+y)//d-a
 
  
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())

X=[]
for i in range(N):
  a=input().split()
  X.append([int(a[0]),int(a[1])])
#print(X)


a=X[0][0]
b=X[0][1]

for i in range(1,N):
  c=X[i][0]
  d=X[i][1]
  if (b*c/d)==int(b*c/d):
    x=int(b*c/d)-a
  else:
    x=int(b/d+1)*c-a
  if x<0:
    x=x%c





  y=int(d*(a+x)/c)-b
  #print("i = "+str(i)+" a = "+str(a)+" b = "+str(b)+" c = "+str(c)+" d = "+str(d)+" x = "+str(x)+" y = "+str(y))
  a=a+x
  b=b+y
print(a+b)

Submission status: Wrong Answer

Solution code:
n = int(input())
tWahl = 0
aWahl = 0

for i in range(n):
    t, a = input().split()
    t = int(t)
    a = int(a)
    while tWahl == 0 or tWahl % t != 0:
        tWahl += t
        tWahl -= (tWahl % t)
    while aWahl == 0 or aWahl % a != 0:
        aWahl += a
        aWahl -= (aWahl % a)
    
    if t*aWahl < a*tWahl:
        aWahl = int(tWahl*a/t)
    elif t*aWahl > a*tWahl:
        tWahl = int(aWahl*t/a)

print(tWahl + aWahl)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
para = [[i for i in map(int,input().split())] for j in range(N)]
now=  [[0,0] for i in range(N+1)]
now[0] = [1,1]

for i in range(N):
    n = max(math.ceil(now[i][0]/para[i][0]),math.ceil(now[i][1]/para[i][1]))
    now[i+1] = [n*para[i][0],n*para[i][1]]

print(sum(now[-1]))

Submission status: Wrong Answer

Solution code:
import math

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

A, B = 1, 1

for t in TA:
    n = max(math.ceil(A / t[0]), math.ceil(B / t[1]))
    A, B = t[0] * n, t[1] * n

print(A + B)

Submission status: Wrong Answer

Solution code:
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())
    
vote_num = A[0] + T[0]
for i in range(1, N):
    if vote_num % (A[i] + T[i]) != 0:
        vote_num = (vote_num // (A[i] + T[i]) + 1) * (A[i] + T[i])

print(vote_num)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
TA = [[int(_) for _ in input().split()] for _ in range(N)]
tak = TA[0][0]
aok = TA[0][1]

if N == 1:
    print(tak+aok)
else:
    for i in range(1, N):
        nowTrate = TA[i][0]
        nowArate = TA[i][1]
        y = max(math.ceil(tak/nowTrate), math.ceil(aok/nowArate))
        tak = nowTrate * y
        aok = nowArate * y
    print(tak+aok)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = math.ceil(x/a)
    yb = math.ceil(y/t)
    c = max(xa,yb)
    x,y = a*c,t*c
print(x+y)

Submission status: Wrong Answer

Solution code:
from math import ceil

N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 2; total_t = 1; total_a = 1;
for t, a in ratio:
    q = max(ceil(total_t / t), ceil(total_a / a))
    total_t = t*q
    total_a = a*q
    ans = total_t + total_a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0; total_t = 0; total_a = 0;
for t, a in ratio:
    q = max(total_t  //  t, total_a // a) + 1
    total_t = t*q
    total_a = a*q
    ans = total_t + total_a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0; total_t = 0; total_a = 0;
for t, a in ratio:
    q = min(total_t  //  t, total_a // a) + 1
    total_t = t*q
    total_a = a*q
    ans = total_t + total_a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0; total_t = 0; total_a = 0;
for t, a in ratio:
    i = 1
    while total_t > t*i and total_a > a*i:
        i += 1
    total_t = t*i
    total_a = a*i
    ans = total_t + total_a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0; total_t = 0; total_a = 0;
for t, a in ratio:
    i = 1
    while total_t > t*i and total_a > a*i:
        i += 1
    ans = (t + a)*i
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ratio = []
for _ in range(N):
    ratio.append(tuple(map(int, input().split())))
ans = 0
for t, a in ratio:
    temp = t + a
    i = 1
    while ans > temp*i:
        i += 1
    ans = temp*i
print(ans)

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    m = max(math.ceil(T_current / T), math.ceil(A_current / A))
    T_current = T * m
    A_current = A * m
print(int(A_current + T_current))

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    m = max(math.ceil(T_current / T), math.ceil(A_current / A))
    T_current, A_current = T * m, A * m
print(int(A_current + T_current))

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    if T < A:
        T_new = T * (math.ceil(T_current / T))
        A_new = T_new * A / T
        if A_new < A_current:
            A_new = A * (math.ceil(A_current / A))
            T_new = A_new * T / A
    else:
        A_new = A * (math.ceil(A_current / A))
        T_new = A_new * T / A
        if T_new < T_current:
            T_new = T * (math.ceil(T_current / T))
            A_new = T_new * A / T
    T_current = T_new
    A_current = A_new
print(int(A_current + T_current))

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    if T > A:
        T_new = T * math.ceil(T_current / T)
        A_new = T_new * A / T
        mult = math.ceil(A_current / A_new)
        T_current = T_new * mult
        A_current = A_new * mult
    else:
        A_new = A * math.ceil(A_current / A)
        T_new = A_new * T / A
        mult = math.ceil(T_current / T_new)
        T_current = T_new * mult
        A_current = A_new * mult

print(int(A_current + T_current))

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    T_min = T * (math.ceil(T_current / T))
    A_min = A * (math.ceil(A_current / A))
    A_cand = T_min * A / T
    T_cand = A_min * T / A
    if T_min + A_cand < A_min + T_cand:
        if A_cand >= A_current:
            T_current = T_min
            A_current = A_cand
        else:
            T_current = T_cand
            A_current = A_min
    else:
        if T_cand >= T_current:
            T_current = T_cand
            A_current = A_min
        else:
            T_current = T_min
            A_current = A_cand

print(int(A_current + T_current))

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    T_min = T * (math.ceil(T_current / T))
    A_min = A * (math.ceil(A_current / A))
    if T < A:
        if T_min * A / T >= A_current:
            T_current = T_min
            A_current = T_min * A / T
        else:
            A_current = A_min
            T_current = A_min * T / A
    else:
        if A_min * T / A >= T_current:
            A_current = A_min
            T_current = A_min * T / A
        else:
            T_current = T_min
            A_current = T_min * A / T

print(int(A_current + T_current))

Submission status: Wrong Answer

Solution code:
import math


N = int(input())
T_current, A_current = 1,1

for i in range(N):
    T, A = map(int, input().split())
    T_min = T * (math.ceil(T_current / T))
    A_min = A * (math.ceil(A_current / A))
    if T < A:
        if T_min * A / T >= A_min:
            T_current = T_min
            A_current = T_min * A / T
        else:
            A_current = A_min
            T_current = A_min * T / A
    else:
        if A_min * T / A >= T_min:
            A_current = A_min
            T_current = A_min * T / A
        else:
            T_current = T_min
            A_current = T_min * A / T

print(int(A_current + T_current))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# WA math.ceilは浮動小数点演算の影響を受けるので、正しく切り上げできないときがある
# >>> math.ceil((12345678901234*456+0.1)/12345678901234)
# 456
# >>> math.ceil((12345678901234*456+1)/12345678901234)
# 457

import math

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

# ans = vote_ratio[0] は同じオブジェクトを参照してしまうので避ける
ans = [vote_ratio[0][0], vote_ratio[0][1]]

for i in range(1,n):
	bairitsu = max(ans[0] / vote_ratio[i][0], ans[1] / vote_ratio[i][1])
	# bairitsu = math.ceil(bairitsu)
	bairitsu =  int(bairitsu)
	if vote_ratio[i][0] * bairitsu < ans[0] \
	or vote_ratio[i][1] * bairitsu < ans[1]:
		bairitsu += 1
	ans = [vote_ratio[i][0] * bairitsu, vote_ratio[i][1] * bairitsu]

print(sum(ans))

Submission status: Wrong Answer

Solution code:
import math

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

# ans = vote_ratio[0] は同じオブジェクトを参照してしまうので避ける
ans = [vote_ratio[0][0], vote_ratio[0][1]]

for i in range(1,n):
	bairitsu = max(ans[0] / vote_ratio[i][0], ans[1] / vote_ratio[i][1])
	bairitsu = math.ceil(bairitsu)
	ans = [vote_ratio[i][0] * bairitsu, vote_ratio[i][1] * bairitsu]

print(sum(ans))

Submission status: Wrong Answer

Solution code:
import math

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

v1 = T[0]
v2 = A[0]

for i in range(1, N):
    if v1<=T[i] and v2<=A[i]:
        v1 = T[i]
        v2 = A[i]
    else:
        n = math.ceil(max(v1/T[i], v2/A[i]))
        v1 = T[i]*n
        v2 = A[i]*n

print(v1+v2)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(1, N):
    n = 1
    if v1<=T[i] and v2<=A[i]:
        v1 = T[i]
        v2 = A[i]
    else:
        n = math.ceil(max(v1/T[i], v2/A[i]))
        v1 = T[i]*n
        v2 = A[i]*n

print(v1+v2)