code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
# ABC145 D
X,Y=map(int,input().split())
a,b=-1,-1
if not (2*X-Y)%3:
b=(2*X-Y)//3
if not (2*Y-X)%3:
a=(2*Y-X)//3
N=10**6
p=10**9+7
f,finv,inv=[0]*N,[0]*N,[0]*N
def nCr_init(L,p):
for i in range(L+1):
if i<=1:
f[i],finv[i],inv[i]=1,1,1
else:
f[i]=(f[i-1]*i)%p
inv[i]=(p-inv[p%i]*(p//i))%p
finv[i]=(finv[i-1]*inv[i])%p
def nCr(n,r,p):
if 0<=r<=n and 0<=n:
return (f[n]*finv[n-r]*finv[r])%p
else:
return 0
nCr_init(a+b+1,p)
if a>=0 and b>=0:
print(nCr(a+b,b,p))
else:
print(0)
|
nq = str(input()).split()
n = int(nq[0])
q = int(nq[1])
p = [str(input()).split() for i in range(n)]
p = [(str(i[0]), int(i[1])) for i in p]
ans = []
time = 0
while len(p) != 0:
t = p.pop(0)
if t[1] > q:
#p = [(s[0], s[1], s[2]+q) for s in p]
time += q
p.append((t[0], t[1]-q))
elif t[1] <= q:
#p = [(s[0], s[1], s[2]+t[1]) for s in p]
ans.append((t[0], t[1]+time))
time += t[1]
for t in ans:
print('{0} {1}'.format(t[0], t[1]))
| 0 | null | 75,008,640,780,000 | 281 | 19 |
import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
L = list(range(N))
L.sort(key = lambda x: A[x], reverse = True)
dp = [[0]*(N+1) for _ in range(N+1)]
for s in range(N):
l = L[s]
a = A[l]
for i in range(s+1):
j = s-i
dp[i+1][j] = max(dp[i+1][j], dp[i][j]+a*abs(l-i))
dp[i][j+1] = max(dp[i][j+1], dp[i][j]+a*abs(l-(N-s+i-1)))
ans = 0
for i in range(N+1):
ans = max(ans, dp[i][N-i])
print(ans)
|
x1,x2,x3,x4,x5=(int(i) for i in input().split())
if x1==0:
print(1)
elif x2==0:
print(2)
elif x3==0:
print(3)
elif x4==0:
print(4)
else:
print(5)
| 0 | null | 23,782,353,730,330 | 171 | 126 |
S=str(input())
n=[]
for i in range(3):
n.append(S[i])
print(''.join(n))
|
line=input()
print(line[:3])
| 1 | 14,773,948,057,132 | null | 130 | 130 |
N=int(input())
res=[1000000000000]
for i in range(1,int(N**0.5)+1):
if(N%i==0):
res.append(i+N//i-2)
print(min(res))
|
import sys
input = sys.stdin.readline
def main():
N = int( input())
S = [input().strip() for _ in range(N)]
Up = []
Down = []
for s in S:
now = 0
m = 0
for t in s:
if t == "(":
now += 1
else:
now -= 1
if now < m:
m = now
# print(t, now)
if now >= 0:
Up.append((m,now))
else:
Down.append((m-now,-now))
up = 0
Up.sort(reverse=True)
for m, inc in Up:
if up+m < 0:
print("No")
return
up += inc
down = 0
Down.sort(reverse=True)
# print(Up, Down)
for m, dec in Down:
if down+m < 0:
print("No")
return
down += dec
if up != down:
print("No")
return
print("Yes")
if __name__ == '__main__':
main()
| 0 | null | 92,568,442,427,580 | 288 | 152 |
a,b,n=map(int,input().split())
if a%n == 0 and b%n == 0:
print((b//n) - (a//n) + 1)
else:
print((b//n) - (a//n))
|
import math
sqrt3 = math.sqrt(3.0)
def koch_curve(n, i, pt1, pt2, pt_array):
if i > n:
return
pt1x, pt1y = pt1
pt2x, pt2y = pt2
pts = (2/3 * pt1x + 1/3 * pt2x, 2/3 * pt1y + 1/3 * pt2y)
ptt = (1/3 * pt1x + 2/3 * pt2x, 1/3 * pt1y + 2/3 * pt2y)
ptx = ptt[0] - pts[0]
pty = ptt[1] - pts[1]
ptu = (1/2 * (ptx - sqrt3 * pty) + pts[0], 1/2 * (sqrt3 * ptx + pty) + pts[1])
koch_curve(n, i+1, pt1, pts, pt_array)
pt_array.append(pts)
koch_curve(n, i+1, pts, ptu, pt_array)
pt_array.append(ptu)
koch_curve(n, i+1, ptu, ptt, pt_array)
pt_array.append(ptt)
koch_curve(n, i+1, ptt, pt2, pt_array)
return
def main():
n = int(input())
pt_array = []
begin = (0.0, 0.0)
end = (100.0, 0.0)
pt_array.append(begin)
koch_curve(n, 1, begin, end, pt_array)
pt_array.append(end)
for pt in pt_array:
print("{:.6f} {:.6f}".format(pt[0], pt[1]))
main()
| 0 | null | 3,867,896,448,830 | 104 | 27 |
MAX = 5 * 10**5
SENTINEL = 2 * 10**9
cnt = 0
def merge(A, left, mid, right):
n1 = mid - left;
n2 = right - mid;
L = A[left:left+n1]
R = A[mid:mid+n2]
global cnt
L.append(SENTINEL)
R.append(SENTINEL)
i = 0
j = 0
for k in range(left, right):
cnt += 1
if L[i] < R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j+= 1
def mergeSort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2;
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
n = int(input())
s = list(map(int, input().split()))
mergeSort(s, 0, len(s))
ans = []
for item in s:
ans.append(str(item))
print(' '.join(ans))
print(cnt)
|
n = int(input())
A = list(map(int, input().split()))
SWAP = 0
def conquer(A, left, mid, right):
L, R = A[left:mid], A[mid:right]
# L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
INFTY = 2 ** 30
L.append(INFTY)
R.append(INFTY)
# i : position in L, j : position in R
i, j = 0, 0
swap_times = 0
# 元のArrayを変えたいため、kを生成
for k in range(left, right):
# print(i, j, L, R, A)
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
swap_times += 1
return swap_times
def divide(A, left, right):
# print(left, right)
# A[right-left]が2つ以上の場合に
if left+1 < right:
mid = (left+right)//2
countL = divide(A, left, mid)
countR = divide(A, mid, right)
return conquer(A, left, mid, right) + countL + countR
return 0
def mergeSort(A):
return divide(A, 0, len(A))
swap = mergeSort(A)
print(" ".join([ str(i) for i in A]))
print(swap)
| 1 | 112,064,986,228 | null | 26 | 26 |
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np
# A = input()
A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(li[A-1])
|
#!/usr/bin/python
s=raw_input()
p=raw_input()
s+=s
print "Yes" if p in s else "No"
| 0 | null | 25,904,176,662,620 | 195 | 64 |
N = int(input())
count = {}
max_count = 0
for _ in range(N):
s = input()
if s not in count:
count[s] = 0
count[s] += 1
max_count = max(max_count, count[s])
longest = []
for s, c in count.items():
if c == max_count:
longest.append(s)
longest.sort()
for s in longest:
print(s)
|
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
c = Counter(s)
m = c.most_common()[0][1]
k = list(c.keys())
v = list(c.values())
l = []
for i in range(len(c)):
if v[i] == m:
l.append(k[i])
l.sort()
print(*l,sep="\n")
| 1 | 69,935,021,249,282 | null | 218 | 218 |
import math, cmath
def koch(p1, p2, n):
if n == 0:
return [p1, p2]
rad60 = math.pi/3
v1 = (p2 - p1)/3
v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
q1 = p1 + v1
q2 = q1 + v2
q3 = q1 + v1
if n == 1:
return [p1,q1,q2,q3,p2]
else:
x1 = koch(p1,q1,n-1)[1:-1]
x2 = koch(q1,q2,n-1)[1:-1]
x3 = koch(q2,q3,n-1)[1:-1]
x4 = koch(q3,p2,n-1)[1:-1]
x = [p1]+x1+[q1]+x2+[q2]+x3+[q3]+x4+[p2]
return x
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
for e in koch(p1,p2,n):
print e.real,e.imag
|
import math
def koch(d,x1,y1,x2,y2):
if d == 0:
return
xs = (2*x1+x2)/3
ys = (2*y1+y2)/3
xt = (x1+2*x2)/3
yt = (y1+2*y2)/3
xu = (xt-xs)*math.cos(math.pi/3) - (yt-ys)*math.sin(math.pi/3) + xs
yu = (xt-xs)*math.sin(math.pi/3) + (yt-ys)*math.cos(math.pi/3) + ys
koch(d-1,x1,y1,xs,ys)
print(xs,ys)
koch(d-1,xs,ys,xu,yu)
print(xu,yu)
koch(d-1,xu,yu,xt,yt)
print(xt,yt)
koch(d-1,xt,yt,x2,y2)
n = int(input())
print(0.00000000,0.00000000)
koch(n,0.0,0.0,100.0,0.0)
print(100.00000000,0.00000000)
| 1 | 126,922,924,470 | null | 27 | 27 |
c=int(input())
ans=0
now=0
for _ in range(c):
if eval(input().replace(" ","==")):
now = now+1
else:
now = 0
ans = max(ans,now)
print("Yes") if ans >= 3 else print("No")
|
a=int(input())
p=a+a**2+a**3
print(p)
| 0 | null | 6,273,811,341,252 | 72 | 115 |
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
m = (l + r) // 2
res = 0
for x in a:
res += n - bisect_left(a, m - x)
if res >= k:
l = m
else:
r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
t = n - bisect_left(a, l - x)
ans += b[t] + x * t
cnt += t
print(ans - (cnt - k) * l)
|
W, H, x, y, r = list(map(int, input().split()))
x_right = x + r
x_left = x - r
y_up = y + r
y_down = y - r
if x_right <= W and x_left >= 0 and y_up <= H and y_down >= 0:
print("Yes")
else:
print("No")
| 0 | null | 54,223,692,532,902 | 252 | 41 |
N=int(input())
ok=0
for i in range(1,10):
j = N/i
if j==int(j) and 1<=j<=9:
ok=1
print('Yes')
break
if ok==0:print('No')
|
n = int(input())
def binary_search(l, target):
left = 0
right = len(l)
while left<right:
mid = (left+right)//2
if target == l[mid]:
return True
elif target < l[mid]:
right = mid
else:
left = mid+1
return False
seki = [i*j for i in range(1, 10) for j in range(1, 10)]
seki.sort()
if binary_search(seki, n):
print('Yes')
else:
print('No')
| 1 | 160,432,683,408,790 | null | 287 | 287 |
# D
N = int(input())
A = list(map(int,input().split()))
next_number = 1
cnt = 0
for a in A:
if a == next_number:
next_number += 1
else:
cnt += 1
if cnt == len(A):
print('-1')
else:
print(cnt)
|
N = int(input())
A = list(map(int, input().split()))
count = 0
now = 1
for i in range(len(A)):
if A[i] == now:
now += 1
else:
count += 1
print(count if now != 1 else -1)
| 1 | 114,609,720,810,578 | null | 257 | 257 |
l,r,d =map(int,input().split())
rd = r//d
ld = (l-1)//d
answer = rd -ld
print(answer)
|
A = ["1", "1", "1", "2", "1", "2", "1", "5", "2", "2", "1", "5", "1", "2", "1", "14", "1", "5", "1", "5", "2", "2", "1", "15", "2", "2", "5", "4", "1", "4", "1", "51"]
K = int(input())
print(A[K-1])
| 0 | null | 28,961,427,205,690 | 104 | 195 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n = input()
if n[-1] in ['2','4','5','7','9']:
print('hon')
elif n[-1] in ['0','1','6','8']:
print('pon')
else:
print('bon')
|
import math
x=int(input());money=100;year=0
while money < x:
money+=money//100
year+=1
print(year)
| 0 | null | 23,042,365,261,172 | 142 | 159 |
import math
a, b = list(map(int, input().split()))
for i in range(1, 1250):
p8 = math.floor(i * 0.08)
p10 = math.floor(i * 0.10)
if p8 == a and p10 == b:
print(i)
exit()
print(-1)
|
import math as mt
x = list(map(float,input().split()))
a = ((x[0]-x[2])**2)+((x[1]-x[3])**2)
print(mt.sqrt(a))
| 0 | null | 28,362,037,824,068 | 203 | 29 |
(h,n),*t=[[*map(int,t.split())]for t in open(0)]
d=[0]*9**8
for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t)
print(d[h])
|
import sys
read = sys.stdin.buffer.read
INF = 1 << 60
def main():
H, N, *AB = map(int, read().split())
dp = [INF] * (H + 1)
dp[0] = 0
for a, b in zip(*[iter(AB)] * 2):
for i in range(H + 1):
if dp[i] > dp[max(i - a, 0)] + b:
dp[i] = dp[max(i - a, 0)] + b
print(dp[H])
return
if __name__ == '__main__':
main()
| 1 | 81,163,617,828,928 | null | 229 | 229 |
h, w, m = list(map(int, input().split()))
count_row = [0 for _ in range(h)]
count_col = [0 for _ in range(w)]
max_col = 0
max_row = 0
max_row_index = []
max_col_index = []
M = set()
for i in range(m):
mh, mw = list(map(int, input().split()))
M.add((mh-1, mw-1))
count_row[mh-1] += 1
count_col[mw-1] += 1
if count_row[mh-1] > max_row:
max_row = count_row[mh-1]
max_row_index = [mh-1]
elif count_row[mh-1] == max_row:
max_row_index.append(mh-1)
if count_col[mw-1] > max_col:
max_col = count_col[mw-1]
max_col_index = [mw-1]
elif count_col[mw-1] == max_col:
max_col_index.append(mw-1)
# max_row_index = [i for i, v in enumerate(count_row) if v == max(count_row)]
# max_col_index = [i for i, v in enumerate(count_col) if v == max(count_col)]
# ans = max(count_row) + max(count_col) -1
ans = max_col + max_row -1
if len(max_col_index)*len(max_row_index) > m:
ans += 1
else:
flag = False
for i in max_row_index:
for j in max_col_index:
if (i, j) not in M:
ans += 1
flag = True
break
if flag:
break
print(ans)
|
a, b = map(int, input().split())
print("unsafe" if (a <= b) else "safe")
| 0 | null | 16,971,894,091,236 | 89 | 163 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
def sub(x):
val = 0
for aa,ff in zip(a,f):
val += max(0, aa - (x//ff))
return val<=k
if sub(0):
ans = 0
else:
l = 0
r = sum(aa*ff for aa,ff in zip(a,f))
while l+1<r:
m = (l+r)//2
if sub(m):
r = m
else:
l = m
ans = r
print(ans)
|
x = int(input())
rl = 400
for i in range(8, 0, -1):
if (rl <= x) and (x <= rl+199):
print(i)
rl += 200
| 0 | null | 86,234,243,448,618 | 290 | 100 |
arr = [[[0 for i1 in range(10)] for i2 in range(3)] for i3 in range(4)]
count=input()
for l in range(int(count)):
b,f,r,v=input().split()
arr[int(b)-1][int(f)-1][int(r)-1]+=int(v)
first_b = arr[0]
second_b = arr[1]
third_b = arr[2]
fourth_b= arr[3]
for m in range(3):
for n in range(10):
print(" "+str(first_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(second_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(third_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(fourth_b[m][n]),end="")
print()
|
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n,k = readInts()
print(min(n%k,k - (n%k)))
| 0 | null | 20,339,794,114,172 | 55 | 180 |
import itertools
n = int(input())
a = [input() for _ in range(n)]
suits = ['S', 'H', 'C', 'D']
cards = ["%s %d" % (s, r) for s, r in itertools.product(suits, range(1, 14))]
answers = [c for c in cards if c not in a]
for card in answers:
print(card)
|
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
n,m,l=map(int,input().split())
ans=[[0]*n for i in range(n)]
for i in range(m):
a,b,c=[int(j) for j in input().split()]
ans[a-1][b-1]=c
ans[b-1][a-1]=c
q=int(input())
st=[]
for i in range(q):
st.append([int(j)-1 for j in input().split()])
ans=floyd_warshall(ans)
for i in range(n):
for j in range(n):
if ans[i][j]<=l:
ans[i][j]=1
else:
ans[i][j]=0
ans=floyd_warshall(ans)
for i,j in st:
if ans[i][j]==float("inf"):
print(-1)
else:
print(int(ans[i][j])-1)
| 0 | null | 86,948,948,183,862 | 54 | 295 |
n,*l=map(int,open(0).read().split())
e=[1]
for i in range(n): e+=[(e[-1]-l[i])*2]
a=t=0
for i in range(n,-1,-1):
if l[i]>e[i]: print(-1); break
t=min(l[i]+t,e[i]); a+=t
else: print(a)
|
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
if ((i+1)*a[i])%2!=0:
ans+=1
print(ans)
| 0 | null | 13,404,710,641,160 | 141 | 105 |
for x in range(1, 10):
for y in range(1, 10):
print "{}x{}={}".format(x, y, x*y)
|
i=[1,2,3,4,5,6,7,8,9]
j=[1,2,3,4,5,6,7,8,9]
for i1 in i:
for j1 in j:
answer=i1*j1
print(str(i1)+"x"+str(j1)+"="+str(answer))
| 1 | 148,940 | null | 1 | 1 |
H_1, M_1, H_2, M_2, K = list(map(int, input().split(' ')))
print((H_2-H_1)*60+(M_2-M_1)-K)
|
h1, m1, h2, m2, k = map(int, input().split())
s = h1*60+m1
t = h2*60+m2
ans = t-s-k
print (max(ans,0))
| 1 | 17,939,489,805,820 | null | 139 | 139 |
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
from bisect import bisect_left
def isok(n):
sum=0
for i in range(N):
sum+=N-bisect_left(A,n-A[i])
return sum>=M
start,end=0,2*10**5+1
while end-start>1:
mid=(start+end)//2
if isok(mid):
start=mid
else:
end=mid
b=[A[0]]
for i in range(1,N):
b.append(b[-1]+A[i])
l=0
ans=0
bn=b[N-1]
for i in range(N):
a=bisect_left(A,start-A[i])
l+=N-a
if a>0:
ans+=A[i]*(N-a)+bn-b[a-1]
else:
ans+=A[i]*(N-a)+bn
ans-=start*(l-M)
print(ans)
|
from decimal import Decimal
A, B = input().split()
A = int(A)
if len(B) == 1:
B = int(B[0] + '00')
elif len(B) == 3:
B = int(B[0] + B[2] + '0')
else:
B = int(B[0]+B[2]+B[3])
x = str(A*B)
print(x[:-2] if len(x) > 2 else 0)
| 0 | null | 62,250,168,186,360 | 252 | 135 |
N = int(input())
ans = [0] * (N+1)
for i in range(N+1):
if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
ans[i] = ans[i-1] + i
else:
ans[i] = ans[i-1]
print(ans[-1])
|
def solve():
N,M = [int(i) for i in input().split()]
ans = 0
if N > 1:
ans += N * (N-1) // 2
if M > 1:
ans += M * (M-1) // 2
print(ans)
if __name__ == "__main__":
solve()
| 0 | null | 40,262,958,117,270 | 173 | 189 |
A, B, C = map(int,input().split())
if A == B and B != C:
print('Yes')
elif C == B and C != A:
print('Yes')
elif A == C and C != B:
print('Yes')
else:
print('No')
|
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
H, W = map(int, readline().split())
masu = []
for _ in range(H):
masu.append(readline().rstrip().decode('utf-8'))
# print(masu)
dp = [[INF]*W for _ in range(H)]
dp[0][0] = int(masu[0][0] == "#")
dd = [(1, 0), (0, 1)]
# 配るDP
for i in range(H):
for j in range(W):
for dx, dy in dd:
ni = i + dy
nj = j + dx
# はみ出す場合
if (ni >= H or nj >= W):
continue
add = 0
if masu[ni][nj] == "#" and masu[i][j] == ".":
add = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add)
# print(dp)
ans = dp[H-1][W-1]
print(ans)
| 0 | null | 58,679,746,742,130 | 216 | 194 |
ab = [int(x) for x in input().split()]
# Naive Algorithm
# m = min(ab)
# gcd = 1
# for i in range(2, int(m/2)):
# if ab[0] % i == 0 and ab[1] % i == 0:
# gcd = i
# print(gcd)
# Euclidean Algorithm
while True:
min_i = ab.index(min(ab))
max_i = ab.index(max(ab))
r = ab[max_i] % ab[min_i]
if r == 0:
print(ab[min_i])
break
else:
ab[max_i] = r
|
def division(x,y):
if y == 0:
return x
return division(y, x%y)
x,y=map(int,input().split())
kotae = division(x,y)
print(kotae)
| 1 | 7,549,450,812 | null | 11 | 11 |
import collections
n,x,m=map(int,input().split())
if n==1 or x==0:
print(x)
exit()
start,end,loopcnt=0,0,0
a={x:0}
wk=x
for i in range(1,m):
wk=(wk*wk)%m
if not wk in a:
a[wk]=i
else:
start=a[wk]
end=i
break
a=sorted(a.items(),key=lambda x:x[1])
koteiindex=min(n,start)
koteiwa=0
for i in range(koteiindex):
koteiwa+=a[i][0]
loopcnt=(n-koteiindex)//(end-start)
loopindex=start-1+(n-koteiindex)%(end-start)
loopwa=0
amariwa=0
for i in range(start,end):
if i<=loopindex:
amariwa+=a[i][0]
loopwa+=a[i][0]
ans=koteiwa+loopwa*loopcnt+amariwa
print(ans)
|
import math
import sys
pin=sys.stdin.readline
def main():
N,X,M=map(int,pin().split())
A=X
d=[X]
su=X
for i in range(N-1):
A=(A**2)%M
if A in d:
t=d.index(A)
T=N-i-1
d=d[t:]
l=len(d)
su+=sum(d)*(T//l)
T=T%(T//l)
su+=sum(d[:T])
print(su)
return
d.append(A)
su+=A
print(su)
return
main()
| 1 | 2,826,473,581,340 | null | 75 | 75 |
import itertools
n = int(input())
ans = 0
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
def q(m):
check = 0
while m >= check * (check + 1) / 2:
check += 1
return check - 1
a = prime_factorize(n)
gr = itertools.groupby(a)
for key, group in gr:
ans += q(len(list(group)))
print(ans)
|
N = int(input())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
if (n == 1):
return []
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
#print(factorization(N))
list_a = factorization(N)
count = 0
for i in range(len(list_a)):
num = list_a[i][1]
cal = 1
while(num > 0):
num -= cal
cal += 1
if(num < 0) :
break
count += 1
#print(num,count)
print(count)
| 1 | 17,058,122,949,306 | null | 136 | 136 |
N = int(input())
ans = (N * 100 + 99) // 108
if N==int(ans*1.08):
print(ans)
else:
print(':(')
|
import math
x1,y1,x2,y2 = map(float, input().split())
a1 = (x2-x1)**2
a2 = (x1-x2)**2
b1 = (y2-y1)**2
b2 = (y1-y2)**2
if x1<x2:
if y1<y2:
print(math.sqrt(a1+b1))
else:
print(math.sqrt(a1+b2))
else:
if y1<y2:
print(math.sqrt(a2+b1))
else:
print(math.sqrt(a2+b2))
| 0 | null | 62,744,119,037,662 | 265 | 29 |
print("\n".join(map(str,sorted([int(input())for _ in[0]*10])[:-4:-1])))
|
class Dice:
def __init__(self, list):
self.list = list #listのinput
def roll_n(self):
self.list = [self.list[1], self.list[5], self.list[2], self.list[3], self.list[0], self.list[4]]
def roll_s(self):
self.list = [self.list[4], self.list[0], self.list[2], self.list[3], self.list[5], self.list[1]]
def roll_e(self):
self.list = [self.list[3], self.list[1], self.list[0], self.list[5], self.list[4], self.list[2]]
def roll_w(self):
self.list = [self.list[2], self.list[1], self.list[5], self.list[0], self.list[4], self.list[3]]
def print0(self):
print(self.list[0])
list = list(map(int, input().split()))
direct = input()
instance = Dice(list)
for i in direct:
if i == 'N':
instance.roll_n()
if i == 'S':
instance.roll_s()
if i == 'E':
instance.roll_e()
if i == 'W':
instance.roll_w()
instance.print0()
| 0 | null | 119,037,061,208 | 2 | 33 |
import numpy as np
a, b, x = map(int,input().split())
if x >= a**2*b/2:
ans = np.arctan(2*(b-x/a**2)/a)
else:
ans = np.arctan(a*b/2/x*b)
print(ans*180/np.pi)
|
n,k=map(int,input().split());n,c=set(range(1,n+1)),set()
for i in range(k):
input();c|=set(map(int,input().split()))
print(len(n^c))
| 0 | null | 94,016,165,514,170 | 289 | 154 |
n = input()
print(n ** 3)
|
n = int(input())
print(n * n * n)
| 1 | 285,046,102,484 | null | 35 | 35 |
N = int(input())
MOD = 1000000007
ans = (10**N - 9**N - 9**N + 8**N) % MOD
print(ans)
|
temp = int(input())
print("Yes" if temp>= 30 else "No")
| 0 | null | 4,493,294,199,320 | 78 | 95 |
k = int(input())
a, b = map(int, input().split())
cal = 0
while cal <= b:
if a <= cal <= b:
print('OK')
break
else:
cal += k
if cal > b:
print('NG')
|
k=int(input())
a,b=map(int,input().split())
print("OK" if (a-1)//k!=b//k else"NG")
| 1 | 26,637,592,438,336 | null | 158 | 158 |
N = int(input())
ans = [0]*(N+1)
root = int(N**0.5)
for x in range(1, root+1):
for y in range(1, root+1):
for z in range(1, root+1):
F = x**2 + y**2 + z**2 + x*y + y*z + z*x
if F <= N:
ans[F] += 1
else:
continue
for i in range(1, N+1):
print(ans[i])
|
from collections import defaultdict
ans = defaultdict(int)
N = int(input())
for i in range(1, 100):
for j in range(1, 100):
for k in range(1, 100):
ans[i*i+j*j+k*k+i*j+j*k+k*i] += 1
for i in range(N):
print(ans[i+1])
| 1 | 8,010,732,293,210 | null | 106 | 106 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
n = int(readline())
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1
for i in range(2,n+1):
dp[i] = dp[i-1] + dp[i-2]
print(dp[n])
if __name__ == "__main__":
main()
|
N = int(input())
def memorize(f) :
cache = {}
def helper(*args) :
if args not in cache :
cache[args] = f(*args)
return cache[args]
return helper
@memorize
def fibonacci(n):
if n == 0 or n == 1:
return 1
res = fibonacci(n - 2) + fibonacci(n - 1)
return res
print(fibonacci(N))
| 1 | 1,904,828,608 | null | 7 | 7 |
S, T = map(str, input().split())
A, B = map(int, input().split())
U = input()
a = A - 1
b = B - 1
if U == S:
print('{} {}'.format(a,B))
else:
print('{} {}'.format(A,b))
|
S,T = (x for x in input().split())
A,B = map(int,input().split())
U = input()
if S == U:
A -= 1
else:
B -= 1
print(A,B)
| 1 | 71,805,564,583,020 | null | 220 | 220 |
N = int(input())
A = [[0]*10 for _ in range(10)]
for i in range(1,N+1):
a = i%10 #1の位
b = i // (10**(len(str(i))-1))
if a!= 0:
A[a][b] += 1
t = 0
for i in range(1,10):
s = A[i][i]
if s != 0:
t += int(s + (s*(s-1)))
for i in range(1,9):
for j in range(i+1,10):
t += A[i][j] * A[j][i]*2
print(t)
|
S = input()
h = S/3600
m = S%3600 / 60
s = S%60
print'%d:%d:%d' % (h,m,s)
| 0 | null | 43,461,072,091,850 | 234 | 37 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from operator import or_
class SegmentTree:
def __init__(self, orig, func, unit):
_len = len(orig)
self.func = func
self.size = 1 << (_len - 1).bit_length()
self.tree = [unit] * self.size + orig + [unit] * (self.size - _len)
self.unit = unit
for i in range(self.size - 1, 0, -1):
self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1])
def update(self, i, v):
i += self.size
self.tree[i] = v
while i:
i //= 2
self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])
def find(self, l, r):
l += self.size
r += self.size
ret = self.unit
while l < r:
if l & 1:
ret = self.func(ret, self.tree[l])
l += 1
if r & 1:
r -= 1
ret = self.func(ret, self.tree[r])
l //= 2
r //= 2
return ret
n = readline()
s = readline()
q = int(readline())
li = [1 << ord(x) - 97 for x in s[:-1]]
seg = SegmentTree(li, or_, 0)
ans = []
for _ in range(q):
f, x, y = readline().split()
x = int(x)
if f == '1':
seg.update(x - 1, 1 << ord(y) - 97)
else:
y = int(y)
z = seg.find(x - 1, y)
cnt = bin(z).count('1')
ans.append(cnt)
print(*ans)
|
S = 13 * 0
H = 13 * 1
C = 13 * 2
D = 13 * 3
#???????????????????¨??????????????????????????????????????????????????????????,???????????????:1???
#??????????????????????????????5???S(???0)+5???????????????11???D(???39)+11??§??¨??????
#?????????0???????????¨
card_count = [0 for i in range(53)]
n = int(input())
for i in range(n):
card_type, card_num = input().split()
card_count[eval(card_type)+int(card_num)] += 1 #???????????£????¨??????¨???????????????????????°???1????¶????
for s in ['S','H','C','D']:
for i in range(1, 13+1):
if card_count[eval(s)+i] == 0: #??????????????°???0??????
print("{0} {1}".format(s,i)) #?¨??????¨?????????????????????
| 0 | null | 31,678,497,401,730 | 210 | 54 |
def main():
match_count = int(input())
matches = [input().split() for i in range(match_count)]
taro_result = [3 if match[0] > match[1] else 1 if match[0] == match[1] else 0 for match in matches]
print('%d %d' % (sum(taro_result), sum(3 if item == 0 else 1 if item == 1 else 0 for item in taro_result)) )
main()
|
K,T=[input() for i in range(2)]
A,B=map(int,T.split())
K=int(K)
if (A//K)*K>=A or((A//K)+1)*K<=B:
print("OK")
else:
print("NG")
| 0 | null | 14,156,950,937,070 | 67 | 158 |
import bisect
N=int(input())
L=[int(i) for i in input().split()]
L.sort()
ans=0
for i in range(N-2):
for j in range(i+1,N-1):
x=L[i]+L[j]
ans+=(bisect.bisect_left(L,x)-j-1)
print(ans)
|
str = input()
str_length = len(str)
import random
start_num = random.randint(0,str_length-3)
print(str[start_num:start_num+3])
| 0 | null | 93,513,988,601,550 | 294 | 130 |
from math import floor
from fractions import Fraction
a,b=map(str,input().split())
a=int(a)
b=Fraction(b)
print(int(a*b))
|
import decimal
a,b=map(str,input().split())
RES = decimal.Decimal(a)*decimal.Decimal(b)
res = int(RES)
print(res)
| 1 | 16,631,077,764,422 | null | 135 | 135 |
N = '0' + input()
INF = float('inf')
dp = [[INF] * 2 for _ in range(len(N) + 1)]
dp[0][0] = 0
for i in range(len(N)):
n = int(N[len(N) - 1 - i])
for j in range(2):
for a in range(10):
ni = i + 1
nj = 0
b = a - n - j
if b < 0:
b += 10
nj = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)
a == b
print(dp[len(N)][0])
|
N = input()
N = [int(i) for i in list(N)][::-1] + [0]
# print(N)
lenN = len(N)
dp = [[float('inf')]*2 for _ in range(len(N)+1)]
dp[0][0] = 0
for i in range(1, len(N)+1):
res0 = float('inf')
res1 = float('inf')
for j in range(2):
for num in range(10):
if j == 1:
# 前に繰り下がりしていたらnumを減らす
num = num - 1
if num >= N[i-1]:
b = num - N[i-1]
res0 = min(res0, dp[i - 1][j] + num + b + j)
else:
b = num - N[i-1] + 10
res1 = min(res1, dp[i - 1][j] + num + b + j)
dp[i][0] = res0
dp[i][1] = res1
# print(dp)
print(min(dp[lenN][0], dp[lenN][1]))
| 1 | 71,151,364,958,532 | null | 219 | 219 |
x = int(input())
ans = x
while True:
jud = 0
if(ans <= 2):
print(2)
break
if(ans%2==0):
jud += 1
i = 3
while i < ans**(1/2):
if(jud>0):
break
if(ans%i == 0):
jud += 1
i += 2
if(jud==0):
print(ans)
break
ans += 1
|
x = int(input())
ans = 0
for i in range(x, 10000000):
is_prime_bool = True
for j in range(2, i - 1):
if i % j == 0:
is_prime_bool = False
break
if is_prime_bool:
print(i)
break
| 1 | 105,498,749,931,068 | null | 250 | 250 |
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
print(sum(map(lambda p: p>=k, nums)))
|
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
N, K = rl()
H = rl()
ans = 0
for h in H:
if h >= K:
ans += 1
print(ans)
| 1 | 179,139,251,750,030 | null | 298 | 298 |
str = raw_input()
q = input()
for ans in range(q):
ans = raw_input()
ans1 = ans.split(' ')
if ans1[0] == 'replace':
str = str[0:int(ans1[1])]+ans1[3]+ str[int(ans1[2])+1:len(str)]
if ans1[0] == 'reverse':
str = str[0:int(ans1[1])]+ str[int(ans1[1]):int(ans1[2])+1][::-1] + str[int(ans1[2])+1:len(str)]
if ans1[0] == 'print':
print str[int(ans1[1]):int(ans1[2])+1]
|
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
n,k=I()
p = l()
x = list(itertools.accumulate(p))
if n==1:
print((p[0]+1)/2)
sys.exit()
if n==k:
print((x[-1]+k)/2)
sys.exit()
for i in range(1,n-k+1):
ans = max(ans,x[i+k-1]-x[i-1])
print((ans+k)/2)
| 0 | null | 38,541,764,893,028 | 68 | 223 |
import sys
sys.setrecursionlimit(300000)
from heapq import heappush, heappop
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N, K = MI()
A = LMI()
if all(a < 0 for a in A) and K % 2 == 1:
A.sort(reverse=True)
ans = 1
for a in A[:K]:
ans = ans * a % MOD
print(ans)
exit(0)
p = []
n = []
for a in A:
if a < 0:
heappush(n, a)
else:
heappush(p, -a)
ans = 1
cnt = 0
while cnt < K:
if cnt == K - 1:
if len(p) > 0:
ans = ans * -heappop(p) % MOD
else:
ans = ans * max(n) % MOD
cnt += 1
break
if len(p) < 1:
ans = ans * heappop(n) * heappop(n) % MOD
cnt += 2
elif len(n) < 2:
ans = ans * -heappop(p) % MOD
cnt += 1
else:
p0, p1 = -p[0], -p[1] if len(p) > 1 else 1
if p0 * p1 > n[0] * n[1]:
ans = ans * -heappop(p) % MOD
cnt += 1
else:
ans = ans * heappop(n) * heappop(n) % MOD
cnt += 2
print(ans)
|
def solve():
if k==n: return P + M
if len(M) == n: return sorted(M, reverse=k%2)[:k]
P.sort(reverse=True)
M.sort()
P.append(-1)
M.append(1) # add endpoint
pa, ma = [], []
while len(pa) + len(ma) < k:
if P[len(pa)] < -M[len(ma)]:
ma.append(M[len(ma)])
else:
pa.append(P[len(pa)])
if len(ma)%2 == 0: return pa + ma
exist_pa = len(pa) > 0
exist_ma = len(ma) > 0
remain_p = len(P) - 1 > len(pa)
remain_m = len(M) - 1 > len(ma)
if exist_pa & exist_ma & remain_p & remain_m:
if abs(pa[-1] * P[len(pa)]) < abs(ma[-1] * M[len(ma)]):
pa.pop()
ma.append(M[len(ma)])
else:
ma.pop()
pa.append(P[len(pa)])
elif exist_ma & remain_p:
ma.pop()
pa.append(P[len(pa)])
elif exist_pa & remain_m:
pa.pop()
ma.append(M[len(ma)])
return pa + ma
n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
if a < 0: M.append(a)
else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)
| 1 | 9,362,697,682,298 | null | 112 | 112 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
s = S()
ans = 0
for i in range(len(s)//2):
if s[i] != s[-(i+1)]:
ans += 1
print(ans)
main()
|
from itertools import repeat
print(sum((lambda a, b, c: map(lambda r, n: n % r == 0,
range(a, b+1), repeat(c))
)(*map(int, input().split()))))
| 0 | null | 60,512,303,672,668 | 261 | 44 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m,k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
sa = [0]*(n+1)
sb = [0]*(m+1)
for i in range(n):
sa[i+1] = sa[i]+a[i]
for i in range(m):
sb[i+1] = sb[i]+b[i]
isb=m
ans = 0
for isa in range(n+1):
if sa[isa]>k:
break
#while isb>0 and sa[isa]+sb[isb]>k:
while sa[isa]+sb[isb]>k:
isb-=1
ans = max(ans, isa+isb)
print(ans)
|
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
cnt = 0
C = []
SA =[0]
SB =[0]
for a in A:
SA.append(SA[-1] + a)
for b in B:
SB.append(SB[-1] + b)
for x in range(N+1):
L = K - SA[x]
if L < 0:
break
y_max = bisect.bisect_right(SB, L) - 1
C.append(y_max + x)
print(max(C))
| 1 | 10,764,255,819,702 | null | 117 | 117 |
S=str(input())
if S.isupper()==True:
print("A")
else:
print("a")
|
x1,y1,x2,y2=map(float, input().split())
if x1<x2:
x1,x2=x2,x1
if y1<y2:
y1,y2=y2,y1
n=((x1-x2)**2+(y1-y2)**2)**(1/2)
print(n)
| 0 | null | 5,711,824,805,310 | 119 | 29 |
s=list(input())
t=list(input())
s_length=len(s)
t_length=len(t)
#print(s[3])
#print(t[3])
count=0
for i in range(s_length):
if s[i]!=t[i]:
count+=1
print(count)
|
#!/usr/bin/env python
# coding: utf-8
# In[21]:
N,K = map(int, input().split())
R,S,P = map(int,input().split())
T = input()
# In[22]:
points = {}
points["r"] = P
points["s"] = R
points["p"] = S
ans = 0
mylist = []
for i in range(N):
mylist.append(T[i])
if i >= K:
if T[i] == mylist[-K-1]:
mylist[-1] = "x"
else:
ans += points[T[i]]
else:
ans += points[T[i]]
print(ans)
# In[ ]:
| 0 | null | 58,588,741,750,030 | 116 | 251 |
class Info:
def __init__(self,arg_start,arg_end,arg_S):
self.start = arg_start
self.end = arg_end
self.S = arg_S
LOC = []
POOL = []
line = input()
loc = 0
sum_S = 0
for ch in line:
if ch == '\\':
LOC.append(loc)
elif ch == '/':
if len(LOC) == 0:
continue
tmp_start = int(LOC.pop())
tmp_end = loc
tmp_S = tmp_end-tmp_start;
sum_S += tmp_S;
#既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
while len(POOL) > 0:
if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
tmp_S += POOL[-1].S
POOL.pop()
else:
break
POOL.append(Info(tmp_start,tmp_end,tmp_S))
else:
pass
loc += 1
print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")
while len(POOL) > 0:
print(" %d"%(POOL[0].S),end = "") #先頭から
POOL.pop(0)
print()
|
S = [s for s in input()]
stack1 = []
stack2 = []
for i in range(len(S)):
if S[i] == '\\':
stack1.append(i)
elif S[i] == '/':
if len(stack1) != 0:
pos = stack1.pop()
area = i - pos
while len(stack2) != 0:
pair = stack2.pop()
if pos < pair[0]:
area += pair[1]
else:
stack2.append(pair)
break
stack2.append((pos, area))
print(sum([s[1] for s in stack2]))
print(len(stack2), *[s[1] for s in stack2])
| 1 | 55,719,952,206 | null | 21 | 21 |
A,B,C,K=map(int,input().split())
ans=0
if A>K:
ans+=K
else:
ans+=A
if B>K-A:
ans+=0
else:
if (K-A-B)<C:
ans+=-(K-A-B)
else:
ans+=-C
print(ans)
|
N = int(input())
ansAC = 0
ansWA = 0
ansTLE = 0
ansRE = 0
for i in range(N):
S = input()
if S == "AC":
ansAC += 1
elif S == "TLE":
ansTLE += 1
elif S == "WA":
ansWA += 1
elif S == "RE":
ansRE += 1
print("AC x " + str(ansAC))
print("WA x " + str(ansWA))
print("TLE x " + str(ansTLE))
print("RE x " + str(ansRE))
| 0 | null | 15,192,175,905,764 | 148 | 109 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
x=input()
p=0
for i in x:
if i=="1":
p+=1
rp=0
rq=0
for i in range(n):
if x[i]=="1":
rp+=pow(2,(n-1-i),p+1)
rp%=p+1
if p!=1:
rq+=pow(2,(n-1-i),p-1)
rq%=p-1
else:
rq=pow(2,(n-1-i))
def popcnt1(n):
return bin(n).count("1")
res=[0]*n
for i in range(1,n+1):
res[i-1]=i%popcnt1(i)
for i in range(n):
ans=0
if x[i]=="1":
if p==1:
print(0)
continue
q=rq-pow(2,(n-1-i),p-1)
q%=p-1
while True:
if q==0:
print(1+ans)
break
ans+=1
q=res[q-1]
else:
q=rp+pow(2,(n-1-i),p+1)
q%=p+1
while True:
if q==0:
print(1+ans)
break
ans+=1
q=res[q-1]
|
n = int(input())
x = input()
def popcount(ni):
n_b = str(bin(ni))
return n_b.count("1")
def ans(n,x):
x_i = int(x, 2)
x_orig = popcount(x_i)
x_i_t = x_i % (x_orig+1)
if x_orig != 1:
x_i_b = x_i % (x_orig-1)
else:
x_i_b = x_i
solve = 0
for i in range(n):
x_count = x_orig
if x[i] == "0":
x_count += 1
solve = x_i_t + pow(2,n-1-i,x_count)
else:
x_count -= 1
if x_count != 0:
solve = x_i_b - pow(2,n-1-i,x_count)
else:
print(0)
continue
count = 0
if x_count != 0 :
solve = solve % x_count
count+=1
while solve > 0:
solve = solve % popcount(solve)
count+=1
print(count)
ans(n,x)
| 1 | 8,309,292,274,208 | null | 107 | 107 |
import sys
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
l, r = 0, max(a)
while r - l > 1:
# satisfy l < t < r
t = (l + r) // 2
c = sum([(e-1) // t for e in a])
if k < c:
l = t
else:
r = t
print(r)
|
###2分探索
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
p = 0###無理(そこまで小さくできない)
q = max(A)###可能
if K == 0:
print(q)
sys.exit(0)
while q-p > 1:
r = (p+q)//2
count = 0
for i in range(N):
if A[i]/r == A[i]//r:
count += A[i]//r - 1
else:
count += A[i]//r
if count > K:
p = r
else:
q = r
#print(p,q)
print(q)
| 1 | 6,516,110,220,258 | null | 99 | 99 |
a=[]
for i in range(3):
da=list(map(int,input().split()))
for j in da:
a.append(j)
n=int(input())
for i in range (n):
b=int(input())
for j in range(len(a)):
if a[j] == b:
a[j]=0
for i in range (3):
if a[i] == a[i+3] and a[i+3]==a[i+6]:
print('Yes')
exit()
for i in range(3):
if a[3*i]==a[3*i+1] and a[3*i]==a[3*i+2]:
print('Yes')
exit()
if a[0]==a[4] and a[0]==a[8]:
print('Yes')
exit()
if a[2]==a[4] and a[2]==a[6]:
print('Yes')
exit()
print('No')
|
from collections import deque
n = int(input())
dlist = deque()
for i in range(n):
code = input().split()
if code[0] == "insert":
dlist.insert(0,code[1])
if code[0] == "delete":
try:
dlist.remove(code[1])
except:
continue
if code[0] == "deleteFirst":
dlist.popleft()
if code[0] == "deleteLast":
dlist.pop()
print(*dlist,sep=" ")
| 0 | null | 29,990,858,646,130 | 207 | 20 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [[1<<60]*(N+1) for _ in range(M+1)]
dp[0][0] = 0
for i in range(M):
for j in range(N+1):
if A[i] <= j:
dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + 1)
else:
dp[i + 1][j] = dp[i][j]
print(dp[M][N])
|
# coding: utf-8
import sys
import collections
def main():
n, quantum = map(int, raw_input().split())
processes = [x.split() for x in sys.stdin.readlines()]
for p in processes:
p[1] = int(p[1])
queue = collections.deque(processes)
elapsed = 0
while queue:
# print elapsed, queue
head = queue.popleft()
if head[1] > quantum:
head[1] -= quantum
queue.append(head)
elapsed += quantum
else:
elapsed += head[1]
print head[0], elapsed
if __name__ == '__main__':
main()
| 0 | null | 90,502,804,952 | 28 | 19 |
n = int(input())
def koch(n,x1,y1,x2,y2):
if n == 0:
print(x1,y1)
else:
a = 3**(1/2)/2
p1 = koch(n-1,x1,y1,(2*x1+x2)/3,(2*y1+y2)/3)
if abs(y1 - y2) <= 10**(-4):
s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,(x1+x2)/2,y1+(x2-x1)*a/3)
u = koch(n-1,(x1+x2)/2,y1+(x2-x1)*a/3,(x1+2*x2)/3,(y1+2*y2)/3)
else:
if x1 < x2 and y1 < y2:
s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3)
u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
elif x1 < x2 and y1 > y2:
s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3)
u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
elif x1 > x2 and y1 < y2:
s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3)
u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
else:
s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3)
u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
t = koch(n-1,(x1+2*x2)/3,(y1+2*y2)/3,x2,y2)
return p1,s,u,t
X = koch(n,0,0,100,0)
print(100,0)
|
# 3
A,B,C=map(int,input().split())
K=int(input())
def f(a,b,c,k):
if k==0:
return a<b<c
return f(a*2,b,c,k-1) or f(a,b*2,c,k-1) or f(a,b,c*2,k-1)
print('Yes' if f(A,B,C,K) else 'No')
| 0 | null | 3,477,190,380,512 | 27 | 101 |
import math
import numpy as np
A,B = np.array(input().split(),dtype = int)
def gcd(x,y):
if y == 0:
return x
else:
return gcd(y,x%y)
print(int(A*B/(gcd(A,B))))
|
while True:
m,f,r=map(int,input().split())
if m==f==r==-1 : break
if m==-1 or f==-1 :
print('F')
elif (m+f)>=80 :
print('A')
elif 65<= (m+f) and (m+f)<80 :
print('B')
elif 50<= (m+f) and (m+f)<65 :
print('C')
elif 30<=(m+f) and (m+f)<50 :
if 50<=r :
print('C')
else:
print('D')
elif (m+f)<30 :
print('F')
| 0 | null | 57,450,372,835,948 | 256 | 57 |
a,b=[int(i) for i in input().split()]
c=max(a,b)
if(a<=b):
d=a
else:
d=b
for i in range(1,100001):
if((d*i)%c==0):
print(d*i)
break
|
from math import gcd
A,B = [int(i) for i in input().split()]
print(A*B//gcd(A,B))
| 1 | 113,711,530,586,040 | null | 256 | 256 |
x = int(input())
while True:
flag =0
for i in range(2,x//2):
if x%i==0:
flag =1
break
if flag ==0:
print(x)
exit()
x = x+1
|
n, m = map(int, input().split())
root = [-1]*n
def r(x):
if root[x] < 0:
return x
else:
root[x] = r(root[x])
return root[x]
def unite(x, y):
x = r(x)
y = r(y)
if x == y:
return
root[x] += root[y]
root[y] = x
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
unite(a, b)
ans = 0
for i in range(n):
ans = max(ans, -root[i])
print(ans)
| 0 | null | 54,838,279,456,840 | 250 | 84 |
H = int(input())
W = int(input())
N = int(input())
m = max(H, W)
print((N + m - 1) // m)
|
h = int(input())
w = int(input())
n = int(input())
lines = 0
act = 0
if h <= w:
# print('w long')
lines = h
act = w
else:
# print('h long')
lines = w
act = h
# print(lines)
# print(act)
draw = 0
for i in range(lines):
if n <= (i + 1) * act:
print(i + 1)
break
| 1 | 89,239,783,098,940 | null | 236 | 236 |
s, t = map(str, input().split())
print('{}{}'.format(t, s))
|
import sys
S,T = input().split()
if not ( S.islower() and T.islower() ): sys.exit()
if not ( 1 <= len(S) <= 100 and 1 <= len(S) <= 100 ): sys.exit()
print(T,S,sep='')
| 1 | 103,137,187,007,426 | null | 248 | 248 |
#ABC167
A,B,C,K=map(int,input().split())
#----------以上入力----------
if A > K:
print(K)
elif A+B >= K:
print(A)
else:
print(A-(K-A-B))
|
n,k=list(map(int ,input().split()))
h=list(map(int ,input().split()))
count=0
for i in range(0,len(h)):
if(h[i] == k or h[i] >=k ):
count+=1
else:
count+=0
print(int(count))
| 0 | null | 99,971,005,104,992 | 148 | 298 |
#クラスカル法
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x): #親を返す
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def unite(self, x, y): #和集合の生成
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x): #所属する集合の大きさ
return -self.parents[self.find(x)]
def same(self, x, y): #同じ集合に属しているか判定
return self.find(x) == self.find(y)
def members(self, x): #同じ集合に属する要素全列挙
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self): #集合のリーダー全列挙
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self): #集合の数
return len(self.roots())
def all_group_members(self): #辞書型,{(リーダーの番号):(その集合の要素全列挙)}
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
a,b=map(int,input().split())
uf.unite(a-1,b-1)
print(-min(uf.parents))
|
'''
We can show that if u and v belong to the same connected component, then they are friends w/ each other
So everyone in a given connected component is friends with one another
So everyone in a given connected component must be separated into different groups
If we have a CC of with sz nodes in it, then we need at least sz different groups
So, the minimum number of groups needed is max sz(CC)
'''
import sys
sys.setrecursionlimit(2*10**5+5)
n, m = map(int,input().split())
adj = [[] for u in range(n+1)]
for i in range(m):
u, v = map(int,input().split())
adj[u].append(v)
adj[v].append(u)
vis = [False for u in range(n+1)]
def dfs(u):
if vis[u]:
return 0
vis[u] = True
sz = 1
for v in adj[u]:
sz += dfs(v)
return sz
CCs = []
for u in range(1,n+1):
if not vis[u]:
CCs.append(dfs(u))
print(max(CCs))
| 1 | 3,977,105,963,900 | null | 84 | 84 |
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
q = int(input())
num = Counter(a)
s = sum(a)
for _ in range(q):
b,c = map(int,input().split())
s += (c-b)*num[b]
num[c] += num[b]
num[b] = 0
print(s)
|
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
list_N = list(map(int,list(input())))
len_N = len(list_N)
list_N = [0] + list_N
K = II()
dp0 = []
dp1 = []
for i in range(len_N+1):
dp0.append([0]*(K+1))
dp1.append([0]*(K+1))
for i in range(1,len_N+1):
dp0[i][0] = 1
dp0[1][1] = max(list_N[1]-1,0)
dp1[1][1] = 1
for i in range(2,len_N+1):
dp1[i][0] = dp1[i-1][0]
for j in range(1,K+1):
num = list_N[i]
if num > 0:
dp0[i][j] = dp0[i-1][j-1] * 9 + dp0[i-1][j] + dp1[i-1][j-1] * (num-1) + dp1[i-1][j]
dp1[i][j] = dp1[i-1][j-1]
else:
dp0[i][j] = dp0[i-1][j-1] * 9 + dp0[i-1][j]
dp1[i][j] = dp1[i-1][j]
print(dp0[len_N][K]+dp1[len_N][K])
dbg(dp0[len_N][K],dp1[len_N][K])
if __name__ == '__main__':
main()
| 0 | null | 44,259,038,468,700 | 122 | 224 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
XY = []
for _ in range(N):
A = int(input())
xy = [list(mapint()) for _ in range(A)]
XY.append(xy)
ans = 0
for i in range(1<<N):
honest = [-1]*N
cnt = 0
ok = True
for j in range(N):
if (i>>j)&1:
honest[j]=1
else:
honest[j]=0
for j in range(N):
if (i>>j)&1:
cnt += 1
for x, y in XY[j]:
if honest[x-1]!=y:
ok = False
break
if ok:
ans = max(ans, cnt)
print(ans)
|
def resolve():
X = int(input())
dp = [0 for _ in range(X + 110)]
dp[0] = 1
for i in range(X + 1):
if dp[i] == 0:
continue
dp[i + 100] = 1
dp[i + 101] = 1
dp[i + 102] = 1
dp[i + 103] = 1
dp[i + 104] = 1
dp[i + 105] = 1
print(dp[X])
resolve()
| 0 | null | 124,132,643,575,820 | 262 | 266 |
import sys
input = sys.stdin.readline
inf = 1000
inf5 = 10**10
n, m, l = map(int, input().split())
graph = [[inf5] * (n+1) for _ in range(n+1)]
for _ in range(m):
a, b, c = map(int, input().split())
graph[a][b] = c
graph[b][a] = c
inf = 1000
def warshall_floyd(d):
for k in range(1, n+1):
for i in range(1, n+1):
for j in range(1, n+1):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
warshall_floyd(graph)
ans = [[inf] * (n+1) for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
if graph[i][j] <= l:
ans[i][j] = 1
warshall_floyd(ans)
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
if ans[s][t] == inf:
print(-1)
continue
print(ans[s][t] - 1)
|
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
import os
import re
with open(__file__) as f:
source = f.read().split('###''nbacl')
for s in source[1:]:
s = re.sub("'''.*", '', s)
sp = s.split(maxsplit=1)
if os.path.dirname(sp[0]):
os.makedirs(os.path.dirname(sp[0]), exist_ok=True)
with open(sp[0], 'w') as f:
f.write(sp[1])
from nbmodule import cc
cc.compile()
import numpy as np
from numpy import int64
from nbmodule import solve
f = open(0)
N, M = [int(x) for x in f.readline().split()]
AB = np.fromstring(f.read(), dtype=int64, sep=' ').reshape((-1, 2))
ans = solve(N, AB)
print(ans)
'''
###nbacl nbmodule.py
import numpy as np
from numpy import int64
from numba import njit
from numba.types import i8
from numba.pycc import CC
import nbacl.dsu as dsu
cc = CC('nbmodule')
@cc.export('solve', (i8, i8[:, ::1]))
def solve(N, AB):
t = np.full(N, -1, dtype=int64)
for i in range(AB.shape[0]):
dsu.merge(t, AB[i, 0] - 1, AB[i, 1] - 1)
ret = 0
for _ in dsu.groups(t):
ret += 1
return ret - 1
if __name__ == '__main__':
cc.compile()
###nbacl nbacl/dsu.py
import numpy as np
from numpy import int64
from numba import njit
@njit
def dsu(t):
t = -1
@njit
def merge(t, x, y):
u = leader(t, x)
v = leader(t, y)
if u == v:
return u
if -t[u] < -t[v]:
u, v = v, u
t[u] += t[v]
t[v] = u
return u
@njit
def same(t, x, y):
return leader(t, x) == leader(t, y)
@njit
def leader(t, x):
if t[x] < 0:
return x
t[x] = leader(t, t[x])
return t[x]
@njit
def size(t, x):
return -t[leader(t, x)]
@njit
def groups(t):
for i in range(t.shape[0]):
if t[i] < 0:
yield i
'''
| 0 | null | 87,609,098,417,060 | 295 | 70 |
x = input()
num = int(x)
print(num*num*num)
|
X , Y = map(int,input().split())
a = 0
ans = "No"
for a in range(0,X+1):
if (a * 2)+((X-a) * 4)==Y:
ans = "Yes"
print(ans)
| 0 | null | 6,975,295,632,572 | 35 | 127 |
S=input()
ch=""
for i in range(len(S)):
ch+="x"
print(ch)
|
S = input()
L = len(S)
for i in range(L):
print("x",end='')
| 1 | 73,231,740,261,010 | null | 221 | 221 |
n, m =map(int,input().split())
c = list(map(int,input().split()))
INF = 10**100
dp = [INF]*500000
dp[0] = 0
for i in range (n+1):
for j in c:
dp[i+j] = min(dp[i+j],dp[i]+1)
print(dp[n])
|
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')
N,M=MAP()
C=LIST()
dp=[INF]*(N+1)
dp[0]=0
for i in range(N):
for j in range(M):
if i+C[j]<=N:
dp[i+C[j]]=min(dp[i+C[j]], dp[i]+1)
print(dp[N])
| 1 | 138,981,308,758 | null | 28 | 28 |
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
mid = sum(A) / 2
x = 0
near_length = 0
for a in A:
x += a
if x >= mid:
if x - mid > abs(x - a - mid):
near_length = abs(x - a)
else:
near_length = x
break
ans = int(abs(mid-near_length) * 2)
print(ans)
if __name__ == "__main__":
main()
|
N = int(input())
A = list(map(int, input().split()))
left = 0
SUM = sum(A)
res = SUM
for i in range(N):
left += A[i]
res = min(res,abs(2*left-SUM))
print(res)
| 1 | 142,070,703,571,830 | null | 276 | 276 |
h1, m1, h2, m2, k = map(int, input().split())
st = h1*60 + m1
end = h2*60 + m2
print(end-st-k)
|
a,b = map(int,input().split())
ans=a*b
print(ans)
| 0 | null | 17,079,770,413,342 | 139 | 133 |
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
A = rl()
if sum(A) >= 22:
print('bust')
else:
print('win')
|
a_1,a_2,a_3=map(int,input().split())
if a_1+a_2+a_3<=21:
print('win')
else:
print('bust')
| 1 | 118,141,330,655,128 | null | 260 | 260 |
n = int(input())
c = input()
t = n
lw, rr = 0, c.count('R')
for ci in c+'Z':
swap = min(lw, rr)
wtor, rtow = max(0, lw-swap), max(0, rr-swap)
t = min(t, swap + wtor + rtow)
lw = lw + (ci == 'W')
rr = rr - (ci == 'R')
print(t)
|
"""
https://atcoder.jp/contests/abc173/tasks/abc173_e
クソだけどやろう
正負・0を分割
0がある場合は、最大を0に更新
0がN-K個より多い場合は即終了
残りの場合は、0を取らなくても構成できる場合のみ
"""
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
pl = []
mi = []
znum = 0
if K == 1:
print (max(A))
sys.exit()
for i in A:
if i > 0:
pl.append(i)
elif i == 0:
znum += 1
else:
mi.append(i)
ans = float("-inf")
if znum > 0:
ans = 0
#0にならざるを得ない場合を処理
if znum > N-K:
print (ans)
sys.exit()
#答えが負になる場合も処理する
#大きいほうからかけていけばいい
#N個の場合 or 正がない場合は負になりえない
mod = 10**9+7
pl.sort()
mi.sort()
if K == N:
ans = 1
for i in range(N):
ans *= A[i]
ans %= mod
print (ans)
sys.exit()
if K % 2 == 1 and len(pl) == 0:
if znum > 0:
ans = 0
else:
ans = 1
mi.reverse()
for i in range(K):
ans *= mi[i]
ans %= mod
print (ans)
sys.exit()
#まず、2個づつセットにすることを考える
#正負でセットにしていって、あまり同士も合成する
if K % 2 == 1:
K -= 1
ans = pl[-1]
del pl[-1]
else:
ans = 1
pl2 = []
pl.reverse()
if len(pl) % 2 == 1:
pl.append(0)
if len(mi) % 2 == 1:
mi.append(0)
for i in range(0,len(pl),2):
pl2.append(pl[i] * pl[i+1])
for i in range(0,len(mi),2):
pl2.append(mi[i] * mi[i+1])
pl2.sort()
pl2.reverse()
for i in range(K//2):
ans *= pl2[i]
ans %= mod
print (ans)
| 0 | null | 7,859,768,144,714 | 98 | 112 |
n, a, b = map(int, input().split())
div, mod = divmod(n, a + b)
ans = div * a + min(mod, a)
print(ans)
|
def divisor(i):
s = []
for j in range(1, int(i ** (1 / 2)) + 1):
if i % j == 0:
s.append(i // j)
s.append(j)
return sorted(set(s))
n = int(input())
ans = 0
d = divisor(n)
d.pop(0)
for i in d:
x = n
while True:
if not x % i == 0:
break
x //= i
if x % i == 1:
ans += 1
d = divisor(n - 1)
ans += len(d)
ans -= 1
print(ans)
| 0 | null | 48,472,460,698,242 | 202 | 183 |
line = input()
s, t = line.split(" ")
ans = t + s
print(ans)
|
n=int(input())
s,t=map(str, input().split())
a=[]
for i in range(n):
a.append(s[i]+t[i])
a = "".join(a)
print(a)
| 0 | null | 107,280,640,887,130 | 248 | 255 |
m1,_ = input().split()
m2,_ = input().split()
if m1==m2:
print(0)
else:
print(1)
|
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
for day in range(N-1):
today_price = A[day]
tommorow_price = A[day+1]
if today_price < tommorow_price:
div,mod = divmod(money, today_price)
stock += div
money = mod
elif today_price > tommorow_price:
money += today_price * stock
stock = 0
money += A[N-1] * stock
print(money)
| 0 | null | 65,859,938,749,020 | 264 | 103 |
s=int(input())
h=s//3600
s-=h*3600
m=s//60
s-=m*60
print(str(h)+":"+str(m)+":"+str(s))
|
X = int(input())
num = X // 100 + 1
calc = X % 100
for a in range(num):
for b in range(num - a):
for c in range(num - a - b):
for d in range(num - a - b - c):
for e in range(num - a - b - c - d):
for f in range(num - a - b - c - d - e):
if calc == 0*a + 1*b + 2*c + 3*d + 4*e + 5*f:
print(1)
exit()
print(0)
| 0 | null | 63,872,616,476,300 | 37 | 266 |
#!/usr/bin/env python3
from math import ceil
import heapq
def main():
n, d, a = map(int, input().split())
q = []
for i in range(n):
x, h = map(int, input().split())
heapq.heappush(q, (x, -ceil(h / a)))
bomb = 0
res = 0
while q:
x, h = heapq.heappop(q)
if h < 0:
h *= -1
if h > bomb:
heapq.heappush(q, (x + 2 * d, h - bomb))
res += h - bomb
bomb = h
else:
bomb -= h
print(res)
if __name__ == "__main__":
main()
|
N, D, A = map(int, input().split())
data = []
for _ in range(N):
data.append(tuple(map(int, input().split())))
data.sort()
queue = []
i = 0
j = 0
total = 0
height = 0
while i < N:
if j >= len(queue) or data[i][0] <= queue[j][0]:
x, h = data[i]
i += 1
if height < h:
count = (h - height + A - 1) // A
total += count
height += count * A
queue.append((x + D * 2, count * A))
else:
height -= queue[j][1]
j += 1
print(total)
| 1 | 82,174,539,899,312 | null | 230 | 230 |
A, B, H, M = map(int, input().split())
# 時針: 12時間720分で360度 1分で0.5度
# 分針: 60分で360度 1分で6度
theta = abs(((0.5 * (H * 60 + M)) - (6 * M)) % 360)
if theta > 180:
theta = 360 - theta
#print(theta)
import math
C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta / 180 * math.pi))
print(C)
|
import math
rad = math.pi/180
A, B, H, M = map(int, input().split())
x = 6*M*rad
y = (60*H + M) * 0.5 * rad
print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(x-y)))
| 1 | 20,101,497,351,612 | null | 144 | 144 |
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def make4(initial, L, M, N, O):
return [[[[initial for i in range(O)]
for n in range(N)]
for m in range(M)]
for l in range(L)]
def make3(initial, L, M, N):
return [[[initial for n in range(N)]
for m in range(M)]
for l in range(L)]
def debug(table, *args):
ret = []
for name, val in table.items():
if val in args:
ret.append('{}: {}'.format(name, val))
print(' | '.join(ret), file=sys.stderr)
yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def main():
N = I()
A = LI()
dp_use = [-IINF] * 3
dp_not_use = [-IINF] * 3
dp_not_use[0] = 0
for i in range(N):
dp_use_next = [-IINF] * 3
dp_not_use_next = [-IINF] * 3
for j in range(3):
if j - 1 >= 0:
dp_not_use_next[j] = max(dp_use[j], dp_not_use[j-1])
else:
dp_not_use_next[j] = dp_use[j]
dp_use_next[j] = dp_not_use[j] + A[i]
# print('dp_use ', *[a if a > -10**10 else '-IINF' for a in dp_use_next])
# print('dp_not_use', *[a if a > -10**10 else '-IINF' for a in dp_not_use_next])
dp_use = dp_use_next
dp_not_use = dp_not_use_next
if N % 2 == 0:
print(max(dp_use[1], dp_not_use[0]))
else:
print(max(dp_use[2], dp_not_use[1]))
if __name__ == '__main__':
main()
|
h = int(input())
w = int(input())
n = int(input())
r = max(h,w)
count = 0
x = 0
while x < n:
count += 1
x += r
print(count)
| 0 | null | 62,972,796,694,388 | 177 | 236 |
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N = int(input())
L = []
Slist1 = []
Slist2 = []
R = []
l = 0; r = 0
for i in range(N):
M = 0; end = None
var = 0
S = input()
for j in S:
if j == "(":
var += 1
l += 1
else:
var -= 1
r += 1
M = min(var, M)
end = var
if M == 0:
L.append([M, end])
elif M == end:
R.append([M, end])
elif M < 0 and end > 0:
Slist1.append([-M, end])
else:
Slist2.append([M - end, M, end])
Slist1 = sorted(Slist1)
Slist2 = sorted(Slist2)
if l != r:
print("No")
return
cnt = 0
X = len(L)
for i in range(X):
cnt += L[i][1]
judge = "Yes"
X = len(Slist1)
for i in range(X):
M = Slist1[i][0]
cnt -= M
if cnt < 0:
judge = "No"
break
else:
cnt += M + Slist1[i][1]
X = len(Slist2)
for i in range(X):
cnt += Slist2[i][1]
if cnt < 0:
judge = "No"
break
else:
cnt -= Slist2[i][0]
print(judge)
if __name__ == '__main__':
main()
|
import itertools
import math
N = int(input())
p = []
for i in range(N):
x, y = [int(n) for n in input().split()]
p.append([x, y])
total_length = 0
k = 0
for pattern in itertools.permutations(p):
k += 1
length = 0
for i in range(N-1):
length += math.sqrt((pattern[i+1][0] - pattern[i][0])**2 + (pattern[i+1][1] - pattern[i][1])**2)
total_length += length
print(total_length/k)
| 0 | null | 86,340,225,087,844 | 152 | 280 |
import math
N = int(input())
A = math.ceil(N/1000)
B = A * 1000
print(B-N)
|
n=int(input())
print(-n%1000)
| 1 | 8,544,063,972,500 | null | 108 | 108 |
n=int(input())
I=list(map(int,input().split()))
for i in range(n):
if (I[i]%2==0):
if (I[i]%3!=0) and (I[i]%5!=0):
print("DENIED")
exit()
print("APPROVED")
|
n, k = map(int, input().split())
mod = 10**9+7
R = 200010
f = [1]*R
p = 1
for i in range(1, R):
p = f[i] = p*i%mod
finv = [1]*R
p = finv[-1] = pow(f[-1], mod-2, mod)
for i in range(R-2, 0, -1):
p = finv[i] = p*(i+1)%mod
def comb(n, k):
return f[n]*finv[n-k]*finv[k]%mod
ans = 0
for m in range(min(k, n-1)+1):
x = comb(n, m)
y = comb(n-1, m)
ans += x*y%mod
print(ans%mod)
| 0 | null | 67,867,475,136,978 | 217 | 215 |
N=int(input())
S=list(input() for _ in range(N))
from collections import Counter
cnt=Counter(S)
max_cnt=cnt.most_common()[0][1]
ans=[]
for k, v in cnt.items():
if v!=max_cnt:
continue
ans.append(k)
print(*sorted(ans), sep="\n")
|
n=map(int,input().split())
a=list(map(int,input().split()))
N=0
new_a=a[::2]
for i in new_a:
if i%2==0:
N += 1
print(len(new_a)-N)
| 0 | null | 38,919,660,594,660 | 218 | 105 |
from sys import stdin
a, b, c = (int(n) for n in stdin.readline().rstrip().split())
cnt = 0
for n in range(a, b + 1):
if c % n == 0:
cnt += 1
print(cnt)
|
x = map(int, raw_input().split())
flag = 0
for i in range(x[0], x[1]+1):
if x[2] % i == 0:
flag += 1
print flag
| 1 | 561,631,297,448 | null | 44 | 44 |
N = int(input())
n = str(N)
le = len(n)
M = 0
for i in range(le):
nn = int(n[i])
M += nn
if M % 9 == 0:
print("Yes")
else:
print("No")
|
n = sum([int(n) for n in input()])
if n % 9 == 0:
print("Yes")
else:
print("No")
| 1 | 4,448,482,945,820 | null | 87 | 87 |
print(input()[1] == "B" and "ARC" or "ABC")
|
s = input()
len_s = len(s)
s_array = [int(i) for i in s]
mod = 2019
mod_array = [0]*mod
num = 0
mod_array[0] += 1
for i in range(len_s):
num = pow(10, i, mod) * s_array[len_s - i - 1] + num
num %= mod
mod_array[num] += 1
ans = 0
for i in mod_array:
ans += (i * (i - 1)) / 2
print(int(ans))
| 0 | null | 27,579,999,225,338 | 153 | 166 |
n, m = (int(i) for i in input().split())
tot = n * (n - 1) // 2 + m * (m - 1) // 2
print(tot)
|
def main():
n = int(input())
a = list(map(int, input().split()))
dp = [-10**15]*(n+1)
dp[2] = max(a[0], a[1])
if n > 2:
dp[3] = max(a[:3])
aa = a[0]+a[2]
for i in range(4, n+1):
if i%2:
aa += a[i-1]
dp[i] = max(dp[i-1], dp[i-2]+a[i-1])
else:
dp[i] = max(aa, dp[i-2]+a[i-1])
print(dp[n])
if __name__ == "__main__":
main()
| 0 | null | 41,378,662,192,634 | 189 | 177 |
N=int(input())
A=list(map(int,input().split()))
L=[[10**10,0]]
for i in range(N):
L.append([A[i],i])
L.sort(reverse=True)
#print(L)
DP=[[0 for i in range(N+1)]for j in range(N+1)]
#j=右に押し込んだ数
for i in range(1,N+1):
for j in range(i+1):
if j==0:
DP[i][j]=DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1))
#print(DP,DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1)))
elif j==i:
DP[i][j]=DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j))
#print(DP,DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j)))
else:
DP[i][j]=max(DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1-j)),DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j)))
#print(DP,DP[i-1][j]+L[i][0]*abs(L[i][1]-(i-1-j)),DP[i-1][j-1]+L[i][0]*abs(L[i][1]-(N-j)))
print(max(DP[-1]))
|
import math
n = int(input())
ans = 10 ** 15
for i in range(1, int(n ** 0.5)+1):
if n % i == 0:
ans = min(ans, i + n // i - 2)
print(ans)
| 0 | null | 98,032,302,935,772 | 171 | 288 |
def main():
if sum(list(map(int, list(input())))) % 9:
print("No")
else:
print("Yes")
main()
|
N = int(input())
n = str(N)
a = list(n)
count = 0
for i in range(len(a)):
count = count + int(a[i])
if count % 9 == 0:
print("Yes")
else:
print("No")
| 1 | 4,425,087,383,178 | null | 87 | 87 |
number = int(input())
Total = []
for i in range(1, number + 1):
if number % 3 == 0 and i % 5 ==0:
"FizzBuzz"
elif i % 3 ==0:
"Fizz"
elif i % 5 == 0:
"Buzz"
else:
Total.append(i)
print(sum(Total))
|
def make_divisors(n: int):
lower_divs = []
upper_divs = []
i = 1
while i**2 <= n:
if n % i == 0:
lower_divs.append(i)
if i != n // i:
upper_divs.append(n // i)
i += 1
return lower_divs + upper_divs[::-1]
n = int(input())
ans = len(make_divisors(n - 1)) - 1
for x in make_divisors(n)[1:]:
if x == 1:
continue
z = n
while z % x == 0:
z = z // x
z = z % x
if z == 1:
ans += 1
print(ans)
| 0 | null | 38,004,856,866,450 | 173 | 183 |
N = int(input())
flg = 'No'
for i in range(1,10):
for j in range(1, 10):
if N == i*j:
flg = 'Yes'
print(flg)
|
import math
x = raw_input()
x = float(x)
S = x*x*math.pi
l = 2*x*math.pi
print("%.6f %.6f" %(S, l))
| 0 | null | 80,036,941,668,410 | 287 | 46 |
#!/usr/bin/env python
from sys import stdin, stderr
def main():
K = int(stdin.readline())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])
return 0
if __name__ == '__main__': main()
|
x, n = map(int, input().split())
if n == 0:
print(x)
else:
a = [int(x) for x in input().split()]
ans1 = x
while ans1 in a :
ans1 -= 1
ans2 = x
while ans2 in a :
ans2 += 1
if abs(x - ans1) <= abs(x - ans2):
print(ans1)
else:
print(ans2)
| 0 | null | 32,157,708,734,602 | 195 | 128 |
def gcd (a,b):
if a%b==0:
return b
if b%a==0:
return a
if a>b:
return gcd(b,a%b)
return gcd(a,b%a)
def lcm (a,b):
return ((a*b)//gcd(a,b))
inp=list(map(int,input().split()))
a=inp[0]
b=inp[1]
print (lcm(a,b))
|
def main():
a, b, c = map(int, input().split())
if (a + b + c) >= 22:
print("bust")
else:
print("win")
main()
| 0 | null | 116,102,166,819,552 | 256 | 260 |
def study_time(h1, m1, h2, m2, k):
result = (h2 - h1) * 60 + m2 - m1 - k
return result
h1, m1, h2, m2, k = tuple(map(int, input().split()))
if __name__ == '__main__':
print(study_time(h1, m1, h2, m2, k))
|
def main():
n, m = map(int, input().split())
matrix = [
list(map(int, input().split()))
for _ in range(n)
]
vector = [
int(input())
for _ in range(m)
]
for v in matrix:
res = sum(x * y for x, y in zip(v, vector))
print(res)
if __name__ == "__main__":
main()
| 0 | null | 9,512,232,529,336 | 139 | 56 |
print(str((lambda x:x**3)(int(input()))))
|
import sys
argvs = sys.argv
for x in sys.stdin:
print str(int(x)**3)
| 1 | 271,689,797,838 | null | 35 | 35 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.