input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
n = int(eval(input()))
re_t = 0
re_a = 0
for i in range(n):
t, a = list(map(int, input().split(' ')))
n = 1
while n*t < re_t or n*a < re_a:
n += 1
re_t = n * t
re_a = n * a
print((re_t + re_a)) | import math
n = int(eval(input()))
a,b = 1,1
for i in range(n):
x,y = list(map(int, input().split(' ')))
tmp = max(-(-a//x), -(-b//y))
a = x * tmp
b = y * tmp
print((a+b)) | p03964 |
N = int(eval(input()))
T = A = 1
for _ in range(N):
t, a = list(map(int, input().split()))
k = max([1, T // t + (T % t != 0), A // a + (A % a != 0)])
T, A = k * t, k * a
print((T + A)) | n = int(eval(input()))
t = 1
a = 1
for i in range(n):
T, A = list(map(int, input().split()))
k = max(1, ~-t//T + 1, ~-a//A + 1)
t = k * T
a = k * A
print((t + a)) | p03964 |
n = int(eval(input()))
t = 1
a = 1
for i in range(n):
T, A = list(map(int, input().split()))
k = max(1, ~-t//T + 1, ~-a//A + 1)
t = k * T
a = k * A
print((t + a)) | n = int(eval(input()))
t = 1
a = 1
for i in range(n):
T, A = list(map(int, input().split()))
k = max(~-t//T + 1, ~-a//A + 1)
t = k * T
a = k * A
print((t + a)) | p03964 |
# -*- coding: utf-8 -*-
N = int(eval(input()))
TA = []
for _ in range(N):
TA.append(list(map(int, input().split())))
t0,a0 = 0,0
hyo = 0
for i in range(N):
t,a = TA[i]
if t0 == t and a0 == a:
pass
else:
tmpt,tmpa = t,a
if t0 > t or a0 > a:
while t0 > t... | # -*- coding: utf-8 -*-
N = int(eval(input()))
TA = []
for _ in range(N):
TA.append(list(map(int, input().split())))
t0,a0 = 0,0
for i in range(N):
t,a = TA[i]
if t0 == t and a0 == a:
pass
else:
if t0 > t or a0 > a:
tmp = max([t0//t + min([1, t0 % t]), a0//a + m... | p03964 |
import fractions
N=int(eval(input()))
vt=va=0
for _ in range(N):
T,A=list(map(int,input().split()))
kt=-(-vt//T)
ka=-(-va//A)
if kt==0 and ka==0:
vt=T
va=A
else:
k=max(kt,ka)
vt=k*T
va=k*A
#print(vt,va)
print((vt+va)) | N=int(eval(input()))
vt=va=0
for _ in range(N):
T,A=list(map(int,input().split()))
kt=-(-vt//T)
ka=-(-va//A)
k=max(kt,ka,1)
vt=k*T
va=k*A
#print(vt,va)
print((vt+va)) | p03964 |
def func(n,x):
if n%x!=0:
return n+(x-n%x)
else:
return n
X=[]
n=int(eval(input()))
for i in range(n):
t,a=list(map(int,input().split()))
X.append([t,a])
T=X[0][0]
A=X[0][1]
for i in range(1,n):
if T<=X[i][0] and A<=X[i][1]:
T=X[i][0]
A=X[i][1]
... | X=[]
n=int(eval(input()))
for i in range(n):
t,a=list(map(int,input().split()))
X.append([t,a])
T=X[0][0]
A=X[0][1]
for i in range(1,n):
N=max(-(-T//X[i][0]),-(-A//X[i][1]))
T=X[i][0]*N
A=X[i][1]*N
print((T+A))
| p03964 |
import math
import fractions
N=int(eval(input()))
t,a=1,1
for i in range(N):
T,A=list(map(int,input().split()))
Te,Ae=T,A
if t>T or a>A:
T,A=T*math.ceil((t+a)/(T+A)),A*math.ceil((t+a)/(T+A))
while t>T or a>A:
T+=Te
A+=Ae
t,a=T,A
print((t+a))
| import fractions
N=int(eval(input()))
t,a=1,1
for i in range(N):
T,A=list(map(int,input().split()))
n=max(-(-a//A),-(-t//T))
# n=max(fractions.ceil(a/A),fractions.ceil(t/T))
t,a=n*T,n*A
print((t+a))
| p03964 |
n = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(n)]
T = A = 0
for t, a in TA:
_t, _a = t, a
while t<T or a<A:
t += _t; a += _a
T = t; A = a
print((T+A)) | n = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(n)]
T = A = 1
for t, a in TA:
r = max(A//a, T//t)
if r*a >= A and r*t >= T:
A = r*a; T = r*t
else:
A = (r+1)*a; T = (r+1)*t
print((T+A)) | p03964 |
import math
from decimal import Decimal
n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
for k in range(n):
if k:
m0 = math.ceil(Decimal(a[k-1][0])/Decimal(a[k][0]))
m1 = math.ceil(Decimal(a[k-1][1])/Decimal(a[k][1]))
m = max(m0, m1)
a[k] = [m... | from math import ceil
from decimal import Decimal as Deci
n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
for k in range(n):
if k:
m0 = ceil(Deci(a[k-1][0])/Deci(a[k][0]))
m1 = ceil(Deci(a[k-1][1])/Deci(a[k][1]))
m = max(m0, m1)
a[k] = [m*a[k... | p03964 |
N = int(eval(input()))
def check(t, a):
T, A = list(map(int, input().split()))
if T >= t and A >= a:
t = T
a = A
return t, a
if T >= t and A < a:
t = T * ((a + (A-1))//A)
a = A * ((a + (A-1))//A)
return t, a
if T < t and A >= a:
t = T... | N = int(eval(input()))
def check(t, a):
T, A = list(map(int, input().split()))
t = T * max((t + (T-1))//T, (a + (A-1))//A)
a = A * max((t + (T-1))//T, (a + (A-1))//A)
return t, a
t = 1
a = 1
for _ in range(N):
t, a = check(t, a)
print((t + a)) | p03964 |
n = int(eval(input()))
x, y = [int(i) for i in input().split()]
for i in range(n-1):
t, a = [int(i) for i in input().split()]
if t >= x and a >= y:
x = t
y = a
else:
c = 2
while True:
x_ = t * c
y_ = a * c
if x_ >= x and y_ >= y:
break
c += 1
... | n = int(eval(input()))
x, y = [int(i) for i in input().split()]
for i in range(n-1):
t, a = [int(i) for i in input().split()]
if t >= x and a >= y:
x = t
y = a
else:
c = max(-(-x//t), -(-y//a))
x = t * c
y = a * c
print((x+y)) | p03964 |
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, digi... | 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, digi... | p03964 |
from math import ceil
from decimal import Decimal
N = int(eval(input()))
T,A = [],[]
for i in range(N):
t,a = list(map(int,input().split()))
T.append(t)
A.append(a)
t,a = 1,1
for i in range(N):
r = Decimal(max(ceil(t/T[i]),ceil(a/A[i])))
t = r*T[i]
a = r*A[i]
print((t+a)) | # python3 (3.4.3)
import sys
input = sys.stdin.readline
# main
from math import ceil
from decimal import *
N = int(eval(input()))
TA = [list(map(int,input().split())) for _ in range(N)]
t,a = 1,1
for i in range(N):
n = Decimal(max(ceil(t/TA[i][0]), ceil(a/TA[i][1])))
t = n*TA[i][0]
a = n*T... | p03964 |
N = int(eval(input()))
def func(T_pre, A_pre, T, A):
for i in range(1, 10**10):
if T_pre <= T and A_pre <= A:
return T, A
else:
T = T*(i+1)/i
A = A*(i+1)/i
for i in range(N):
T, A = list(map(int, input().split()))
if i == 0:
T_pre = T
A_pre = A
else:
T_pre, A_... | N = int(eval(input()))
def func(T_pre, A_pre, T, A):
if T_pre <= T and A_pre <= A:
return T, A
else:
t = -(-T_pre//T)
a = -(-A_pre//A)
x = max(t, a)
return T*x, A*x
for i in range(N):
T, A = list(map(int, input().split()))
if i == 0:
T_pre = T
A_pre = A
else:
T_p... | p03964 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemge... | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemge... | p03964 |
N = int(eval(input()))
vote = [1,1]
for i in range(N):
ratio = list(map(int, input().split()))
for j in range(2):
while(vote[j] % ratio[j] != 0):
vote[j] += 1
if vote[0] * ratio[1] < vote[1] * ratio[0]:
while (vote[0] * ratio[1] != vote[1] * ratio[0]):
vote[0... | N = int(eval(input()))
vote = [1,1]
for i in range(N):
ratio = list(map(int, input().split()))
for j in range(2):
while(vote[j] % ratio[j] != 0):
vote[j] += 1
if vote[0] * ratio[1] < vote[1] * ratio[0]:
vote[0] = vote[1] // ratio[1] * ratio[0];
if vote[0] * ratio[1] ... | p03964 |
n = int(eval(input()))
A = [list(map(int,input().split())) for i in range(n)]
# def gcd(x, y):
# #print(x, y)
# while x != 0 and y != 0:
# x, y = max(x, y), min(x, y)
# x %= y
# return y
# def lcm(x, y):
# return x * y // gcd(x, y)
# for i in range(1, n):
# lcms = [0... | n = int(eval(input()))
A = [list(map(int,input().split())) for i in range(n)]
# def gcd(x, y):
# #print(x, y)
# while x != 0 and y != 0:
# x, y = max(x, y), min(x, y)
# x %= y
# return y
# def lcm(x, y):
# return x * y // gcd(x, y)
# for i in range(1, n):
# lcms = [0... | p03964 |
n = int(eval(input()))
ta = [[int(i) for i in input().split()] for j in range(n)]
a = ta[0][0]
b = ta[0][1]
for i in range(1, n):
tempa = ta[i][0]
tempb = ta[i][1]
j = 2
while(tempa < a or tempb < b):
tempa = ta[i][0] * j
tempb = ta[i][1] * j
j += 1
a = tempa
... | import math
n = int(eval(input()))
ta = [[int(i) for i in input().split()] for j in range(n)]
a = 1
b = 1
for i in range(n):
#n = max(math.floor(a/ta[i][0]), math.floor(b/ta[i][1]))
n = max(~-a//ta[i][0] + 1, ~-b//ta[i][1] + 1)
a = n * ta[i][0]
b = n * ta[i][1]
print((a+b))
| p03964 |
n = int(eval(input()))
x,y = list(map(int,input().split()))
for i in range(n-1):
t,a = list(map(int,input().split()))
o = t
p = a
while x > o or y > p:
o += t
p += a
x = o
y = p
print((x+y)) | n = int(eval(input()))
A,B = 0,0
for i in range(n):
x,y = list(map(int,input().split()))
t,a = 1,1
if A > x:
t = A // x
if A % x != 0:
t += 1
if B > y:
a = B // y
if B % y != 0:
a += 1
m = max(t,a)
A = x*m
B = y*m
print(... | p03964 |
def find_current_score(current_big_score, current_small_score, big_ratio, small_ratio):
candidate_big_score = current_big_score
candidate_small_score = 0
while(True):
candidate_small_score = candidate_big_score / big_ratio * small_ratio
flag1 = candidate_small_score % 1 == 0.0
... | def compute_current_score(previous_t_score, previous_a_score, current_t_ratio, current_a_ratio):
initial_divisor = max(previous_t_score // current_t_ratio, previous_a_score // current_a_ratio)
current_t_score = 0
current_a_score = 0
while(True):
current_t_score = initial_divisor * current_t... | p03964 |
# C問題
N = int(eval(input()))
TA = []
for i in range(N):
TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1, N+1):
tmp_t = 0
tmp_a = 0
if i == N:
flag = False
while flag:
tmp_t += TA[i][... | # C問題
N = int(eval(input()))
TA = []
for i in range(N):
TA.append(list(map(int, input().split())))
#T, A互いに素なので1枚目はそのまま取ってきて良い
t = TA[0][0]
a = TA[0][1]
flag = True
for i in range(1, N+1):
tmp_t = 0
tmp_a = 0
if i == N:
flag = False
break
k = max(t // TA[i][0], a // T... | p03964 |
n=int(eval(input()))
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
if (ta[i-1][0]<ta[i][0]) and (ta[i-1][1]<ta[i][1]):
pass
else:
r=ta[i][0]
l=ta[i][1]
while (ta[i-1][0]>ta[i][0]) or (ta[i-1][1]>ta[i][1]):
ta[i][0]+=r
ta[i][1]+=l
print((... | n=int(eval(input()))
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
if (ta[i-1][0]<=ta[i][0]) and (ta[i-1][1]<=ta[i][1]):
pass
else:
l=ta[i-1][0]//ta[i][0]
if ta[i-1][0]%ta[i][0]!=0:
l+=1
r=ta[i-1][1]//ta[i][1]
if ta[i-1][1]%ta[i][1]!=0:
... | p03964 |
N=int(eval(input()))
import copy
inp=[]
for i in range(N):
inp.append(list(map(int,input().split(" "))))
def compare(A,B):
if A[0]>=B[0] and A[1]>=B[1]:
return A
else:
A0=copy.copy(A[0])
A1=copy.copy(A[1])
while A0<B[0] or A1<B[1]:
A0+=A[0]
... | N=int(eval(input()))
import copy
inp=[]
for i in range(N):
inp.append(list(map(int,input().split(" "))))
def compare(A,B):
if A[0]>=B[0] and A[1]>=B[1]:
return A
else:
if B[0]%A[0]!=0:
i=B[0]//A[0]+1
else:
i=B[0]//A[0]
if B[1]%A[1]!=0:
... | p03964 |
N = int(eval(input()))
t = []
a = []
for i in range(0,N):
tokuhyousuu = list(map(int,input().split()))
t.append(tokuhyousuu[0])
a.append(tokuhyousuu[1])
T = t[0]
A = a[0]
r = 1
r_2 = 1
for j in range(0,N):
if(T<=t[j] and A<=a[j]):
T = t[j]
A = a[j]
elif(T>t[j] and A>a[j]):
for k in rang... | N = int(eval(input()))
t = []
a = []
for i in range(0,N):
tokuhyousuu = list(map(int,input().split()))
t.append(tokuhyousuu[0])
a.append(tokuhyousuu[1])
T = 1
A = 1
for j in range(0,N):
if(T<=t[j] and A<=a[j]):
T = t[j]
A = a[j]
elif(T>t[j] and A>a[j]):
if(T%t[j] == 0):
r_1 = T//t[j]
... | p03964 |
n = int(eval(input()))
x, y = 1, 1
for _ in range(n):
t, a = list(map(int, input().split()))
if x <= t and y <= a:
x = t
y = a
elif x <= t and y > a:
i = 1
while y > a:
a //= i
i += 1
a *= i
x = i*t
y = a
... | n = int(eval(input()))
x, y = 1, 1
for _ in range(n):
t, a = list(map(int, input().split()))
if x <= t and y <= a:
x = t
y = a
elif x <= t and y > a:
if y % a == 0:
i = y // a
else:
i = y // a + 1
y = i*a
x = i*t
elif ... | p03964 |
n=int(eval(input()))
suji=[]
for i in range (n):
suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
if i%2==0:
tlist.append(suji[i])
else:
alist.append(suji[i])
for i in range(n-1):
k=1
while tlist[i]>tlist[i+1]*k or alist[i]>alist[i+1]*k:
k+=1
tlist[i+1]=tlist[... | n=int(eval(input()))
suji=[]
for i in range (n):
suji=suji+list(map(int,input().split()))
tlist=[]
alist=[]
for i in range(2*n):
if i%2==0:
tlist.append(suji[i])
else:
alist.append(suji[i])
for i in range(n-1):
aaa=alist[i]//alist[i+1]
ttt=tlist[i]//tlist[i+1]
if alist[i]%alist[i+1]!=0:
aaa... | p03964 |
n=int(eval(input()))
p,q=1,1
for _ in range(n):
t,a=list(map(int,input().split()))
n=1
while p>n*t or q>n*a:
n+=1
p,q=n*t,n*a
print((p+q)) | n=int(eval(input()))
p,q=1,1
for _ in range(n):
t,a=list(map(int,input().split()))
#n=1
#hile p>n*t or q>n*a:
# n+=1
n=max((p+t-1)//t,(q+a-1)//a)
p,q=n*t,n*a
#print(n,p,q)
print((p+q)) | p03964 |
N=int(eval(input()))
TA=[list(map(int, input().split())) for _ in range(N)]
ls=[[TA[0][0],TA[0][1]]]
for i in range(1,N):
tmp=[TA[i][0],TA[i][1]]
j=2
while 1:
if tmp[0]>=ls[-1][0] and tmp[1]>=ls[-1][1]:
break
tmp[0]=TA[i][0]*j
tmp[1]=TA[i][1]*j
j+=1
... | N=int(eval(input()))
TA=[list(map(int, input().split())) for _ in range(N)]
ls=[[TA[0][0],TA[0][1]]]
for i in range(1,N):
tmp=[TA[i][0],TA[i][1]]
a=max(-(ls[-1][0]//(-tmp[0])),-(ls[-1][1]//(-tmp[1])))
tmp[0]*=a
tmp[1]*=a
ls.append([tmp[0],tmp[1]])
print((ls[-1][0]+ls[-1][1]))
| p03964 |
def main():
n = int(eval(input()))
t = []
a = []
for i in range(n):
in_t,in_a = list(map(int,input().split(' ')))
t.append(in_t)
a.append(in_a)
if n == 1:
return t[0]+a[0]
tmp_t = t[0]
tmp_a = a[0]
for i in range(1,n):
while True:
... | def main():
n = int(eval(input()))
t = []
a = []
for i in range(n):
in_t,in_a = list(map(int,input().split(' ')))
t.append(in_t)
a.append(in_a)
if n == 1:
return t[0]+a[0]
tmp_t = t[0]
tmp_a = a[0]
for i in range(1,n):
if tmp_t%t[i] !=... | p03964 |
from sys import stdin
n = int(stdin.readline())
t_votes, a_votes = (int(x) for x in stdin.readline().split())
p_t, p_a = t_votes, a_votes
for _ in range(n-1):
t, a = (int(x) for x in stdin.readline().split())
if (t, a) == (p_t, p_a):
continue
for i in range(1, 1000000):
t_v,... | from sys import stdin
n = int(stdin.readline())
m = 10 ** 18 + 7
t_votes, a_votes = (int(x) for x in stdin.readline().split())
p_t, p_a = t_votes, a_votes
for _ in range(n-1):
t, a = (int(x) for x in stdin.readline().split())
if (t, a) == (p_t, p_a):
continue
for i in range(max(... | p03964 |
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
NT=1
NA=1
for i in range(N):
T,A=MI()
xt=NT//T
xa=NA//A
... | import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
NT=1
NA=1
for i in range(N):
T,A=MI()
xt=(NT+T-1)//T
xa=(N... | p03964 |
n = int(eval(input()))
t, a = [0] * n, [0] * n
for i in range(n):
t[i], a[i] = list(map(int, input().split()))
ans = a[0] + t[0]
j_pre = 1
for i in range(1, n):
j = 1
vote = t[i] + a[i]
while vote * j < ans or (t[i] * j < t[i - 1] * j_pre or a[i] * j < a[i - 1] * j_pre):
j += 1
... |
n = int(eval(input()))
t, a = [0] * n, [0] * n
for i in range(n):
t[i], a[i] = list(map(int, input().split()))
ans = a[0] + t[0]
j_pre = 1
for i in range(1, n):
j = max(-(-(t[i - 1] * j_pre) // t[i]), -(-(a[i - 1] * j_pre) // a[i]) )
ans = (t[i] + a[i]) * j
j_pre = j
#print(t[i] * j, a[i... | p03964 |
n = int(eval(input()))
x = 1
y = 1
for i in range(n):
t, a = [int(_) for _ in input().split()]
tt = t
aa = a
while tt < x or aa < y:
tt += t
aa += a
x = tt
y = aa
print((x+y)) | # import math
n = int(eval(input()))
x = 1
y = 1
for i in range(n):
t, a = [int(_) for _ in input().split()]
if x%t == 0:
kt = x//t
else:
kt = x//t + 1
if y % a == 0:
ka = y // a
else:
ka = y // a + 1
k = max(kt, ka)
x = t*k
y = a*k
pr... | p03964 |
N = int(eval(input()))
T = 0
A = 0
for _ in range(N):
t, a = list(map(int, input().split()))
i = 1
while T > i*t or A > i*a:
i += 1
T = i*t
A = i*a
print((T+A)) | N = int(eval(input()))
T = 0
A = 0
for _ in range(N):
t, a = list(map(int, input().split()))
i = max(T//t, A//a, 1)
while T > i*t or A > i*a:
i += 1
T = i*t
A = i*a
print((T+A)) | p03964 |
n=int(eval(input()))
for i in range(n):
if i==0:
x,y=list(map(int,input().split()))
else:
t,a=list(map(int,input().split()))
v=t
w=a
while v<x or w<y:
v+=t
w+=a
x=v
y=w
print((x+y))
| n=int(eval(input()))
x=1
y=1
for i in range(n):
t,a=list(map(int,input().split()))
c=max(-(-x//t),-(-y//a))
x=t*c
y=a*c
print((int(x+y)))
| p03964 |
n = int(eval(input()))
t = []
a = []
for i in range(0, n):
ti, ai = [int(_) for _ in input().split()]
t.append(ti)
a.append(ai)
newest_t = t[0]
newest_a = a[0]
for i in range(0, n):
div_t = newest_t // t[i]
div_a = newest_a // a[i]
for j in range(min(div_t, div_a)-1, max(div_... | n = int(eval(input()))
t = []
a = []
for i in range(0, n):
ti, ai = [int(_) for _ in input().split()]
t.append(ti)
a.append(ai)
newest_t = t[0]
newest_a = a[0]
for i in range(0, n):
div_t = newest_t // t[i]
div_a = newest_a // a[i]
for j in range(max(div_t, div_a)-1, max(div_... | p03964 |
import math
n = int(eval(input()))
ans = 0
pret = 0
prea = 0
for x in range(n):
t, a = list(map(int, input().split()))
if ans == 0 :
ans = t + a
pret = t
prea = a
else:
sum = t + a
ans = math.ceil(ans / sum) * sum
while (pret > (ans * t // sum)... | import math
n = int(eval(input()))
ans = 0
t_1, a_1 = list(map(int, input().split()))
pret = t_1
prea = a_1
for x in range(n - 1):
t, a = list(map(int, input().split()))
m = -min(-pret//t,-prea//a)
pret = m * t
prea = m * a
print((pret + prea)) | p03964 |
n=int(eval(input()))
t=[]
a=[]
for i in range(n):
ti,ai=list(map(int,input().split()))
t.append(ti)
a.append(ai)
ti=t[0]
ai=a[0]
for i in range(n-1):
ta=a[i+1]*t[i+1]
for ii in range(1,10000000):
if ta*ii//a[i+1]>=ti and ta*ii//t[i+1]>=ai:
ti=ta*ii//a[i+1]
... | icase=0
if icase==0:
n=int(eval(input()))
t=[0]*n
a=[0]*n
for i in range(n):
t[i],a[i]=list(map(int,input().split()))
elif icase==1:
n=5
t=[3,48,31,231,3]
a=[10,17,199,23,2]
ans=6930
ti=t[0]
ai=a[0]
dt=1
for i in range(n-1):
if ti/t[i+1]>ai/a[i+1]:
... | p03964 |
n=int(eval(input()))
a=1
b=1
for i in range(n):
ti,ai=list(map(int,input().split()))
m=1
while a>m*ti or b>m*ai:
m=m+1
# print(m,a,m*ti,b,m*ai)
# print(m,a,m*ti,b,m*ai)
a=m*ti
b=m*ai
# print(a,b,m)
print((a+b)) | n=int(eval(input()))
a=1
b=1
for i in range(n):
ti,ai=list(map(int,input().split()))
# m=max(int((a-1)/ti)+1,int((b-1)/ai)+1)
m=max(int((a-1)//ti)+1,int((b-1)//ai)+1)
a=m*ti
b=m*ai
print((a+b)) | p03964 |
N = int(eval(input()))
ratios = [[i for i in map(int,input().split())] for j in range(N)]
ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]
for ratio in ratios:
i = min(ans_a // ratio[0], ans_t // ratio[1])
while True:
temp_a = ratio[0]*i
temp_t = ratio[1]*i
... | N = int(eval(input()))
ratios = [[i for i in map(int,input().split())] for j in range(N)]
ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]
for ratio in ratios:
i = max(ans_a // ratio[0], ans_t // ratio[1])
while True:
temp_a = ratio[0]*i
temp_t = ratio[1]*i
if ... | p03964 |
N = int(eval(input()))
TA = [list(map(int, input().split(" "))) for _ in range(N)]
n_t, n_a = 1, 1
for t, a in TA:
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)) | N = int(eval(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(-(-n_t//t), -(-n_a//a))
n_t, n_a = t*v, a*v
print((n_t+n_a))
| p03964 |
N=int(eval(input()))
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1
def UP(V1,V2,R1,R2):
r1,r2=R1,R2
while V1>R1 or V2>R2:
R1+=r1
R2+=r2
return [R1,R2]
for i in range(N):
up=UP(Taka,Aoki,TA[i][0],TA[i][1])
Taka=up[0]
Aoki=up[1]
print((Taka... | N=int(eval(input()))
TA=[list(map(int,input().split())) for i in range(N)]
Taka=1
Aoki=1
def UP(V1,V2,R1,R2):
n=max(-(-V1//R1),-(-V2//R2))
return(n*R1,n*R2)
for i in range(N):
up=UP(Taka,Aoki,TA[i][0],TA[i][1])
# print(up)
Taka=up[0]
Aoki=up[1]
print((Taka+Aoki)) | p03964 |
N = int(eval(input()))
TT=0
AA=0
for k in range(N):
T,A = list(map(int,input().split()))
k=min(TT//T,AA//A)
for k in range(100000000000000000):
k+=1
if T*k>=TT and A*k>=AA:
TT=T*k
AA=A*k
break
print((TT+AA)) | N = int(eval(input()))
TT,AA= list(map(int,input().split()))
for k in range(1,N):
T,A = list(map(int,input().split()))
j = max((TT-1+T)//T,(AA-1+A)//A)
TT = T*j
AA = A*j
print((TT + AA)) | p03964 |
N = int(eval(input()))
a,b = list(map(int,input().split()))
for i in range(N-1):
aa,bb = list(map(int,input().split()))
taa,tbb = aa,bb
while True:
if aa >= a and bb >=b:
break
aa += taa
bb += tbb
a,b = aa,bb
print((a+b))
| N = int(eval(input()))
a,b = 1,1
for i in range(N):
aa,bb = list(map(int,input().split()))
k = max((a+aa-1)//aa,(b+bb-1)//bb)
aa *= k
bb *= k
a,b = aa,bb
print((a+b))
| p03964 |
from math import ceil
def solve():
N = int(eval(input()))
T = []
A = []
for _ in range(N):
t, a = list(map(int,input().split()))
T.append(t)
A.append(a)
now_t = T[0]
now_a = A[0]
for i in range(1,N):
j = ceil(now_t / T[i])
mul_t = ... | from math import ceil
def solve():
N = int(eval(input()))
T = []
A = []
for _ in range(N):
t, a = list(map(int,input().split()))
T.append(t)
A.append(a)
now_t = T[0]
now_a = A[0]
for i in range(1,N):
mul = f(now_t,now_a,T[i],A[i])
... | p03964 |
from math import ceil
def solve():
N = int(eval(input()))
T = []
A = []
for _ in range(N):
t, a = list(map(int,input().split()))
T.append(t)
A.append(a)
now_t = T[0]
now_a = A[0]
for i in range(1,N):
mul = f(now_t,now_a,T[i],A[i])
... | def solve():
N = int(eval(input()))
now_t, now_a = 1,1
for _ in range(N):
t, a = list(map(int,input().split()))
n = max(-(-now_t//t), -(-now_a//a))
now_t = t * n
now_a = a * n
print((now_t + now_a))
if __name__ == '__main__':
solve() | p03964 |
import math
def read_input():
n = int(eval(input()))
ratios = []
for i in range(n):
t, a = list(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]
... | import math
def read_input():
n = int(eval(input()))
ratios = []
for i in range(n):
t, a = list(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]
... | p03964 |
N=int(eval(input()))
B=[]
for i in range(N):
a,b, = list(map(int, input().split()))
B.append([a,b])
a=B[0][0]
b=B[0][1]
for i in range(1,N):
a1=B[i][0]
b1=B[i][1]
if a>B[i][0] or b>B[i][1]:
while a>a1 or b>b1:
a1+=B[i][0]
b1+=B[i][1]
a=a1... | N = int(eval(input()))
A = 1
B = 1
for _ in range(N):
x, y = list(map(int, input().split()))
na = A // x if A % x == 0 else A // x + 1
nb = B // y if B % y == 0 else B // y + 1
n = max(na, nb)
A = n * x
B = n * y
print((A + B)) | p03964 |
n = int(eval(input()))
t = 0
r = 0
for i in range(n):
a,b = list(map(int,input().split()))
g = a
h = b
while a < t or b < r:
a += g
b += h
t = a
r = b
print((a + b)) | n = int(eval(input()))
t = 1; a = 1;
for _ in range(n):
ti,ai = list(map(int,input().split()))
if t%ti != 0 : t = (t//ti+1)*ti
if a%ai != 0 : a = (a//ai+1)*ai
r = max(t//ti,a//ai)
t = ti*r
a = ai*r
print((a+t))
| p03964 |
n = int(eval(input()))
ab = [list(map(int, input().split())) for _ in range(n)]
x = 1
y = 1
for i in range(n):
a = ab[i][0]
b = ab[i][1]
for j in range(2, 10**18):
if x <= a and y <= b:
x = a
y = b
break
else:
a = ab[i][0] * j
... | n = int(eval(input()))
ab = [list(map(int, input().split())) for _ in range(n)]
x = 1
y = 1
for i in range(n):
a = ab[i][0]
b = ab[i][1]
m = max(-(-x // a), -(-y // b))
x = m * a
y = m * b
print((x + y))
| p03964 |
### ----------------
### ここから
### ----------------
import sys
from io import StringIO
import unittest
def yn(b):
print(("Yes" if b==1 else "No"))
return
def resolve():
readline=sys.stdin.readline
#a,b,c=map(int, readline().rstrip().split())
#arr=list(map(int, readline().rstrip().... | import sys
def resolve():
readline=sys.stdin.readline
n=int(readline())
a,b=list(map(int, readline().rstrip().split()))
for _ in range(n-1):
x,y=list(map(int, readline().rstrip().split()))
start=max(a//x,b//y)
for z in range(start,start+1000):
if x*z>=a a... | p03964 |
N = int(eval(input()))
TA = [list(map(int,input().split())) for _ in range(N)]
lcms = TA[0]
for t,a in TA[1:]:
tmp = [t,a]
while tmp[0] < lcms[0]:
tmp[0] += t
tmp[1] += a
while tmp[1] < lcms[1]:
tmp[0] += t
tmp[1] += a
lcms = tmp
print((sum(lcms)... |
N = int(eval(input()))
TA = [list(map(int,input().split())) for _ in range(N)]
lcms = TA[0]
for t,a in TA[1:]:
tmp = [t,a]
m1 = (lcms[0]+tmp[0]-1)//tmp[0]
m2 = (lcms[1]+tmp[1]-1)//tmp[1]
m = max(m1,m2)
if m != 0:
tmp[0] *= m
tmp[1] *= m
lcms = tmp
... | p03964 |
def ceil(a, b):
return a // b + (a % b > 0)
N = int(eval(input()))
T = A = 1
for i in range(N):
t, a = list(map(int, input().split()))
m = max(ceil(T, t), ceil(A, a))
T = t * m
A = a * m
print((T + A)) | N = int(eval(input()))
T = A = 1
for i in range(N):
t, a = list(map(int, input().split()))
m = max(-(-T // t), -(-A // a))
T = t * m
A = a * m
print((T + A)) | p03964 |
n = int(eval(input()))
t, a = list(map(int, input().split()))
for _ in range(n-1):
ti, ai = list(map(int, input().split()))
tt, aa = ti, ai
while tt < t or aa < a:
tt += ti
aa += ai
t = tt
a = aa
print((t + a)) | n = int(eval(input()))
t, a = list(map(int, input().split()))
for _ in range(n-1):
ti, ai = list(map(int, input().split()))
mt = t // ti if t % ti == 0 else t // ti + 1
ma = a // ai if a % ai == 0 else a // ai + 1
m = max(mt, ma)
t = m * ti
a = m * ai
print((t + a)) | p03964 |
def ceil(a0,b0):
if a0%b0 == 0:
return a0//b0
else:
return a0//b0 +1
t_num,a_num = 1,1
n = int(eval(input()))
for i in range(n):
t,a = list(map(int,input().split()))
k = max(ceil(t_num,t),ceil(a_num,a))
#その比に票を合わせる
t_num = k*t
a_num = k*a
#print([t_num,a_num])
... | n = int(eval(input()))
t = [0 for i in range(n)]
a = [0 for i in range(n)]
for i in range(n):
t[i],a[i] = list(map(int,input().split()))
t_num = t[0]
a_num = a[0]
for i in range(1,n):
k = max(-(-t_num//t[i]),-(-a_num//a[i]))
#その比に票を合わせる
t_num,a_num = k*t[i],k*a[i]
print((t_num + a_n... | p03964 |
N = int(eval(input()))
t, a = list(map(int, input().split()))
for i in range(N - 1):
nt, na = list(map(int, input().split()))
pt, pa = nt, na
while pt < t or pa < a:
pt += nt
pa += na
t = pt
a = pa
print((t + a))
| N = int(eval(input()))
t, a = list(map(int, input().split()))
for i in range(N - 1):
nt, na = list(map(int, input().split()))
p = max(t // nt, a // na)
pt = nt * p
pa = na * p
while pt < t or pa < a:
pt += nt
pa += na
t = pt
a = pa
print((t + a))
| p03964 |
N = int(eval(input()))
T = [0] * N
A = [0] * N
for i in range(N):
T[i], A[i] = list(map(int, input().split()))
x = 1
y = 1
for i in range(N):
n = 1
while not (x <= n * T[i] and y <= n * A[i]):
n += 1
else:
x = n * T[i]
y = n * A[i]
else:
print((x + y)) | N = int(eval(input()))
T = [0] * N
A = [0] * N
for i in range(N):
T[i], A[i] = list(map(int, input().split()))
x = 1
y = 1
for i in range(N):
k = max(-(-x // T[i]), -(-y // A[i]))
x = k * T[i]
y = k * A[i]
else:
print((x + y)) | p03964 |
n,t,a,*u=list(map(int,open(0).read().split()))
for u,b in zip(u[::2],u[1::2]):
v,c=u,b
while v<t or c<a:
v+=u
c+=b
t,a=v,c
print((t+a)) | n,t,a,*u=list(map(int,open(0).read().split()))
for u,b in zip(u[::2],u[1::2]):
x=0-min(-t//u,-a//b)
t,a=u*x,b*x
print((t+a)) | p03964 |
import math
from decimal import Decimal
n = int(eval(input()))
i = 0
list = []
while i < n:
list.append(input().split())
i += 1
h = 0
th = 1
ah = 1
while h < n:
listh = list[h]
x = int(listh[0])
y = int(listh[1])
m = max(math.ceil(th/x),math.ceil(ah/y))
th = Decimal(m*x)
... | import math
from decimal import Decimal
n = int(eval(input()))
i = 0
list = []
while i < n:
list.append(input().split())
i += 1
h = 0
th = 1
ah = 1
while h < n:
listh = list[h]
x = int(listh[0])
y = int(listh[1])
m = max((th+x-1)//x, (ah+y-1)//y)
th = m*x
ah = m*y
... | p03964 |
n = int(eval(input()))
a,b = list(map(int,input().split()))
for _ in range(n-1):
c,d = list(map(int,input().split()))
deltaA = 0
deltaB = d/c * (a + deltaA) - b
#print(deltaA,deltaB)
while deltaB < 0 or int(deltaB) != deltaB:
deltaA += 1
deltaB = d/c * (a + deltaA) - b
... | n = int(eval(input()))
a,b = 1,1
for _ in range(n):
x,y = list(map(int,input().split()))
k = -min(-a//x,-b//y)
a = k*x
b = k*y
print((a+b)) | p03964 |
n = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(n)]
PQ = [TA[0]]
for i in range(1, n):
p0, q0 = PQ[i-1]
p1, q1 = TA[i]
t, a = TA[i]
while p1 < p0 or q1 < q0:
p1 += t
q1 += a
PQ.append([p1, q1])
print((sum(PQ[-1]))) | n = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(n)]
XY = [TA[0]]
for i in range(1, n):
x0, y0 = XY[i-1]
x1, y1 = TA[i]
xq, xr = divmod(x0, x1)
yq, yr = divmod(y0, y1)
if xr != 0:
xq += 1
if yr != 0:
yq += 1
q = max(xq, yq)
x1, ... | p03964 |
N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N)]
t,a = src[0]
for ti,ai in src[1:]:
tn = t + (ti - t%ti)%ti
an = tn // ti * ai
while an < a:
tn += ti
an += ai
t,a = tn,an
print((t + a))
| N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N)]
ans_t, ans_a = src[0]
for t,a in src[1:]:
t1 = ans_t + (t - ans_t%t)%t
a1 = t1 // t * a
a2 = ans_a + (a - ans_a%a)%a
t2 = a2 // a * t
if a1 < ans_a:
ans_t, ans_a = t2,a2
else:
ans_t, ans... | p03964 |
def ceil(x, y):
if x % y == 0:
return x // y
else:
return x // y + 1
n = int(eval(input()))
t = a = 1
for i in range(n):
T, A = list(map(int, input().split()))
n = max(ceil(t, T), ceil(a, A))
t = n * T
a = n * A
print((t + a)) | n = int(eval(input()))
t = a = 1
for i in range(n):
T, A = list(map(int, input().split()))
n = max(-(-t // T), -(-a // A))
t = n * T
a = n * A
print((t + a)) | p03964 |
from math import ceil
n = int(eval(input()))
votes = [0, 0]
for i in range(n):
a, b = list(map(int, input().split()))
if i == 0:
votes = [a, b]
else:
if a == b:
x = max(votes)
votes = [x, x]
else:
num = min(ceil(votes[0]/a), cei... | n = int(eval(input()))
votes = [0, 0]
for i in range(n):
a, b = list(map(int, input().split()))
if i == 0:
votes = [a, b]
else:
num = max(-(-votes[0]//a), -(-votes[1]//b))
x = a * num
y = b * num
votes = [x, y]
print((sum(votes)))
| p03964 |
import math
N = int(eval(input()))
t = 0
a = 0
for i in range(N):
T, A = list(map(int, input().split()))
if i == 0:
t += T
a += A
continue
if (T >= t and A >= a):
t = T
a = A
continue
max_ta = max(t, a)
g = math.gcd(t, a)
tg, ag... | import math
N = int(eval(input()))
t = 0
a = 0
for i in range(N):
T, A = list(map(int, input().split()))
if i == 0:
t += T
a += A
continue
if (T >= t and A >= a):
t = T
a = A
continue
max_ta = max(t, a)
g = math.gcd(t, a)
tg, ag... | p03964 |
N = int(eval(input()))
T, A = [0]*N, [0]*N
for i in range(N):
T[i], A[i] = list(map(int, input().split()))
ans = T[0]+A[0]
for i in range(N-1):
for j in range(10**18):
if (ans+j)%(T[i+1]+A[i+1])==0 and (ans+j)*T[i+1]/(T[i+1]+A[i+1])>=ans*T[i]/(T[i]+A[i]) and (ans+j)*A[i+1]/(T[i+1]+A[i+1])>=an... | N = int(eval(input()))
T, A = [0]*N, [0]*N
for i in range(N):
T[i], A[i] = list(map(int, input().split()))
t = a = 1
for i in range(N):
n = max(-(-t//T[i]), -(-a//A[i]))
t = n*T[i]
a = n*A[i]
print((t+a))
| p03964 |
n = int(eval(input()))
ary = list(map(int, input().split()))
for i in range(n - 1):
tmp_ary = list(map(int, input().split()))
t_rate = (ary[0] - 1) // tmp_ary[0] + 1
a_rate = (ary[1] - 1) // tmp_ary[1] + 1
rate = max([t_rate, a_rate])
ary = list([x * rate for x in tmp_ary])
print((int(ary[0] + ary[1])... | n = int(eval(input()))
ary = list(map(int, input().split()))
for i in range(n - 1):
tmp_ary = list(map(int, input().split()))
# 桁が大きいとceil, floorでは正しく判定ができない
t_rate = (ary[0] - 1) // tmp_ary[0] + 1
a_rate = (ary[1] - 1) // tmp_ary[1] + 1
rate = max([t_rate, a_rate])
ary = list([x * rate for x in tmp... | p03964 |
N = int(eval(input()))
TA = [list(map(int, input().split())) for i in range(N)]
x = 0
y = 0
for t, a in TA:
if x <= t and y <= a:
x = t
y = a
else:
if t >= a:
while(1):
if (x*a) % t == 0 and (x*a) // t >= y:
y = (x*a) // t
... | import math
N = int(eval(input()))
TA = [list(map(int, input().split())) for i in range(N)]
x = 1
y = 1
for t, a in TA:
if x <= t and y <= a:
x = t
y = a
else:
v = max(-(-x//t), -(-y//a))
x = v * t
y = v * a
print((x+y))
| p03964 |
n = int(eval(input()))
l = [input().split() for _ in range(n)]
ans = [0,0]
for i in range(n):
ref_1 = int(l[i][0])
ref_2 = int(l[i][1])
for j in range(2,10**18-1):
if (ans[0]>ref_1) or (ans[1]>ref_2):
ref_1 = int(l[i][0])
ref_2 = int(l[i][1])
ref_1 *= j
... | n = int(eval(input()))
A, B = 0, 0
for i in range(n):
x, y = list(map(int,input().split()))
dx, dy = 1, 1
if A > x:
dx = A // x
if A % x != 0:
dx += 1
if B > y:
dy = B // y
if B % y != 0:
dy += 1
a = max(dx, dy)
A, B =... | p03964 |
N = int(eval(input()))
# initial
p_t, p_a = 1, 1
for i in range(N) :
t, a = list(map(int, input().split()))
t_up, a_up = t, a
if t >= p_t and a >= p_a :
p_t, p_a = t, a
else :
while t_up < p_t or a_up < p_a :
t_up += t
a_up += a
... | N = int(eval(input()))
# initial
p_t, p_a = 1, 1
for i in range(N) :
t, a = list(map(int, input().split()))
t_up, a_up = t, a
if t >= p_t and a >= p_a :
p_t, p_a = t, a
else :
f = max(
p_t // t if p_t % t == 0 else p_t // t + 1,
p_a // a if... | p03964 |
N = int(eval(input()))
TA = [list(map(int, input().split())) for i in range(N)]
t = 1
a = 1
for i in range(N):
T, A = TA[i]
mul = 2
while t > T or a > A:
T = TA[i][0] * mul
A = TA[i][1] * mul
mul += 1
t = T
a = A
print((t+a)) | N = int(eval(input()))
TA = [list(map(int, input().split())) for i in range(N)]
t = 1
a = 1
for i in range(N):
T, A = TA[i]
if t > T or a > A:
tmul = (t+T-1) // T
amul = (a+A-1) // A
mul = max(tmul, amul)
T *= mul
A *= mul
t = T
a = A
print((t+a)... | p03964 |
N = int(eval(input()))
A = []
B = []
for i in range(N) :
in_a,in_b = list(map(int,input().split()))
A.append(in_a)
B.append(in_b)
for i in range(1,N) :
a = A[i]
b = B[i]
while ((A[i-1] > a) or (B[i-1] > b)) :
a += A[i]
b += B[i]
A[i] = a
B[i] = b
ans ... | N = int(eval(input()))
A = []
B = []
for i in range(N) :
in_a,in_b = list(map(int,input().split()))
A.append(in_a)
B.append(in_b)
for i in range(1,N) :
if A[i-1] > A[i] :
if A[i-1] % A[i] == 0 :
a = A[i-1]//A[i]
else :
a = A[i-1]//A[i] + 1
e... | p03964 |
import math
from decimal import *
n = int(eval(input()))
l = [[int(i) for i in input().split()] for j in range(n)]
def newT(t, ratio):
a = Decimal(t[0]) / Decimal(ratio[0])
b = Decimal(t[1]) / Decimal(ratio[1])
if a <= 1 and b <= 1:
return ratio
else:
c = math.ceil(max([a, ... | import math
from decimal import *
n = int(eval(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
c = max((t[0]+ratio[0]-1)//ratio[0], (t[1]+ratio[1]-1)//ratio[... | p03964 |
# C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
# 比がa:bとなる合計最小の票分布はa,b
# 次にc:dになったとき、a<=cかつb<=dを満たすまでc,dを2倍、3倍、と増やしていく
N = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(N)]
a, b = TA[0]
ans = a + b
for idx in range(1,N):
c, d = TA[idx]
ori_c, ori_d = c, d
whi... | # C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
# 比がa:bとなる合計最小の票分布はa,b
# 次にc:dになったとき、a<=cかつb<=dとなるようにc,dに同じ数をかける
import math
N = int(eval(input()))
TA = [list(map(int, input().split())) for _ in range(N)]
a, b = TA[0]
c, d = a, b
for idx in range(1,N):
c, d = TA[idx]
multi = max((a+c-1)... | p03964 |
n=int(eval(input()))
a,b=list(map(int,input().split()))
if n!=1:
for _ in range(n-1):
A,B=list(map(int,input().split()))
c=0
d=0
k=1
while a>c or b>d:
c=k*A
d=k*B
k+=1
a=c
b=d
print((a+b)) | n=int(eval(input()))
a,b=list(map(int,input().split()))
if n!=1:
for _ in range(n-1):
A,B=list(map(int,input().split()))
k=max(1,(a+A-1)//A,(b+B-1)//B)
a=k*A
b=k*B
print((a+b)) | p03964 |
n = int(eval(input()))
tkhs = 1
aoki = 1
for _ in range(n):
t, a = list(map(int, input().split()))
k = 1
while not(tkhs <= k*t and aoki <= k*a):
k += 1
tkhs = k*t
aoki = k*a
print((tkhs+aoki))
| n = int(eval(input()))
from math import ceil
tkhs = 1
aoki = 1
for _ in range(n):
t, a = list(map(int, input().split()))
k = max((tkhs+t-1)//t, (aoki+a-1)//a)
tkhs = k*t
aoki = k*a
print((tkhs+aoki))
| p03964 |
from math import *
from decimal import *
N = int(eval(input()))
T = []
A = []
for i in range(0, N):
ti, ai = [Decimal(int(x)) for x in input().split()]
T.append(ti)
A.append(ai)
prevT = T[0]
prevA = A[0]
for i in range(1, N):
nextfacT = int(ceil(prevT / T[i]))
nextfacA = int(ceil(pre... | from math import *
N = int(eval(input()))
T = []
A = []
for i in range(0, N):
ti, ai = [int(x) for x in input().split()]
T.append(ti)
A.append(ai)
prevT = T[0]
prevA = A[0]
for i in range(1, N):
nextfacT = int(ceil((prevT + T[i] - 1) // T[i]))
nextfacA = int(ceil((prevA + A[i] - 1) // ... | p03964 |
n = int(eval(input()))
tvote = 1
avote = 1
for i in range(n):
t, a = [int(n) for n in input().split()]
num = 1
while True:
tnow = num*t
anow = num*a
if tnow >= tvote and anow >= avote:
tvote = tnow
avote = anow
break
num += 1
print((tvote+avote))
| n = int(eval(input()))
tvote = 1
avote = 1
for i in range(n):
t, a = [int(n) for n in input().split()]
k = (tvote-1)//t + 1
tnow = t * k
anow = a * k
if avote > anow:
k = (avote-1)//a + 1
tnow = t * k
anow = a * k
tvote = tnow
avote = anow
print((avote+tvote)) | p03964 |
def gcd(x,y):
if y==0:
return x
else:
return gcd(y,x%y)
def lcm(x,y):
return x*y//gcd(x,y)
N=int(eval(input()))
x,y=0,0
for i in range(N):
p=0
T,A=list(map(int,input().split()))
if i==0:
x,y=T,A
continue
if x<=T and y<=A:
x,y=T,A
elif x<=T and A<y:
... | N=int(eval(input()))
x,y=0,0
for i in range(N):
p=0
T,A=list(map(int,input().split()))
if i==0:
x,y=T,A
continue
if x<=T and y<=A:
x,y=T,A
elif x<=T and A<y:
if y%A!=0:
p=1
x=T*(y//A+p)
y=A*(y//A+p)
elif T<x and y<=T:
if x%T!=0:
p=1
y=A*(x//T+p)
... | p03964 |
import fractions
N=int(eval(input()))
T,A=list(map(int,input().split()))
for i in range(1,N):
nT,nA=list(map(int,input().split()))
m,p=nT,nA
while(nT<T or nA<A):
nT+=m;nA+=p
T,A=nT,nA
print((T+A)) | import fractions
N=int(eval(input()))
T,A=list(map(int,input().split()))
for i in range(1,N):
nT,nA=list(map(int,input().split()))
if(nT>=T and nA>=A):
T,A=nT,nA
continue
pT,pA=T//nT,A//nA
if(T%nT!=0):
pT+=1
if(A%nA!=0):
pA+=1
T,A=nT*max(pT,pA),nA*max... | p03964 |
n = int(eval(input()))
ratio_array = [tuple(map(int, input().split())) for _ in range(n)]
votes_nums = (1, 1)
for x, y in ratio_array:
t, a = votes_nums
m = max((t+x-1)//x, (a+y-1)//y)
votes_nums = (m*x, m*y)
print((sum(votes_nums))) | n = int(eval(input()))
ratio_array = [tuple(map(int, input().split())) for _ in range(n)]
t, a = 1, 1
for x, y in ratio_array:
m = max((t+x-1)//x, (a+y-1)//y)
t, a = m*x, m*y
print((t + a)) | p03964 |
n = int(eval(input()))
t,a = list(map(int,input().split()))
for i in range(n-1):
T,A=list(map(int,input().split()))
count = 0
while (A*count < a) or (T*count < t):
count += 1
a = count * A
t = count * T
print((a+t)) | n = int(eval(input()))
t,a = list(map(int,input().split()))
for i in range(n-1):
T,A=list(map(int,input().split()))
count = max(a//A,t//T)
while (A*count < a) or (T*count < t):
count += 1
a = count * A
t = count * T
print((a+t)) | p03964 |
n=int(eval(input()))
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=0,0
for i in range(n):
x,y=ta[i]
j,k=x,y
t=0
while(1):
t+=1
if j*t>=a and k*t>=b:
break
a,b=j*t,k*t
print((a+b)) | n=int(eval(input()))
ta=[list(map(int, input().split())) for _ in range(n)]
a,b=1,1
import math
for i in range(n):
x,y=ta[i]
t=max(-(-a//x),-(-b//y))
a,b=t*x,t*y
print((a+b)) | p03964 |
#!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, T: "List[int]", A: "List[int]"):
a0, a1 = T[0], A[0]
for t, a in zip(T, A):
while a0*a != a1*t:
if a0/a1 - t/a > 0:
a1 += 1
else:
a0 += 1
# print(a0, a1... | #!/usr/bin/env python3
import sys
INF = float("inf")
def main():
# i回目 Ti : Ai
N = int(eval(input()))
T, A = [], []
for i in range(N):
t, a = list(map(int, input().split()))
T.append(t)
A.append(a)
num = [0, 0]
for i, (t, a) in enumerate(zip(T, A)):
... | p03964 |
def c_AtCoDeer_and_ElectionReport(N, R):
from math import ceil
from decimal import Decimal
t = 1 # 高橋の票数
a = 1 # 青木の票数
for x, y in R:
n = Decimal(max(ceil(t / x), ceil(a / y)))
t = n * x
a = n * y
return t + a
N = int(eval(input()))
R = [[int(i) for i in in... | def c_atcodeer_and_election_report(N, R):
t, a = 1, 1 # 高橋, 青木の票数
for x, y in R:
# t<=nx ∧ a<=ny を満たす最小のnを求める
n = max(t // x, a // y)
if t > n * x or a > n * y:
n += 1
t = n * x
a = n * y
return t + a
N = int(eval(input()))
R = [[int(i) for i... | p03964 |
N = int(eval(input()))
T,A = (int(T) for T in input().split())
for TN in range(1,N):
TNext,ANext = (int(T) for T in input().split())
Cnt = 1
while TNext*Cnt<T or ANext*Cnt<A:
Cnt += 1
T = TNext*Cnt
A = ANext*Cnt
print((A+T)) | N = int(eval(input()))
TNow,ANow = (int(T) for T in input().split())
for TN in range(1,N):
TNext,ANext = (int(T) for T in input().split())
Magn = max(TNow//TNext+(TNow%TNext!=0),ANow//ANext+(ANow%ANext!=0))
TNow,ANow = TNext*Magn,ANext*Magn
print((TNow+ANow)) | p03964 |
N = int(eval(input()))
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
i = 1
while True:
if l2[0] * i >= l1[0] and l2[1] * i >= l1[1]:
l2[0] *= i
l2[1] *= i
break
i += 1
for i in range(N-1):
modify(info[i],info[i+1])... | N = int(eval(input()))
info = [list(map(int,input().split())) for i in range(N)]
def modify(l1,l2):
# k >= b / a
# a * k >= b
k1 = l1[0]//l2[0]
k2 = l1[1]//l2[1]
k = max(k1,k2)
for i in range(k,k+2):
if l2[0] * i >= l1[0] and l2[1] * i >= l1[1]:
l2[0] *= i
... | p03964 |
n = int(eval(input()))
last_t = 0
last_x = 0
last_y = 0
for i in range(n):
t, x, y = list(map(int, input().split()))
if abs(last_x - x) + abs(last_y - y) > t - last_t:
print("No")
exit()
else:
if (t % 2 == 1 and (x + y) % 2 == 0) or (t % 2 == 0 and (x + y) % 2 == 1):
... | n = int(eval(input()))
T, X, Y = 0, 0, 0
for i in range(n):
t, x, y = list(map(int, input().split()))
dxy = abs(X - x) + abs(Y - y)
dt = t - T
if dxy > dt or dxy % 2 != dt % 2:
print("No")
exit()
print("Yes") | p03459 |
n,m,r=list(map(int,input().split()))
a,b=sorted([n-1,r-m*n])
if a<1:print((0))
else:
d=1
for i in range(a):d*=i+1
u=1
for i in range(b,a+b):u*=i+1
print((u//d))
| n,m,r=list(map(int,input().split()))
r-=n*m
if r<0:print((0))
else:
from math import*
print((factorial(n+r-1)//factorial(r)//factorial(n-1)))
| p00514 |
n,m,r=list(map(int,input().split()))
r-=m*n
if r<0:print((0))
else:
a=1
for i in range(r):a*=i+n
for i in range(r):a//=i+1
print(a)
| n,m,r=list(map(int,input().split()))
r-=m*n
if r<0:print((0))
else:
d=1
for i in range(r):d*=i+1
u=1
for i in range(r):u*=i+n
print((u//d))
| p00514 |
def fact(a):
res = 1
while a:
res *= a
a -= 1
return res
n,m,r = list(map(int,input().split()))
r-=n*m
if r < 0:
print((0))
else:
print((fact(r+n-1)//fact(n-1)//fact(r))) | def fact(n):
res = 1
for i in range(1, n+1):
res *= i
return res
def combination(n, k):
return fact(n)//fact(n-k)//fact(k)
n, m, r = list(map(int, input().split()))
print((combination(r - n*m + n - 1, n-1))) | p00514 |
from collections import deque
import heapq
def dijkstra(s,g):
color=[0]*n
dis={}
for i in range(n):
dis[i]=float('inf')
dis[s]=0
heapq.heappush(pq,[0,s])
while len(pq)!=0:
t,u=heapq.heappop(pq)
color[u]=2
if dis[u]<t:
continue
f... | import heapq
def dijkstra(s,g):
color=[0]*n
dis={}
for i in range(n):
dis[i]=float('inf')
dis[s]=0
heapq.heappush(pq,[0,s])
while len(pq)!=0:
t,u=heapq.heappop(pq)
color[u]=2
if dis[u]<t:
continue
for v,cost in g[u]:
... | p00539 |
import itertools
from copy import deepcopy
def stuck(Array,Order):
remain = len(Array)
if remain == 0: return G(Order),Order
minG,minOrder = 9999999,[]
w = sum([int(Array[i][1]) for i in range(remain)])
for i in range(remain):
if int(Array[i][2]) >= w-int(Array[i][1]):
array = deepcopy(Array)
o... | def stuck(array):
order=[]
while array:
r = len(array)
w = sum([array[i][1] for i in range(r)])
mx = 0
for i in range(r):
if array[i][2] >= w-array[i][1] and array[i][1] > mx:
mx = array[i][1]
id = i
order.append(array.pop(id)[0])
return order
def change(a):
return a[0],int(a[1])... | p00170 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0170
"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
from itertools import permutations
def solve(items):
total_weight = 0
for i in items:
total_weight +=... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0170
"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
from itertools import permutations
def solve(items):
total_weight = 0
for i in items:
total_weight +=... | p00170 |
def solve(placed, w1, w2):
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
a = tuple(placed)
D1[a] = w1
D2[a] = w2
return
for e in x:
w = Food[e][0]
if w2 > Food[e][1]: return
a = w1 + w * n
b = w2 + w
solve(placed+[e], a, b)
return
... | def solve(placed, w1, w2):
global weight, D
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
if weight > w1:
D = placed
weight = w1
return
for e in x:
w = Food[0][e]
if w2 > Food[1][e]: return
a = w1 + w * n
if a > weight: return
b ... | p00170 |
def solve(placed, w1, w2):
global weight, D
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
if weight > w1:
D = placed
weight = w1
return
for e in x:
w = Food[0][e]
if w2 > Food[1][e]: return
a = w1 + w * n
if a > weight: return
b ... | def solve(placed, w1, w2):
global weight, D
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
if weight > w1:
D = placed
weight = w1
return
for e in x:
w = W[e]
if w2 > S[e]: return
a = w1 + w * n
if a > weight: return
b = w2 + w
... | p00170 |
def solve(placed, w1, w2):
global weight, D
n = len(N) - len(placed)
x = list(set(N) - set(placed))
if x == []:
if weight > w1:
D = placed
weight = w1
return
for e in x:
w = W[e]
if w2 > S[e]: return
a = w1 + w * n
if a > weight: return
b = w2 + w
... | def solve(placed, w1, w2):
global ans
n = len(N) - len(placed)
if n==0:
ans = min(ans, [w1, placed])
return
for e in N:
if e in placed: continue
w, lim, s = Food[e]
if w2 > lim: return
a = w1 + w * n
if a > ans[0]: return
solve(placed+[e], a, w2 + w)
return
w... | p00170 |
def solve(placed, w1, w2):
global ans
n = len(N) - len(placed)
if n==0:
ans = min(ans, [w1, placed])
return
for e in N:
if e in placed: continue
w, lim, s = Food[e]
if w2 > lim: return
a = w1 + w * n
if a > ans[0]: return
solve(placed+[e], a, w2 + w)
return
w... | def solve(G1, G2, w1, w2):
global ans
n = len(G2)
for e in G2:
w, lim, s = Food[e]
a = w1 + w * n
if w2 > lim or a > ans[0]: return
b = G1 + [e]
if n == 1:
ans = min(ans, [a, b])
else:
x = G2[:]
x.remove(e)
solve(b, x, a, w2 + w)
return
while 1:
... | p00170 |
while 1:
w = input()
if w=="0000": break
if int(w)%1111==0:
print("NA")
continue
ans = 0
while(w!="6174"):
w = str(int("".join(sorted(w,reverse=True)))-int("".join(sorted(w))))
ans += 1
print(ans) | while 1:
w = input()
if w=="0000": break
if int(w)%1111==0:
print("NA")
continue
ans = 0
while(w!="6174"):
w = ("".join(sorted(w))).zfill(4)
w = str(int(w[::-1])-int(w))
ans += 1
print(ans) | p00254 |
while 1:
n=list(input())
if n==["0"]*4: break
elif n[0]==n[1]==n[2]==n[3]:
print("NA")
continue
count=0
while 1:
if n==["6","1","7","4"]:
print(count)
break
l=int("".join(map(str,sorted(n)[::-1])))
s=int("".join(map(str,sorted(n)[n.count("0"):])))
n=list(str(l-s))
for i in range(4... | while 1:
n=list(input())
if n==["0"]*4: break
elif n[0]==n[1]==n[2]==n[3]:
print("NA")
continue
count=0
while 1:
if n==["6","1","7","4"]:
print(count)
break
l=int("".join(map(str,sorted(n)[::-1])))
s=int("".join(map(str,sorted(n)[n.count("0"):])))
n=list(str(l-s))
n=["0"]*(4-len(n... | p00254 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.