s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s380750038 | p03963 | u996284376 | 1512900630 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 153 | #include <stdio.h>
#include <math.h>
int main(void) {
int a, b, ans;
scanf("%d %d",&a, &b);
printf("%d",(b*(int)pow((double)(b-1),(double)(a-1))));
} |
s812280202 | p03963 | u405509847 | 1478405241 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3068 | 79 | N, K = map(int, raw_input().split())
# N, K = 10, 8
print (K * (K-1) ** (N-1)) |
s028689545 | p03963 | u272496669 | 1477844426 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 94 | list = input().split()
a = bin(int(list[0])-1)
b = int(list[1])-1
print(pow(b,a)*int(list[1])) |
s372357795 | p03963 | u083668616 | 1477622847 | Python | Python (2.7.6) | py | Runtime Error | 48 | 3520 | 181 | def exp(x, n):
if n == 0:
return 1
else:
return x * exp(x, n-1)
def main():
inpt = raw_input().split()
n = int(inpt[0])
k = int(inpt[1])
print k * exp(k-1, n-1)
main()
|
s710703985 | p03963 | u731028462 | 1476675968 | Python | Python (3.4.2) | py | Runtime Error | 24 | 3064 | 329 | n, m = list(map(int, input().split()))
a = [input() for i in range(n)]
print(n,m)
##
## Template
##
## map, filter, reduce
# map(lambda x: x*2, range(10))
# filter(lambda x: x % 2, range(10))
# from functools import reduce
# reduce(lambda sum,x: sum+x, range(10))
# [x * 2 for x in range(1, 10) if x % 3 == 1]
# => [2, 8, 14]
|
s994846045 | p03963 | u729300713 | 1476582644 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 257 | import sys
n, k = map(int, raw_input().split())
ans = k # first
if n = 1 and k = 1:
print ans
sys.exit()
for i in range(n-1):
ans *= k-1
print ans
|
s064851493 | p03963 | u729300713 | 1476582607 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 248 | import sys
n, k = map(int, raw_input().split())
ans = k # first
if n = 1 and k = 1:
print ans
sys.exit()
for i in range(n-1):
ans *= k-1
|
s348719510 | p03963 | u442810826 | 1476581396 | Python | Python (2.7.6) | py | Runtime Error | 16 | 2568 | 104 | K = raw_input().split()
N=int(N)
K=int(K)
if N==1:
print K
else:
A = K*pow(K-1,N-1)
print A
|
s721911247 | p03963 | u442810826 | 1476581344 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 107 |
N,K = raw_input().split()
N=int(N)
K=int(K)
if N==1:
print K
else:
A = K*pow(K-1,N-1)
print A
|
s613843470 | p03963 | u442810826 | 1476581216 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3064 | 107 |
N,K = raw_input().split()
N=int(N)
K=int(K)
if N==1:
print K
else:
A = K*pow(K-1,N-1)
print A
|
s199105175 | p03964 | u648315264 | 1601065890 | Python | PyPy3 (7.3.0) | py | Runtime Error | 118 | 68572 | 1005 | import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7
import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
N = i_input()
t0,a0 = 1,1
for i in range(N):
t1,a1 = i_map()
f0 = t0//t1
if t0%t1 != 0:
f0 += 1
f1 = a0 // a1
if a0%a1 != -:
f1 += 1
f = max(f0, f1)
t0, a0 = t1*f, a1*f
print(t0+a0)
if __name__=="__main__":
main()
|
s160975742 | p03964 | u825685913 | 1600884000 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9196 | 324 | import math
n = int(input())
A, B = 0, 0
for i in range(n):
x, y = 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 = a * x, a * y
print(A + B) |
s074512407 | p03964 | u748241164 | 1592942902 | Python | PyPy3 (7.3.0) | py | Runtime Error | 216 | 79952 | 640 | import fractions
N = int(input())
for i in range(N):#1000
t, a = map(int, input().split())
if i == 0:
taka, aoki = t, a
else:
now = [10 ** 10, -1, -1]
for i in range(1001):
if ((taka + i) * (a / t)) % 1 == 0:
a2 = int((taka + i) * (a / t))
if (now[0] >= a2 + taka + i) and (a2 >= aoki):
now = [taka + i + a2, taka + i, a2]
if ((aoki + i) * (t / a)) % 1 == 0:
b2 = int((aoki + i) * (t / a))
if (now[0] >= b2 + aoki + i) and (b2 >= taka):
now = [aoki + i + b2, b2, aoki + i]
taka = now[1]
aoki = now[2]
#print(now)
print(now[0])
|
s130746901 | p03964 | u102367647 | 1592575275 | Python | Python (3.8.2) | py | Runtime Error | 116 | 26936 | 1270 | import sys
import numpy as np
import random
import math
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007
def main():
n = I()
x, y = 1, 1
for _ in range(n):
t, a = LI()
m = max((x+t-1)//a,(y+a-1)//b)
x, y = m*t, m*a
print(x+y)
if __name__ == '__main__':
main() |
s664716685 | p03964 | u312078744 | 1591853934 | Python | Python (3.4.3) | py | Runtime Error | 36 | 5088 | 429 | import math
from fractions import Fraction
n = int(input())
x, y = map(int, input().split())
t, a = x, y
for _ in range(n - 1):
tt, aa = map(int, input().split())
#c = 1
'''
if (t >= a):
c = math.ceil(tt / t)
else:
c = math.ceil(aa / a)
'''
#c = math.ceil(t / tt, a / aa)
c = math.ceil(Fraction(t, tt), Fraction(a / aa))
t = tt * c
a = aa * c
ans = t + a
print(ans)
|
s919740094 | p03964 | u029000441 | 1591739649 | Python | PyPy3 (2.4.0) | py | Runtime Error | 164 | 38384 | 1320 | # coding: utf-8
# hello worldと表示する
import sys
import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
global p
global q
#print(x,y,a,b)
for i in range(max(1,min(floor(x/a),floor(y/b))),max(ceil(x/a),ceil(y/b))+1):
p,q=a*i,b*i
if p>=x and q>=y:
break
return [p,q]
#return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
#for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=pairs[0]
for i in range(n-1):
u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print(u+v) |
s113971099 | p03964 | u308918401 | 1591316578 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 264 | import math
n=int(input())
x,y=map(int,input().split())
gcd=math.gcd(x,y)
x=int(x/gcd)
y=int(y/gcd)
for i in range(n-1):
s,t=map(int,input().split())
if s<x:
w=int(x/s)+1
s*=w
t*=w
if t<y:
w=int(y/t)+1
s*=w
t*=w
x=s
y=t
print(x+y) |
s580394855 | p03964 | u935077683 | 1590864913 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 228 | from math import gcd, ceil
n = int(input())
a, b = 1, 1
for _ in range(n):
x, y = map(int, input().split())
xx, yy = (ceil(a / x) * x, ceil(b / y) * y)
f = max(xx // x, yy // y)
a, b = f * x, f * y
print(a + b)
|
s021070782 | p03964 | u935077683 | 1590863831 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 282 | from math import gcd, ceil
n = int(input())
a, b = map(int, input().split())
g = gcd(a, b)
a //= g
b //= g
for _ in range(n - 1):
x, y = map(int, input().split())
xx, yy = (ceil(a / x) * x, ceil(b / y) * y)
f = max(xx // x, yy // y)
a, b = f * x, f * y
print(a + b) |
s070262538 | p03964 | u935077683 | 1590863431 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 315 | from math import *
n = int(input())
a, b = map(int, input().split())
g = gcd(a, b)
a //= g
b //= g
for _ in range(n - 1):
x, y = map(int, input().split())
x //= gcd(x, y)
y //= gcd(x, y)
xx, yy = (ceil(a / x) * x, ceil(b / y) * y)
f = max(xx // x, yy // y)
a, b = f * x, f * y
print(a + b)
|
s190897837 | p03964 | u405256066 | 1590369718 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 299 | from sys import stdin
import math
N = int(stdin.readline().rstrip())
t,a = [int(x) for x in stdin.readline().rstrip().split()]
for _ in range(N-1):
T,A = [int(x) for x in stdin.readline().rstrip().split()]
int(n) = max(math.ceil(t/T),math.ceil(a/A))
t = n*T
a = n*A
print(t+a) |
s047603790 | p03964 | u792512290 | 1589741442 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 332 | n = int(input())
ary = []
for i in range(n):
tmp_ary = list(map(int, input().split()))
if len(ary) == 0:
ary = tmp_ary[:]
else:
t_rate = math.ceil(ary[0] / tmp_ary[0])
a_rate = math.ceil(ary[1] / tmp_ary[1])
rate = max([t_rate, a_rate])
ary = list(map(lambda x: x * rate, tmp_ary))
print(ary[0] + ary[1])
|
s170956528 | p03964 | u513081876 | 1589650753 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3188 | 352 | N = int(input())
TA = [[int(i) for i in input().split()] for i in range(N)]
Takahashi, Aoki = TA[0][0], TA[0][1]
for ta, ao in TA:
if Takahashi <= ta and Aoki <= ao:
Takahashi, Aoki = ta, ao
else:
num = max(math.ceil(Takahashi / ta), math.ceil(Aoki / ao))
Takahashi, Aoki = num * ta, num * ao
print(Takahashi + Aoki)
|
s162303940 | p03964 | u127499732 | 1589488090 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 276 | def main():
from math import ceil
n = int(input())
a, b = 1, 1
for _ in range(n):
i, j = map(int, input().split())
x = max((a + s - 1) // s, (b + t - 1) // t)
a, b = x * i, x * j
print(a + b)
if __name__ == '__main__':
main()
|
s777056538 | p03964 | u287132915 | 1588818229 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3064 | 886 | import math
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
n = int(input())
t_lst, a_lst = [], []
for i in range(n):
ti, ai = map(int, input().split())
t_lst.append(ti)
a_lst.append(ai)
t, a = 1, 1
for i in range(n):
ti, ai = t_lst[i], a_lst[i]
if ti>=t and ai>=a:
t, a = ti, ai
elif ti<t and ai>=a:
t = ti * math.ceil(t/ti)
a = ai * math.ceil(t/ti)
elif ti>=t and ai<a:
t = ti * math.ceil(a/ai)
a = ai * math.ceil(a/ai)
else:
t_lcm = lcm_base(ti, t)
a_lcm = lcm_base(ai, a)
new1 = [t_lcm*math.ceil(a/(t_lcm/ti*ai)), t_lcm/ti*ai*math.ceil(a/(t_lcm/ti*ai))]
new2 = [a_lcm/ai*ti*math.ceil(t/(a_lcm/ai*ti)), a_lcm*math.ceil(t/(a_lcm/ai*ti))]
if sum(new1) < sum(new2):
t, a = new1[0], new1[1]
else:
t, a = new2[0], new2[1]
print(t+a) |
s018744870 | p03964 | u287132915 | 1588818096 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3064 | 892 | import math
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
n = int(input())
t_lst, a_lst = [], []
for i in range(n):
ti, ai = map(int, input().split())
t_lst.append(ti)
a_lst.append(ai)
t, a = 1, 1
for i in range(n):
ti, ai = t_lst[i], a_lst[i]
if ti>=t and ai>=a:
t, a = ti, ai
elif ti<t and ai>=a:
t = ti * math.ceil(t/ti)
a = ai * math.ceil(t/ti)
elif ti>=t and ai<a:
t = ti * math.ceil(a/ai)
a = ai * math.ceil(a/ai)
else:
t_lcm = lcm_base(ti, t)
a_lcm = lcm_base(ai, a)
new1 = [t_lcm*math.ceil(a/(t_lcm//ti*ai)), t_lcm//ti*ai*math.ceil(a/(t_lcm//ti*ai))]
new2 = [a_lcm//ai*ti*math.ceil(t/(a_lcm//ai*ti)), a_lcm*math.ceil(t/(a_lcm//ai*ti))]
if sum(new1) < sum(new2):
t, a = new1[0], new1[1]
else:
t, a = new2[0], new2[1]
print(t+a) |
s644317656 | p03964 | u287132915 | 1588817353 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 776 | import math
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
n = int(input())
t, a = 1, 1
for i in range(n):
ti, ai = map(int, input().split())
if ti>=t and ai>=a:
t, a = ti, ai
elif ti<t and ai>=a:
t = ti * math.ceil(t/ti)
a = ai * math.ceil(t/ti)
elif ti>=t and ai<a:
t = ti * math.ceil(a/ai)
a = ai * math.ceil(a/ai)
else:
t_lcm = lcm_base(ti, t)
a_lcm = lcm_base(ai, a)
new1 = [t_lcm*math.ceil(a/(t_lcm//ti*ai)), t_lcm//ti*ai*math.ceil(a/(t_lcm//ti*ai))]
new2 = [a_lcm//ai*ti*math.ceil(t/(a_lcm//ai*ti)), a_lcm*math.ceil(t/(a_lcm//ai*ti))]
if sum(new1) < sum(new2):
t, a = new1[0], new1[1]
else:
t, a = new2[0], new2[1]
print(t+a) |
s963874872 | p03964 | u423665486 | 1588438535 | Python | PyPy3 (2.4.0) | py | Runtime Error | 200 | 39280 | 239 | def resolve():
n = int(input())
v = []
for _ in range(n):
v.append(list(map(int, input().split())))
t, a = 1, 1
for i in range(n):
tv, av = v[i]
c = max(math.ceil(t/tv), math.ceil(a/av))
t, a = c*tv, c*av
print(t+a)
resolve() |
s322874776 | p03964 | u423665486 | 1588438373 | Python | PyPy3 (2.4.0) | py | Runtime Error | 241 | 39280 | 254 | def resolve():
n = int(input())
v = []
for _ in range(n):
v.append(list(map(int, input().split())))
t, a = v[0][0], v[0][1]
for i in range(1, n):
tv, av = v[i]
c = max(math.ceil(t/tv), math.ceil(a/av))
t, a = c*tv, c*av
print(t+a)
resolve() |
s401791776 | p03964 | u934868410 | 1587430443 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3060 | 187 | import math
n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
a,b = map(int,input().split())
m = max(math.ceil(A/a), math.ceil(B/b))
A,B = A * m, B * m
print(A+B) |
s276471622 | p03964 | u934868410 | 1587430414 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 175 | n = int(input())
A,B = map(int,input().split())
for _ in range(n-1):
a,b = map(int,input().split())
m = max(math.ceil(A/a), math.ceil(B/b))
A,B = A * m, B * m
print(A+B) |
s295348045 | p03964 | u556610039 | 1583331942 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 284 | import math
n = int(input())
ans = 0
t_1, a_1 = map(int, input().split())
pret = t_1
prea = a_1
for x in range(n - 1):
t, a = map(int, input().split())
else:
m = max(math.ceil(pret / t), math.ceil(prea / a))
pret = m * t
prea = m * a
print(pret + prea) |
s838151169 | p03964 | u620157187 | 1582619800 | Python | Python (3.4.3) | py | Runtime Error | 25 | 3700 | 328 | import math
from functools import reduce
N = int(input())
t = [0] * N
A = [0] * N
total = []
for i in range(N):
t[i], A[i] = map(int, input().split())
total.append(t[i]+A[i])
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
print(lcm_list(total)) |
s950874418 | p03964 | u052221988 | 1582422156 | Python | Python (3.4.3) | py | Runtime Error | 1633 | 22328 | 914 | import numpy as np
n = int(input())
vlist = [input().split() for i in range(n)]
for m in range(n) :
vlist[m] = [int(l) for l in vlist[m]]
for j in range(n-1) :
if vlist[j][0] <= vlist[j+1][0] and vlist[j][1] <= vlist[j][1] :
continue
if vlist[j][0] > vlist[j+1][0] and vlist[j][0] > vlist[j][1] :
vlist[j+1] = [int(k*(np.lcm(vlist[j][0], vlist[j+1][0]))/vlist[j+1][0]) for k in vlist[j+1]]
continue
elif vlist[j][1] > vlist[j+1][1] and vlist[j][1] > vlist[j][0]:
vlist[j+1] = [int(k*(np.lcm(vlist[j][1], vlist[j+1][1]))/vlist[j+1][1]) for k in vlist[j+1]]
continue
elif vlist[j+1][0] > vlist[j+1][1] :
vlist[j+1] = [int(k*(np.lcm(vlist[j][1], vlist[j+1][1]))/vlist[j+1][1]) for k in vlist[j+1]]
continue
else :
vlist[j+1] = [int(k*(np.lcm(vlist[j][0], vlist[j+1][0]))/vlist[j+1][0]) for k in vlist[j+1]]
print(sum(vlist[n-1])) |
s413760209 | p03964 | u052221988 | 1582422024 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3316 | 895 | n = int(input())
vlist = [input().split() for i in range(n)]
for m in range(n) :
vlist[m] = [int(l) for l in vlist[m]]
for j in range(n-1) :
if vlist[j][0] <= vlist[j+1][0] and vlist[j][1] <= vlist[j][1] :
continue
if vlist[j][0] > vlist[j+1][0] and vlist[j][0] > vlist[j][1] :
vlist[j+1] = [int(k*(np.lcm(vlist[j][0], vlist[j+1][0]))/vlist[j+1][0]) for k in vlist[j+1]]
continue
elif vlist[j][1] > vlist[j+1][1] and vlist[j][1] > vlist[j][0]:
vlist[j+1] = [int(k*(np.lcm(vlist[j][1], vlist[j+1][1]))/vlist[j+1][1]) for k in vlist[j+1]]
continue
elif vlist[j+1][0] > vlist[j+1][1] :
vlist[j+1] = [int(k*(np.lcm(vlist[j][1], vlist[j+1][1]))/vlist[j+1][1]) for k in vlist[j+1]]
continue
else :
vlist[j+1] = [int(k*(np.lcm(vlist[j][0], vlist[j+1][0]))/vlist[j+1][0]) for k in vlist[j+1]]
print(sum(vlist[n-1])) |
s189299201 | p03964 | u052221988 | 1582421987 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 772 | for j in range(n-1) :
if vlist[j][0] <= vlist[j+1][0] and vlist[j][1] <= vlist[j][1] :
continue
if vlist[j][0] > vlist[j+1][0] and vlist[j][0] > vlist[j][1] :
vlist[j+1] = [int(k*(np.lcm(vlist[j][0], vlist[j+1][0]))/vlist[j+1][0]) for k in vlist[j+1]]
continue
elif vlist[j][1] > vlist[j+1][1] and vlist[j][1] > vlist[j][0]:
vlist[j+1] = [int(k*(np.lcm(vlist[j][1], vlist[j+1][1]))/vlist[j+1][1]) for k in vlist[j+1]]
continue
elif vlist[j+1][0] > vlist[j+1][1] :
vlist[j+1] = [int(k*(np.lcm(vlist[j][1], vlist[j+1][1]))/vlist[j+1][1]) for k in vlist[j+1]]
continue
else :
vlist[j+1] = [int(k*(np.lcm(vlist[j][0], vlist[j+1][0]))/vlist[j+1][0]) for k in vlist[j+1]]
print(sum(vlist[n-1])) |
s092733794 | p03964 | u941753895 | 1578287083 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 760 | https://atcoder.jp/contests/abc046/tasks/arc062_a
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
n=I()
t,a=LI()
l=[LI() for _ in range(n-1)]
# t<=nt' and a<=na'
# t/t'<=n and a/a'<=n
for _t,_a in l:
_n=max(-(-t//_t),-(-a//_a))
t=_n*_t
a=_n*_a
return t+a
# main()
print(main())
|
s853909654 | p03964 | u906428167 | 1577416083 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38384 | 249 | n = int(input())
from math import ceil, gcd
tkhs = 1
aoki = 1
for _ in range(n):
t, a = map(int, input().split())
t, a = t // gcd(t,a), a // gcd(t,a)
k = max(ceil(tkhs/t), ceil(aoki/a))
tkhs = k*t
aoki = k*a
print(tkhs+aoki)
|
s591010511 | p03964 | u710659690 | 1577181084 | Python | PyPy3 (2.4.0) | py | Runtime Error | 165 | 38452 | 216 | import numpy as np
N = int(input())
ans1 = 1
ans2 = 1
for _ in range(N):
i1, i2 = list(map(int, input().split()))
n = max(np.ceil(ans1/i1), np.ceil(ans2/i2))
ans1 = i1 * n
ans2 = i2 * n
print(int(ans1+ans2)) |
s589038754 | p03964 | u716530146 | 1576982938 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3188 | 186 | def ceil(x,y):
return x//y+(not( not x%y))
n=int(input())
a,b=1,1
for i in range(n):
t,s = map(int,input().split())
i = max( ceil(a/t), ceil(b/s) )
a=t*i;b=s*i
print(a+b) |
s461624541 | p03964 | u716530146 | 1576963000 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3188 | 252 | from math import ceil
# def ceil(x,y):
# return (x-1)//y+1
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
rate = max(ceil(t, T), ceil(a, A))
t = T * rate
a = A * rate
print(t + a)
|
s166218640 | p03964 | u716530146 | 1576962405 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3188 | 213 | from math import ceil
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
t, a = 1, 1
for T, A in TA:
rate = max(ceil(t, T), ceil(a, A))
t = T * rate
a = A * rate
print(t + a)
|
s048653337 | p03964 | u923659712 | 1572694199 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 268 | n=int(input())
t=[0]*n
a=[0]*n
for i in range(n):
t,a=map(int,input().split())
for i in range(n-1):
while (t[i]>t[i+1]) or (a[i]>a[i+1]):
for k in range(1,100000000000000000000000000000000):
t[i+1]*=k
a[i+1]*=k
print(a[n]+t[n]) |
s225800430 | p03964 | u886747123 | 1571426681 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3188 | 463 | # C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
# 比がa:bとなる合計最小の票分布はa,b
# 次にc:dになったとき、a<=cかつb<=dとなるようにc,dに同じ数をかける
import math
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
a, b = TA[0]
for idx in range(1,N):
c, d = TA[idx]
multi = max(math.ceil(a/c), math.ceil(b/d))
c *= multi
d *= multi
a,b = c,d
print(c+d) |
s113272521 | p03964 | u595716769 | 1570686948 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 30 | 5
3 10
48 17
31 199
231 23
3 2 |
s434776632 | p03964 | u780962115 | 1569162591 | Python | Python (3.4.3) | py | Runtime Error | 40 | 5432 | 431 | #greedy方法
import fractions
n=int(input())
lists=[]
for x in range(n):
x,y=map(int,input().split())
lists.append([x,y])
lists.append([1,1])
a=lists[0][0]
b=lists[0][1]
k=0
cnt=0
while cnt<n:
k=max(fractions.ceil(a/lists[cnt+1][0]),fractions.ceil(b/lists[cnt+1][1]))
a=lists[cnt+1][0]*k
b=lists[cnt+1][1]*k
cnt+=1
print(a+int(a*(min(lists[n-1][0],lists[n-1][1])/max(lists[n-1][0],lists[n-1][1])) )) |
s142128199 | p03964 | u252828980 | 1568830391 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3064 | 444 | n = int(input())
a,b = map(int,input().split())
for i in range(n-1):
c,d = map(int,input().split())
if (c>=a and d>=b):
a = c
b = d
elif not(c>=a and d>=b):
if a%c != 0:
e = a//c+1
elif a%c == 0:
e = a//c
if b%d != 0:
f = b//d+1
elif b%d == 0:
f = b//d
c *= max(e,f)
d *= max(e,f)
a = c
b = d
print(c+d) |
s676722563 | p03964 | u252828980 | 1568828553 | Python | Python (3.4.3) | py | Runtime Error | 2103 | 3064 | 500 | n = int(input())
a,b = map(int,input().split())
for i in range(n-1):
c,d = map(int,input().split())
if (c>=a and d>=b):
a = c
b = d
if not(c>=a and d>=b):
#print(not(c>=a and d>=b))
#print(c,d)
k,l = c,d
m = 1
while True:
#print(c,d)
c += k
d += l
if c>=a and d>=b:
a = c
b = d
break
else:
m += 1
print(c+d) |
s643901421 | p03964 | u759412327 | 1568173536 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 191 | N = int(input())
t = 0
a = 0
for _iin range(N):
rt,ra = map(int,input().split())
c = max((t-1)//rt+1,(a-1)//ra+1)
t = rt*c
a = ra*c
if a+t == 0:
t += rt
a += ra
print(a+t) |
s806981738 | p03964 | u759412327 | 1568081052 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 191 | N = int(input())
t = 0
a = 0
for _ in range(N):
rt,ra = map(int,input().split())
c = max((t-1)//rt+1 (a-1)//ra+1)
t = rt*c
a = ra*c
if a+t == 0:
t += rt
a += ra
print(a+t) |
s691480446 | p03964 | u433532588 | 1567134197 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1 | x |
s598015482 | p03964 | u626337957 | 1565781971 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 348 | N = int(input())
T, A = map(int, input().split())
num = T + A
for _ in range(N-1):
t, a = map(int, input().split())
while True:
if num%(t+a) == 0 and (num*t)//(t+a) >= T and (num*a)//(t+a) >= A:
T = (num*t)//(t+a)
A = (num*a)//(t+a)
break
if num%(t+a) == 0
num += num
else:
num += num%(t+a)
print(num)
|
s723869875 | p03964 | u084324798 | 1565369582 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 344 | num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
ans = [[arr[0][0], arr[0][1]]
for i in range(num-1):
ans.append([arr[i+1][0], arr[i+1][1]])
while ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
ans[i+1][0] += arr[i+1][0]
ans[i+1][1] += arr[i+1][1]
print(ans[num-1][0] + ans[num-1][1]) |
s620925739 | p03964 | u626337957 | 1565292192 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 194 | N = int(input())
num = 1
for _ in range(N):
x, y = map(int, input().split())
sum_xy = sum(x, y)
while True:
if num%sum_xy == 0:
break
else:
num += num%sum_xy
print(num) |
s885160342 | p03964 | u172111219 | 1563914394 | Python | PyPy3 (2.4.0) | py | Runtime Error | 233 | 40944 | 287 | if __name__ =="__main__":
n = int(input())
ls = [[int(x) for x in input().split()] for _ in range(n)]
now_t,now_a = ls[0]
for i in range(1,n):
x = max([~-now_t/ls[i][0] +1 ,~-now_a/ls[i][1] +1])
now_t,now_a = x*ls[i][0],x*ls[i][1]
print(now_t+now_a) |
s693902363 | p03964 | u172111219 | 1563914330 | Python | PyPy3 (2.4.0) | py | Runtime Error | 212 | 40048 | 285 | if __name__ =="__main__":
n = int(input())
ls = [[int(x) for x in input().split()] for _ in range(n)]
now_t,now_a = ls[0]
for i in range(1,n):
x = max([~-now_t/ls[i][0]+1 ,~-now_a/ls[i][1]+1])
now_t,now_a = x*ls[i][0],x*ls[i][1]
print(now_t+now_a) |
s700803530 | p03964 | u567434159 | 1562989835 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 187 | from math import gcd
a, b = 1, 1
for _ in range(int(input())):
x, y = map(int, input().split())
k = int(max((a + x - 1) // x, (b + y - 1) // y))
a = x * k
b = y * k
print(a + b)
|
s195995775 | p03964 | u567434159 | 1562989805 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 187 | from math import gcd
a, b = 1, 1
for _ in range(int(input())):
x, y = map(int, input().split())
k = int(max((a + x - 1) // x, (b + y - 1) // y))
a = x * k
b = y * k
print(a + b)
|
s428122140 | p03964 | u567434159 | 1562989631 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 199 | from math import gcd
from math import ceil
a, b = 1, 1
for _ in range(int(input())):
x, y = map(int, input().split())
k = int(max(ceil(x / a), ceil(y / b)))
a = x * k
b = y * k
print(a + b)
|
s934610944 | p03964 | u567434159 | 1562989604 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 209 | from math import gcd
from math import ceil
a, b = 1, 1
for _ in range(int(input())):
x, y = map(int, input().split())
k = int(max(math.ceil(x / a), math.ceil(y / b)))
a = x * k
b = y * k
print(a + b)
|
s472516242 | p03964 | u567434159 | 1562988591 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 135 | from math import gcd
rs = 1
for _ in range(int(input())):
x = sum(map(int, input().split()))
rs = x * rs / gcd(x, rs)
print(rs)
|
s504210987 | p03964 | u474423089 | 1562295100 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3444 | 666 | from collections import deque
def main():
n = int(input())
t = []
a = []
for i in range(n):
in_t,in_a = map(int,input().split(' '))
t.append(in_t)
a.append(in_a)
q= deque()
q.append([t[0],a[0]])
for i in range(1,n):
while True:
tmp_t,tmp_a=q.popleft()
if tmp_t/tmp_a == t[i]/a[i]:
q.clear()
q.append([tmp_t,tmp_a])
break
elif tmp_t/tmp_a < t[i]/a[i]:
q.append([tmp_t+1,tmp_a])
else:
q.append([tmp_t,tmp_a+1])
return tmp_t+tmp_a
if __name__ == '__main__':
print(main()) |
s903541145 | p03964 | u223646582 | 1561658921 | Python | Python (3.4.3) | py | Runtime Error | 36 | 5048 | 203 | import fractions
N=int(input())
t,a=1,1
for i in range(N):
T,A=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)
|
s215110176 | p03964 | u223646582 | 1561651200 | Python | PyPy3 (2.4.0) | py | Runtime Error | 296 | 63980 | 172 | import fractions
N=int(input())
t,a=1,1
for i in range(N):
T,A=map(int,input().split())
n=max(fractions.ceil(a/A),fractions.ceil(t/T))
t,a=n*T,n*A
print(t+a)
|
s993008987 | p03964 | u704001626 | 1560230101 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3188 | 370 | # -*- coding: utf-8 -*-
n = int(input())
ta = [list(map(int,input().split())) for i in range(n)]
cur_t = 1
cur_a = 1
def ceil(a, b):
return a // b + int(a % b != 0)
for t,a in ta:
if cur_t > t or cur_a > a:
rate = ceil(max([cur_t/t,cur_a/a]))
cur_t = t*rate
cur_a = a*rate
else:
cur_t=t
cur_a=a
print(cur_t+cur_a)
|
s091385862 | p03964 | u655834330 | 1556562805 | Python | PyPy3 (2.4.0) | py | Runtime Error | 202 | 38768 | 548 |
import math
def read_input():
n = int(input())
ratios = []
for i in range(n):
t, a = map(int, input().split())
ratios.append((t, a))
return n, ratios
def get_votes(ex_votes, ratio):
base = max(math.ceil(ex_votes[0]/ratio[0]), math.ceil(ex_votes[1]/ratio[1]))
return (base * ratio[0], base * ratio[1])
def submit():
n, ratios = read_input()
votes = ratios[1]
for ratio in ratios[1:]:
votes = get_votes(votes, ratio)
print(sum(votes))
if __name__ == '__main__':
submit() |
s238918815 | p03964 | u037430802 | 1554525450 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 272 | import math
n = int(input())
pt = [0] * n
pa = [0] * n
for i in range(n):
t, a = map(int, input().split())
if i == 0:
pt[0] = t
pa[0] = a
else:
tmp = math.ceil(max(pt[i-1]/, pa[i-1]/a))
pt[i]=tmp*t
pa[i]=tmp*a
print(int(pt[-1] + pa[-1])) |
s749496527 | p03964 | u037430802 | 1554525430 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 274 | import math
n = int(input())
pt = [0] * n
pa = [0] * n
for i in range(n):
t, a = map(int, input().split())
if i == 0:
pt[0] = t
pa[0] = a
else:
tmp = math.ceil(max(pt[i-1]/t*, pa[i-1]/a))
pt[i]=tmp*t
pa[i]=tmp*a
print(int(pt[-1] + pa[-1])) |
s619944907 | p03964 | u037430802 | 1554525033 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 282 | import math
n = int(input())
pt = [0] * n
pa = [0] * n
for i in range(n):
t, a = map(int, input().split())
if i == 0:
pt[0] = t
pa[0] = a
else:
tmp = math.ceil(max([pt[i-1]/t*1.0, pa[i-1]a*1.0]))
pt[i]=tmp*t
pa[i]=tmp*a
print(int(pt[-1] + pa[-1])) |
s118671673 | p03964 | u026155812 | 1554247443 | Python | Python (3.4.3) | py | Runtime Error | 38 | 5144 | 493 | import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque
N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
print(a+b)
else:
for x, y in zip(T[1:], A[1:]):
c = max((a11)//(x+1), (b-1)/(y+1))
a, b = x*c, y*c
print(a+b) |
s596954251 | p03964 | u026155812 | 1554246204 | Python | Python (3.4.3) | py | Runtime Error | 22 | 2940 | 527 | import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque
N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
T[i], A[i] = map(int, input().split())
a, b = 1, 1
else:
for x, y in zip(T, A):
if a>x or b>y:
c = max(math.ceil(a/x), math.ceil(b/y))
a, b = x*c, y*c
else:
a, b = x, y
print(a+b) |
s125581178 | p03964 | u001024152 | 1553281853 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 243 | N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1
for nt,na in ratio:
if nt<t or na<a:
r = max(-(-t//nt), -(-a//na)
nt *= r
na *= r
t,a = nt,na
#print(t, a)
print(t+a)
|
s410359592 | p03964 | u001024152 | 1553279017 | Python | PyPy3 (2.4.0) | py | Runtime Error | 216 | 39536 | 288 | from math import ceil
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1
for nt,na in ratio:
r = 1
if nt<t:
r *= ceil(t/nt)
if na*r<a:
r *= ceil(a/na)
na = r*na
nt = r*nt
t,a = nt,na
#print(t, a)
print(t+a) |
s255489824 | p03964 | u001024152 | 1553278676 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3188 | 286 | from math import ceil
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1
for nt,na in ratio:
r = 1
if nt<t:
r *= ceil(t/nt)
if na<a:
r *= ceil(a/na)
na = r*na
nt = r*nt
t,a = nt,na
#print(t, a)
print(t+a) |
s031530386 | p03964 | u518064858 | 1551507494 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 349 | n=int(input())
for i in range(n):
if i==0:
x,y=map(int,input().split())
else:
t,a=map(int,input().split())
if t==1 and a==1:
x=max(x,y)
y=max(x,y)
else:
t=t*max(int(x/t),int(y/a))
a=a*max(int(x/t),int(y/a))
x=t
y=a
print(x+y)
|
s971689172 | p03964 | u518064858 | 1551504753 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 258 | n=int(input())
for i in range(n):
if i==1:
x,y=map(int,input().split())
else:
t,a=map(int,input().split())
v=t
w=a
while t<x or a<y:
v+=t
w+=a
x=v
y=w
print(x+y)
|
s966800604 | p03964 | u964763428 | 1551328001 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 433 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int N;
cin >> N;
vector<ll> T(N);
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> T.at(i) >> A.at(i);
}
ll t=1,a=1;
for (int i = 0; i < N; i++) {
ll x=t/T.at(i);
ll y=a/A.at(i);
if(t%T.at(i)!=0) x++;
if(a%A.at(i)!=0) y++;
int co=max(x,y);
t=co*T.at(i);
a=co*A.at(i);
}
cout << t+a << endl;
}
|
s312978946 | p03964 | u369752439 | 1548108316 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3188 | 953 | from math import *
N = int(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]))
nextfacA = int(ceil(prevA / A[i]))
nextfac = max(nextfacT, nextfacA)
while(nextfac * T[i] < prevT and nextfac * A[i] < prevA):
nextfac += 1
prevT = nextfac * T[i]
prevA = nextfac * A[i]
print(prevA+prevT)
from math import *
N = int(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]))
nextfacA = int(ceil(prevA / A[i]))
nextfac = max(nextfacT, nextfacA)
while(nextfac * T[i] < prevT and nextfac * A[i] < prevA):
nextfac += 1
prevT = nextfac * T[i]
prevA = nextfac * A[i]
print(prevA+prevT) |
s461979673 | p03964 | u575431498 | 1547686087 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 393 | A = []
for _ in range(N):
t, a = map(int, input().split())
T.append(t)
A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
if curT > curA:
if curT % T[i] != 0:
curT += T[i] - curT % T[i]
curA = curT // T[i] * A[i]
else:
if curA % A[i] != 0:
curA += A[i] - curA % A[i]
curT = curA // A[i] * T[i]
print(curT+curA) |
s385447184 | p03964 | u343930666 | 1547294441 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 1359 | #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;
template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}
int main(int argc, char* argv[])
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll N;
std::cin >> N;
std::vector< ll > va(N, 0LL);
std::vector< ll > vb(N, 0LL);
for (ll i = 0; i < N; i++) {
std::cin >> va[i] >> vb[i];
}
ll a = 1;
ll b = 1;
for (ll i = 0; i < N; i++) {
ll n = std::max((a + va[i] - 1) / va[i], (b + vb[i] - 1) / vb[i]);
a = n * va[i];
b = n * vb[i];
//std::cout << a << " " << b << std::endl;
}
std::cout << a + b << std::endl;
return 0;
}
|
s095353751 | p03964 | u499966353 | 1545580334 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3188 | 408 | n = int(input())
rates = [list(map(int, input().split())) for i in range(n)]
def nextgen(points, nextrate):
pro = 0
boolnow = True
while(boolnow):
pro += 1
boolnow = not(poits[0] <= pro * nextrate[0] and points[1] <= pro * nextrate[1])
return [nextrate[0] * pro, nextrate[1] * pro]
pointnow = [1, 1]
for i in range(n):
pointnow = nextgen(pointnow, rates[i])
print(sum(pointnow))
|
s554682445 | p03964 | u557437077 | 1545090490 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3060 | 517 | import math
n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
t, a = [int(i) for i in input().split()]
k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
vote = [t * k, a * k]
if sum(vote) > 10**10:
t[1000000000] = 1
# print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])
|
s422311421 | p03964 | u513081876 | 1544894227 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3064 | 443 | 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) |
s426940192 | p03964 | u513081876 | 1543170927 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3060 | 311 | 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)
#print(T,A)
T = n*t
A = n*a
print(sum(T+A)) |
s306280147 | p03964 | u060392346 | 1542887254 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 320 | 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) |
s234469751 | p03964 | u140251125 | 1542814582 | Python | Python (3.4.3) | py | Runtime Error | 30 | 3828 | 368 | from functools import reduce
import math
# input
N = int(input())
TA = [list(map(int, input().split())) for _ in range(N)]
# 最小公倍数
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
ans = 1
for i in range(N):
if TA[i][0] + TA[i][1] >= ans:
ans = TA[i][0] + TA[i][1]
else:
ans = lcm_base(ans, TA[i][0] + TA[i][1])
print(ans)
|
s993037216 | p03964 | u681150536 | 1540318515 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 490 | import math
from Decimal import *
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 = Decimal(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() |
s884804046 | p03964 | u681150536 | 1540274872 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3064 | 814 | 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):
if math.gcd(A[i], T[i]) != 1:
A[i] = A[i] // math.gcd(A[i], T[i])
T[i] = T[i] // math.gcd(A[i], T[i])
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() |
s580798749 | p03964 | u761989513 | 1536899431 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 255 | def ceil(x, y):
if x % y == 0:
return x // y
else:
return x // y + 1
n = int(input())
t = a = 1
for i in range(n):
T, A = map(int, input().split())
n = max(ceil(t / T), ceil(a / A))
t = n * T
a = n * A
print(t + a) |
s086876154 | p03964 | u466105944 | 1536863985 | Python | Python (3.4.3) | py | Runtime Error | 21 | 3060 | 254 | def ceil(x,y):
if x%y == 0:
return x//y
if x%y == 1:
return x//y + 1
n = int(input())
x,y = 1,1
for _ in range(n):
t,a = map(int,input().split())
temp = max(ceil(x,t),ceil(y,a))
x = t*temp
y = a*temp
print(x+y) |
s938079301 | p03964 | u255280439 | 1535087142 | Python | Python (3.4.3) | py | Runtime Error | 41 | 4852 | 3768 | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in inspect.currentframe().f_back.f_locals.items()
}
print(', '.join(
names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if (r < 0 or r > n):
return 0
r = min(r, n - r)
return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD
# --------------------------------------------
dp = None
def main():
N = int(input())
D = [li_input() for _ in range(N)]
t, a = D[0][0], D[0][1]
for i in range(1, N):
t_rate, a_rate = D[i]
if t_rate == a_rate:
t = max(t, a)
a = max(t, a)
elif t_rate > a_rate:
if a_rate != 1:
a = a + (a_rate - (a % a_rate))
if a // a_rate * t_rate >= t:
t = a // a_rate * t_rate
else:
pre_t = t
t = a // a_rate * t_rate
insuff = pre_t - t
need = math.ceil(insuff / t_rate)
a += (need * a_rate)
t += (need * t_rate)
else:
if t_rate != 1:
t = t + (t_rate - (t % t_rate))
if t // t_rate * a_rate >= a:
a = t // t_rate * a_rate
else:
pre_a = a
a = t // t_rate * a_rate
insuff = pre_a - a
need = math.ceil(insuff / a_rate)
a += (a * need)
t += (t * need)
print(a + t)
main()
|
s525995661 | p03964 | u826263061 | 1534020082 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 410 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
t, a = list(map(int, input().split()))
if ti == t and ai == a:
continue
ti = t
ai = a
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(nit, nia))
vi = ni*(ti+ai)
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s736574718 | p03964 | u826263061 | 1534019532 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 468 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
t, a = list(map(int, input().split()))
if ti == t and ai == a:
continue
ti = t
ai = a
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(nit, nia))
vi = ni*(ti+ai)
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s843931820 | p03964 | u826263061 | 1534019418 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 501 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
t, a = list(map(int, input().split()))
if ti == t and ai == a:
continue
ti = t
ai = a
niv = vp/(ti+ai)
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(nit, nia))
vi = ni*(ti+ai)
vp = vi
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s349138037 | p03964 | u826263061 | 1534018459 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3188 | 563 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
t, a = list(map(int, input().split()))
if ti == t and ai == a:
continue
ti = t
ai = a
niv = vp/(ti+ai)
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(niv, nit, nia))
vi = ni*(ti+ai)
if vi <= vp:
ni += 1
vi = ni*(ti+ai)
vp = vi
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s649440113 | p03964 | u826263061 | 1534018353 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 506 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
t, a = list(map(int, input().split()))
if ti == t and ai == a:
continue
ti = t
ai = a
niv = vp/(ti+ai)
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(niv, nit, nia))
vi = ni*(ti+ai)
vp = vi
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s996624530 | p03964 | u826263061 | 1534016876 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 494 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
t, a = list(map(int, input().split()))
if ti == t and ai == a:
continue
ti = t
ai = a
niv = vp/(ti+ai)
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(niv, nit, nia))
vi = ni*(ti+ai)
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s433189630 | p03964 | u826263061 | 1534016421 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 429 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
ti, ai = list(map(int, input().split()))
niv = vp/(ti+ai)
nit = tp/ti
nia = ap/ai
ni = math.ceil(max(niv, nit, nia))
vi = ni*(ti+ai)
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s146672585 | p03964 | u826263061 | 1534014986 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 451 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
ti, ai = list(map(int, input().split()))
niv = math.ceil(vp/(ti+ai))
nit = math.ceil(tp/ti)
nia = math.ceil(ap/ai)
ni = max(niv, nit, nia)
vi = ni*(ti+ai)
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
s218140839 | p03964 | u826263061 | 1534014593 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 3064 | 444 | # -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
ti, ai = list(map(int, input().split()))
ni = math.ceil(vp/(ti+ai))
while ni*ti < tp:
ni += 1
while ni*ai < ap:
ni += 1
vi = ni*(ti+ai)
#print(ni, vi)
tp = ni*ti
ap = ni*ai
print(vi) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.