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
|
---|---|---|---|---|---|---|
from itertools import product
n = int(input())
data = {}
for p in range(1, n+1):
a = int(input())
# 人p=1~の証言
data[p] = [list(map(int, input().split())) for _ in range(a)]
# パターン生成
ans = 0
for honest in product(range(2), repeat=n):
for p,hk in enumerate(honest, 1):
if hk == 1:
# 証言の矛盾をチェック
if not all([honest[x-1] == y for x,y in data[p]]):
break
else:
ans = max(ans, sum(honest))
print(ans) | N = int(input())
table = []
for i in range(N):
A = int(input())
dic = {}
for j in range(A):
x,y = map(int, input().split())
dic[x-1] = y
table.append(dic)
res = 0
for i in range(2**N):
bi = [j for j in range(N) if (i >> j &1)]
dic = {}
for b in bi:
dic[b] = 1
endfor = False
for b1 in bi:
if endfor:
break
said = table[b1]
for k in said.keys():
if k not in dic.keys():
if said[k]:
endfor = True
break
dic[k] = said[k]
elif dic[k] == said[k]:
continue
else:
endfor = True
break
if not endfor:
res = max(res, len(bi))
print(res) | 1 | 121,842,418,258,080 | null | 262 | 262 |
# coding: utf-8
N = list(map(int,list(input())))
sN = sum(N)
if sN%9 ==0:
print("Yes")
else:
print("No")
| n = int(input())
print("Yes" if n % 9 == 0 else "No") | 1 | 4,422,473,232,968 | null | 87 | 87 |
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
N = int(input())
A = list(map(int,input().split()))
ans = 0
lcm = lcm_list(A)
for i in range(N):
ans += lcm//A[i]
print(ans%1000000007) | import math
def main():
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split(' ')))
# 答えは sum(lcm(A) / A)
L = 1
for a in A:
L = L * a // math.gcd(L, a)
ans = 0
for a in A:
ans += L * pow(a, MOD - 2, MOD)
ans %= MOD
print(ans)
if __name__ == '__main__':
main() | 1 | 87,884,420,436,032 | null | 235 | 235 |
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() | from functools import reduce
n, *s = open(0).read().split()
u = []
for t in s:
close_cnt = 0
tmp = 0
for c in t:
tmp += (1 if c == '(' else -1)
close_cnt = min(close_cnt, tmp)
u.append((close_cnt, tmp - close_cnt))
M = 10**6 + 1
acc = 0
for a, b in sorted(u, key=lambda z: (- M - z[0] if sum(z)>= 0 else M - z[1])):
if acc + a < 0:
print("No")
exit(0)
else:
acc += a + b
print(("No" if acc else "Yes")) | 1 | 23,659,509,490,112 | null | 152 | 152 |
def main():
data_count = int(input())
data = [list(map(int, input().split())) for i in range(data_count)]
for item in data:
item.sort()
print('YES') if item[0]**2 + item[1]**2 == item[2]**2 else print('NO')
main() | from collections import deque
N = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = A[0]
q = deque((A[1], A[1]))
for i in range(2, N):
ans += q.popleft()
q.append(A[i])
q.append(A[i])
print(ans) | 0 | null | 4,597,610,146,348 | 4 | 111 |
k = int(input())
num = 7 % k
ans = 1
mod = [0 for _ in range(k)]
mod[num] = 1
while(num):
num = (num * 10 + 7) % k
if mod[num] > 0:
ans = -1
break
ans += 1
mod[num] += 1
print(ans)
| n = int(input())
a = 10000
ans = (a - n) % 1000
print(ans) | 0 | null | 7,367,723,070,400 | 97 | 108 |
n = int(input())
a = list(map(int, input().split()))
b = a[0]
for v in a[1:]:
b ^= v
print(*map(lambda x: x ^ b, a))
| n=int(input())
a=list(map(int,input().split()))
xor=0
for i in a:
xor ^= i
pop=0 #xorのpopにする
while(xor >> pop >=1):
pop += 1
sum_xor=xor #各猫の排他的論理和
ans=[]
for i in a:
x=i^sum_xor
ans.append(x)
print(" ".join(map(str, ans))) | 1 | 12,452,923,891,282 | null | 123 | 123 |
N=int(input())
c=-(-N//2)-1
print(c) | #!/usr/bin/env python3
n = int(input())
print(int((n - 1) / 2) if n % 2 == 1 else int(n / 2) - 1)
| 1 | 153,087,769,343,550 | null | 283 | 283 |
X = input().split()
print(X.index("0") + 1)
| X = list(map(int, input().split()))
for i, x in enumerate(X):
if x == 0:
print(i+1)
exit() | 1 | 13,474,771,423,652 | null | 126 | 126 |
i = 0
while True:
x = int(input()); i += 1
if x == 0:
break
print("Case {}: {}".format(i, x))
| i=1
while 1:
j=int(input())
if j==0:
break
print("Case",str(i)+":",j)
i+=1 | 1 | 488,522,453,670 | null | 42 | 42 |
n,k = map(int,input().split())
sunuke = []
for _ in range(k):
d = input()
tmp = [int(s) for s in input().split()]
for i in range(len(tmp)):
sunuke.append(tmp[i])
print(n - len(set(sunuke))) | import math
a,b,x = list(map(int,input().split()))
theta = math.degrees(math.atan(a*b*b/2/x))
if(b/math.tan(math.radians(theta)) > a):
theta = math.degrees(math.atan((2*a*a*b-2*x)/a/a/a))
print('{:.7f}'.format(theta))
| 0 | null | 93,562,069,619,046 | 154 | 289 |
import sys
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
dp = [0]*(t+1)
AB = [list(map(int,readline().split())) for i in range(n)]
AB.sort(reverse=True)
for i in range(n):
a,b = AB[i]
for j in range(t):
if j+a > t:
dp[j] = max(dp[j],b)
else:
dp[j] = max(dp[j],dp[j+a]+b)
print(dp[0]) | H=int(input())
def n_attack(h):
if h==1:return(1)
else:return 1+2*n_attack(h//2)
print(n_attack(H)) | 0 | null | 116,040,974,143,388 | 282 | 228 |
MOD = 998244353
N, K = map(int, input().split())
rl = [list(map(int, input().split())) for _ in range(K)]
dp = [0] * (N + 1)
dp[1] = 1
dp[2] = -1
for i in range(1, N + 1):
dp[i] += dp[i - 1]
for j in range(K):
l, r = rl[j][0], rl[j][1]
if i + l <= N:
dp[i + l] += dp[i]
dp[i + l] %= MOD
if i + r + 1 <= N:
dp[i + r + 1] -= dp[i]
dp[i + r + 1] %= MOD
print(dp[N] % MOD) | N, K = map(int, input().split())
L = [0] * K
R = [0] * K
for i in range(0, K):
L[i], R[i] = map(int, input().split())
moves = [0] * N
moves[0] = 1
rui_wa = [0] * N
rui_wa[0] = 1
for i in range(1, N):
for j in range(0, K):
l = max(i - L[j], 0)
r = max(i - R[j], 0)
if i - L[j] < 0:
continue
moves[i] += (rui_wa[l] - rui_wa[r - 1]) % 998244353
rui_wa[i] = (moves[i] + rui_wa[i - 1]) % 998244353
print(moves[N - 1] % 998244353)
| 1 | 2,703,606,379,748 | null | 74 | 74 |
n=int(input())
l=list(map(int,input().split()))
sum_l=sum(l)
ans=0
mod=10**9+7
for i in range(n):
sum_l-=l[i]
ans+=l[i]*sum_l
print(ans%mod) | while True:
x,y = map(int, input().split())
if x == 0 and y == 0 :
break
elif x <= y :
print (x,y)
else :
print (y,x) | 0 | null | 2,153,947,666,090 | 83 | 43 |
N = int(input())
S = input()
n = int(N/2)
print('Yes' if N > 1 and S[:n] == S[n:] else 'No') | n = input()
d = {"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}
print(d[n]) | 0 | null | 139,846,175,945,382 | 279 | 270 |
n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18
if n % 2:
dp = [[[-INF,-INF,-INF] for i in range(2)] for i in range(n+1)]
dp[0][0][0] = 0
# 初期化条件考える
for i,v in enumerate(a):
for j in range(2):
if j:
dp[i+1][0][0] = max(dp[i+1][0][0],dp[i][1][0])
dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][1][1])
dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][1][2])
else:
dp[i+1][1][0] = max(dp[i+1][1][0],dp[i][0][0] + v)
dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][0][0])
dp[i+1][1][1] = max(dp[i+1][1][1],dp[i][0][1] + v)
dp[i+1][0][2] = max(dp[i+1][0][2],dp[i][0][1])
dp[i+1][1][2] = max(dp[i+1][1][2],dp[i][0][2] + v)
print(max(max(dp[n][0]),max(dp[n][1][1:])))
else:
odd_sum,even_sum = 0,0
cumsum = []
for k,v in enumerate(a):
if k % 2:
odd_sum += v
cumsum.append(odd_sum)
else:
even_sum += v
cumsum.append(even_sum)
ans = max(cumsum[n-2],cumsum[n-1])
for i in range(2,n,2):
ans = max(ans, cumsum[i-2]+cumsum[n-1]-cumsum[i-1])
print(ans) | import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import defaultdict
N, *A = map(int, read().split())
INF = 10**18
dp_not = defaultdict(lambda : -INF)
dp_take = defaultdict(lambda: -INF)
dp_not[(0,0)] = 0
for i,x in enumerate(A,1):
j = (i-1)//2
for n in (j,j+1):
dp_not[(i,n)] = max(dp_not[(i-1,n)], dp_take[(i-1,n)])
dp_take[(i,n)] = dp_not[(i-1,n-1)] + x
print(max(dp_not[(N, N//2)], dp_take[(N, N//2)])) | 1 | 37,464,191,265,452 | null | 177 | 177 |
from operator import itemgetter
n = int(input())
lis = []
for _ in range(n):
x,l = map(int,input().split())
lis.append([x-l,x+l])
lis.sort(key = itemgetter(1))
ans = 0
last = -float("inf")
for i in range(n):
if lis[i][0] >= last:
ans += 1
last = lis[i][1]
print(ans) | def gcds(*numbers):
from math import gcd
from functools import reduce
return reduce(gcd, numbers)
def resolve():
K = int(input())
ans = 0
import itertools
for i, j, k in itertools.combinations_with_replacement(range(1, K+1), 3):
l = len(set([i, j, k]))
mu = 1
if l == 3:
mu = 6
elif l == 2:
mu = 3
ans += gcds(i, j, k) * mu
print(ans)
if '__main__' == __name__:
resolve() | 0 | null | 62,826,476,814,516 | 237 | 174 |
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
import subprocess
import sys
if sys.argv[-1] == "ONLINE_JUDGE":
import zlib, base64
exe_bin = "c%1E9eRLDol^=Z=8w`>lCNW<@p(ceSR;(bvB4)8{3C2V?Ua*OiKqg`&V>Plwq!HNJmT)jm859v8&Th-eZduap>85mhmQA;Na_H`2aDa5TJta*~!ZvBvrwy$XH^E&Jz5;0Pee<3?GuAZeZvW)@*!SJvyZ65P?!5PA=FRo9f#7Ph$;7c@;r@(6Zp5MRjTEnU6-5B6=O)A7JGpt>B;c(oIX%5%($b1zKZ;(xncCOUxtx}oRJ4pUE+aFwl;fO5J@mD1o`TlRb82Xg_S;sb)iYB)p6c;bo>2$YW0Z~0N`KoauBU!ZORbc)otMH`AG%H9^)$$7DbxFN(3`}4{z5M=x1RQA6qmEqUq;z=xIY%%vdnXTEL<Cl#?!sEz4gm#mw8;NgzEv~lY`2xY3(5Lc)iUkpQ|W_?QdS#zhiXmUdzC|j?srczAMmo?_YhzOl8=0!w8!|vx?fNIykjC^|f+laze?#?~D@oca3o9Xh8|Q!$5w}R2n~IfPc%tPMv}Lvj+ID4D2j3kpGE+{F4Uwe2&e0ZRs+wf6M@P7}$Bx08bhC(+c*dbF;Wcr=sPc6Yxu%f<Jkef>*PN3G*@~g~faC#kshQ6NIfjiMWuGLP<#wIH9F|oe+*BBU_^>DUxho*Bnd4BkiFrv53-Ey5+If4bfyOus%wviC8LtwGGk|F&Zb3R3A;Gge{>|#M2UwN`7}>I}va%7X+z0nb-ksVIdTYB}8lp$J(~*^xR8ReQ{CP5tX{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)
subprocess.run(["./kyomu"], shell=True) | class UnionFind():
def __init__(self, N):
# parent of each node
self.parent = [n for n in range(N)]
# number of nodes in union
self.rank = [1] * N
def find(self, u):
if self.parent[u] == u:
return u
else:
# recursive call
return self.find(self.parent[u])
def union(self, u, v):
pu = self.find(u)
pv = self.find(v)
# same union
if pu == pv:
return
# let pv join into pu union
if self.rank[pu] < self.rank[pv]:
pu, pv = pv, pu
self.rank[pu] += self.rank[pv]
self.parent[pv] = pu
N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
A, B = map(int, input().split())
A, B = A-1, B-1
UF.union(A, B)
ret = 0
for n in range(N):
ret = max(ret, UF.rank[n])
print(ret)
| 1 | 4,005,994,318,948 | null | 84 | 84 |
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = []
Y = []
C = []
for _ in range(M):
x,y,c = map(int,input().split())
X.append(x)
Y.append(y)
C.append(c)
ans = min(a) + min(b)
for i in range(M):
ans = min(ans,a[X[i]-1] + b[Y[i] - 1] - C[i])
print(ans)
| A, B, m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minp = min(a) + min(b)
for i in range(m):
x, y, c = map(int,input().split())
minp = min(minp, a[x-1] + b[y-1] -c)
print(minp) | 1 | 54,056,946,831,732 | null | 200 | 200 |
mod = 10**9+7
s = int(input())
dp = [0]*2500
dp[0] = 1
for i in range(1, s+1):
for j in range(0, i-2):
dp[i]+=dp[j]
dp[i]%=mod
print(dp[s]) | S = int(input())
if S == 1 or S == 2:
print(0)
elif S == 3:
print(1)
else:
mod = 10 ** 9 + 7
dp = [0 for _ in range(S)]
dp[0] = dp[1] = 0
dp[2] = dp[3] = 1
for i in range(3, S):
dp[i] = (dp[i - 3] + dp[i - 1]) % mod
print(dp[-1]) | 1 | 3,334,351,244,670 | null | 79 | 79 |
l=map(str,raw_input().split())
chk=[]
op='-+*'
while len(l):
k=l.pop(0)
if k in op:
b=chk.pop()
a=chk.pop()
chk.append(str(eval(a+k+b)))
else:
chk.append(k)
print chk[0] |
def revPoland(expr):
stack = []
for l in expr:
if l.isdigit():
stack.append(int(l))
# print(stack)
else:
a = stack.pop()
b = stack.pop()
c = eval(str(b) + l + str(a))
stack.append(c)
# print(stack)
return stack.pop()
expr = input().split()
print(revPoland(expr)) | 1 | 36,617,046,648 | null | 18 | 18 |
N = int(input())
A = list(map(int, list(input().split())))
total = 0
for i in range(1, N):
step = A[i-1] - A[i]
if step > 0 :
total = total + step
A[i] = A[i] + step
print(total) | N = int(input())
As = list(map(int,input().split()))
max = 0
sum = 0
for i in range(N):
if max < As[i]:
max = As[i]
else:
sum += (max-As[i])
print(sum)
| 1 | 4,542,251,591,628 | null | 88 | 88 |
from itertools import permutations as p
from math import factorial as f
from math import sqrt as s
def func(x1, x2, y1, y2): return s((x2-x1) ** 2 + (y2-y1) ** 2)
N = int(input())
xy = list(list(map(int,input().split())) for _ in range(N))
total = 0
for l in p(range(1, N+1)):
for i in range(N-1):
total += func(xy[l[i]-1][0], xy[l[i+1]-1][0], xy[l[i]-1][1], xy[l[i+1]-1][1])
print(total / f(N)) | # 町a,b(a < b)の距離をあらかじめdictionaryで保存しておく
# そのうえで、全探索可能
import sys
readline = sys.stdin.readline
N = int(readline())
town = [None] * N
for i in range(N):
town[i] = tuple(map(int,readline().split()))
from collections import defaultdict
dist = defaultdict(float)
for i in range(N - 1):
for j in range(i + 1, N):
ix,iy = town[i]
jx,jy = town[j]
dist[(i,j)] = ((ix - jx) ** 2 + (iy - jy) ** 2) ** 0.5
# 距離を求めたので、あとは全パターン検索
ans = 0
import itertools
for perm in itertools.permutations(range(N)):
d = 0
for i in range(1, len(perm)):
a,b = perm[i - 1],perm[i]
if a > b:
a,b = b,a
d += dist[(a, b)]
ans += d
pat = 1
for i in range(2, N + 1):
pat *= i
print(ans / pat) | 1 | 148,287,681,702,762 | null | 280 | 280 |
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)]
print(*S,sep="")
"""
import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限
n = int(input())
s,t = input().split()
ans=""
for _ in range(n):
ans+=s[_]+t[_]
print(ans) | n = int(input())
s, t = input().split()
combination_of_letters = ''
for i in range(n):
combination_of_letters += s[i] + t[i]
print(combination_of_letters) | 1 | 111,867,267,438,094 | null | 255 | 255 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
import math
x=0
y=10**9
z=5*(10**8)
s=0
for i in range(100):
t=0
for j in range(n):
t+=a[j]//z
if t<=k:
s=t
y=z
z=(x+y)/2
else:
x=z
z=(x+y)/2
print(math.ceil(z))
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# def
def int_mtx(N):
x = []
for _ in range(N):
x.append(list(map(int,input().split())))
return np.array(x)
def str_mtx(N):
x = []
for _ in range(N):
x.append(list(input()))
return np.array(x)
def int_map():
return map(int,input().split())
def int_list():
return list(map(int,input().split()))
def print_space(l):
return print(" ".join([str(x) for x in l]))
# import
import numpy as np
import collections as col
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
# main
N,M =int_map()
AB = int_mtx(M)
n, _ = connected_components(csr_matrix(([1]*M, (AB[:,0]-1, AB[:,1]-1)),(N,N)))
print(n-1) | 0 | null | 4,388,462,028,018 | 99 | 70 |
import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
N, M = MI()
if N == M:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | def solve(i, m):
if dp[i][m] != -1:
return dp[i][m]
if m == 0:
dp[i][m] = 1
elif i >= n:
dp[i][m] = 0
elif solve(i+1, m):
dp[i][m] = 1
elif solve(i+1, m-A[i]):
dp[i][m] = 1
else:
dp[i][m] = 0
return dp[i][m]
n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())
dp = [[-1 for col in range(2000)] for row in range(n+1)]
for i in range(p):
if solve(0, m[i]):
print 'yes'
else:
print 'no' | 0 | null | 41,635,671,177,452 | 231 | 25 |
#a(n) = 2^ceiling(log_2(n+1))-1
import math
print(2**(math.ceil(math.log2(int(input())+1)))-1) | import math
H = int(input())
ans = 0
num = 0
while True:
ans += 2**num
if H == 1:
print(ans)
break
else:
H = math.floor(H/2)
num += 1 | 1 | 79,859,605,230,932 | null | 228 | 228 |
cnt = 0
n = int(input())
a = list(map(int,input().split()))
for i in range(0,n):
mini = i
for j in range(i,n):
if a[j]<a[mini]:
mini = j
a[i],a[mini] = a[mini],a[i]
if i!=mini:
cnt += 1
print(" ".join(map(str,a)))
print(cnt) | def SelectionSort(A, n):
sw = 0
for i in xrange(n):
minj = i
for j in xrange(i, n):
if A[j] < A[minj]:
minj = j
temp = A[minj]
A[minj] = A[i]
A[i] = temp
if i != minj:
sw += 1
return sw
def printArray(A, n):
for i in xrange(n):
if i < n-1:
print A[i],
else:
print A[i]
n = input()
arr = map(int, raw_input().split())
cnt = SelectionSort(arr, n)
printArray(arr, n)
print cnt | 1 | 19,399,710,760 | null | 15 | 15 |
def main():
n = int(input())
ans = 0
for a in range(1, n):
for b in range(1, n):
c = n - a * b
if c <= 0:
break
ans += 1
return ans
if __name__ == '__main__':
print(main())
| # Aizu Problem ITP_1_2_A: Small, Large or Equal
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
a, b = [int(_) for _ in input().split()]
if a < b:
print("a < b")
elif a > b:
print("a > b")
else:
print("a == b") | 0 | null | 1,471,721,842,118 | 73 | 38 |
A=list(map(int,input().split()))
if A[0]+A[1]+A[2]<=21:
print("win")
else:
print("bust") | A1,A2,A3=map(int,input().split())
if A1+A2+A3>=22:
print('bust')
else:
print('win') | 1 | 119,186,487,514,080 | null | 260 | 260 |
class Dice:
dice = {'N':2, 'E':4, 'S':5, 'W':3}
currTop = 1
def top(self):
return self.currTop
def rot(self, direction):
newTop = self.dice[direction]
currTop = self.currTop
self.currTop = newTop
if direction == 'N':
self.dice['N'] = 7 - currTop
self.dice['S'] = currTop
elif direction == 'S':
self.dice['N'] = currTop
self.dice['S'] = 7 - currTop
elif direction == 'E':
self.dice['E'] = 7 - currTop
self.dice['W'] = currTop
elif direction == 'W':
self.dice['E'] = currTop
self.dice['W'] = 7 - currTop
faces = list(map(int, input().split()))
cmd = input()
d = Dice()
for c in cmd:
d.rot(c)
print(faces[d.top()-1]) | import sys
input = sys.stdin.readline
N,M=map(int,input().split());S=input()[:-1]
if S.find("1"*M)>0:
print(-1)
exit()
k=[N+1]*(N+1)
k[0]=N
c=1
for i in range(N-1,-1,-1):
if int(S[i])==0:
if k[c-1]-i <= M:
k[c]=i
else:
c+=1
k[c]=i
print(*[j-i for i,j in zip(k[c::-1],k[c-1::-1])]) | 0 | null | 69,630,870,325,280 | 33 | 274 |
l=map(int,raw_input().split())
a=l[0]
b=l[1]
c=l[2]
if a>b:
a,b=b,a
if b>c:
b,c=c,b
if a>b:
a,b=b,a
print a,b,c | from math import gcd
K = int(input())
ans = 0
r = range(1, K+1)
for i in r:
for j in r:
for k in r:
ans += gcd(gcd(i, j), k)
print(ans)
| 0 | null | 18,066,902,766,084 | 40 | 174 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def calc(p, P):
ans = 0
for i in range(1, len(p)):
x1, y1 = P[p[i - 1]]
x2, y2 = P[p[i]]
ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
return ans
def solve():
N = int(input())
P = []
for _ in range(N):
X, Y = map(int, input().split())
P.append((X, Y))
ans = 0
num = 0
for p in permutations(range(N)):
ans += calc(p, P)
num += 1
print(ans / num)
def main():
solve()
if __name__ == '__main__':
main()
| from itertools import permutations
n = int(input())
x = []
y = []
ans,count,tempx,tempy = 0,0,0,0
for _ in range(n):
a,b = map(int,input().split())
x.append(a)
y.append(b)
order = list(permutations(range(n)))
for i in order:
for j in i:
if j == i[0]:
tempx = x[j]
tempy = y[j]
continue
count += (((x[j]-tempx)**2)+((y[j]-tempy)**2)) ** (0.5)
tempx = x[j]
tempy = y[j]
ans += count / len(order)
count = 0
print(ans) | 1 | 148,223,634,762,360 | null | 280 | 280 |
S=input()
print(S.replace('?','D')) | MOD = 10**9+7
def solve(n):
"""
0: {}
1: {0}
2: {9}
3: {0,9}
"""
dp = [[0]*4 for i in range(n+1)]
dp[0][0] = 1
x = [1,0,0,0]
for i in range(n):
x = [
(8*x[0]) % MOD,
(9*x[1] + x[0]) % MOD,
(9*x[2] + x[0]) % MOD,
(10*x[3] + x[2] + x[1]) % MOD
]
return x[3]
n = int(input())
print(solve(n)) | 0 | null | 10,800,171,065,372 | 140 | 78 |
# D - Prediction and Restriction
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()
# じゃんけんの勝敗を返す関数
def judge(a,b):
if a == 'r' and b == 2:
return True
elif a == 's' and b == 0:
return True
elif a == 'p' and b == 1:
return True
return False
# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]
# v 回目のじゃんけん
for v in range(1,N+1):
# v 回目に出した手
for w in range(3):
# v-K 回目に出した手
for k in range(3):
if w == k:
continue
# じゃんけんで勝ったとき
if judge(T[v-1],w):
dp[v][w] = max(dp[v][w],dp[v-K][k] + RSP[w])
# じゃんけんで負けか引き分けたとき
else:
dp[v][w] = max(dp[v][w],dp[v-K][k])
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
ans += max(dp[-a])
print(ans) | n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
hand=["" for _ in range(k)]
point=[0 for _ in range(k)]
for i in range(n):
index=i%k
#初めの手(制限なし)
if index==i:
if t[i]=="r":
hand[index]="p"
point[index]+=p
elif t[i]=="s":
hand[index]="r"
point[index]+=r
else:
hand[index]="s"
point[index]+=s
#2番目以降の手
else:
if t[i]=="r":
if hand[index]=="p":
hand[index]="x"
else:
hand[index]="p"
point[index]+=p
elif t[i]=="s":
if hand[index]=="r":
hand[index]="x"
else:
hand[index]="r"
point[index]+=r
else:
if hand[index]=="s":
hand[index]="x"
else:
hand[index]="s"
point[index]+=s
print(sum(point)) | 1 | 106,607,783,312,590 | null | 251 | 251 |
import numpy as np
mod = 998244353
n, s = map(int, input().split())
dp = np.zeros((n+1, s+1), dtype=int)
dp[0, 0] = 1
for i, a in enumerate(map(int, input().split())):
dp[i+1] = dp[i] * 2 % mod
dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod
print(dp[-1, -1]) | x = int(input())
r = 0
divider = ((500,1000), (5, 5))
for i in divider:
x, remain = divmod(x, i[0])
r += x * i[1]
x = remain
print(r) | 0 | null | 30,114,413,800,864 | 138 | 185 |
#d
n=int(input())
x=input()
def popcount(m):
return bin(m).count("1")
intx = int( "0b"+x ,0 )
popcount0 = x.count("1")
intx_mod_pp1 = intx %(popcount0+1)
if popcount0!=1:
intx_mod_pm1 = intx %(popcount0-1)
jisho = ["yet"]*n
for i in range(n):
if x[i]=="1" and popcount0==1:
print(0)
continue
pow2ip = pow(2,n-i-1,popcount0+1)
if popcount0!=1: pow2im = pow(2,n-i-1,popcount0-1)
intxi=1
c=0
while intxi!=0:
if c==0:
if x[i]=="0":
pop = popcount0+1
intxi = (intx_mod_pp1 + pow2ip%pop )%pop
else:
pop = popcount0-1
intxi = (intx_mod_pm1 - pow2im%pop )%pop
else:
if jisho[intxi]=="yet":
togo = intxi%popcount(intxi)
jisho[intxi]= togo
intxi = togo
else:
intxi =jisho[intxi]
c+=1
print(c) | import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
x = input()
p = [-1 for _ in range(2*(10**5)+1)]
cnt = x.count('1')
def calc(a):
#print('a=',a)
if p[a] != -1:
return p[a]
else:
if a == 0:
ret = 0
else:
b = bin(a).count('1')
ret = 1+calc(a%b)
p[a] = ret
return ret
if cnt > 1:
x0 = int(x,2)%(cnt-1)
xx0 = [1]
for i in range(n):
xx0.append((xx0[-1]*2)%(cnt-1))
x1 = int(x,2)%(cnt+1)
xx1 = [1]
for i in range(n):
xx1.append((xx1[-1]*2)%(cnt+1))
y = list(x)
for i in range(n):
if y[i] == '0':
xx = xx1[n-i-1]
print(calc((x1+xx)%(cnt+1))+1)
else:
if cnt == 1:
print(0)
else:
xx = xx0[n-i-1]
print(calc((x0-xx)%(cnt-1))+1) | 1 | 8,141,416,599,862 | null | 107 | 107 |
N = int(input())
if N%2:
N += 1
print(N//2-1) | # -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def main():
N = inputInt()
ans = N-1
ans = ans // 2
print(ans)
if __name__ == "__main__":
main()
| 1 | 153,391,263,233,188 | null | 283 | 283 |
a = [int(s) for s in input().split()]
N = a[0]
bks = a[1]
bd = a[2]
s = [input().split() for i in range(N)]
anslist = []
for i in range(2**N):
templist = []
for t in range(bks+1):
templist.append(int(0))
for j in range(N):
if (i >> j) & 1 == 1:
for k in range(bks + 1):
templist[k] += int(s[j][k])
anslist.append(templist)
ans = int(-1)
flag = int(0)
for i in range(2**N):
flag = 0
for j in range(1, bks+1):
if anslist[i][j] < bd:
flag = 1
break
else:
pass
if flag == 0:
if anslist[i][0] < ans or ans == -1:
ans = anslist[i][0]
print(ans) | INF = 10**9 + 7
def main():
N, M, X = (int(i) for i in input().split())
CA = [[int(i) for i in input().split()] for j in range(N)]
ans = INF
for bit in range(1 << N):
wakaru = [0]*M
cur = 0
for i in range(N):
if bit & (1 << i):
c, *A = CA[i]
cur += c
for j in range(M):
wakaru[j] += A[j]
if all(m >= X for m in wakaru):
ans = min(ans, cur)
if ans == INF:
print(-1)
else:
print(ans)
if __name__ == '__main__':
main()
| 1 | 22,252,448,926,422 | null | 149 | 149 |
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
import numpy
N = int(input())
A = list(map(int, input().split()))
a = numpy.argsort(A)
b = []
for i in range(N):
b.append(str(a[i]+1))
print(" ".join(b)) | import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
ans = np.argsort(a)
print(*ans + 1) | 1 | 180,633,441,943,542 | null | 299 | 299 |
S = input()
count = 0
for i in range(len(S)//2):
if S[i] != S[len(S)-i-1]:
count = count+1
print(count) | s=list(input());print(sum([1 for i,j in list(zip(s[:(len(s)//2)],s[len(s)//2:][::-1])) if i!=j])) | 1 | 120,077,348,028,988 | null | 261 | 261 |
import math
count = 0
n,d = (int(x) for x in input().split())
for i in range(n):
x,y = (int(x) for x in input().split())
result = math.sqrt(x * x + y * y)
if result <= d:
count += 1
print(count) | n=int(input())
ans=0
tmp=0
p=1
if n%2==0:
k=n//2
while True:
tmp =k//pow(5,p)
ans+=tmp
p+=1
if tmp==0:
break
print(ans)
| 0 | null | 60,712,901,979,652 | 96 | 258 |
N = int(input())
judge = N%10
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if judge in hon:
print("hon")
elif judge in pon:
print("pon")
elif judge in bon:
print("bon") | N = input().rstrip()
N = int(N[-1])
A = {2,4,5,7,9}
B = {0,1,6,8}
if N in A:
print("hon")
elif N in B:
print("pon")
else:
print("bon") | 1 | 19,321,986,553,792 | null | 142 | 142 |
N = int(input())
if N%1000 == 0:
print(0)
else:
print((int(N/1000)+1)*1000-N)
| from sys import stdin
input = stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
res = a[0]
cnt = N - 2
cur = 1
while cnt:
if cnt == 1:
res += a[cur]
break
else:
res += a[cur] * 2
cur += 1
cnt -= 2
print(res) | 0 | null | 8,840,182,158,610 | 108 | 111 |
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
n,k=MI()
p=LI()
for i in range(n):
p[i]=p[i]/2+0.5
#print(p)
ans=sum(p[:k])
now=sum(p[:k])
for i in range(n-k):
now=now-p[i]+p[i+k]
ans=max(ans,now)
print(ans)
if __name__ == "__main__":
main()
| def expect(n):
return (n+1)/2
nk = input().split()
N = int(nk[0])
K = int(nk[1])
p = input().split()
tmp = 0
for i in range (K):
tmp += expect(int(p[i]))
tmpMax = tmp
for i in range(N - K):
tmp -= expect(int(p[i]))
tmp += expect(int(p[i+K]))
tmpMax = max(tmpMax, tmp)
print(tmpMax)
| 1 | 74,992,498,805,140 | null | 223 | 223 |
n = int(input())
s = []
t = []
for i in range(n):
si, ti = input().split()
s.append(si)
t.append(int(ti))
x = input()
insleep = s.index(x)
ans = sum(t[insleep+1:])
print(ans) | class My_Queue:
def __init__(self, S):
self.S = S
self.q = [0 for i in range(S)]
self.head = 0
self.tail = 0
def enqueue(self, x):
if self.isFull():
print('overflow')
raise
else:
self.q[self.tail] = x
if self.tail + 1 == self.S:
self.tail = 0
else:
self.tail += 1
def dequeue(self):
if self.isEmpty():
print('underflow')
raise
else:
x = self.q[self.head]
self.q[self.head] = 0
if self.head + 1 == self.S:
self.head = 0
else:
self.head += 1
return x
def isEmpty(self):
return self.head == self.tail
def isFull(self):
return self.head == (self.tail + 1) % self.S
def main():
n, qms = map(int, input().split())
elapsed_time = 0
q = My_Queue(n + 1)
for i in range(n):
name, time = input().split()
time = int(time)
q.enqueue([name, time])
while(q.head != q.tail):
a = q.dequeue()
if a[1] <= qms:
elapsed_time += a[1]
print(a[0], elapsed_time)
else:
a[1] -= qms
elapsed_time += qms
q.enqueue(a)
if __name__ == "__main__":
main() | 0 | null | 48,318,384,014,270 | 243 | 19 |
s = set()
for _ in range(int(input())):
c = input().split()
if c[0] == 'insert':
s.add(c[1])
else:
print('yes' if c[1] in s else 'no') | def main():
import sys
def input(): return sys.stdin.readline().rstrip()
a,b,c = map(int, input().split())
import numpy as np
if c-a-b >=0 and (c-a-b)**2-4*a*b > 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 26,028,153,492,000 | 23 | 197 |
import sys
read=sys.stdin.read
h,w,n=map(int, read().split())
m=max(h,w)
print(n//m+(n%m!=0)) | s=list(input())
s.reverse()
mod=2019
n=[0]*len(s)
n[0]=1
cnt=[0]*len(s)
cnt[0]=int(s[0])
ans=[0]*2019
answer=0
for i in range(1,len(s)):
n[i]+=(n[i-1]*10)%mod
for i in range(1,len(s)):
cnt[i]=(cnt[i-1]+int(s[i])*n[i])%mod
for i in cnt:
ans[i]+=1
for i in range(len(ans)):
answer+=(ans[i]*(ans[i]-1))//2
answer+=ans[0]
print(answer) | 0 | null | 59,915,765,671,080 | 236 | 166 |
from copy import copy
import random
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
ps = [0]*26
for j in range(26):
pl = copy(last)
pl[j] = i+1
ps[j] += s[i][j]
for k in range(26):
ps[j] -= c[k]*(i+1-pl[k])
idx = ps.index(max(ps))
last[idx] = i+1
ans[i] = idx+1
score += max(ps)
for k in range(1,40001):
na = copy(ans)
x = random.randint(1,365)
y = random.randint(1,365)
na[x-1] = na[y-1]
last = [0]*26
ns = 0
for i in range(D):
last[na[i]-1] = i+1
ns += s[i][na[i]-1]
for j in range(26):
ns -= c[j]*(i+1-last[j])
if k%100 == 1:
T = 80-(79*k/40000)
p = pow(math.e,-abs(ns-score)/T)
if ns > score or random.random() < p:
ans = na
score = ns
for a in ans:
print(a) | import numpy as np
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
I = [[0 for i in range(26)] for j in range(D)]
for d in range(D):
for t in range(26):
I[d][t] = (c[t] * (D-(d+1))) + s[d][t]
for line in I:
print(line.index(max(line))+1) | 1 | 9,795,690,565,810 | null | 113 | 113 |
def selection_Sort(A,N):
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
count += 1
return (count)
if __name__ == '__main__':
n = int(input())
data = [int(i) for i in input().split()]
result = selection_Sort(data,n)
print(" ".join(map(str,data)))
print(result) | n = -100, -100
while n[0] != 0 or n[1] != 0:
n = map( int, raw_input().split())
if n[0] != 0 or n[1] != 0:
print min(n[0],n[1]),max(n[0],n[1]) | 0 | null | 265,917,598,652 | 15 | 43 |
x = int(input())
def check(input):
one = 1800
two = 1999
kyu = 1
while one >= 400:
if one <= input <= two:
return kyu
kyu += 1
one -= 200
two -= 200
print(check(x))
| num = input().split()
num.sort()
print(num[0], num[1], num[2]) | 0 | null | 3,586,251,548,702 | 100 | 40 |
from sys import stdin
inf = 10**9 + 1
def solve():
n = int(stdin.readline())
R = [int(stdin.readline()) for i in range(n)]
ans = max_profit(n, R)
print(ans)
def max_profit(n, R):
max_d = -inf
min_v = R[0]
for i in range(1, n):
max_d = max(max_d, R[i] - min_v)
min_v = min(min_v, R[i])
return max_d
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve() | n = input()
min_val = float("inf")
max_val = -float("inf")
for i in range(n):
tmp = input()
max_val = max(max_val, tmp - min_val)
min_val = min(min_val, tmp)
print max_val | 1 | 13,406,327,352 | null | 13 | 13 |
str = input()
num = int(str)
if num % 2 == 0:
print('-1');
else:
i = 1
j = 7
while j % num != 0 and i <= num:
j = (j % num) * 10 + 7
i += 1
if i > num:
print('-1');
else:
print(i);
| k=int(input())
if k%2==0 or k%5==0:
print(-1)
else:
i=1
t=7
while t%k!=0:
i+=1
t=(t*10+7)%k
print(i) | 1 | 6,144,828,951,550 | null | 97 | 97 |
n=int(input())
p=[input().split() for _ in range(n)]
x=input()
ans=0
flag=False
for i in p:
if i[0]==x:
flag=True
continue
if flag:
ans+=int(i[1])
print(ans)
| #n=int(input())
#a,b,n=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())
print("".join(s[0:3]))
| 0 | null | 56,030,754,651,860 | 243 | 130 |
x=list(map(int,input()))
if x[-1]==2 or x[-1]==4 or x[-1]==5 or x[-1]==7 or x[-1]==9:
print("hon")
elif x[-1]==0 or x[-1]==1 or x[-1]==6 or x[-1]==8:
print("pon")
else:
print("bon") | a,b,c,d=map(int,input().split())
print("No" if (a-1)//d<(c-1)//b else"Yes") | 0 | null | 24,484,881,740,628 | 142 | 164 |
def main() :
lst = input().split()
stack = []
for i in lst :
if i == "+" :
x = stack.pop()
y = stack.pop()
stack.append(x + y)
elif i == "-" :
x = stack.pop()
y = stack.pop()
stack.append(y - x)
elif i == "*" :
x = stack.pop()
y = stack.pop()
stack.append(x * y)
else :
stack.append(int(i))
print(stack.pop())
if __name__ == "__main__" :
main() | M = 1000000007
N = int(input())
A = list(map(int, input().split()))
ans = 1
rgb = [0, 0, 0]
for i in range(N):
c = rgb.count(A[i])
if c == 0:
ans = 0
break
p = rgb.index(A[i])
ans *= c
rgb[p] += 1
print(ans % M) | 0 | null | 65,236,810,378,330 | 18 | 268 |
N = int(input())
s, t = [0]*N, [0]*N
for i in range(N):
s[i], t[i] = input().split()
X = input()
ans = 0
flag = False
for i in range(N):
if flag:
ans += int(t[i])
if s[i] == X:
flag = True
print(ans) | import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def solve():
n = getN()
li = [0 for i in range(n)]
for nn in getList():
# nn = getN()
li[nn-1] += 1
for nn in li:
print(nn)
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve() | 0 | null | 64,883,769,859,360 | 243 | 169 |
N,K=map(int,input().split())
H=list(map(int,input().split()))
P=0
for i in range(N):
if K<=H[i]:
P+=1
print(P) | n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse=True)
a = 0
for hh in h:
if hh >= k:
a += 1
else:
break
print(a)
| 1 | 178,900,074,011,460 | null | 298 | 298 |
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
d = abs(a - b)
u = abs(v - w)
if w >= v:
print("NO")
else:
if u * t >= d:
print('YES')
else:
print('NO') | n, k = list(map(int, input().split()))
list = list(map(int, input().split()))
ans = [l for l in list if l >= k]
print(len(ans)) | 0 | null | 96,757,287,403,680 | 131 | 298 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
a = int(input())
b = int(input())
if (a == 1 and b == 2):
print(3)
elif(a == 1 and b == 3):
print(2)
elif (a == 2 and b == 1):
print(3)
elif (a == 2 and b == 3):
print(1)
elif (a == 3 and b == 1):
print(2)
elif (a == 3 and b == 2):
print(1)
| n = input()
if n[-1]== "2" or n[-1]== "4" or n[-1]== "5" or n[-1]== "7" or n[-1]== "9":
print("hon")
elif n[-1]== "3":
print("bon")
else:
print("pon") | 0 | null | 65,363,515,359,260 | 254 | 142 |
N=int(input())
k=N%1000
if k==0:
t=0
else:
t=1000-k
print(t) | N=int(input())
M=1000
if N%M==0:
print(0)
else:
print(M-N%M) | 1 | 8,431,188,727,040 | null | 108 | 108 |
s = input()
if s == 'AAA' or s == 'BBB':
print('No')
else:
print('Yes') | def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
s=input()
from collections import Counter
c=Counter(s)
if len(c.keys())>=2:
print("Yes")
else:
print("No") | 1 | 54,792,518,276,960 | null | 201 | 201 |
W = raw_input()
S = []
while True:
tmp = map(str, raw_input().split())
if tmp[0] == "END_OF_TEXT":
break
else:
S.append(tmp)
cnt = 0
for i in range(len(S)):
for j in range(len(S[i])):
if W == S[i][j].lower():
cnt += 1
print cnt | D = 100000
N = int(raw_input())
for i in xrange(N):
D += D/20
if D % 1000 > 0:
D += 1000-D%1000
print D | 0 | null | 905,616,253,202 | 65 | 6 |
from copy import deepcopy
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
ans = 0
queue = [[1,0],[-1,0],[0,1],[0,-1]]
def now(n,s):
t = []
for i in queue:
j = n[0] + i[0]
k = n[1] + i[1]
if 0 <= j < H and 0 <= k < W:
if s[j][k] == ".":
t.append([j,k])
s[j][k] = "#"
return [t,s]
def bfs(trust, a, s):
t = []
for i in trust:
tt, s = now(i,s)
t += tt
if len(t) == 0:
return a
else:
a = a + 1
return bfs(t, a, s)
for i in range(H):
for j in range(W):
s = deepcopy(S)
if S[i][j] == ".":
s[i][j] = "#"
ans = max(ans, bfs([[i,j]], 0, s))
print(ans) | def divideprime(n):
ret = []
i = 2
while i*i <= n:
cnt = 0
if(n%i != 0):
i += 1
continue
while n % i == 0:
cnt += 1
n //= i
ret.append([i,cnt])
i += 1
if n != 1:
ret.append([n,1])
return ret
N = int(input())
divp = divideprime(N)
ans = 0
for t in divp:
cnt = 0
e = 0
s = set([])
while (t[1]-e > 0) and (t[1]-e not in s):
ans += 1
cnt += 1
e += cnt
s.add(cnt)
print(ans) | 0 | null | 55,643,650,677,602 | 241 | 136 |
n = int(input())
P = list(map(int,input().split()))
tmp = float('inf')
cnt = 0
for i,p in enumerate(P):
if p <=tmp:
cnt += 1
tmp = min(tmp,p)
print(cnt)
| import math
from functools import reduce
def getD(num):
input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
input_list[0] = 0
bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
sqrt = int(math.sqrt(num))
for serial in range(3, sqrt + 1, 2):
if bool_list[serial]:
for s in range(serial ** 2, num+1, serial):
if bool_list[s]:
input_list[s] = serial
bool_list[s] = False
return input_list
N = int(input())
A = list(map(int, input().split()))
D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for k in A:
while k != 1:
div = D[k]
if div in use_divnum:
pairwise_coprime = False
break
else:
use_divnum.add(div)
while k % div == 0 and k > 1:
k = k // div
if pairwise_coprime:
print('pairwise coprime')
exit()
if reduce(math.gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| 0 | null | 44,769,369,758,620 | 233 | 85 |
#!/usr/bin/env python3
import sys
from itertools import chain
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np
def solve(N: int, K: int, p: "List[int]"):
p = sorted(p)
return sum(p[:K])
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, K, p = map(int, line.split())
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
p = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, K, p)
print(answer)
if __name__ == "__main__":
main()
| N,M = map(int, input().split())
A = list(map(int, input().split()))
total = sum(A)
A.sort(reverse=True)
if A[M-1] >= total / (4*M):
print('Yes')
else:
print('No') | 0 | null | 25,150,868,971,872 | 120 | 179 |
N = input()[::-1]
l = len(N)
dp = [[0,0] for i in range(l+1)]
for i in range(l):
dp[i+1][0] = min(dp[i][0] + int(N[i]), dp[i][1] + int(N[i]) + 1)
if i == 0:
dp[i+1][1] = 10 - int(N[i])
else:
dp[i+1][1] = min(dp[i][0] + 10 - int(N[i]), dp[i][1] + 9 - int(N[i]))
print(min(dp[-1][0],dp[-1][1]+1))
| def main():
S = list(input())
cnt = 0
for i in range(int(len(S) / 2)):
if S[i] != S[-i - 1]:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 95,554,766,071,032 | 219 | 261 |
A, B = map(int, input().split())
print(max([0, A-2*B])) | s = input()
for _ in range(int(input())):
o = list(map(str, input().split()))
a = int(o[1])
b = int(o[2])
if o[0] == "print":
print(s[a:b+1])
elif o[0] == "reverse":
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
else:
s = s[:a] + o[3] + s[b+1:]
| 0 | null | 84,603,510,409,372 | 291 | 68 |
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
line.sort(reverse=True)
if line[len(line) -1]== 0:
print(0)
exit()
for num in line:
sum = sum * num
if sum > 10 ** 18:
print(-1)
exit()
print(sum) | n = int(input())
h = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
b, f, r, v = [int(e) for e in input().split()]
h[b-1][f-1][r-1] += v
for i, b in enumerate(h):
if i != 0:
print('#'*20)
for f in b:
print(' ', end='')
print(*f) | 0 | null | 8,702,275,192,362 | 134 | 55 |
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
p_1, p_2, p_3, p_infinit = 0, 0, 0, 0
dis_list = []
for i in range(n):
dis_list.append(abs(x[i] - y[i]))
sum_d = abs(x[i] - y[i])
p_1 += sum_d
p_2 += sum_d ** 2
p_3 += sum_d ** 3
p_2 = math.sqrt(p_2)
p_3 = p_3 ** (1 / 3)
print(p_1)
print(p_2)
print(p_3)
print(max(dis_list))
| n=int(input())
x,y=[list(map(int,input().split()))for _ in range(2)]
d=[abs(s-t)for s,t in zip(x,y)]
f=lambda n:sum([s**n for s in d])**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')
| 1 | 208,509,565,642 | null | 32 | 32 |
import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, X, M = NMI()
A = []
A_ID = {}
break_flag = False
start = 0
end = N
for i in range(M):
if i == 0:
A.append(X)
A_ID[X] = 0
else:
x = A[-1]**2 % M
if x not in A_ID:
A.append(x)
A_ID[x] = i
else:
A.append(x)
start = A_ID[x]
end = i
break_flag = True
if break_flag:
break
if N < start+1:
print(sum(A[:N]))
exit()
ans = sum(A[:start])
lp = sum(A[start:end])
gap = end - start
lp_n = (N - start) // gap
rem = (N - start) % gap
ans += lp * lp_n + sum(A[start: start + rem])
print(ans)
if __name__ == "__main__":
main() | # 繰り返しの始まり + 繰り返し + 途中で終わった繰り返し分
N,X,M = map(int,input().split())
p = [0] * (M+2)
sum = [0] * (M+2)
p[X] = 1
sum[1] = X
repeat_start = 0
repeat_end = 0
for i in range(2,N+1):
X = (X**2) % M
if p[X] != 0:
repeat_start = p[X]
repeat_end = i
break
else:
sum[i] = sum[i-1] + X
p[X] += i
if repeat_start == 0:
print(sum[N])
else:
repeat_cnt,mod=divmod(N-repeat_start+1,repeat_end-repeat_start)
print(repeat_cnt*(sum[repeat_end-1]-sum[repeat_start-1]) + sum[repeat_start+mod-1]) | 1 | 2,785,862,000,192 | null | 75 | 75 |
import queue
def main():
h, w = map(int, input().split())
st = [[1]*(w+2) for _ in range(h+2)]
for i in range(h):
s = input()
for j in range(w):
if s[j] == ".":
st[i+1][j+1] = 0
ans = 0
for i in range(1, h+2):
for j in range(1, w+2):
if st[i][j] == 0:
fs = [[float("inf")]*(w+2) for _ in range(h+2)]
q = queue.Queue()
fs[i][j] = 0
q.put([i, j])
while not q.empty():
y, x = q.get()
if st[y-1][x] == 0 and fs[y-1][x] > fs[y][x] + 1:
fs[y-1][x] = fs[y][x] + 1
q.put([y-1, x])
if st[y+1][x] == 0 and fs[y+1][x] > fs[y][x] + 1:
fs[y+1][x] = fs[y][x] + 1
q.put([y+1, x])
if st[y][x-1] == 0 and fs[y][x-1] > fs[y][x] + 1:
fs[y][x-1] = fs[y][x] + 1
q.put([y, x-1])
if st[y][x+1] == 0 and fs[y][x+1] > fs[y][x] + 1:
fs[y][x+1] = fs[y][x] + 1
q.put([y, x+1])
if ans < fs[y][x]:
ans = fs[y][x]
print(ans)
if __name__ == "__main__":
main()
| import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
H, W = NMI()
grid = [SI() for _ in range(H)]
DH = [-1, 1, 0, 0]
DW = [0, 0, -1, 1]
def bfs(sh, sw):
queue = deque()
seen = make_grid(H, W, -1)
queue.append([sh, sw])
seen[sh][sw] = 0
while queue:
now_h, now_w = queue.popleft()
for dh, dw in zip(DH, DW):
next_h = now_h + dh
next_w = now_w + dw
if not(0 <= next_h < H and 0 <= next_w < W):
continue
if seen[next_h][next_w] != -1 or grid[next_h][next_w] == "#":
continue
queue.append([next_h, next_w])
seen[next_h][next_w] = seen[now_h][now_w] + 1
return max([max(l) for l in seen])
ans = 0
for h in range(H):
for w in range(W):
if grid[h][w] == ".":
ans = max(ans, bfs(h, w))
print(ans)
if __name__ == "__main__":
main() | 1 | 94,558,306,880,648 | null | 241 | 241 |
import sys
for line in sys.stdin:
a,op,b=line.split()
if op == '?':
break
print eval(line) | count = -1
a = []
while True:
count += 1
n = input()
a.append(n.split())
boy = a[count][0]
fuck = a[count][1]
girl = a[count][2]
if fuck == "+":
print(int(boy)+int(girl))
elif fuck == "-":
print(int(boy)-int(girl))
elif fuck == "*":
print(int(boy)*int(girl))
elif fuck == "/":
print(int(int(boy)/int(girl)))
if a[count][1] == "?":
break | 1 | 668,958,602,350 | null | 47 | 47 |
i = 0
while True:
t = int(input())
if t == 0:
break
else:
i += 1
print('Case '+str(i)+': '+str(t)) | def isprime(n):
if n < 2: return 0
elif n == 2: return 1
if n % 2 == 0: return 0
for i in range(3, n, 2):
if i > n/i: return 1
if n % i == 0 : return 0
return 1
N = int(input())
n = [int(input()) for i in range(N)]
a = [i for i in n if isprime(i)]
print(len(a))
| 0 | null | 256,083,564,890 | 42 | 12 |
suit = ['S', 'H', 'C', 'D']
cards = [[i, j] for i in suit for j in map(str, range(1, 14))]
for i in range(input()):
cards.remove(raw_input().split())
for i in cards:
print i[0],i[1] | n = input()
mark = ['S', 'H', 'C', 'D']
cards = ["{} {}".format(mark[i], j+1) for i in range(4) for j in range(13)]
for i in range(n):
cards.remove(raw_input())
while len(cards) != 0:
print cards.pop(0) | 1 | 1,029,600,342,342 | null | 54 | 54 |
N = int(input())
P = list(map(lambda p : int(p), input().split(" ")))
left_min = P[0]
cnt = 0
for i in range(len(P)):
if left_min >= P[i]:
cnt += 1
left_min = P[i]
print(cnt) | n=int(input())
p=list(map(int,input().split()))
min_val=10**18
ans=0
for i in range(n):
if i==0:
min_val=p[i]
ans+=1
continue
if min_val>=p[i]:
min_val=p[i]
ans+=1
print(ans)
| 1 | 85,684,056,029,924 | null | 233 | 233 |
print(input()**2) | '''
Created on 2020/08/31
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,M=map(int,pin().split())
ans=[0]*N
for _ in [0]*M:
s,c=map(int,pin().split())
if s==1 and c==0 and N!=1:
print(-1)
return
if ans[s-1]!=0 and ans[s-1]!=c:
print(-1)
return
ans[s-1]=c
if N==3:
if ans[0]==0:
if ans[1]==0:
print(f"{1}{0}{ans[2]}")
else:
print(f"{1}{ans[1]}{ans[2]}")
return
else:
print(f"{ans[0]}{ans[1]}{ans[2]}")
return
elif N==2:
if ans[0]==0:
print(f"{1}{ans[1]}")
else:
print(f"{ans[0]}{ans[1]}")
return
else:
print(ans[0])
return
return
main() | 0 | null | 102,834,556,765,820 | 278 | 208 |
while True:
Input = raw_input().split()
a = int(Input[0])
op = Input[1]
b = int(Input[2])
if op == "+":
ans = a + b
print ans
elif op == "-":
ans = a - b
print ans
elif op == "/":
ans = a / b
print ans
elif op == "*":
ans = a * b
print ans
elif op == "?":
break | while True:
a, b, c = input().split()
a = int(a)
c = int(c)
if b == "?":
break
if b == "+":
print(a + c)
if b == "-":
print(a - c)
if b == "*":
print(a * c)
if b == "/":
print(a // c)
| 1 | 673,055,606,958 | null | 47 | 47 |
import numpy as np
k = int(input())
x = np.arange(1,k+1)
# np.ufunc.outer: c_ij = f(a_i, b_j)
a = np.gcd.outer(np.gcd.outer(x,x),x)
print(a.sum()) | n=int(input())
s=input()
judge=''
for i in range(n):
if s[i]==judge:
n-=1
judge=s[i]
print(n) | 0 | null | 102,839,239,602,330 | 174 | 293 |
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
dp = [[10000000000000]*(H+1) for _ in range(N+1)]
for y in range(N):
a,b = AB[y]
for x in range(H+1):
if x <= a:
dp[y+1][x] = min(dp[y][x], b)
else:
dp[y+1][x] = min(dp[y][x], dp[y+1][x-a]+b)
print(dp[-1][-1]) | h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
INF = 1 << 60
dp = [INF] * (h + 1)
dp[0] = 0
for i in range(0, h + 1):
# hを超えるために必要な最小コストは?
for a, b in ab:
if i + a <= h:
dp[i + a] = min(dp[i] + b, dp[i + a])
else:
dp[h] = min(dp[i] + b, dp[h])
print(dp[h]) | 1 | 81,011,132,468,828 | null | 229 | 229 |
N = input()
flag = 0
for n in N:
if int(n) == 7:
flag = 1
break
if flag==0:
print("No")
else:
print("Yes") | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
As = list(mapint())
mod = 10**9+7
bits = [0]*70
for a in As:
for l in range(a.bit_length()):
if (a>>l)&1:
bits[l] += 1
ans = 0
for i in range(70):
one = bits[i]
zero = N-one
mul = pow(2, i, mod)
ans += one*zero*mul
ans %= mod
print(ans) | 0 | null | 78,455,302,550,598 | 172 | 263 |
def main():
a = int(input())
b = int(input())
if a == 1 and b == 2 or a == 2 and b == 1:
print(3)
elif a == 2 and b == 3 or a == 3 and b == 2:
print(1)
elif a == 3 and b == 1 or a == 1 and b == 3:
print(2)
if __name__ == '__main__':
main() | c= '123'
a= str(input())
b= str(input())
c= c.replace(a, '')
c= c.replace(b, '')
print(c) | 1 | 110,922,172,856,248 | null | 254 | 254 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
x = int(input())
print(10-x//200)
| # -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
x = int(input())
print(10 - x // 200)
if __name__ == '__main__':
main()
| 1 | 6,736,724,973,920 | null | 100 | 100 |
a,b,c=map(int,input().split())
d=0
while a!=b+1:
if c%a==0:d+=1
a+=1
print(d)
| s = raw_input().rstrip().split(" ")
ans=0
for i in range(int(s[0]),int(s[1])+1):
if int(s[2])%i==0:ans+=1
print ans | 1 | 553,699,009,380 | null | 44 | 44 |
a, b, c = map(int, input().split())
d = 0
if a > b:
d = a
a = b
b = d
else: pass
d = 0
if b > c:
d = b
b = c
c = d
else: pass
d = 0
if a > b:
d = a
a = b
b = d
else: pass
print(a, b, c)
| A = input().split()
B = sorted(A)
C = map(str, B)
print(' '.join(C)) | 1 | 418,262,125,482 | null | 40 | 40 |
def main():
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
def f(a,l):
ans = 0
for i in range(len(a)):
ans += math.ceil(a[i]/l)-1
return ans
l,r = 1,max(a)
while r-l>1:
mid = (l+r)//2
g = f(a,mid)
if g>k:
l = mid+1
else:
r = mid
if f(a,l)<=k:
print(l)
else:
print(r)
if __name__ == "__main__":
main()
| N = int(input())
S = input()
anchor = ''
ans = 0
for i in range(N):
if anchor != S[i]:
anchor = S[i]
ans += 1
print(ans) | 0 | null | 88,534,220,757,248 | 99 | 293 |
n = int(input())
mod = 1000000007
if n < 2:
print(0)
else:
print((pow(10, n, mod) - 2 * pow(9, n, mod) + pow(8, n, mod)) % mod) | n, k = map(int , input().split())
hn = [int(num) for num in input().split()]
hn.sort(reverse = True)
if len(hn) > k:
print(sum(hn[k:]))
else :
print(0) | 0 | null | 41,134,152,537,078 | 78 | 227 |
ans = 0
N = int(input())
for i in range(N):
a = int(input())
if a == 2:
ans += 1
elif a%2 == 0:
continue
else:
if pow(2, a-1, a) == 1:
ans += 1
print(ans) | stdin = [input() for i in range(3)]
line = stdin[0].split(' ')
A = int(line[0])
V = int(line[1])
line = stdin[1].split(' ')
B = int(line[0])
W = int(line[1])
T = int(stdin[2])
length = 0
if B > A:
length = B-A
else:
length = A-B
if (V-W)*T < length:
print('NO')
else:
print('YES') | 0 | null | 7,601,202,142,720 | 12 | 131 |
def COMinit():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,max):
fac[i] = fac[i-1]*i%mod
inv[i] = mod - inv[mod%i]*(mod//i)%mod
finv[i] = finv[i-1]*inv[i]%mod
def COM(n,k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k]*finv[n-k]%mod)%mod
mod = 10**9+7
X, Y = map(int,input().split())
a = X%2 #1の数
b = X//2 #2の数
for i in range(b+1):
if a*2 + b*1 == Y:
break
a += 2
b -= 1
if a*2 + b*1 != Y:
print(0)
else:
max = a+b+1
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
print(COM(a+b,a))
| import math
x = int(input())
ans = 0
y = 100
while y < x:
y += y//100
ans += 1
print(ans) | 0 | null | 88,422,842,430,010 | 281 | 159 |
X, Y = [int(_) for _ in input().split()]
ans = 0
V = [400000, 300000, 200000, 100000]
if X <= 3:
ans += V[X]
if Y <= 3:
ans += V[Y]
if X == Y == 1:
ans += V[0]
print(ans)
|
def resolve():
x,y=(int(i) for i in input().split())
if x==1 and y==1:
print(1000000)
return
c=0
if x==1:
c+=300000
if x==2:
c+=200000
if x==3:
c+=100000
if y==1:
c+=300000
if y==2:
c+=200000
if y==3:
c+=100000
print(c)
if __name__ == "__main__":
resolve() | 1 | 140,312,716,762,828 | null | 275 | 275 |
# https://atcoder.jp/contests/abc153/tasks/abc153_f
# 座標圧縮、貪欲法、imos法
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
def read_tuple(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
# まず、何回攻撃すればいいのかを計算する。これがとにかく必要だ(なくてもいいけど)。
#
# 素直な戦略として、左から倒せるギリギリの爆弾を投下して倒すのが最適
# だけどナイーブに実装すると、O(N^2)。だから体力を管理するのが重要。
# どこにどれだけダメージが蓄積したのかはimos法(デルタ関数をおいてから累積和)で管理できる。
from bisect import bisect_left
N, D, A = read_ints()
XH = read_tuple(N)
XH.sort() # 座標でソート
n_atk = [] # 何回攻撃するのが必要か
X = [] # 座標アクセス用配列
for x, h in XH:
n_atk.append((h - 1) // A + 1)
X.append(x)
damege = [0] * (N + 10) # ダメージ管理用、配列外アクセスがめんどくさいので長めに取る
ans = 0
# j = 0 # 次のxが、今のx+2d以下でもっとも大きなidx
for i, (x, n) in enumerate(zip(X, n_atk)):
damege[i] += damege[i - 1] # 積分して、現時点の蓄積回数を表示
atk = max(0, n - damege[i]) # iには何回攻撃したか
ans += atk
# 攻撃下回数を記録
damege[i] += atk
# 効果が切れる点を予約 # 尺取ならO(1)で次に行けるけど二分探索でも間に合うか
damege[bisect_left(X, x + 2 * D + 1, lo=i)] -= atk # 効果切れを予約
print(ans)
| class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(self.n+1) # 1-indexed
def init(self, init_val):
for i, v in enumerate(init_val):
self.add(i, v)
def add(self, i, x):
# i: 0-indexed
i += 1 # to 1-indexed
while i <= self.n:
self.bit[i] += x
i += (i & -i)
def sum(self, i, j):
# return sum of [i, j)
# i, j: 0-indexed
return self._sum(j) - self._sum(i)
def _sum(self, i):
# return sum of [0, i)
# i: 0-indexed
res = 0
while i > 0:
res += self.bit[i]
i -= i & (-i)
return res
class RangeAddBIT:
def __init__(self, n):
self.n = n
self.bit1 = BIT(n)
self.bit2 = BIT(n)
def init(self, init_val):
self.bit2.init(init_val)
def add(self, l, r, x):
# add x to [l, r)
# l, r: 0-indexed
self.bit1.add(l, x)
self.bit1.add(r, -x)
self.bit2.add(l, -x*l)
self.bit2.add(r, x*r)
def sum(self, l, r):
# return sum of [l, r)
# l, r: 0-indexed
return self._sum(r) - self._sum(l)
def _sum(self, i):
# return sum of [0, i)
# i: 0-indexed
return self.bit1._sum(i)*i + self.bit2._sum(i)
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def main():
n, d, a = map(int, input().split())
XH = []
for i in range(n):
x, h = map(int, input().split())
XH.append((x-d, h))
XH.sort()
X = []
H = []
for x, h in XH:
X.append(x)
H.append(h)
bit = RangeAddBIT(n+1)
bit.init(H)
import bisect
ans = 0
for i in range(n):
h = bit.sum(i, i+1)
if h > 0:
q = (h+a-1)//a
ans += q
j = bisect.bisect_right(X, X[i]+2*d)
bit.add(i, j, -q*a)
print(ans)
if __name__ == '__main__':
main()
| 1 | 82,610,267,944,380 | null | 230 | 230 |
def main() :
N = input()
sum = 0
for i in range(len(N)):
sum += int(N[i])
if sum % 9 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | s = input()
q = []
for i in s:
q.append(int(i))
if sum(q)%9 == 0:
print('Yes')
else:print('No') | 1 | 4,434,185,195,682 | null | 87 | 87 |
n = int( raw_input( ) )
dic = {}
for i in range( n ):
cmd, word = raw_input( ).split( " " )
if "insert" == cmd:
dic[ word ] = True
elif "find" == cmd:
if not dic.get( word ):
print( "no" )
else:
print( "yes" ) | n = int(input())
s = input()
rs = s.count('R')
oks = s[:rs].count('R')
print(rs - oks) | 0 | null | 3,178,055,658,570 | 23 | 98 |
from collections import deque
import sys
si = sys.stdin.readline
def BFS(g, s):
d = 0
dt = dict()
visited = set()
visited.add(s)
Q = deque([s])
while len(Q):
d += 1
Qs = len(Q)
for _ in range(Qs):
Qpop = Q.popleft()
for node in g[Qpop]:
if node not in visited:
Q.append(node)
visited.add(node)
dt[node] = d
return dt
def main():
l = [int(e) for e in si().split()]
n, u, v = l[0], l[1], l[2]
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
l = [int(e) for e in si().split()]
graph[l[0]].append(l[1])
graph[l[1]].append(l[0])
udt = BFS(graph, u)
vdt = BFS(graph, v)
udt[u], vdt[v] = 0, 0
vdmax = 0
for i in range(1, n+1):
if (vdt[i]-udt[i]) > 0 and vdt[i] > vdmax:
vdmax = vdt[i]
print(vdmax-1)
if __name__ == '__main__':
main()
| N, u, v = map(int, input().split())
u, v = u-1, v-1
ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
#%%
roots = [[] for _ in range(N)]
for AB in ABs:
roots[AB[0]].append(AB[1])
roots[AB[1]].append(AB[0])
#BFS
def BFS(roots, start):
from collections import deque
seen = [-1 for _ in range(N)]
seen[start] = 0
todo = deque([start])
while len(todo) > 0:
checking = todo.pop()
for root in roots[checking]:
if seen[root] == -1:
seen[root] = seen[checking] +1
todo.append(root)
return seen
from_u = BFS(roots, u)
from_v = BFS(roots, v)
from collections import deque
todo = deque([u])
max_distance = from_v[u]
position = u
seen = [False for _ in range(N)]
seen[u] = True
while len(todo) > 0:
checking = todo.pop()
for root in roots[checking]:
if from_u[root] < from_v[root] and seen[root] == False:
seen[root] = True
todo.append(root)
if max_distance < from_v[root]:
max_distance = from_v[root]
position = root
print(max_distance-1) | 1 | 117,773,263,697,530 | null | 259 | 259 |
n = int(input())
list_ = []
for _ in range(n):
x, l = map(int, input().split())
list_.append([x-l, x+l])
list_.sort(key=lambda x: x[1])
res = n
pos = -float('inf')
for l, r in list_:
if l < pos:
res -= 1
else:
pos = r
print(res) | n = int(input())
ranges = []
for i in range(n):
x, l = map(int, input().split())
ranges.append([max(x-l, 0), x+l])
ranges.sort(key=lambda x: x[1])
start = 0
ans = 0
for range in ranges:
if range[0] >= start:
start = range[1]
ans += 1
print(ans) | 1 | 89,883,901,242,080 | null | 237 | 237 |
from collections import deque
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
M = [[0 for _ in range(N)] for _ in range(N)]
color = [0 for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
nt = [0 for _ in range(N)]
tt = 0
def main():
n = int(input())
for _ in range(n):
u, k, *v_s = map(int, input().split(' '))
for j in range(k):
M[u-1][v_s[j-1]-1] = 1
dfs(n)
for i in range(n):
print('{} {} {}'.format(i+1, d[i], f[i]))
def dfs(n):
for u in range(n):
if color[u] == WHITE:
dfs_visit(n, u)
def dfs_visit(n, r):
global tt
color[r] = GRAY
tt += 1
d[r] = tt
for v in range(0, n):
if M[r][v] == 0:
continue
if color[v] == WHITE:
dfs_visit(n, v)
color[r] = BLACK
tt += 1
f[r] = tt
if __name__ == '__main__':
main()
| import collections
N = int(input())
a = [input()for i in range(N)]
c = collections.Counter(a)
print(len(c.keys())) | 0 | null | 15,254,265,786,588 | 8 | 165 |
import sys
def main():
input = sys.stdin.buffer.readline
a, b, c = map(int, input().split())
print("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No")
if __name__ == "__main__":
main()
| a,b,c = map(int,input().split())
if c<=a+b:
print("No")
else:
if 4*a*b<(c-a-b)**2:
print("Yes")
else:
print("No") | 1 | 51,651,400,314,514 | null | 197 | 197 |
N, P = map(int, input().split())
S = input()
if P == 2:
ans = 0
for i, d in enumerate(map(int, S)):
if d % 2 == 0:
ans += i+1
print(ans)
elif P == 5:
ans = 0
for i, d in enumerate(map(int, S)):
if d % 5 == 0:
ans += i+1
print(ans)
else:
mods = [0] * P
mods[0] = 1
cur_mod = 0
for i, digit in enumerate(map(int, S)):
cur_mod += pow(10, N-i-1, P) * digit
cur_mod %= P
mods[cur_mod] += 1
ans = 0
for count in mods:
ans += count * (count - 1) // 2
print(ans) | x = list(map(int,input().split()))
H = x[0]
W = x[1]
if H == 1 or W == 1:
print(1)
else:
if W % 2 == 0:
print(int(H*W/2))
else:
if H % 2 == 0:
print(int(H*(W-1)/2 + H/2))
else:
print(int(H*(W-1)/2 + (H+1)/2))
| 0 | null | 54,764,403,109,404 | 205 | 196 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, M: int, A: "List[int]"):
t = sum(A)/4/M
return [YES, NO][len([a for a in A if a >= t]) < M]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, M, A)}')
if __name__ == '__main__':
main()
| n, m = input().split()
a = list(map(int, input().split()))
b = []
s = 0
for i in a:
s += i
for i in a:
if float(i) >= float(int(s)/(4*int(m))):
b.append(i)
if len(b) == int(m):
break
if len(b) == int(m):
print("Yes")
else:
print("No") | 1 | 38,774,205,387,872 | null | 179 | 179 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
n = int(input())
if n == 1:
print(1/1)
elif n % 2 == 0:
print(1/2)
elif n % 2 != 0:
print((n//2 + 1)/n)
| #!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
N=input()
K,=pin()
#degit DP
#dp_table["index"][smaller][cond]=cond:=ちょうどK個の数がある を満たす総数
rb=(0,1)
dp_table=[[[0 for cnd in range(K+1)]for sml in rb]for ind in range(len(N)+1)]
dp_table[0][0][0]=1
#print(dp_table)
#print("degit,sml,k,prove,l,x<n,dp_table[degit-1][sml][k]")#
for degit in range(len(N)+1):
n=int(N[degit-1])
for sml in rb:
t=10 if sml else int(N[degit-1])+1
for k in range(K+1):
for prove in range(t):
x=prove
try:#Indexerror
#print(degit,sml,k,prove,"l",x<n,dp_table[degit-1][sml][k])
#if sml==False and x==n:print(n,":")
dp_table[degit][sml or x<n][k+(x!=0)]+=dp_table[degit-1][sml][k]
except :pass
print(dp_table[-1][0][K]+dp_table[-1][1][K])
#print(dp_table)
#%%submit!
resolve()
| 0 | null | 126,256,900,287,972 | 297 | 224 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.