code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
class Main:
S = input()
if S[-1] == 's':
print(S+'es')
else :
print(S+'s') | hs=[int(input()) for i in range(10)]
h=sorted(hs,reverse=True)
for i in range(3):
print(h[i])
| 0 | null | 1,203,201,411,302 | 71 | 2 |
INF = 1<<60
def resolve():
def judge(j):
for i in range(group):
cnt_Wchoco[i] += div_G[i][j]
if cnt_Wchoco[i] > K:
return False
return True
H, W, K = map(int, input().split())
G = [list(map(int, input())) for _ in range(H)]
ans = INF
for bit in range(1<<(H-1)):
group = 0 # 分かれたブロック数
row = [0]*H
for i in range(H):
# 分割ライン
row[i] = group
if bit>>i & 1:
group += 1
group += 1 # 1つ折ったら2つに分かれるのでプラス1, 折らなかったら1つ
# 分割したブロックを列方向で見る
div_G = [[0] * W for _ in range(group)]
for i in range(H):
for j in range(W):
div_G[row[i]][j] += G[i][j]
num = group-1
cnt_Wchoco = [0]*group
for j in range(W):
if not judge(j):
num += 1
cnt_Wchoco = [0] * group
if not judge(j):
num = INF
break
ans = min(ans, num)
print(ans)
if __name__ == "__main__":
resolve()
| H, W, K = map(int, input().split())
Ss = [list(map(int, input().replace("\n", ""))) for _ in range(H)]
cut_yoko_patterns = ["0","1"]
options = ["0","1"]
import copy
for i in range(H-2):
cut_yoko_patterns = [cut_yoko_patterns[i] + options[j] for i in range(len(cut_yoko_patterns)) for j in range(len(options))]
answer = int(1e+5)
for cut_yoko_pattern in cut_yoko_patterns:
yoko_cut_num = cut_yoko_pattern.count("1")
boxs = [0 for _ in range(yoko_cut_num+1)]
box_num = [0 for _ in range(H)]
for i in range(H-1):
if cut_yoko_pattern[i] == "1":
box_num[i+1] = box_num[i] + 1
else:
box_num[i+1] = box_num[i]
tate_cut_num = 0
for j in range(W):
temp_boxs = [0 for _ in range(yoko_cut_num+1)]
for i in range(H):
if Ss[i][j] == 1:
temp_boxs[box_num[i]] += 1
Impossible = False
Should_cut = False
for i in range(yoko_cut_num+1):
if temp_boxs[i] > K:
Impossible = True
elif boxs[i] + temp_boxs[i] > K:
Should_cut = True
if Impossible == True:
break
elif Should_cut ==True:
boxs = copy.deepcopy(temp_boxs)
tate_cut_num += 1
else:
for i in range(yoko_cut_num+1):
boxs[i] += temp_boxs[i]
else:
if tate_cut_num+yoko_cut_num < answer:
answer = tate_cut_num + yoko_cut_num
print(answer) | 1 | 48,255,098,566,080 | null | 193 | 193 |
def f(n):
res = 0
s = 0
for i in range(1,n+1):
s += i
if s <=n:
res = i
else:
break
return res
n = int(input())
p =2
ans = 0
while p*p <= n:
e = 0
while n%p == 0:
e += 1
n//=p
ans += f(e)
p +=1
if n >1:
ans += 1
print(ans) | #!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def factorization(n):
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
def main():
N = int(input())
ans = 1e18
for i in range(1, N + 1):
if i * i > N:
break
if N % i != 0:
continue
j = N // i
ans = min(ans, i + j - 2)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 89,544,618,809,272 | 136 | 288 |
word = input()
if word == 'AAA' or word == 'BBB':
print('No')
else:
print('Yes') | n = int(input())
ls = [0]*n
param_list = [0]*2**n
for i in range(2**n):
l = [False]*n
for id_r, row in enumerate(ls):
if i & (2 ** id_r) >0:
l[id_r] = True
param_list[i] = l
for i in range(n):
A = int(input())
for k in range(A):
a,b = map(int, input().split())
b = (1==b)
new_param =[]
for d in param_list:
if d[i]:
if d[a-1] == b:
new_param.append(d)
pass
else:
#print(2)
pass
else:
new_param.append(d)
#if d[a-1] is b:
#print(3)
#pass
#else:
#print(4)
#new_param.append(d)
#pass
param_list = new_param
#print(param_list)
ans = 0
for d in param_list:
ans = max(ans, d.count(True))
print(ans) | 0 | null | 87,760,046,309,852 | 201 | 262 |
#!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
# In[16]:
ans = 0
if N%2 != 0:
print(ans)
else:
i = 1
while 1:
tmp = (5**i)*2
if tmp <= N:
ans += N//tmp
i += 1
else:
break
print(ans)
# In[ ]:
| n=int(input())
if n%2==1:
print(0)
else:
ans=0
k=10
while k<=n:
t=n//k
ans+=t
k*=5
print(ans) | 1 | 115,683,324,626,168 | null | 258 | 258 |
a,b = input().split()
#print(a,b)
A = int(a)
x,y = b.split('.')
B = int(x)*100+int(y)
print(int(A*B)//100) | def area_cal(input_fig):
stack = []
# area = [[面積計算が始まった位置, 面積],・・・]
area = []
total = 0
for i in range(len(input_fig)):
fig = input_fig[i]
if fig == "\\":
stack.append(i)
elif fig == "/" and stack:
j = stack.pop()
width = i - j
total += width
while area and area[-1][0] > j:
width += area[-1][1]
area.pop()
area.append([i,width])
return area, total
input_fig = input()
area, total = area_cal(input_fig)
print(total)
if area:
print(len(area),*list(zip(*area))[1])
else:
print(0)
| 0 | null | 8,369,176,447,842 | 135 | 21 |
def main():
H,W,M = map(int,input().split())
s = []
h_cnt = [0 for i in range(H)]
w_cnt = [0 for i in range(W)]
for i in range(M):
h,w = map(int,input().split())
s.append([h-1,w-1])
h_cnt[h-1] += 1
w_cnt[w-1] += 1
h_m,w_m = max(h_cnt), max(w_cnt)
h_mp,w_mp = [],[]
for i in range(H):
if h_cnt[i] == h_m:
h_mp.append(i)
for i in range(W):
if w_cnt[i] == w_m:
w_mp.append(i)
f = 0
for i in range(M):
if h_cnt[s[i][0]] == h_m and w_cnt[s[i][1]] == w_m:
f += 1
if len(w_mp)*len(h_mp)-f<1:
print(h_m+w_m-1)
else:
print(h_m+w_m)
if __name__ == "__main__":
main()
| #!/usr/bin/python3
# -*- coding: utf-8 -*-
h, w, m = map(int, input().split())
bom_set = set()
h_dict = {}
w_dict = {}
for i in range(m):
hh, ww = map(int, input().split())
bom_set.add(tuple([hh, ww]))
if hh in h_dict:
h_dict[hh] += 1
else:
h_dict[hh] = 1
if ww in w_dict:
w_dict[ww] += 1
else:
w_dict[ww] = 1
h_max_count = max(h_dict.values())
w_max_count = max(w_dict.values())
hh_dict = {}
ww_dict = {}
for hh in h_dict:
if h_dict[hh] == h_max_count:
hh_dict[hh] = h_max_count
for ww in w_dict:
if w_dict[ww] == w_max_count:
ww_dict[ww] = w_max_count
flag = 0
for hh in hh_dict:
for ww in ww_dict:
if tuple([hh, ww]) not in bom_set:
flag = 1
break
if flag == 1:
break
if flag == 1:
print(h_max_count + w_max_count)
else:
print(h_max_count + w_max_count - 1) | 1 | 4,709,618,447,936 | null | 89 | 89 |
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for x in a:
for y in a:
ans = x * y
print(str(x)+'x'+str(y)+'='+str(ans))
| n = int(input())
a = 100000
while n>0:
a *= 1.05
if a % 1000 != 0:
a = int(a + 1000 - (a%1000))
n -= 1
print(a) | 0 | null | 498,222,560 | 1 | 6 |
N, K = map(int, input().split())
*A, = map(int, input().split())
*F, = map(int, input().split())
A.sort()
F.sort(reverse=True)
def f(x):
ans = 0
for i,j in zip(A, F):
ans += (i*j-x+j-1)//j if i*j-x>=0 else 0
return ans<=K
l, r = -1, 10**18+1
while r-l>1:
mid = (r+l)//2
if f(mid):
r = mid
else:
l = mid
print(r) | def abc144_e():
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)[::-1]
low = -1
up = 10**12
while up - low > 1:
v = (up + low) // 2
x = A - v // F
if x[x > 0].sum() > K:
low = v
else:
up = v
print(up)
if __name__ == '__main__':
abc144_e() | 1 | 164,813,381,124,672 | null | 290 | 290 |
N = int(input())
ls = []
for i in range(N):
s = input().split()
ls.append(s)
X = input()
ans = 0
mode = 0
for i in range(N):
if ls[i][0] == X:
mode = 1
else:
if mode == 1:
ans += int(ls[i][1])
print(ans) | s = input()
l = [0,'SAT','FRI','THU','WED','TUE','MON','SUN']
print(l.index(s)) | 0 | null | 115,154,194,409,198 | 243 | 270 |
n, k, s = map(int,input().split())
t1 = [str(s)] * k
if s != 10**9:
t2 = [str(s+1)] * (n-k)
else:
t2 = [str(1)] * (n-k)
print(*(t1+t2)) | N,K,S = [int(hoge) for hoge in input().split()]
import math
#累積和数列であって、Ar-Al=Sを満たすものが丁度K個ある
if S==10**9:
print(*([S]*K + [27]*(N-K)))
elif S:
print(*([S]*K + [S+1]*(N-K)))
else:
ans = []
while 1:
if K==2:
ans +=[0,1,0]
break
for R in range(N):
if (R+1)*(R+2)//2 > K:break
print(K)
if K==0:break
ans += [0]*R+[1]
K = K - R*(R+1)//2
print(ans + [1]*(N-len(ans))) | 1 | 90,987,125,192,910 | null | 238 | 238 |
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0
A=list(map(int,input().split()))
for ai in A:
if ai==1:
ans+=300000
elif ai==2:
ans+=200000
elif ai==3:
ans+=100000
if A[0]==1 and A[1]==1:
ans+=400000
print(ans) | N, M = map(int, input().split())
SC = [tuple(map(int, input().split())) for _ in range(M)]
for num in range(1000):
if len(str(num)) != N: continue
for s, c in SC:
s -= 1
if str(num)[s] != str(c):
break
else:
print(num)
exit()
print(-1) | 0 | null | 100,989,633,625,450 | 275 | 208 |
from math import ceil
n = int(input())
a = [chr(i) for i in range(97, 97+26)]
s = 0
for i in range(1,100):
l = n - s
s += 26**i
if n <= s:
m = i
break #第m群l番目
name = [0] * m
div = [0] * m
rem = [0] * m
rem[-1] = l
for j in range(m):
div[j] = ceil(rem[j-1] / (26**(m-j-1)))
rem[j] = rem[j-1] % (26**(m-j-1))
if rem[j] == 0:
rem[j] == 26**(m-j-1)
name[j] = a[div[j]-1]
print(''.join(name)) | N = int(input())
alphabet = list("abcdefghijklmnopqrstuvwxyz")
res = ""
while (N > 0):
N -= 1
num = int(N % 26)
res += alphabet[num]
N /= 26
N = N // 1
print(res[::-1]) | 1 | 11,866,396,441,824 | null | 121 | 121 |
H ,W = map(int,input().split())
from collections import deque
S = [input() for i in range(H)]
directions = [[0,1],[1,0],[-1,0],[0,-1]]
counter = 0
#インデックス番号 xが行番号 yが列番号
for x in range(H):
for y in range(W):
if S[x][y]=="#":
continue
que = deque([[x,y]])
memory = [[-1]*W for _ in range(H)]
memory[x][y]=0
while True:
if len(que)==0:
break
h,w = que.popleft()
for i,k in directions:
x_new,y_new = h+i,w+k
if not(0<=x_new<=H-1) or not(0<=y_new<=W-1) :
continue
elif not memory[x_new][y_new]==-1 or S[x_new][y_new]=="#":
continue
memory[x_new][y_new] = memory[h][w]+1
que.append([x_new,y_new])
counter = max(counter,max(max(i) for i in memory))
print(counter)
| import queue
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
# print(maze)
def bfs(dist, i, j):
q = queue.Queue()
q.put((i, j, 0))
while not q.empty():
i, j, c = q.get()
# print(i, j, c, dist)
if i != 0 and dist[i-1][j] == 0:
dist[i-1][j] = c+1
q.put((i-1, j, c+1))
if j != 0 and dist[i][j-1] == 0:
dist[i][j-1] = c+1
q.put((i, j-1, c+1))
if i != h-1 and dist[i+1][j] == 0:
dist[i+1][j] = c+1
q.put((i+1, j, c+1))
if j != w-1 and dist[i][j+1] == 0:
dist[i][j+1] = c+1
q.put((i, j+1, c+1))
return dist, c
ans = 0
for i in range(h):
for j in range(w):
if maze[i][j] == '.':
dist = [[(maze[y][x] == '#')*-1 for x in range(w)] for y in range(h)]
dist[i][j] = -10
dist, c = bfs(dist, i, j)
tmp_ans = c
if tmp_ans > ans:
ans = tmp_ans
print(ans)
| 1 | 94,703,663,821,108 | null | 241 | 241 |
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
x = Ii()
for i in range(121):
for j in range(-119,120):
if x == i**5 - j**5:
print(i,j)
exit(0) | def main():
x = int(input())
for i in range(-118, 120):
for j in range(-119, 119):
if i**5 - j**5 == x:
print(i, j)
exit()
if __name__ == '__main__':
main() | 1 | 25,365,520,912,872 | null | 156 | 156 |
import math
X=list()
Y=list()
s=0
N=int(input())
for i in range(N):
x,y=map(int,input().split())
X.append(x)
Y.append(y)
for i in range(N):
for j in range(N):
s+=math.sqrt(((X[i]-X[j])**2)+((Y[i]-Y[j])**2))
print(s*(1/N)) | N = int(input())
ans = 0
for i in range(1,N+1): #1-N
first = i; kosu = N//i
end = kosu*i
temp = (first+end)*kosu//2
ans += temp
print(ans)
| 0 | null | 79,554,657,344,892 | 280 | 118 |
#! python3
# coding:utf-8
def main():
a,b,c,d = map(int,input().split())
while ((a>0) and (c>0)):
c = c - b
if c <= 0:
print("Yes")
break
a = a - d
if a <= 0:
print("No")
if __name__ == "__main__":
main() | import bisect as bs
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(len(L)-1):
for j in range(i+1, len(L)):
ans += bs.bisect_left(L, L[i]+L[j])-j-1
print(ans) | 0 | null | 100,823,161,345,400 | 164 | 294 |
import math
in1 = list(map(int,input().split()))
Nin = in1[0]
Din = in1[1]
xy = [map(int, input().split()) for _ in range(Nin)]
x, y = [list(i) for i in zip(*xy)]
count=0
for i in range(Nin):
dist = math.sqrt(x[i]**2 + y[i]**2)
if dist <= Din:
count += 1
print(count)
| N, D = [int(v) for v in input().split()]
D = D*D
ans = 0
for _ in range(N):
x, y = [int(v) for v in input().split()]
if (x**2 + y**2) <= D:
ans += 1
print(ans) | 1 | 5,880,989,281,920 | null | 96 | 96 |
N = int(input())
A = input().split()
ans = 1
zero_count = A.count("0")
if zero_count != 0:
print(0)
else:
for i in range(N):
ans *= int(A[i])
if ans > 10**18:
ans = -1
break
print(ans) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
if 0 in set(a):
print(0)
quit()
res = 1
for x in a:
res *= x
if res > 10**18:
print(-1)
quit()
print(res) | 1 | 16,152,900,342,610 | null | 134 | 134 |
from collections import deque
n,p=map(int ,input().split())
que=deque([])
for i in range(n):
name,time=input().split()
time=int(time)
que.append([name,time])
t=0
while len(que)>0:
atop=que.popleft()
spend=min(atop[1],p)
atop[1]-=spend
t+=spend
if(atop[1]==0):
print(atop[0],t)
else:
que.append(atop) | def main():
n, q = map(int, input().split())
queue = [[x for x in input().split()] for _ in range(n)]
queue = [(x[0], int(x[1])) for x in queue]
elapsed_time = 0
while len(queue) > 0:
process, time = queue.pop(0)
if time > q:
queue.append((process, time - q))
elapsed_time += q
else:
elapsed_time += time
print('{} {}'.format(process, str(elapsed_time)))
return
main()
| 1 | 43,928,038,092 | null | 19 | 19 |
n = int(input())
S=[]
for i in range(n):
S.append(input())
S.sort()
c=1
for i in range(n-1):
if S[i]!=S[i+1] :
c+=1
print( c ) | S = int(input())
if S == 1:
print(0)
exit()
MOD = 10**9 + 7
A = [0] * (S + 1)
A[0] = 1
A[1] = 0
A[2] = 0
cumsum = 1
for i in range(3, len(A)):
A[i] = (A[i - 1] + A[i - 3]) % MOD
print(A[-1])
| 0 | null | 16,669,612,500,352 | 165 | 79 |
n,nWorks,nSp = map(int,input().split())
s = input()
leftList = [0]*n
rightList = [0]*n
num = 0
count = 0
while num < n:
if s[num] == "o":
leftList[num] = 1
count +=1
num += 1 + nSp
else:
num +=1
if count > nWorks:
exit()
num = n-1
count = 0
while num >= 0:
if s[num] == "o":
rightList[num] = 1
count +=1
num -= (1 + nSp)
else:
num -=1
for kk in range(n):
if leftList[kk] and rightList[kk]:
print(kk+1) | n,k,c=map(int,input().split())
s=input()
def greedy_work(days,rest,plan):
day_count=0
go=[0]*n
while day_count < days:
if plan[day_count]=='o':
go[day_count]=1
day_count += rest+1
else:
day_count += 1
return(go)
front = greedy_work(n,c,s)
back = greedy_work(n,c,s[::-1])
back = back[::-1]
if front.count(1)==k:
for i in range(n):
if front[i]==1 and back[i]==1:
print(i+1) | 1 | 40,784,671,973,602 | null | 182 | 182 |
H=int(input())
W=int(input())
N=int(input())
if N%max(H,W)==0:
print(N//max(H,W))
else:
print(N//max(H,W)+1) | k = int(input())
a, b = map(int, input().split())
for n in range(a, b+1):
if n % k == 0:
print('OK')
break
if n == b:
print('NG') | 0 | null | 57,874,452,237,128 | 236 | 158 |
N, K = map(int, input().split())
def sub_sum(l, r):
return (l + r) * (r - l + 1) / 2
ans = 0
for i in range(K, N+2):
l = sub_sum(0, i-1)
r = sub_sum(N-i+1, N)
ans += r - l + 1
ans = ans % (10**9+7)
print(int(ans))
| def main():
n, k = map(int, input().split())
mod = 10 ** 9 + 7
cnt = 0
for i in range(k, n+2):
l = (i-1)*i//2
h = (n+n-i+1)*i//2
cnt += h - l + 1
print(cnt % mod)
if __name__ == '__main__':
main() | 1 | 33,297,557,930,040 | null | 170 | 170 |
import math
n, d, a = map(int,input().split())
e = [[] for i in range(n)]
for i in range(n):
x, h = map(int,input().split())
e[i] = [x,h]
num = 0
e.sort()
sd = [0 for i in range(n)]
l = [i for i in range(n)]
for i in range(n):
for j in range(l[i-1],i):
if e[i][0]-e[j][0] <= 2*d:
l[i] = j
break
for i in range(n):
res = e[i][1] - sd[i-1] + sd[l[i]-1]
if res < 0:
sd[i] = sd[i-1]
else:
k = math.ceil(res/a)
sd[i] = sd[i-1]+k*a
num += k
print(num)
| N = int(input())
S = ""
while 0<N:
N-=1
S+=chr(97+N%26)
N//=26
print(S[::-1]) | 0 | null | 46,931,245,655,322 | 230 | 121 |
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
S,T = LS()
ans = ""
for i in range(N):
ans += S[i]
ans += T[i]
print(ans)
main()
| count = 0
def merge(data, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L = []
R = []
for i in range(n1):
L.append(data[left+i])
for i in range(n2):
R.append(data[mid+i])
L.append(float('inf'))
R.append(float('inf'))
i = 0
j = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
data[k] = L[i]
i += 1
else:
data[k] = R[j]
j += 1
def merge_sort(data, left, right):
if left + 1 < right:
mid = (left + right) / 2
merge_sort(data, left, mid)
merge_sort(data, mid, right)
merge(data, left, mid, right)
def main():
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
merge_sort(num_list, 0, len(num_list))
num_list = map(str, num_list)
print " ".join(num_list)
print count
if __name__ == '__main__':
main() | 0 | null | 55,748,196,709,348 | 255 | 26 |
INF = 1e5
n, m = list(map(int, input().split()))
C = list(map(int, input().split()))
dp = [[INF] * (n + 1) for _ in range(m)]
for i in range(m):
dp[i][0] = 0
for j in range(1 + n):
dp[0][j] = j
from itertools import product
for i, j in product(range(1, m), range(1, n + 1)):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if 0 <= j - C[i]:
dp[i][j] = min(dp[i][j], dp[i][j - C[i]] + 1)
print(dp[i][j])
| inf=10**9
n,m=map(int,input().split())
C=list(map(int,input().split()))
DP=[inf]*(n+1)
DP[0]=0
for i in range(n+1):
for c in C:
if 0<=i+c<=n:
DP[i+c]=min(DP[i+c],DP[i]+1)
print(DP[n])
| 1 | 145,967,496,990 | null | 28 | 28 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
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())
from collections import defaultdict
from collections import Counter
import bisect
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
N = S()
K = I()
dig = len(N)
if dig < K:
print(0)
exit()
ans = 0
for i in range(dig):
if K == 0:
ans += 1
break
if int(N[i]) == 0:
continue
if dig - i - 1 >= K:
ans += combinations_count(dig - i - 1, K) * pow(9, K)
if dig - i - 1 >= K - 1:
ans += (int(N[i]) - 1) * combinations_count(dig - i - 1, K - 1) * pow(9, K - 1)
if i == dig - 1:
ans += 1
K -= 1
print(ans)
if __name__ == "__main__":
main()
| N = input()
K = int(input())
L = len(N)
dp = [[[0 for j in range(L + 10)] for i in range(L + 10)] for _ in range(2)]
dp[0][0][0] = 1
for i in range(L):
Ni = int(N[i])
for j in range(L):
if Ni == 0:
dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 1
dp[0][i + 1][j + 1] += dp[0][i][j + 0] * 0
dp[1][i + 1][j + 0] += dp[0][i][j + 0] * 0 + dp[1][i][j + 0] * 1
dp[1][i + 1][j + 1] += dp[0][i][j + 0] * 0 + dp[1][i][j + 0] * 9
else:
dp[0][i + 1][j + 0] += dp[0][i][j + 0] * 0
dp[0][i + 1][j + 1] += dp[0][i][j + 0] * 1
dp[1][i + 1][j + 0] += dp[0][i][j + 0] * 1 + dp[1][i][j + 0] * 1
dp[1][i + 1][j + 1] += dp[0][i][j + 0] * (Ni - 1) + dp[1][i][j + 0] * 9
#print(dp[0])
#print(dp[1])
print(dp[0][L][K] + dp[1][L][K]) | 1 | 75,856,739,345,634 | null | 224 | 224 |
n, m, x = list(map(int, input().split()))
books = []
for _ in range(n):
books.append(list(map(int, input().split())))
# 参考書の組み合わせ
price_min = pow(10, 6) * n
found = False
for bits in range(2 ** n):
level = [0] * m
price = 0
# ビットが立っている参考書の理解度と値段を加算
for book in range(n):
if (bits >> book) & 1:
price += books[book][0]
for alg in range(m):
level[alg] += books[book][alg + 1]
# 理解度がXに満たないアルゴリズムを抽出
level = list(filter(lambda lv: lv < x, level))
# 理解度の条件を満たし、かつ合計額が最低値を下回るときに最低値を更新
if len(level) == 0 and price < price_min:
found = True
price_min = price
print(price_min if found else "-1") | import numpy as np
n, m, x = map(int, input().split())
data = []
for i in range(n):
temp = list(map(int, input().split()))
data.append(temp)
# ------------------------
# 今回の場合は、MとNが異様に小さいので、全探索して、Xを超える条件をMinで取るのがBetter
cost = 10 ** 17
# 0の場合は全部がOFFなので、はじく。
for bit in range(1, 2 ** n):
# print(bit)
ttt = np.zeros(m + 1)
for j in range(n):
# onの場合
if (bit >> j & 1):
#print('OK!', j)
tar = np.array(data[j])
ttt += tar
check = np.where(ttt[1:] >= x)[0]
if (len(check) == m):
cost = min(cost, ttt[0])
else:
pass
if (cost == 10 ** 17):
print(-1)
else:
print(int(cost))
| 1 | 22,298,802,940,040 | null | 149 | 149 |
N, X, T = map(int, input().split())
print((N // X + bool(N % X))* T)
| import numpy as np
a,b,c = map(int,input().split())
print(int(np.ceil(a/b)*c)) | 1 | 4,212,592,878,040 | null | 86 | 86 |
s = input()
li = list(s)
if sum([int(n) for n in li]) % 9 == 0:
print("Yes")
else:
print("No") | n = int(input())
titles = []
times = []
for i in range(n):
title,m = input().split()
titles.append(title)
times.append(int(m))
print(sum(times[titles.index(input())+1:])) | 0 | null | 50,493,236,891,018 | 87 | 243 |
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
A = sorted(A, reverse=True)
l = 0
r = max(A)+1
def cut(l, k):
# 長さlの丸太を最大とすることができるかどうかを返す
for a in A:
if a > l:
k -= (-(-a//l) - 1)
return k >= 0
while r-l > 1:
mid = (r+l)//2
if cut(mid, k):
r = mid
else:
l = mid
print(r) | import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
"""def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)"""
"""def pw(a,b):
result=1
while(b>0):
if(b%2==1): result*=a
a*=a
b//=2
return result"""
def inpt():
return [int(k) for k in input().split()]
def check(mid,k,ar):
ct=k
for i in ar:
if(i<=mid):
continue
ct-=(i//mid)
return ct>=0
def main():
n,k=map(int,input().split())
ar=inpt()
i,j=1,100000000000
while(i<j):
mid=(i+j)//2
if(check(mid,k,ar)):
j=mid
else:
i=mid+1
print(i)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
| 1 | 6,480,957,325,388 | null | 99 | 99 |
n = int(input())
digit = 1
while n > 26 ** digit:
n -= 26 ** digit
digit += 1
ans = []
n -= 1
char = 'abcdefghijklmnopqrstuvwxyz'
for i in list(range(digit)):
ans.append(char[n % 26])
n -= n%26
n = int(n/26)
print(''.join(reversed(ans))) | X = int(input())
A = []
for i in range(200):
A.append(pow(i, 5))
for i in range(200):
for j in range(200):
a = abs(A[i] - A[j])
b = A[i] + A[j]
if a == X:
if i <= j:
B = [j, i]
else:
B = [i, j]
print(' '.join(map(str, B)))
exit()
elif b == X:
B = [i, -j]
print(' '.join(map(str, B)))
exit()
| 0 | null | 18,815,408,960,752 | 121 | 156 |
def solve():
# tmp_max = P[0]
tmp_min = P[0]
cnt = 1
for i in range(0,N):
if P[i] < tmp_min:
tmp_min = P[i]
cnt += 1
print(cnt)
if __name__ == "__main__":
N = int(input())
P = list(map(int, input().split()))
solve()
| N = int(input())
cc = map(int,input().split())
min_num = N
count = 0
for i in cc:
if i <= min_num:
min_num = i
count += 1
print(count) | 1 | 85,232,872,365,488 | null | 233 | 233 |
N = int(input())
sum_ = 0
for i in range(1, N + 1):
n = int(N / i)
sum_ += (n / 2) * (2 * i + (n - 1) * i)
print(int(sum_))
| #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())
ans=0
for i in range(1,n+1):
num=n//i
ans+=(num*(i+num*i))//2
print(ans) | 1 | 11,060,632,234,976 | null | 118 | 118 |
#coding:utf-8
from copy import deepcopy
n = int(input())
c = ["white" for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
S = []
class DFS:
def __init__(self, key, color="white",nex=None):
self.color = color
self.nex = nex
self.key = key
objListCopy = [DFS(i+1) for i in range(n)]
for i in range(n):
data = list(map(int,input().split()))
times = data[1]
obj = objListCopy[i]
for j in range(times):
index = data[2+j] - 1
nextobj = DFS(index+1)
obj.nex = nextobj
obj = obj.nex
time = 1
objList = objListCopy[:]
def check(first,time):
obj = objList[first]
c[first] = "gray"
d[first] = time
f[first] = time
S.append(first+1)
while S != []:
index = S[-1] - 1
u = objList[index]
v = u.nex
time += 1
if v != None:
if c[v.key - 1] == "white":
objList[index] = v
index = v.key - 1
v = objList[index]
c[v.key-1] = "gray"
d[index] = time
S.append(v.key)
else:
objList[index] = v
time -= 1
else:
S.pop()
c[u.key-1] = "black"
f[index] = time
return time
for i in range(n):
if f[i] == 0:
objList = deepcopy(objListCopy)
time = check(i,time) + 1
k = 1
for i,j in zip(d,f):
print(k,i,j)
k += 1
| N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
t = list(map(int, input().split()))
for j in range(t[1]):
edge[t[0]].append(t[j+2])
#print(1)
def dfs(v, t):
if d[v] == 0:
d[v] = t
t += 1
else:
return t
for nv in edge[v]:
t = dfs(nv, t)
if f[v] == 0:
f[v] = t
t += 1
return t
t = 1
for i in range(1,1+N):
if d[i] == 0:
t = dfs(i, t)
for i in range(1,1+N):
print(i, d[i], f[i])
| 1 | 2,865,165,920 | null | 8 | 8 |
import math
n = int(input())
a = [float(x) for x in list(input().split())]
b = [float(x) for x in list(input().split())]
result = 0
for aa, bb in zip(a, b):
result += abs(aa - bb)
print(round(result, 6))
result = 0
for aa, bb in zip(a, b):
result += abs(aa - bb) ** 2
print(round(math.sqrt(result), 8))
result = 0
for aa, bb in zip(a, b):
result += abs(aa - bb) ** 3
print(round(math.pow(result, 1/3), 8))
result = []
for aa, bb in zip(a, b):
result.append(abs(aa - bb))
print(max(result))
| class UnionFind:
def __init__(self, numV):
self.pars = list(range(numV))
self.ranks = [0] * numV
self.sizes = [1] * numV
def getRoot(self, x):
par = self.pars[x]
if par != x:
self.pars[x] = par = self.getRoot(par)
return par
def merge(self, x, y):
x, y = self.getRoot(x), self.getRoot(y)
sx, sy = self.sizes[x], self.sizes[y]
if x == y: return (0, 0)
if self.ranks[x] < self.ranks[y]:
self.pars[x] = y
self.sizes[y] += sx
else:
self.pars[y] = x
self.sizes[x] += sy
if self.ranks[x] == self.ranks[y]:
self.ranks[x] += 1
return (sx, sy)
def isSame(self, x, y):
return self.getRoot(x) == self.getRoot(y)
def updatePars(self):
for v in range(len(self.pars)):
self.getRoot(v)
def getSize(self, x):
return self.sizes[self.getRoot(x)]
n, m, k = map(int, input().split())
uf = UnionFind(n)
ex = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.merge(a,b)
ex[a].append(b)
ex[b].append(a)
for i in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if uf.getRoot(c) == uf.getRoot(d):
ex[c].append(d)
ex[d].append(c)
ans = []
for i in range(n):
r = uf.getRoot(i)
ans.append(uf.sizes[r] - len(list(set(ex[i]))) - 1)
ans = [str(i) for i in ans]
print(' '.join(ans)) | 0 | null | 30,894,377,937,632 | 32 | 209 |
def penalty(day, last, c):
val = 0
for i in range(26):
val += c[i] * (day - last[i])
return val
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
last = [-1]*26
ans = [0]*(d+1)
for day in range(d):
ans[day+1] = ans[day] + s[day][t[day]-1]
last[t[day]-1] = day
ans[day+1] -= penalty(day, last, c)
for v in ans[1:]:
print(v) | N, T = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
dp1 = [[0]*(T) for _ in range(N+1)]
dp2 = [[0]*(T) for _ in range(N+2)]
for i in range(N):
for j in range(T):
dp1[i+1][j] = max(dp1[i][j], dp1[i][j-A[i]]+B[i]) if j-A[i]>=0 else dp1[i][j]
for i in range(N, 0, -1):
for j in range(T):
dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-A[i-1]]+B[i-1]) if j-A[i-1]>=0 else dp2[i+1][j]
ans = -1
for i in range(1, N+1):
for j in range(T):
ans = max(ans, dp1[i-1][j]+dp2[i+1][T-j-1]+B[i-1])
print(ans) | 0 | null | 80,886,078,884,488 | 114 | 282 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
ans = 'No'
cnt = 0
for i in range(n):
a, b = M()
if a == b:
cnt += 1
if cnt == 3:
ans = 'Yes'
break
else:
cnt = 0
print(ans) | import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
n = ni()
a = na()
b = []
for i in range(n):
b.append((a[i],i))
b.sort(reverse=True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
x,y = b[i-1]
for j in range(i+1):
left = dp[i-1][j-1] + x*abs(y-j+1) if j > 0 else -1
right = dp[i-1][j] + x*abs(n-i+j-y) if j < i else -1
dp[i][j] = max(left,right)
print(max(dp[-1])) | 0 | null | 18,144,569,697,448 | 72 | 171 |
from math import sqrt
while True:
n = int(input())
if n == 0:
break
scores = list(map(int,input().split()))
m = sum(scores)/len(scores)
print(sqrt(sum((sc -m)**2 for sc in scores)/len(scores))) | while True:
n = int(input())
if n == 0:
break
x = tuple(map(float, input().strip().split()))
y = (sum(x)/n)**2
z = sum(map(pow, x, (2 for i in range(n))))/n
print((z-y)**0.5) | 1 | 201,089,510,400 | null | 31 | 31 |
W, H, x, y, r = map(int, input().split())
flg = False
for X in [x - r, x + r]:
for Y in [y - r, y + r]:
if not 0 <= X <= W:
flg = True
if not 0 <= Y <= H:
flg = True
print(["Yes", "No"][flg])
| W,H,x,y,r=map(int,input().split())
if 0<=x-r<x<x+r<=W and 0<=y-r<y<y+r<=H:
print("Yes")
else:
print("No")
| 1 | 458,555,351,492 | null | 41 | 41 |
base, rate = 100, 1.05
for _ in range(int(input())):
base *= rate
if not base.is_integer():
base = int(base) + 1
print(base * 1000) | n = input()
money = 100000
for i in range(n):
money = int(money * 1.05)
if money != money / 1000 * 1000:
money = money / 1000 * 1000 + 1000
print money | 1 | 959,357,600 | null | 6 | 6 |
#coding:utf-8
num = input()
print num * num * num | n = input()
print pow(n, 3) | 1 | 271,211,645,850 | null | 35 | 35 |
while True:
inVal = input().split()
if inVal[1] == "?":
break
if inVal[1] == "+":
print(int(inVal[0]) + int(inVal[2]))
elif inVal[1] == "-":
print(int(inVal[0]) - int(inVal[2]))
elif inVal[1] == "*":
print(int(inVal[0]) * int(inVal[2]))
elif inVal[1] == "/":
print(int(inVal[0]) // int(inVal[2]))
| def mk_tree(A,N):
B = [None for _ in range(N+1)]
B[0] = 1
#B[i]:深さiの頂点の個数
A_sum = [A[i] for i in range(N+1)]
for i in reversed(range(N)):
A_sum[i] += A_sum[i+1]
for i in range(1,N+1):
B[i] = min(2*(B[i-1]-A[i-1]),A_sum[i])
if B[N] == A[N]:
return sum(B)
else:
return -1
def main():
N = int(input())
A = list(map(int,input().split()))
print(mk_tree(A,N))
if __name__ == "__main__":
main()
| 0 | null | 9,693,969,013,388 | 47 | 141 |
n,m,l = map(int,input().split())
g = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
a,b,c = map(int,input().split())
a-=1
b-=1
g[a][b] = c
g[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
g[i][j] = min(g[i][j],g[i][k] + g[k][j])
h = [[float('inf')]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if g[i][j]<=l:
h[i][j] = 1
for k in range(n):
for i in range(n):
for j in range(n):
h[i][j] = min(h[i][j],h[i][k] + h[k][j])
Q = int(input())
for _ in range(Q):
s,t = map(int,input().split())
s -=1
t-=1
if h[s][t] ==float('inf'):
print(-1)
else:
print(h[s][t]-1)
| n,t= map(int, input().split())
a= [list(map(int, input().split())) for i in range(n)]
# dp[i][j]: i番目の料理まで見て時間がjの時の満足度のMAX
dpA=[[0]*t for i in range(n+1)]
# dp[i][j]: n-i番目の料理まで見て時間がjのときの満足度のMAX
dpB=[[0]*t for i in range(n+1)]
for i in range(n):
for j in range(t):
if a[i][0]>j:
dpA[i+1][j]=dpA[i][j]
else:
dpA[i+1][j]=max(dpA[i][j-a[i][0]]+a[i][1],dpA[i][j])
for i in range(n):
for j in range(t):
if a[n-i-1][0]>j:
dpB[n-i-1][j]=dpB[n-i][j]
else:
dpB[n-i-1][j]=max(dpB[n-i][j-a[n-i-1][0]]+a[n-i-1][1],dpB[n-i][j])
ans=0
for i in range(n):
for j in range(t):
ans=max(dpA[i][j]+dpB[i+1][t-j-1]+a[i][1],ans)
print(ans) | 0 | null | 162,798,231,177,498 | 295 | 282 |
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
i = 0
waru = 1
while a > 0:
if a % (waru * 2) != 0:
a -= waru
bit[i] += 1
waru *= 2
i += 1
answer = 0
for i, b in enumerate(bit):
answer += (2 ** i) * (b * (N-b))
print(answer % MOD) | import collections
N = int(input())
A = list(map(int, input().split()))
#i + Ai
plus = [0] * N
#i - Ai
minus = [0] * N
for i in range(N):
plus[i] = i + 1 + A[i]
minus[i] = i + 1 - A[i]
#print(plus, minus)
plus = dict(collections.Counter(plus))
minus = dict(collections.Counter(minus))
#print(plus)
#print(minus)
ans = 0
for i in plus.keys():
#print(i)
if i in minus:
#print(i)
ans += plus[i] * minus[i]
#print(ans)
print(ans)
| 0 | null | 74,731,130,273,678 | 263 | 157 |
from itertools import accumulate
N, K = map(int, input().split())
P = tuple(accumulate(map(int, input().split())))
ans = P[K - 1]
for i in range(N - K):
ans = max(P[i + K] - P[i], ans)
print((ans + K) / 2) | N, K = map(int, input().split())
p = list(map(int, input().split()))
def calc(x):
return (x+1)/2
pe = []
for i in range(N):
pe.append(calc(p[i]))
cs = [pe[0]] + [0]*(N-1)
for i in range(1, N):
cs[i] = pe[i] + cs[i-1]
ans = cs[K-1]
for i in range(K, N):
wa = cs[i] - cs[i-K]
ans = max(ans, wa)
print(ans)
| 1 | 74,834,607,651,702 | null | 223 | 223 |
def main():
a,b,c = map(int,input().split(" "))
if (c-a-b)**2 > a*b*4 and c > a + b:
print("Yes")
else:
print("No")
main() | class Dice(object):
def __init__(self, n):
self.n = n
def move(self, to):
if to == 'N':
self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4]
elif to == 'E':
self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2]
elif to == 'S':
self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1]
elif to == 'W':
self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3]
def top(self):
return self.n[0]
dice = Dice([int(i) for i in input().split()])
move = input()
for m in move:
dice.move(m)
print(dice.top())
| 0 | null | 25,753,714,281,568 | 197 | 33 |
R,C,k = map(int,input().split())
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
item = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
r,c,v = map(int,input().split())
dp1[r][c] = v
for i in range(1,R+1):
for j in range(1,C+1):
a = dp1[i][j]
dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a)
print(max(dp1[R][C],dp2[R][C],dp3[R][C])) | #!/usr/bin/env python3
(R, C, K), *D = [[*map(int,o.split())] for o in open(0)]
V = [[0] * C for _ in [None] * R]
for r, c, v in D:
V[r - 1][c - 1] = v
dp = [[[-1] * C for _ in [None] * R] for _ in [None] * 4]
dp[0][0][0] = 0
for r in range(R):
for c in range(C):
v = V[r][c]
for i in range(4):
if dp[i][r][c] > -1:
if r < R - 1:
dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[i][r][c])
if c < C - 1:
dp[i][r][c + 1] = max(dp[i][r][c + 1], dp[i][r][c])
if i < 3 and v:
if r < R - 1:
dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[i][r][c] + v)
if c < C - 1:
dp[i + 1][r][c + 1] = max(dp[i + 1][r][c + 1], dp[i][r][c] + v)
v = V[R - 1][C - 1]
ans = dp[3][R - 1][C - 1]
for i in range(3):
ans = max(ans, dp[i][R - 1][C - 1] + v)
print(ans) | 1 | 5,613,618,822,900 | null | 94 | 94 |
import math
a, b, x = map(float, input().split())
vol = a * a * b
if x <= vol/2:
height = (x * 2.0) / (b * a)
ans = math.atan(b / height) * 180 / math.pi
else:
height = ((vol - x) * 2.0) / (a * a)
ans = math.atan(height / a) * 180 / math.pi
print(ans) | n=int(input())
ans=1000*((n+999)//1000)-n
print(ans) | 0 | null | 85,701,026,861,582 | 289 | 108 |
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array
# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
# 再帰の制限設定
sys.setrecursionlimit(10000000)
def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
for _ in range(n)]
def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
for _ in range(n)]
def lcm(x, y): return (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
D = [il() for _ in range(N)]
for i in range(N - 2):
for j in range(i, i + 3):
if D[j][0] != D[j][1]:
break
else:
print('Yes')
exit()
else:
print('No')
if __name__ == '__main__':
main()
| counter = int(input())
result_flg = False
fir_fir, fir_sec = map(int, input().split())
sec_fir, sec_sec = map(int, input().split())
for i in range(2, counter):
thi_fir, thi_sec = map(int, input().split())
if fir_fir == fir_sec:
if sec_fir == sec_sec:
if thi_fir == thi_sec:
result_flg = True
break
# reset content
fir_fir = sec_fir
fir_sec = sec_sec
sec_fir = thi_fir
sec_sec = thi_sec
if result_flg == True:
print('Yes')
else:
print('No') | 1 | 2,498,345,398,612 | null | 72 | 72 |
from collections import deque
#スタックを使った深さ優先探索の実装
l = int(input())
rlist = []
for i in range(l):
li = list(map(int, input().split()))
rlist.append(deque([ll-1 for ll in li[2:]]))
color = ['white'] * l
find_time = [0] * l
stop_time = [0] * l
stack = []
time = 0
def dfs(u):
global time
stack.append(u)
color[u] = 'gray'
time += 1
find_time[u] = time
while len(stack) > 0:
#print(stack)
#print(color)
#print(rlist)
u = stack[-1]
#頂点uにまだ訪問すべき頂点が残っているなら
if len(rlist[u]) > 0:
if color[rlist[u][0]] == 'white':
time += 1
find_time[rlist[u][0]] = time
color[rlist[u][0]] = 'gray'
stack.append(rlist[u][0])
rlist[u].popleft()
#頂点uにもう訪問すべき頂点が残っていないなら
else:
time += 1
stop_time[u] = time
color[u] = 'black'
stack.pop()
for i in range(l):
if color[i] == 'white':
dfs(i)
for i in range(len(find_time)):
print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i]))
| # -*- coding: utf-8 -*-
class Graph:
def __init__(self, n, adj_matrix):
self.n = n
self.adj_matrix = adj_matrix
def show(self):
for _ in self.adj_matrix:
print(*_)
def dfs(self):
self.states = [2] * self.n
self.d = [None] * self.n
self.f = [None] * self.n
self.time = 0
for u in range(self.n):
if self.states[u] == 2:
self.dfs_visit(u)
def dfs_visit(self, u):
self.states[u] = 1
self.time += 1
self.d[u] = self.time
for v, edge in enumerate(self.adj_matrix[u]):
if edge and self.states[v] == 2:
self.dfs_visit(v)
self.states[u] = 0
self.time += 1
self.f[u] = self.time
def show_dfs(self, start=0):
self.dfs()
for i, (d, f) in enumerate(zip(self.d, self.f)):
print(i + 1, d, f)
if __name__ == '__main__':
n = int(input())
adj_matrix = [[0] * n for i in range(n)]
for i in range(n):
for v in input().split()[2:]:
adj_matrix[i][int(v) - 1] = 1
g = Graph(n, adj_matrix)
g.show_dfs()
| 1 | 2,752,156,592 | null | 8 | 8 |
import math
H = int(input())
print(2**(math.floor(math.log2(H))+1)-1)
| import sys
import math
a = []
for l in sys.stdin:
a.append(int(l))
h = a[0]
n = 0
while h > 1:
h = math.floor(h / 2)
n = n + 1
print(2 ** (n + 1) - 1) | 1 | 79,873,771,343,956 | null | 228 | 228 |
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 7 01:24:25 2020
@author: saito
"""
# %% import phase
# %% define phase
# %% input phase
N = int(input())
# %% process phase
answer = 1000-((N-1)%1000+1)
# %%output phase
print(answer) | N = int(input())
for i in range(11):
b = i * 1000
c = b - N
if c >= 0:
break
print(c) | 1 | 8,451,199,079,268 | null | 108 | 108 |
N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7
ans = 1
cnt = [0, 0, 0]
for a in A:
if a not in cnt:
ans = 0
break
ans = ans * cnt.count(a) % mod
cnt[cnt.index(a)] += 1
print(ans)
| #!/usr/bin/env python3
#import
#import math
#import numpy as np
s = input()
q = int(input())
inv = False
fro = ""
end = ""
for _ in range(q):
query = list(map(str, input().split()))
if query[0] == "1":
inv = not inv
else:
t = int(query[1])
instr = query[2]
if not inv:
if t == 1:
fro = instr + fro
else:
end = end + instr
else:
if t == 1:
end = end + instr[::-1]
else:
fro = instr[::-1] + fro
ans = fro + s + end
if not inv:
print(ans)
else:
print(ans[::-1]) | 0 | null | 93,699,444,541,560 | 268 | 204 |
#!/usr/bin/env python3
def pow(N,R,mod):
ans = 1
i = 0
while((R>>i)>0):
if (R>>i)&1:
ans *= N
ans %= mod
N = (N*N)%mod
i += 1
return ans%mod
def main():
N,K = map(int,input().split())
li = [0 for _ in range(K)]
mod = 10**9+7
ans = 0
for i in range(K,0,-1):
mm = K//i
mm = pow(mm,N,mod)
for j in range(2,(K//i)+1):
mm -= li[i*j-1]
li[i-1] = mm
ans += (i*mm)%mod
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| MOD = 1000000007
N, K = map(int, input().split())
ans = 0
f = [0] * (K+1)
g = [0] * (K+1)
for t in range(K, 0, -1):
f[t] = pow(K//t, N, MOD)
g[t] = f[t]
for s in range(2 * t, K+1, t):
g[t] -= g[s]
ans = (ans + t * g[t]) % MOD
print(ans) | 1 | 36,757,717,325,420 | null | 176 | 176 |
def main():
a = list(map(int, list(input())))
n = len(a)
dp = [[0, 0] for _ in [0]*(n+1)]
dp[0][1] = 1
for i in range(n):
dp[i+1][0] = min(dp[i][0]+a[i], dp[i][1]+10-a[i])
dp[i+1][1] = min(dp[i][0]+a[i]+1, dp[i][1]+9-a[i])
print(dp[n][0])
main()
| a, b, c = map(int, raw_input().split())
if a > b > c or a < b < c:
print "Yes"
else:
print "No" | 0 | null | 35,577,996,126,420 | 219 | 39 |
n, k, c = map(int, input().split())
c += 1
s = list(input())
a = []
i = 0
while i < len(s) and len(a) < k:
if s[i] == 'x':
i += 1
continue
a.append(i)
i += c
b = []
j = len(s)-1
while j > -1 and len(b) < k:
if s[j] == 'x':
j -= 1
continue
b.append(j)
j -= c
b = b[::-1]
for i in range(len(a)):
if a[i] == b[i]:
print(a[i] + 1)
| class BIT:
from operator import add, sub, mul, floordiv
X_unit = 0
X_f = add
X_f_rev = sub
def __init__(self, seq):
N = len(seq)
self.N = N
self.X = seq[:]
for i in range(self.N):
j = i + ((i+1) & -(i+1))
if j < self.N:
self.X[j] = self.X_f(self.X[i], self.X[j])
def set_val(self, i, x):
while(i < self.N):
self.X[i] = self.X_f(self.X[i], x)
i += (i+1) & -(i+1)
def cum_val(self, i):
res = self.X_unit
while(i > -1):
res = self.X_f(res, self.X[i])
i -= (i+1) & -(i+1)
return res
#区間[L, R)
def fold(self, L, R):
return self.X_f_rev(self.cum_val(R-1), self.cum_val(L-1))
def bisect_left(self, w):
if w > self.cum_val(self.N - 1):
return self.N
elif self.N == 2:
return 1
n = 2**((self.N - 1).bit_length() - 1)
res = 0
while(n):
if res + n - 1 > self.N - 1:
n //= 2
continue
if w <= self.X[res + n - 1]:
n //= 2
else:
w -= self.X[res + n - 1]
res += n
n //= 2
return res
def bisect_right(self, w):
if w >= self.cum_val(self.N - 1):
return self.N
elif self.N == 2:
return 1
n = 2**((self.N - 1).bit_length() - 1)
res = 0
while(n):
if res + n - 1 > self.N - 1:
n //= 2
continue
if w < self.X[res + n - 1]:
n //= 2
else:
w -= self.X[res + n - 1]
res += n
n //= 2
return res
def lower_bound(self, w):
ans = self.bisect_right(self.cum_val(w))
if ans == self.N:
return -1
else:
return ans
def upper_bound(self, w):
ans = self.bisect_left(self.cum_val(w-1))
return ans
N = int(input())
S = list(input())
L = [BIT([0]*N) for _ in range(26)]
for i in range(N):
L[ord(S[i])-97].set_val(i, 1)
Q = int(input())
for _ in range(Q):
q, a, b = input().split()
if q == "1":
a = int(a)
L[ord(S[a-1])-97].set_val(a-1, -1)
L[ord(b)-97].set_val(a-1, 1)
S[a-1] = b
else:
a, b = int(a), int(b)
ans = 0
for i in range(26):
if L[i].fold(a-1, b) >= 1:
ans += 1
print(ans) | 0 | null | 51,576,354,062,982 | 182 | 210 |
N = int(input())
r, mod = divmod(N, 2)
print(r - 1 + mod) | N, M = map(int, input().split())
S = input()
if N <= M:
print(N)
exit()
if '1'*M in S:
print(-1)
exit()
from collections import deque
count = deque([])
for k in range(M+1):
if S[k] == '1':
count.append(-1)
else:
count.append(k)
sgn = deque([])
k = 0
while k < N:
k += 1
if S[k] == '0':
sgn.append(M)
else:
d = 0
while k < N:
if S[k] == '1':
k += 1
d += 1
continue
else:
break
while d > 0:
sgn.append(M-d)
d -= 1
sgn.append(M)
now = M
while now < N:
now += 1
a = sgn.popleft()
if S[now] == '1':
count.append(-1)
else:
count.append(a)
count = list(count)
c = 0
ans = ''
while c < N:
ans = str(count[-1-c]) + ' ' + ans
c += count[-1-c]
print(ans) | 0 | null | 145,706,830,818,036 | 283 | 274 |
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
if(a%b==0):return(b)
return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
gyaku=pow(2,mod-2,mod)
N2=pow(2,N-1,mod)
dp=[0 for n in range(3001)]
for n in range(N):
a=A[n]
for s in range(0,S+1)[::-1]:
if s+a<=S:
dp[s+a]+=dp[s]*gyaku%mod
dp[s+a]%=mod
dp[a]+=N2
dp[a]%=mod
print(dp[S])
| a, b = map(int, input().split())
if b * 2 >= a:
print('0')
else:
print(a - b * 2) | 0 | null | 92,334,782,302,560 | 138 | 291 |
X= int(input())
if(X>=400 and X<=599):
print(8)
elif(X>599 and X<800):
print(7)
elif(X>=800 and X<1000):
print(6)
elif(X>=1000 and X<1200):
print(5)
elif(X>=1200 and X<1400):
print(4)
elif(X>=1400 and X<1600):
print(3)
elif(X>=1600 and X<1800):
print(2)
elif(X>=1800 and X<2000):
print(1) | import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
x = inp()
if x < 600:
ans = 8
elif x < 800:
ans = 7
elif x < 1000:
ans = 6
elif x < 1200:
ans = 5
elif x < 1400:
ans = 4
elif x < 1600:
ans = 3
elif x < 1800:
ans = 2
elif x < 2000:
ans = 1
print(ans) | 1 | 6,719,006,601,820 | null | 100 | 100 |
n = int(input())
x = []
y = []
for _ in range(n):
a,b = map(int,input().split())
x.append(a)
y.append(b)
ans = 0
for i in range(n):
for j in range(n):
ans += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5
print(ans/n) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
XY = np.array(read().split(),np.int64)
X = XY[::2]; Y = XY[1::2]
dx = X[:,None] - X[None,:]
dy = Y[:,None] - Y[None,:]
dist_mat = (dx * dx + dy * dy) ** .5
answer = dist_mat.sum() / N
print(answer) | 1 | 148,154,834,099,932 | null | 280 | 280 |
#!usr/bin/env python3
import sys
def init_card_deck():
# S: spades
# H: hearts
# C: clubs
# D: diamonds
card_deck = {'S': [], 'H': [], 'C': [], 'D': []}
n = int(sys.stdin.readline())
for i in range(n):
lst = [card for card in sys.stdin.readline().split()]
card_deck[lst[0]].append(lst[1])
return card_deck
def print_missing_cards(card_deck):
card_symbols = ['S', 'H', 'C', 'D']
for i in card_symbols:
for card in range(1, 14):
if not str(card) in card_deck[i]:
print(i, card)
def main():
print_missing_cards(init_card_deck())
if __name__ == '__main__':
main() | S,H,C,D = [],[],[],[]
def adding(card):
if card[0] == 'S':
S.append(int(card[1]))
else:
if card[0] == 'H':
H.append(int(card[1]))
else:
if card[0] == 'C':
C.append(int(card[1]))
else:
if card[0] == 'D':
D.append(int(card[1]))
def sort():
S.sort()
H.sort()
C.sort()
D.sort()
def check(pattern,cards):
answer=[]
for i in range(1,13+1):
if not (i in cards):
print pattern,i
if __name__ == '__main__':
number = input()
for i in range(number):
card = map(str,raw_input().split())
adding(card)
sort()
check('S',S)
check('H',H)
check('C',C)
check('D',D) | 1 | 1,035,332,950,162 | null | 54 | 54 |
import sys
input = sys.stdin.readline
from collections import Counter
def rle(list):
dict = {}
for i in list:
if i in dict.keys():
dict[i] += 1
else:
dict[i] = 1
return dict
n = int(input())
a = list(map(int, input().split()))
minus = Counter([i-a[i] for i in range(n)])
plus = Counter([i+a[i] for i in range(n)])
cnt = 0
for i in minus:
if i in plus:
cnt += minus[i] * plus[i]
print(cnt)
| A, B, C, K = map(int, input().split())
D = A + B
if D >= K:
print(min(K,A))
else:
K -= D
print(A-K)
| 0 | null | 23,794,445,339,380 | 157 | 148 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
A, B = map(int, input().split())
# リストのlcm
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
print(lcm_base(A, B)) | from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
a,b = mi()
print((a*b)//math.gcd(a,b)) | 1 | 113,357,195,679,350 | null | 256 | 256 |
#
# m_solutions2020 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """7 2 5
3"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 4 2
3"""
output = """No"""
self.assertIO(input, output)
def resolve():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print("Yes")
break
else:
print("No")
if __name__ == "__main__":
# unittest.main()
resolve()
| def main():
a, b, c = [int(x) for x in input().split()]
count = int(input())
while a >= b:
b *= 2
count -= 1
while b >= c:
c *= 2
count -= 1
print('Yes' if count >= 0 else 'No')
if __name__ == '__main__':
main()
| 1 | 6,929,871,662,688 | null | 101 | 101 |
n, k = map(int, input().split())
mod = 998244353
m_list = []
for _ in range(k):
m_list.append(list(map(int, input().split())))
dp = [0]*n
dp[0] = 1
dp_sum = [0]*n
dp_sum[0] = 1
for i in range(1, n):
for j in range(k):
l, r = m_list[j]
il = i-l
ir = i-r-1
if il < 0:
continue
else:
if ir < 0 :
dp[i] += dp_sum[il]
else:
dp[i] += dp_sum[il] - dp_sum[ir]
dp[i] %= mod
dp_sum[i] = dp_sum[i-1] + dp[i]
dp_sum[i] %= mod
print(dp[n-1] % mod) | # D - Friend Suggestions
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def root(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.root(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.root(x)
y = self.root(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 same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.parents[self.root(x)]
N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
x,y = map(int,input().split())
block[x] += 1
block[y] += 1
friend.union(x,y)
for _ in range(K):
x,y = map(int,input().split())
if friend.same(x,y):
block[x] += 1
block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans) | 0 | null | 32,022,338,241,764 | 74 | 209 |
s = input()
s_l = [0] * (len(s) + 1)
s_r = [0] * (len(s) + 1)
for i in range(len(s)):
if s[i] == '<':
s_l[i + 1] = s_l[i] + 1
for i in range(len(s)):
if s[- i - 1] == '>':
s_r[- i - 2] = s_r[- i - 1] + 1
ans = 0
for i, j in zip(s_l, s_r):
ans += max(i, j)
print(ans) |
s = input()
data = []
cnt = 0
for i in range(len(s)-1):
cnt += 1
if s[i] != s[i+1]:
if s[i] == "<" and s[i+1] == ">":
data.append(cnt)
data.append(-1)
else:
data.append(cnt)
cnt = 0
data.append(cnt+1)
for i in range(len(data)-1):
if data[i] == -1:
if data[i-1] < data[i+1]:
data[i-1] -= 1
else:
data[i-1] > data[i+1]
data[i+1] -= 1
ans = 0
for i in range(len(data)):
if data[i] != -1:
for j in range(1, data[i]+1):
ans += j
# print(data)
print(ans)
| 1 | 156,207,696,552,558 | null | 285 | 285 |
N = int(input())
print(N // 2 - 1 if N % 2 == 0 else (N-1) // 2) | K = int(input())
s = 'ACL'
print(s * K)
| 0 | null | 78,059,338,701,892 | 283 | 69 |
s = list(input())
num = 0
n = len(s)
l = 0
i = 0
while i < n:
if s[i] == '<':
l+=num
num+=1
i+=1
if i==n:
l+=num
else:
cur = 0
while i < n and s[i]=='>':
i+=1
cur+=1
if cur <= num:
l+=num
cur-=1
l+=(cur*(cur+1))//2
num = 0
print(l) | from math import gcd
from functools import reduce
n = int(input())
A = list(map(int, input().split()))
res = ['pairwise coprime', 'setwise coprime', 'not coprime']
MAX = 10 ** 6 + 1000
dp = [i for i in range(MAX)]
# dp[x]はxを割り切る最小の素数
for x in range(2, MAX):
if dp[x] < x: continue
for y in range(x + x, MAX, x):
if dp[y] == y:
dp[y] = x
def get_factor(n):
factors = []
while n > 1:
factors.append(dp[n])
n //= dp[n]
return factors
prime_factors = []
for a in A:
factor = get_factor(a)
factor_set = list(set(factor))
prime_factors.extend(factor_set)
if len(prime_factors) == len(set(prime_factors)):
print(res[0])
elif reduce(gcd, A) == 1:
print(res[1])
else:
print(res[2])
| 0 | null | 80,096,562,216,242 | 285 | 85 |
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
a[i],b[i] = map(int,input().split())
a.sort()
b.sort()
if n % 2 == 1:
print(b[n//2] - a[n//2] + 1)
else:
front = n//2
back = (n-1)//2
print((b[front] + b[back] - (a[front] + a[back]) + 1))
| n=int(input())
arr1=[]
arr2=[]
for _ in range(n):
a,b=map(int,input().split())
arr1.append(a)
arr2.append(b)
arr1=sorted(arr1)
arr2=sorted(arr2)
if n%2==1:
l=arr1[n//2]
r=arr2[n//2]
else:
l=arr1[n//2-1]+arr1[n//2]
r=arr2[n//2-1]+arr2[n//2]
print(r-l+1) | 1 | 17,196,265,667,500 | null | 137 | 137 |
n,m,l= map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(m)]
for u in range(n):
for w in range(l):
c=0
for z in range(m):
c+=a[u][z]*b[z][w]
if w==l-1:
print(c)
else:
print(c,end=" ")
| n = int(input())
count=0
for i in range(1,n//2+1):
j = n - i
if i != j:
count += 1
print(count) | 0 | null | 77,397,561,146,048 | 60 | 283 |
def solve_knapsack_problem(A,n,m):
a=[[0 for i in range(m+1)]for j in range(n+1)]
for i in range(1,n+1):
for j in range(1,m+1):
if A[i-1]<=j:
a[i][j] = max(a[i-1][j-A[i-1]]+A[i-1],a[i-1][j])
else:
a[i][j] = a[i-1][j]
if a[i][j] == m:
return True
return False
if __name__ == "__main__":
n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
result=[]
for i in range(q):
if solve_knapsack_problem(A,n,m[i]):
print("yes")
else:
print("no")
| class Dice(object):
def __init__(self, nums):
from collections import deque
self.ns = deque([nums[4], nums[0], nums[1]])
self.we = deque([nums[3], nums[0], nums[2]])
self.bk = deque([nums[5]])
def __str__(self):
return str({"ns": self.ns, "we": self.we, "bk": self.bk})
def operation(self, o):
if o == "N":
self.n()
elif o == "S":
self.s()
elif o == "W":
self.w()
elif o == "E":
self.e()
else:
raise BaseException("invalid", o)
def n(self):
self.ns.append(self.bk.popleft())
self.bk.append(self.ns.popleft())
self.we[1] = self.ns[1]
def s(self):
self.ns.appendleft(self.bk.pop())
self.bk.appendleft(self.ns.pop())
self.we[1] = self.ns[1]
def w(self):
self.we.append(self.bk.popleft())
self.bk.append(self.we.popleft())
self.ns[1] = self.we[1]
def e(self):
self.we.appendleft(self.bk.pop())
self.bk.appendleft(self.we.pop())
self.ns[1] = self.we[1]
def rotate_right(self):
tmp = self.ns
tmp.reverse()
self.ns = self.we
self.we = tmp
def fit_top_s(self, top, s):
while self.get_top() != top:
if top in self.ns:
self.n()
elif top in self.we:
self.w()
else:
self.n()
self.n()
while self.get_s() != s:
self.rotate_right()
def get_top(self):
return self.ns[1]
def get_s(self):
return self.ns[2]
def get_e(self):
return self.we[2]
def resolve():
nums = [int(i) for i in input().split()]
dc = Dice(nums)
q = int(input())
for _ in range(q):
top, s = [int(i) for i in input().split()]
dc.fit_top_s(top, s)
print(dc.get_e())
resolve()
| 0 | null | 177,781,292,660 | 25 | 34 |
n,m=map(int,input().split())
if n%2==1:
x=[f"{i+1} {n-i}" for i in range(m)]
print(" ".join(x))
else:
x=[f"{i+1} {n-i}" if i<m/2 else f"{i+1} {n-i-1}" for i in range(m)]
print(" ".join(x))
| N, M = map(int, input().split())
for i in range((M + 1) // 2):
print(i + 1, i + (M - 2 * i) + 1)
for i in range(M - (M + 1) // 2):
print(M + 1 + i + 1, M + 1 + i + (M - 1 - 2 * i) + 1) | 1 | 28,683,866,346,560 | null | 162 | 162 |
n=int(input())
a=[]
b=[]
for i in range(n):
ai,bi=map(int,input().split())
a.append(ai)
b.append(bi)
a.sort()
b.sort()
if n%2==0:
n2=n//2
ca=(a[n2-1]+a[n2])
cb=(b[n2-1]+b[n2])
c=cb-ca+1
else:
n2=(n-1)//2
ca=a[n2]
cb=b[n2]
c=cb-ca+1
print(c)
| import math
n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
a[i], b[i] = list(map(int, input().split()))
a.sort()
b.sort()
ans = 0
h = int(n/2)
if n % 2 == 0:
a_harf = a[h-1] + a[h]
b_harf = b[h-1] + b[h]
ans = b_harf - a_harf + 1
else:
ans = b[h] - a[h] + 1
print(ans) | 1 | 17,161,039,386,320 | null | 137 | 137 |
A, B = map(int, input().split())
if A == B:
print('Yes')
else:
print('No') | a,b = [float(i) for i in input().split()]
d = int(a/b)
r = int(a) % int(b)
f = a/b
f = "{:.9f}".format(f)
print(d,r,f)
| 0 | null | 41,957,464,402,752 | 231 | 45 |
N = int(input())
A = [int(_) for _ in input().split()]
A.sort(reverse=True)
ans = 0
for i in range(N-1):
ans += A[(i+1) // 2]
print(ans)
| def solve(string):
n, *a = map(int, string.split())
a = sorted(a, reverse=True)
ans = sum(a[:(n + 1) // 2]) * 2 - a[0]
ans -= a[(n + 1) // 2 - 1] if n % 2 else 0
return str(ans)
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 9,156,909,544,380 | null | 111 | 111 |
N = int(input())
a = list(map(int,input().split()))
ans = []
x = a[0]
for i in range(1,N):
x ^= a[i]
for i in a:
ans.append(x^i)
print(*ans) | m,n=map(long,raw_input().split())
print m/n,
print m%n,
print '%.5f' % (float(m)/n) | 0 | null | 6,542,862,033,290 | 123 | 45 |
from itertools import product
h, w = map(int, input().split())
maze = [input() for _ in range(h)]
def neighbors(ih, iw):
for ih1, iw1 in (
(ih - 1, iw),
(ih + 1, iw),
(ih, iw - 1),
(ih, iw + 1),
):
if 0 <= ih1 < h and 0 <= iw1 < w and maze[ih1][iw1] == '.':
yield (ih1, iw1)
def len_maze(ih, iw):
# BFS
if maze[ih][iw] == '#':
return 0
stepped = [[False] * w for _ in range(h)]
q0 = [(ih, iw)]
l = -1
while q0:
q1 = set()
for ih0, iw0 in q0:
stepped[ih0][iw0] = True
for ih1, iw1 in neighbors(ih0, iw0):
if not stepped[ih1][iw1]:
q1.add((ih1, iw1))
q0 = list(q1)
l += 1
return l
answer = max(len_maze(ih, iw) for ih, iw in product(range(h), range(w)))
print(answer)
| count = 1
while True:
x = int(input())
if x == 0:
break
print('Case %d: %d' % (count, x))
count += 1
| 0 | null | 47,736,608,413,728 | 241 | 42 |
N = int(input())
l = []
for i in range(N+1):
if i % 5 == 0 or i % 3 == 0:
l.append(0)
else:
l.append(i)
print(sum(l)) | n = int(input())
a = 0
for i in range(n+1):
if i%3== 0: continue
elif i%5 == 0:continue
elif i%3 ==0 and i %5 ==0:continue
else: a+=i
print(a) | 1 | 34,897,146,895,322 | null | 173 | 173 |
while True:
H, W = map(int, raw_input().split())
if H == 0 or W == 0:
break
for _ in range(H):
print '#' * W
print '' | S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]
MOD = 2019
p10 = [1] * N
for i in range(1, N):
p10[i] = (p10[i - 1] * 10) % MOD
for i in range(N):
A[i] = (A[i] * p10[i]) % MOD
cumsum = [A[0]] * N
for i in range(1, N):
cumsum[i] = (cumsum[i - 1] + A[i]) % MOD
cnt = [0] * MOD
cnt[0] = 1
for i in range(N):
cnt[cumsum[i]] += 1
ans = 0
for i in range(MOD):
ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
| 0 | null | 15,802,404,109,548 | 49 | 166 |
print " ".join(sorted(map(str, map(int, raw_input().split(" "))))) | R=int(input())
print(2*R*3.1419) | 0 | null | 15,871,978,790,900 | 40 | 167 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
B = 4
F = 3
R = 10
SHARPS = 20
def main():
"""
The function to be called when this script is run as a script.
"""
info_number = int(input())
given_info_str = (info.split() for info in (
input() for _ in range(info_number)))
given_info_int = (list(map(int, info)) for info in given_info_str)
houses = [[[0 for i in range(R)] for j in range(F)] for k in range(B)]
for info in given_info_int:
houses[info[0] - 1][info[1] - 1][info[2] - 1] += info[3]
for num, building in enumerate(houses):
for floor in building:
print (" " + " ".join(map(str, floor)))
if num < (B - 1):
print("#" * 20)
if __name__ == "__main__":
main() | from collections import deque
n, q = [int(_) for _ in input().split()]
processes = deque([tuple(input().split()) for i in range(n)])
time = 0
while processes:
process = processes.popleft()
if int(process[1]) <= q:
time += int(process[1])
print(process[0], time)
else:
time += q
processes.append((process[0], int(process[1]) - q))
| 0 | null | 559,279,761,428 | 55 | 19 |
d,t,s=map(int,input().split())
print("Yes" if t>=d/s else "No") | A, B = map(int, input().split())
print(max([0, A-2*B])) | 0 | null | 85,344,504,035,372 | 81 | 291 |
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
minus_a_ct = Counter([-a-i for i,a in enumerate(a_ls)])
a_ct = Counter([a-i for i,a in enumerate(a_ls)])
_sum = 0
for k, v in a_ct.items():
_sum += v * minus_a_ct[k]
print(_sum) | def isPrime( x ):
if 2 == x or 3 == x:
return True
if 0 == x%2:
return False
i = 3
while i*i <= x:
if 0 == x%i:
return False
i += 1
return True
n = int( raw_input( ) )
nums = []
i = 0
while i < n:
nums.append( int( raw_input( ) ) )
i += 1
cnt = i = 0
for num in nums:
if isPrime( num ):
cnt += 1
i += 1
print( cnt ) | 0 | null | 12,919,056,358,052 | 157 | 12 |
def main():
n = int(input())
ans = 0
for k in range(1,n+1):
ans += k * (n//k) * (n//k+1) //2
print(ans)
if __name__ == "__main__":
main()
| import sys
x,y = map(int,input().split())
for n in range(x+1):
kame = x - n
tsuru_leg = n*2
kame_leg = kame*4
if y == tsuru_leg + kame_leg:
print('Yes')
sys.exit()
print('No') | 0 | null | 12,323,189,101,582 | 118 | 127 |
def solve():
N, M = map(int, input().split())
return N - M*2 if N //2 >= M else 0
print(solve())
| n=int(input())
minv=int(input())
maxv=-float('inf')
for _ in range(n-1):
tmp=int(input())
maxv=max(maxv,tmp-minv)
minv=min(minv,tmp)
print(maxv)
| 0 | null | 83,110,636,133,296 | 291 | 13 |
H, N = map(int, input().split())
A = map(int, input().split())
print('Yes' if H <= sum(A) else 'No') | N = int(input())
total = 0
for num in range(1, N+1):
if num % 15 == 0:
continue
if num % 3 == 0 or num % 5 == 0:
continue
total += num
print(total) | 0 | null | 56,495,926,537,280 | 226 | 173 |
N = int(input())
p = [[None] for i in range(N)]
for i in range(N):
p[i] = list(map(int, input().split()))
p.sort()
#print(p)
INFINITE = 5 * 10**9
maxUp = {}
minDown = {}
for i in range(1, N):
maxUp[i] = max(maxUp.get(i-1, -INFINITE), p[i-1][1] - p[i-1][0])
for i in range(1, N):
minDown[i] = min(minDown.get(i-1, INFINITE), p[i-1][0] + p[i-1][1])
#print(maxUp)
#print(minDown)
ans = -INFINITE
for i in range(1, N):
ans = max(ans,
p[i][0] - p[i][1] + maxUp.get(i, -INFINITE)
)
ans = max(ans,
p[i][0] + p[i][1] - minDown.get(i, INFINITE)
)
print(ans) | n = int(input())
x = [None]*n
y = [None]*n
for i in range(n):
x[i],y[i] = map(int,input().split())
#y=x+k1 <=> x-y=-k1
k1 = [0]*n
#y=-x+k2 <=> x+y=k2
k2 = [0]*n
for i in range(n):
k1[i] = -(x[i]-y[i])
k2[i] = x[i]+y[i]
print(max(max(k1)-min(k1),max(k2)-min(k2))) | 1 | 3,447,415,853,420 | null | 80 | 80 |
def fibonacci(n):
if n == 0 or n == 1:
F[n] = 1
return F[n]
if F[n] is not None:
return F[n]
F[n] = fibonacci(n - 1) + fibonacci(n - 2)
return F[n]
n = int(input())
F = [None]*(n + 1)
print(fibonacci(n)) | N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
ans = 1
dp = [0]*3
for a in A:
cnt = 0
for i in range(3):
if a == dp[i]:
cnt += 1
for i in range(3):
if a == dp[i]:
dp[i] += 1
break
ans = ans*cnt % MOD
print(ans)
| 0 | null | 65,130,632,852,208 | 7 | 268 |
a,b,x=map(int,input().split())
import math
v=a*a*b
if x>=v/2:
print(180*math.atan(2*(v-x)/(a*a*a))/math.pi)
else:
print(90-(180*math.atan(2*x/(a*b*b)))/math.pi) | import sys
from operator import itemgetter
import math
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()
def main():
a, b, x = mi()
V = a**2 * b
if V // 2 < x:
X = 2*x / a**2 - b
Y = b - X
ans = math.degrees(math.asin(Y/math.sqrt(a**2 + Y**2)))
else:
X = 2*x / (a*b)
ans = math.degrees(math.asin(b/math.sqrt(X**2 + b**2)))
print(ans)
return
main()
| 1 | 163,566,647,279,722 | null | 289 | 289 |
from collections import deque
N=int(input())
color=["w"]*(N+1)
start=[None]*(N+1)
finish=[0]*(N+1)
rinsetu=[[] for i in range(N+1)]
for i in range(1,N+1):
a=list(map(int,input().split()))
a=a[2:]
rinsetu[i]=a
def dfs(i,t):
if color[i]=="w":
t+=1
start[i]=t
color[i]="g"
for j in rinsetu[i]:
t=dfs(j,t)
t+=1
finish[i]=t
return t
else:return t
t=dfs(1,0)
while(None in start[1:]):
a=start[1:].index(None)
t=dfs(a+1,t)
for i in range(1,N+1):
print("%d %d %d" %(i,start[i],finish[i]))
| n = input()
cube = n ** 3
print cube | 0 | null | 144,001,820,440 | 8 | 35 |
S = input()
T = input()
S = list(S)
T = list(T)
result = len(T)
x = 0
for i in range(len(S)-len(T)+1):
for j in range(len(T)):
if S[i+j] != T[j]:
x += 1
if result > x:
result = x
x = 0
print(result)
| S, T = [input() for i in range(2)]
ans = float("inf")
for start in range(len(S) - len(T) + 1):
diff = 0
for t, s in zip(T, S[start:]):
if t != s:
diff += 1
ans = min(ans, diff)
print(ans)
| 1 | 3,732,670,112,832 | null | 82 | 82 |
import math
def solve():
N = int(input())
ans = 0
for i in range(2, int(math.sqrt(N)) + 2):
n = 1
cnt = 0
while N % i == 0:
N //= i
cnt += 1
if cnt == n:
cnt = 0
n += 1
ans += 1
if N != 1:
ans += 1
return ans
print(solve())
| #! /usr/bin/env python3
noOfInputs = int(input())
for i in range(noOfInputs):
numsInStr = input().split()
nums = []
for n in numsInStr:
nums.append(int(n))
largest = max(nums)
nums.remove(max(nums))
#print(nums)
if (largest**2 == sum([i**2 for i in nums])):
print('YES')
else:
print('NO') | 0 | null | 8,484,797,586,042 | 136 | 4 |
input()
print(" ".join(reversed(input().split())))
| suit = {"S": 0, "H": 1, "C": 2, "D": 3}
suit_keys = list(suit.keys())
deck = [[suit_keys[i] + " " + str(j + 1) for j in range(13)] for i in range(4)]
for _ in range(int(input())):
card = input().split()
deck[suit[card[0]]][int(card[1]) - 1] = ""
for i in range(4):
for j in range(13):
if deck[i][j] != "":
print(deck[i][j])
| 0 | null | 1,007,035,563,660 | 53 | 54 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]
n = int(input())
s = [input() for _ in range(n)]
h = {}
for i in range(n):
if (s[i] in h):
h[s[i]] += 1
else:
h[s[i]] = 1
ans = []
highScore = max(h.values())
for k,v in h.items():
if v== highScore:
ans.append(k)
ans.sort()
for i in range(len(ans)):
print(ans[i])
| K = int(input())
A, B = map(int, input().split())
i = A
while (i % K != 0) and (i <= B):
i += 1
if i == B+1:
print("NG")
else:
print("OK") | 0 | null | 48,385,597,405,468 | 218 | 158 |
n,m,k = map(int,input().split())
if n >= k:
print(n-k,m)
else:
if m - (k-n) < 0:
m = 0
else:
m -= k - n
print(0,m) | #! python3
# toggling_cases.py
x = input()
rst = ''
for c in x:
if c.isupper():
rst += c.lower()
elif c.islower():
rst += c.upper()
else:
rst += c
print(rst)
| 0 | null | 53,022,761,894,480 | 249 | 61 |
# coding: utf-8
N,S=map(int,input().split())
A=list(map(int,input().split()))
MOD=998244353
dp=[[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
a=A[i-1]
for j in range(0,S+1):
dp[i][j]+=dp[i-1][j]*2
if j-a>=0:
dp[i][j]+=dp[i-1][j-a]
dp[i][j]=dp[i][j]%MOD
print(dp[N][S]) | import sys
sys.setrecursionlimit(10000000)
MOD = 998244353
INF = 10 ** 15
def main():
N,S = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0]*(1 + S) for _ in range(N + 1)]
dp[0][0] = pow(2,N,MOD)
inv2 = pow(2,MOD - 2,MOD)
for i,a in enumerate(A):
for j in range(S + 1):
if j < a:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = (dp[i][j] + dp[i][j - a] * inv2)%MOD
print(dp[N][S])
if __name__ == '__main__':
main() | 1 | 17,754,931,185,600 | null | 138 | 138 |
x=int(input())
for i in range(-118,120):
for j in range(-118,120) :
if i**5-j**5==x :
print(i,j)
exit()
else :
continue | x=int(input())
a=0
while True:
for b in range(10**3):
if a**5-b**5==x:
print(a,b)
exit()
elif a**5+b**5==x:
print(a,-b)
exit()
elif -a**5+b**5==x:
print(-a,-b)
exit()
a+=1 | 1 | 25,660,322,652,612 | null | 156 | 156 |
import fractions
A,B = (int(a) for a in input().split())
print(A * B // fractions.gcd(A,B)) | # 高橋君の夏休みが N 日間
# 夏休みの宿題が M個出されており、i 番目の宿題をやるには A i日間かかる
# 条件 複数の宿題を同じ日にはできない。
# また宿題をやる日は遊べない。
# 夏休み中に全ての宿題を終わらせるとき、最大何日遊ぶことができるか。
# 終わらない時は-1
N, M = map(int, input().split())
A = list(map(int, input().split()))
# 宿題にかかる合計日数
play_day = N - sum(A)
if play_day < 0:
print("-1")
else:
print(play_day) | 0 | null | 72,320,371,309,600 | 256 | 168 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.