code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
while True:
num = raw_input()
if num == "0":
break
output = 0
for i in num:
output += int(i)
print output
|
import sys
input = sys.stdin.readline
class Unionfind(): # Unionfind
def __init__(self, N):
self.N = N
self.parents = [-1] * N
def find(self, x): # グループの根
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y): # グループの併合
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x): # グループのサイズ
return - self.parents[self.find(x)]
def same(self, x, y): # 同じグループか否か
return self.find(x) == self.find(y)
# 解説AC
n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]
uf = Unionfind(n)
frnd = [0] * n
for a, b in ab:
uf.union(a - 1, b - 1)
frnd[a - 1] += 1
frnd[b - 1] += 1
brck = [0] * n
for c, d in cd:
if uf.same(c - 1, d - 1):
brck[c - 1] += 1
brck[d - 1] += 1
ans = []
for i in range(n):
ans.append(uf.size(i) - frnd[i] - brck[i] - 1)
print(*ans)
| 0 | null | 31,786,808,307,860 | 62 | 209 |
def is_ok(x):
trainings = 0
for i in range(N):
t = A[i] - x // F[i]
if t > 0:
trainings += t
return trainings <= K
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = A[-1] * F[0]
while ok - ng > 1:
m = ng + (ok - ng) // 2
if is_ok(m):
ok = m
else:
ng = m
print(ok)
|
'''
A[i]<A[j]
F[i]<F[j]
となる組み合わせが存在したと仮定
max(A[i]*F[i],A[j]*F[j])=A[j]*F[j]
>A[i]*F[j]
>A[j]*F[i]
より、この場合はiとjを入れ替えたほうが最適となる。
結局
Aを昇順ソート
Fを降順ソート
するのが最適となる。
問題は修行の割当である。
順序を保ったまま修行していっても問題ない
3,2->1,2と
3.2->2,1は同じとみなせるため
二分探索
成績をmidにするために必要な修行コスト
lowならK回より真に大
highならK回以下
'''
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort(reverse=True)
low=-1
high=max(A)*max(F)+1
while(high-low>1):
mid=(high+low)//2
tmp=0
for i in range(N):
#A[i]*F[i]-mid<=X*F[i]
x=(A[i]*F[i]-mid+F[i]-1)//F[i]
if x<0:
continue
tmp+=x
if tmp<=K:
high=mid
else:
low=mid
print(high)
| 1 | 164,864,706,508,164 | null | 290 | 290 |
X = int(input())
c = 0
i = 100
while True:
c += 1
i = i + i//100
if X <= i:
break
print(c)
|
def binary_search(*, ok, ng, func):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def main():
N, K = map(int, input().split())
*A, = sorted(map(int, input().split()))
*F, = sorted(map(int, input().split()), reverse=True)
def is_ok(score):
rest = K
for a, f in zip(A, F):
exceed = max(0, a * f - score)
if exceed:
need = (exceed + f - 1) // f
if need > a or need > rest:
return False
rest -= need
return True
ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 95,968,037,150,572 | 159 | 290 |
N_str, q_str = raw_input().split()
N = int(N_str)
q = int(q_str)
A =[]
B =[]
total =0
for i in range(N):
t = raw_input().split()
A.append([t[0],int(t[1])])
while A:
name, time = A.pop(0)
if time <= q:
total += time
B.append(name+" "+ str(total))
else:
time -= q
total += q
A.append([name, time])
print '\n'.join(B)
|
n,q = map(int,input().split())
name = []
time = []
for i in range(n):
tmp = input().split()
name.append(str(tmp[0]))
time.append(int(tmp[1]))
total = 0
result = []
while True:
try:
if time[0] > q:
total += q
time[0] = time[0] - q
tmp = time.pop(0)
time.append(tmp)
tmp = name.pop(0)
name.append(tmp)
elif q >= time[0] and time[0] > 0:
total += time[0]
time.pop(0)
a = name.pop(0)
print(a,total)
else:
break
except:
break
| 1 | 45,765,940,516 | null | 19 | 19 |
n=int(input())
x=0--n//2
print(x/n)
|
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
res=0
m=1
for i in a:
b=m-i
if b<0:
print(-1)
exit(0)
res+=i
res+=b
s-=i
m=min(b*2,s)
print(res)
| 0 | null | 97,912,253,766,668 | 297 | 141 |
n=int(input())
l=list(map(int,input().split()))
a=[]
for i in range(n):
a.append(0)
for i in range(n-1):
a[l[i]-1]+=1
for i in range(n):
print(a[i])
|
N=int(input())
A=list(map(int,input().split()))
Subordinate=[[] for i in range(N)]
for i in range(len(A)):
A_i=A[i]
Subordinate[A_i-1].append(A_i)
for i in Subordinate:
print(len(i))
| 1 | 32,434,757,313,280 | null | 169 | 169 |
S = list(input())
N = len(S)
if N % 2 == 0:
m = int(N/2)
LS = S[:m]
RS = S[N:m-1:-1]
ans = 0
for i in range(m):
if LS[i] == RS[i]:
pass
else:
ans += 1
else:
m = int((N+1)/2)
LS = S[:m-1]
RS = S[N:m-1:-1]
ans = 0
for i in range(m-1):
if LS[i] == RS[i]:
pass
else:
ans += 1
print(ans)
|
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(input())
A = list(map(int,input().split()))
dp0 = [0] * (n+11)
dp1 = [0] * (n+11)
dp2 = [0] * (n+11)
for i,ai in enumerate(A):
dp2[i+11] = (max(dp0[i+7] + ai, dp1[i+8] + ai, dp2[i+9] + ai) if i >= 2 else 0)
dp1[i+11] = (max(dp0[i+8] + ai, dp1[i+9] + ai) if i >= 1 else 0)
dp0[i+11] = dp0[i+9] + ai
if n % 2 == 0:
print(max(dp0[n + 9], dp1[n + 10]))
else:
print(max(dp0[n + 8], dp1[n + 9], dp2[n + 10]))
# debug
# print(dp0,dp1,dp2,sep="\n")
| 0 | null | 78,532,449,284,640 | 261 | 177 |
from collections import deque
def main():
n = int(input())
_next = [[] for _ in range(n)]
for _ in range(n):
u, k, *v = map(lambda s: int(s) - 1, input().split())
_next[u] = v
queue = deque()
queue.append(0)
d = [-1] * n
d[0] = 0
while queue:
u = queue.popleft()
for v in _next[u]:
if d[v] == -1:
d[v] = d[u] + 1
queue.append(v)
for i, v in enumerate(d, start=1):
print(i, v)
if __name__ == '__main__':
main()
|
n=int(input())
a=[]
from collections import deque as dq
for i in range(n):
aaa=list(map(int,input().split()))
aa=aaa[2:]
a.append(aa)
dis=[-1]*n
dis[0]=0
queue=dq([0])
while queue:
p=queue.popleft()
for i in range(len(a[p])):
if dis[a[p][i]-1]==-1:
queue.append(a[p][i]-1)
dis[a[p][i]-1]=dis[p]+1
for i in range(n):
print(i+1,dis[i])
| 1 | 3,873,578,526 | null | 9 | 9 |
n=input().split()
x=int(n[0])
y=int(n[1])
if 1<=x<1000000000 and 1<=y<=1000000000:
if x>y:
while y!=0:
t=y
y=x%t
x=t
print(x)
else:
while x!=0:
t=x
x=y%t
y=t
print(y)
|
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i in range(n - 2):
a = L[i]
for j in range(i + 1, n - 1):
b = L[j]
l = j
r = n
while r - l > 1:
p = (l + r) // 2
if L[p] < a + b:
l = p
else:
r = p
count += l - j
print(count)
| 0 | null | 85,992,224,945,368 | 11 | 294 |
def solve():
can_positive = False
if len(P) > 0:
if k < n: can_positive = True
else: can_positive = len(M)%2 == 0
else: can_positive = k%2 == 0
if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k]
P.sort()
M.sort(reverse = True)
p, m = [], []
while len(p) + len(m) < k:
if len(P) > 0 and len(M) <= 0: p.append(P.pop())
elif len(P) <= 0 and len(M) > 0: m.append(M.pop())
elif P[-1] < -M[-1]: m.append(M.pop())
else: p.append(P.pop())
if len(m)%2:
Mi = M.pop() if len(p)*len(M) else 1 # 1 is no data
Pi = P.pop() if len(m)*len(P) else -1 # -1 is no data
if Mi < 0 and Pi >= 0:
if abs(p[-1] * Pi) < abs(m[-1] * Mi):
p.pop()
m.append(Mi)
else:
m.pop()
p.append(Pi)
elif Mi < 0:
p.pop()
m.append(Mi)
elif Pi >= 0:
m.pop()
p.append(Pi)
return p + m
n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
if a < 0: M.append(a)
else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)
|
mod=10**9+7
n,k=map(int,input().split())
A=list(map(int,input().split()))
K=k
B,C=[],[]
for i in A:
if i>=0:B.append(i)
else:C.append(i)
B.sort()
C.sort(key=lambda x:abs(x))
ans,flag=1,1
while k!=0:
if k>=2:
point=0
if len(B)>=2 and len(C)>=2:
if B[-1]*B[-2]>C[-1]*C[-2]:
ans *=B.pop()
point=1
else:ans *=C.pop()*C.pop()
elif len(B)>=2:ans *=B.pop()*B.pop()
elif len(C)>=2:ans *=C.pop()*C.pop()
else:flag=0
k -=2-point
else:
if len(B)>=1:ans *=B.pop()
else:flag=0
k -=1
ans %=mod
if flag:print(ans)
else:
ans=1
A=sorted(A,key=lambda x:abs(x))
for i in range(K):
ans *=A[i]
ans %=mod
print(ans)
| 1 | 9,459,837,587,200 | null | 112 | 112 |
N = int(input())
def dfs(s, mx):
if (len(s) == N):
print(s)
return
for i in range(mx + 1):
dfs(s + chr(97 + i), mx + (i == mx))
dfs('', 0)
|
from collections import deque
n=int(input())
alpha=['a','b','c','d','e','f','g','h','i','j','k']
q=deque(['a'])
for i in range(n-1):
qi_ans=[]
while(len(q)>0):
qi=q.popleft()
qiword_maxind=0
for j in range(len(qi)):
qi_ans.append(qi+qi[j])
qij_ind=alpha.index(qi[j])
if(qiword_maxind<qij_ind):
qiword_maxind=qij_ind
else:
qi_ans.append(qi+alpha[qiword_maxind+1])
qi_ans=sorted(list(set(qi_ans)))
# print(qi_ans)
q.extend(qi_ans)
lenq=len(q)
for i in range(lenq):
print(q.popleft())
| 1 | 52,158,428,550,180 | null | 198 | 198 |
from math import gcd
from functools import reduce
n,m=map(int,input().split())
lst=list(map(lambda x : int(x)//2,input().split()))
divi=0
x=lst[0]
while x%2==0:
x//=2
divi+=1
for i in range(1,n):
divi2=0
x=lst[i]
while x%2==0:
x//=2
divi2+=1
if divi!=divi2 :
print(0)
exit()
work=reduce(lambda x,y: x*y//gcd(x,y),lst)
print((m//work+1)//2)
|
import math
n=int(input())
x=list(map(int,input().split(" ")))
y=list(map(int,input().split(" ")))
def minkowski(x,y,p):
tmp=[math.fabs(x[i]-y[i])**p for i in range(len(x))]
return sum(tmp)**(1/p)
ans=[minkowski(x,y,i) for i in range(1,4)]
ans.append(max([math.fabs(x[i]-y[i])for i in range(len(x))]))
for i in ans:
print(i)
| 0 | null | 50,966,237,887,772 | 247 | 32 |
MAX = 100000
def check(p):
i = 0
for j in range(k):
s = 0
while s + T[i] <= p:
s = s + T[i]
i = i + 1
if i == n:
return n
return i
def solve():
left = 0
right = MAX * 10000
while (right - left > 1):
mid = (left + right) / 2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
return right
n, k = map(int, raw_input().split())
T = []
for i in range(n):
T.append(input())
ans = solve()
print ans
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation
????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????
n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????
"""
import sys
# ??????????????\????????????
def kenzan(P, w, n, k):
# print("P:{} kosu:{} track:{}".format(P,n,k))
t = 1 # ????????????
s = 0 # ?????????
st = 0
for i in range(n):
x = s + w[i]
# print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
if x > P: # ????????????
t += 1
st += s
s = w[i]
# print("next track:{} sekisai:{}".format(t,s))
if t > k: # ??°??°????????????
# print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
return st
else:
s = x
# print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
return 0
def main():
""" ????????? """
n,k = list(map(int,input().split()))
istr = sys.stdin.read()
wi = list(map(int,istr.splitlines()))
# ?????§?????¨???????????¨????°????????±???????
P = 0
total = 0
min = 100000
for w in wi:
if P < w:
P = w
if min > w:
min = w
total += w
na = int(total / n) # ?????????????????????
if total % n > 0:
na += 1
ka = int(total / k) # ???????????????????????????
if total % k > 0:
ka += 1
# ?????? P (??????????????§??????????????????????????????????±?????????????
# print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
if P < na:
P = na
if P < ka:
P = ka
z = 0
while P <= total:
st = kenzan(P, wi, n, k)
# print("??????????????°:{} ??????????????°??°:{} ?????????????????§??????:{} ????????????????????????:{} ??????????????????:{} ??????:{}".format(n, k, P, total, st,z))
if st == 0:
a = P - z
b = P
break
z = int((total-st)/k)
if z < 1:
z = 1
P += z
while b - a > 0:
x = int((b - a) / 2)
if x < 1:
a = b
P = x + a
st = kenzan(P, wi, n, k)
# print("P:{} MAX:{} MIN:{} sekisai:{}".format(P, b, a, st))
if st == 0:
b = P
else:
a = P
print(P)
if __name__ == '__main__':
main()
| 1 | 88,737,010,080 | null | 24 | 24 |
import collections
n = int(input())
l = []
for i in range(n):
l.append(input())
c = collections.Counter(l)
m = max(c.values())
chars = [key for key, value in c.items() if value == m]
chars.sort()
for s in chars:
print(s)
|
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B
x = int(input())
y = list(map(int,input().split()))
z = 0
for i in range(x):
minj = i
for j in range(i,x):
if y[j] < y[minj]:
minj = j
if not i == minj:
y[i], y[minj] = y[minj], y[i]
z += 1
print(" ".join(list(map(str,y))))
print(z)
| 0 | null | 35,129,488,114,890 | 218 | 15 |
A, B = list(map(int,input().split()))
if A>0 and A<10 and B>0 and B<10:
print(A*B)
else:
print(-1)
|
n=int(input())
S=[]
for i in range(n):
S.append(input())
print('AC', 'x', S.count('AC'))
print('WA', 'x', S.count('WA'))
print('TLE', 'x', S.count('TLE'))
print('RE', 'x', S.count('RE'))
| 0 | null | 83,159,807,489,440 | 286 | 109 |
n = int(input())
cou = 0
ans = False
for i in range(n):
da, db = map(int, input().split())
if da == db:
cou += 1
else:
cou = 0
if cou == 3:
ans = True
if ans:
print('Yes')
else:
print('No')
|
tes1 = input()
tes1 = int(tes1)
tes1 = tes1**3
print(tes1)
| 0 | null | 1,405,144,144,756 | 72 | 35 |
n = int(input())
a = ord("a")
def dfs(s, mx):
if len(s) == n:
print(s)
else:
for i in range(a, mx + 2):
if i != mx + 1:
dfs(s + chr(i), mx)
else:
dfs(s + chr(i), mx + 1)
dfs("a", a)
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
MAX_PRIME = 10**4
def prime_list():
sqrt_max = int(MAX_PRIME ** 0.5)
primes = [True for i in range(MAX_PRIME+1)]
primes[0] = primes[1] = False
for p in range(sqrt_max):
if primes[p]:
for px in range(p*2, MAX_PRIME, p):
primes[px] = False
p_list = [i for i in range(MAX_PRIME) if primes[i]]
return p_list
def is_prime(n, prime_list):
sqrt_n = int(n ** 0.5)
for i in prime_list:
if i > sqrt_n:
break
if n % i == 0:
return False
return True
p_list = prime_list()
n = int(sys.stdin.readline())
num_p = 0
for i in range(n):
x = int(sys.stdin.readline())
if is_prime(x, p_list):
num_p += 1
print(num_p)
| 0 | null | 26,218,789,241,584 | 198 | 12 |
import math
r = float(input())
S= r * r * math.pi
C= 2 * r * math.pi
print('{0:.6f} {1:.6f}'.format(S, C))
|
r = input()
r = float(r)
a = 3.14159265359*r*r
c = 2*3.14159265359*r
print("%.6f %.6f" % (a, c))
| 1 | 639,698,619,804 | null | 46 | 46 |
#ciが R のとき赤、W のとき白です。
#入力
#N
#c1...cN
N = int(input())
C = input()
Rednum = C.count('R')
#print(Rednum)
#Rの数 - 左にある赤の数が答
NewC = C[:Rednum]
#print(NewC)
Whinum = NewC.count('R')
print(Rednum - Whinum)
|
import collections
n= int(input())
g=[]
for _ in range(n):
v,k,*varray= map(int,input().split())
g.append(varray)
d= [-1]* (n+10)
d[0]=0
q= collections.deque()
q.append(0)
while len(q)> 0:
cur = q.popleft()
for next in g[cur]:
if d[next-1]== -1:
d[next-1]= d[cur]+1
q.append(next-1)
for i in range(n):
print(i+1,d[i])
| 0 | null | 3,162,530,688,440 | 98 | 9 |
S,T=list(input().split())
T+=S
print(T)
|
s=input()
#\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\
stack=[]
i=0
result=0
#みずたまりは、[左側の位置と、数量を表す]
mizutamari=[[-1,0]]
for item in s:
#print(stack,mizutamari)
if item=="\\":
stack.append(i)
elif item=="/":
if len(stack)>0:
temp=stack.pop()
result+=i-temp
left=mizutamari.pop()
if left[0]>temp:
vol=i-temp
while 1:
vol=left[1]+vol
mizutamari.append([temp,vol])
if len(mizutamari)<=2:
break
bk=mizutamari.pop()
bkbk=mizutamari.pop()
if bkbk<bk:
mizutamari.append(bkbk)
mizutamari.append(bk)
break
else:
left=bkbk
else:
#print(left[0],"<",temp,":","naze",left,temp)
mizutamari.append(left)
mizutamari.append([temp,i-temp])
#print(mizutamari)
i+=1
print(result)
s=""
for item in mizutamari[1:]:
s+=str(item[1])+" "
if result==0:
print(0)
else:
print(len(mizutamari)-1,s[:-1])
| 0 | null | 51,488,202,486,812 | 248 | 21 |
n = int(input())
stmp = list(input())
Q = int(input())
target = ord("a")
s = [ord(stmp[i])-target for i in range(n)]
class BIT:
"""
<Attention> 0-indexed.
query ... return the sum [0 to m]
sum ... return the sum [a to b]
sumall ... return the sum [all]
add ... 'add' number to element (be careful that it doesn't set a value.)
search ... the sum version of bisect.right
output ... return the n-th element
listout ... return the BIT list
"""
def query(self, m):
res = 0
while m > 0:
res += self.bit[m]
m -= m&(-m)
return res
def sum(self, a, b):
return self.query(b)-self.query(a)
def sumall(self):
bitlen = self.bitlen-1
return self.query(bitlen)
def add(self, m, x):
m += 1
bitlen = len(self.bit)
while m <= bitlen-1:
self.bit[m] += x
m += m&(-m)
return
def __init__(self, n):
self.bitlen = n+1
self.bit = [0]*(n+1)
b = [BIT(n) for i in range(26)]
for i in range(n):
b[s[i]].add(i, 1)
for _ in range(Q):
q,qtmpa,qtmpb = input().split()
if q[0] == "1":
qa = int(qtmpa)
t = ord(qtmpb)-target
b[t].add(qa-1, 1)
b[s[qa-1]].add(qa-1, -1)
s[qa-1] = t
else:
ans = 0
qta = int(qtmpa)
qtb = int(qtmpb)
for i in range(26):
if b[i].sum(qta-1, qtb) != 0:
ans += 1
print(ans)
|
from collections import deque
class SegmentTree():
def __init__(self,n,ide_ele,merge_func,init_val):
self.n=n
self.ide_ele=ide_ele
self.merge_func=merge_func
self.val=[0 for i in range(1<<n)]
self.merge=[0 for i in range(1<<n)]
self.parent=[-1 for i in range(1<<n)]
deq=deque([1<<(n-1)])
res=[]
while deq:
v=deq.popleft()
res.append(v)
if not v&1:
gap=(v&-v)//2
self.parent[v-gap]=v
deq.append(v-gap)
self.parent[v+gap]=v
deq.append(v+gap)
for v in res[::-1]:
if v-1<len(init_val):
self.val[v-1]=init_val[v-1]
self.merge[v-1]=self.val[v-1]
if not v&1:
gap=(v&-v)//2
self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])
def update(self,id,x):
self.val[id]=x
pos=id+1
while pos!=-1:
if pos&1:
self.merge[pos-1]=self.val[pos-1]
else:
gap=(pos&-pos)//2
self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
pos=self.parent[pos]
def cnt(self,k):
lsb=(k)&(-k)
return (lsb<<1)-1
def lower_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(l)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
id=r
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
return res
else:
id=l
else:
res=self.merge_func(res,self.val[id-1])
return res
def upper_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(r)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
id=l
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
return res
else:
id=r
else:
res=self.merge_func(res,self.val[id-1])
return res
def query(self,l,r):
id=1<<(self.n-1)
while True:
if id-1<l:
id+=((id)&(-id))//2
elif id-1>r:
id-=((id)&(-id))//2
else:
res=self.val[id-1]
if id%2:
return res
gap=((id)&(-id))//2
L,R=id-gap,id+gap
#print(l,r,id,L,R)
left=self.upper_kth_merge(L,id-1-l-1)
right=self.lower_kth_merge(R,r-id)
return self.merge_func(res,left,right)
ide_ele=0
def seg_func(*args):
res=ide_ele
for val in args:
res|=val
return res
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
import sys
input=sys.stdin.readline
N=int(input())
S=input().rstrip()
init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegmentTree(19,ide_ele,seg_func,init_val)
for _ in range(int(input())):
t,l,r=input().split()
t,l=int(t),int(l)
if t==1:
val=ord(r)-97
test.update(l-1,1<<val)
else:
r=int(r)
res=test.query(l-1,r-1)
print(popcount(res))
| 1 | 62,345,318,215,040 | null | 210 | 210 |
import math
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(map(int, input().split()))
def i_row(N): return [int(input()) for _ in range(N)]
def i_row_list(N): return [list(map(int, input().split())) for _ in range(N)]
mnum,snum=i_map()
snholder=set()
for i in range(snum):
d=i_input()
ls=i_list()
snholder=snholder | set(ls)
print(mnum-len(snholder))
|
n,k = map(int,input().split())
a = [0]*(n+1)
answer = 0
for i in range(k):
d = int(input())
b = list(map(int,input().split()))
for j in range(d):
a[b[j]] +=1
for q in range(1,n+1):
if(a[q]==0):
answer +=1
print(answer)
| 1 | 24,544,125,745,568 | null | 154 | 154 |
import datetime
def main():
H1, M1, H2, M2, K = map(int,input().split())
start = H1 * 60 + M1
end = H2 * 60 + M2
ans = end - start - K
print(ans)
if __name__ == "__main__":
main()
|
h, m, h2, m2, k = map(int, input().split())
ans = (h2 * 60 + m2) - (h * 60 + m) - k
print(ans)
| 1 | 18,067,340,301,320 | null | 139 | 139 |
N=input("").split(" ")
S=int(N[0])
W=int(N[1])
if S<=W:
print("unsafe")
else:
print("safe")
|
weatherS = input()
p = weatherS[0] == 'R'
q = weatherS[1] == 'R'
r = weatherS[2] == 'R'
if p and q and r:
serial = 3
elif (p and q) or (q and r):
serial = 2
elif p or q or r:
serial = 1
else:
serial = 0
print(serial)
| 0 | null | 17,039,419,126,912 | 163 | 90 |
N = int(input())
r, mod = divmod(N, 2)
print(r - 1 + mod)
|
N = int(input())
if N % 2 == 0:
ans = int(N / 2) - 1
else:
ans = int(N / 2)
print(ans)
| 1 | 153,146,947,183,438 | null | 283 | 283 |
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9+7)
CNT = [0] * (N+10)
CNT[-1] = 3
ans = 1
for a in A:
CNT[a] += 1
ans *= CNT[a-1]
ans %= mod
CNT[a-1] -= 1
print(ans)
|
n = int(input())
p= []
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(n):
p.append(input())
for j in p :
if j == "AC":
AC += 1
elif j == "WA":
WA += 1
elif j == "TLE":
TLE += 1
else:
RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))
| 0 | null | 69,316,420,346,068 | 268 | 109 |
import math
N = int(input())
A_max = int(math.sqrt(N) + 1)
A = list(range(2, A_max))
prime_check = [0] * (A_max + 1)
multi_list = []
def multi_x(X, n):
i = 1
result = 0
while X % (n**i) == 0:
result = i
i += 1
return result
for a in A:
if prime_check[a] == 0:
i = 2
x = multi_x(N, a)
if x != 0:
multi_list.append(x)
N = N // a**x
while a * i <= A_max:
prime_check[a * i] = 1
i += 1
if N > A_max:
ans = 1
else:
ans = 0
for m in multi_list:
i = 1
buf = m
while buf >= i:
buf -= i
i += 1
ans += 1
print(ans)
|
# -*- coding:utf-8 -*-
def solve():
N = int(input())
"""
■ 解法
N = p^{e1} * p^{e2} * p^{e3} ...
と因数分解できるとき、
z = p_i^{1}, p_i^{2}, ...
としていくのが最適なので、それを数えていく
(例) N = 2^2 * 3^2 * 5 * 7
のとき、
2,3,5,7の4回割れる。(6で割る必要はない)
■ 計算量
素因数分解するのに、O(√N)
割れる回数を計算するのはたかだか素因数分解するより少ないはずなので、
全体としてはO(√N+α)くらいでしょ(適当)
"""
def prime_factor(n):
"""素因数分解する"""
i = 2
ans = {}
while i*i <= n:
while n%i == 0:
if not i in ans:
ans[i] = 0
ans[i] += 1
n //= i
i += 1
if n != 1:
ans[n] = 1
return ans
pf = prime_factor(N)
ans = 0
for key, value in pf.items():
i = 1
while value-i >= 0:
value -= i
ans += 1
i += 1
print(ans)
if __name__ == "__main__":
solve()
| 1 | 16,954,447,141,280 | null | 136 | 136 |
n,k=map(int,input().split())
s=0
for m in map(int,input().split()):
if m>=k:s+=1
print(s)
|
import math
a, b = map(int, input().split())
if a%b == 0:
ans = a
elif b%a == 0:
ans = b
else:
ans = int(a*b / math.gcd(a, b))
print(ans)
| 0 | null | 146,409,799,429,450 | 298 | 256 |
a, b, c = map(int, input().split())
ans = 0
for i in range(a, b+1):
if c % i == 0: ans += 1
print(ans)
|
n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
| 0 | null | 32,463,395,232,232 | 44 | 212 |
nums = input().split()
W = int( nums[0])
H = int( nums[1])
x = int( nums[2])
y = int( nums[3])
r = int( nums[4])
if (x - r) >= 0 and (x + r) <= W:
if (y - r) >= 0 and (y + r) <= H:
print( "Yes")
else:
print( "No")
else:
print( "No")
|
N = int(input())
X = []
for i in range(N):
X.append(input().split())
S = input()
flg = False
ans = 0
for x in X:
if flg:
ans += int(x[1])
if S == x[0]:
flg = True
print(ans)
| 0 | null | 48,562,400,958,208 | 41 | 243 |
answer = [True] * 3
a = int(input())
b = int(input())
answer[a - 1] = False
answer[b - 1] = False
for i, ans in enumerate(answer):
if ans:
print(i + 1)
|
not_ans = []
not_ans.append(int(input()))
not_ans.append(int(input()))
for i in range(1, 4):
if i not in not_ans:
print(i)
| 1 | 110,543,027,653,432 | null | 254 | 254 |
S = input()
T = input()
S = list(S)
T = list(T)
for i in range(len(S)):
if S[i] != T[i]:
print('No')
exit()
print('Yes')
|
count = 0
def mergesort(A, left, right):
if left + 1 < right:
mid = (left + right)/2
mergesort(A, left, mid)
mergesort(A, mid, right)
merge(A, left, mid, right)
def merge(A, left, mid, right):
global count
n1 = mid -left
n2 = right - mid
L = []
R = []
for i in range(0, n1):
L.append(A[left + i])
for i in range(0, n2):
R.append(A[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]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
if __name__ == "__main__":
num = int(raw_input())
num_list = raw_input().strip().split()
num_list = map(int, num_list)
mergesort(num_list, 0, len(num_list))
num_list = map(str, num_list)
print " ".join(num_list)
print count
| 0 | null | 10,794,398,424,050 | 147 | 26 |
n = int(input())
a = sorted([(v, i) for i, v in enumerate(list(map(int, input().split())))])[::-1]
dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
ans = 0
for i in range(n):
for j in range(n - i):
v, p = a[i + j]
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v * abs(n - 1 - i - p))
dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + v * abs(j - p))
ans = max(ans, dp[i + 1][j], dp[i][j + 1])
print(ans)
|
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 9
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
A = LI()
S = sorted([(A[k], k + 1) for k in range(n)], reverse=True)
ans = 0
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(n):
if i and i <= S[i + j - 1][1]:
dp[i][j] = max(dp[i][j], dp[i - 1][j] + S[i + j - 1][0] * abs(i - S[i + j - 1][1]))
if j and S[i + j - 1][1] <= n - j + 1:
dp[i][j] = max(dp[i][j], dp[i][j - 1] + S[i + j - 1][0] * abs(n - j + 1 - S[i + j - 1][1]))
if i + j == n:
ans = max(ans, dp[i][j])
break
print(ans)
| 1 | 33,796,843,196,260 | null | 171 | 171 |
import collections
n=int(input())
A=list(map(int,input().split()))
if A[0]!=0:
print(0)
exit()
mod=998244353
C=[0]*n
for i in range(n):
C[A[i]]+=1
ans=1
if C[0]!=1:
print(0)
exit()
for i in range(n-1):
ans=ans*pow(C[i],C[i+1],mod)%mod
print(ans)
|
n=int(input())
d=list(map(int,input().split()))
r=1 if d[0]==0 else 0
d=d[1:]
d.sort()
c=1
nc=0
j=1
mod=998244353
for i in d:
if i<j:
r=0
elif i==j:
nc+=1
r=(r*c)%mod
elif i==j+1:
j=i
c=nc
nc=1
r=(r*c)%mod
else:
r=0
print(r)
| 1 | 154,852,562,005,472 | null | 284 | 284 |
n = int(input())
xl = [list(map(int, input().split())) for i in range(n)]
lr = list(map(lambda x:[x[0]-x[1], x[0]+x[1]], xl))
lr.sort(key=lambda x:x[1])
#print(lr)
limit = lr[0][1]
ans=n
for i in range(1, n):
if lr[i][0]<limit:
ans-=1
else:
limit=lr[i][1]
print(ans)
|
n = int(input())
dat = []
for _ in range(n):
x, l =map(int, input().split())
dat.append([x-l, x+l])
dat.sort(key=lambda x: x[1])
#print(dat)
prevr = -99999999999999999
res = 0
for i in range(n):
if dat[i][0] >= prevr:
prevr = dat[i][1]
res += 1
print(res)
| 1 | 90,365,433,770,908 | null | 237 | 237 |
import math
a,b,c=map(int,input().split())
C=(c/180)*math.pi
S=(a*b*math.sin(C))/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
print("%.5f\n%.5f\n%.5f\n"%(S,L,h))
|
def resolve():
s = input()
n = len(s)
a = s[:n//2]
b = s[::-1][:n//2]
cnt = 0
for i in range(len(a)):
if a[i] != b[i]:
cnt += 1
print(cnt)
resolve()
| 0 | null | 60,238,299,471,282 | 30 | 261 |
n = int(input())
s = input()
ans = 0
for pin in range(10**3):
str_pin = str(pin)
str_pin = str_pin.zfill(3)
nex = 0
for i in range(n):
searching_for = str_pin[nex]
now_s = s[i]
if searching_for == now_s:
nex += 1
if nex == 3:
ans += 1
break
print(ans)
|
n, x, m = map(int, input().split())
ans = []
c = [0]*m
flag = False
for i in range(n):
if c[x] == 1:
flag = True
break
ans.append(x)
c[x] = 1
x = x**2 % m
if flag:
p = ans.index(x)
l = len(ans) - p
d, e = divmod(n-p, l)
print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e]))
else:
print(sum(ans))
| 0 | null | 65,898,546,499,552 | 267 | 75 |
import sys,math
inputs = list()
for n in sys.stdin:
inputs.append(list(map(int,n.split())))
for n in inputs:
print(math.floor(math.log10(n[0]+n[1]))+1)
|
import sys
for a in sys.stdin:
b,c=map(int,a.split())
d=len(str(b+c))
print(d)
| 1 | 122,808,852 | null | 3 | 3 |
def resolve():
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [], [], []
dis = []
for i in range(M):
xt, yt, ct = list(map(int, input().split()))
dis.append(a[xt-1] + b[yt-1] - ct)
x.append(xt)
y.append(yt)
c.append(ct)
a.sort()
b.sort()
dis.sort()
ans = min(a[0] + b[0], dis[0])
print(ans)
return
resolve()
|
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,M = mi()
a = li()
b = li()
xyc = [li() for i in range(M)]
ans = min(a)+min(b)
for i in range(M):
ans = min(ans,a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2])
print(ans)
| 1 | 53,846,256,334,026 | null | 200 | 200 |
H = int(input())
res, cnt = 0, 1
while H > 1:
H = H // 2
res += cnt
cnt *= 2
print(res + cnt)
|
s=list(input())
length=len(s)
if(s[length-1]=='s'):
s.append('es')
else:
s.append('s')
s = ''.join(s)
print(s)
| 0 | null | 41,014,620,142,624 | 228 | 71 |
N=int(input())
C=[0]*4
S=['AC','WA','TLE','RE']
for _ in range(N):
s=input()
if s==S[0]:
C[0]+=1
elif s==S[1]:
C[1]+=1
elif s==S[2]:
C[2]+=1
else:
C[3]+=1
for i in range(4):
print(S[i],'x',C[i])
|
if __name__ == '__main__':
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
ww = [0]*n
for i in range(n):
ww[i] = int(input())
max_w = 10000
max_p = max_w*n
min_p = 0
def number_of_track(p):
ans = 1
sum_w = 0
for w in ww:
if w > p:
return n+1
if sum_w + w > p:
ans += 1
sum_w = w
else:
sum_w += w
return ans
while min_p != max_p:
mid = (max_p + min_p)//2
if number_of_track(mid) <= k:
max_p = mid
else:
min_p = mid+1
print(max_p)
| 0 | null | 4,397,879,382,930 | 109 | 24 |
N = int(input())
#stones = list(input())
stones = input()
#print(stones)
a = stones.count('W')
b = stones.count('R')
left_side =stones.count('W', 0, b)
print(left_side)
|
def main():
K = int(input())
ans = False
if K % 2 == 0:
print(-1)
exit()
cnt = 7 % K
for i in range(1, K+1):
if cnt == 0:
ans = True
print(i)
exit()
cnt = (10 * cnt + 7) % K
if ans == False:
print(-1)
exit()
main()
| 0 | null | 6,157,439,903,940 | 98 | 97 |
def f(u, i, d, t, vis):
if vis[u]:
return
vis[u] = True
z = t[u]
c = 1
for v in z:
if vis[v]:
continue
if c == i:
c += 1
d[u].update({v: c})
f(v, c, d, t, vis)
c += 1
def main():
from collections import defaultdict
import sys
sys.setrecursionlimit(100000)
n = int(input())
t = [[] for _ in range(n + 1)]
m = []
for _ in range(n - 1):
i, j = map(int, input().split())
t[i].append(j)
t[j].append(i)
m.append([i, j])
d = defaultdict(dict)
vis = [False for _ in range(n + 1)]
f(1, len(t[1]) + 1, d, t, vis)
ans = ''
if t.count([]) == n:
ans += str(n - 1) + '\n'
else:
ans += str(max(len(i) for i in t)) + '\n'
for (u, v) in m:
ans += str(d[u][v]) + '\n'
print(ans)
if __name__ == '__main__':
main()
|
import copy
def countKuro( t,p1,p2 ):
count=0
for i in range(h):
if p1 & (1<<i) :
for j in range(w):
if p2 & (1<<j) :
if t[i][j]=="#":
count+=1
return count
h,w,k=map(int, input().split())
s=[]
for i in range(h):
s.append( input() )
t=copy.copy(s)
ans=0
for i in range(1<<h):
for j in range(1<<w):
# print(i,j, countKuro(s,i,j))
if k==countKuro(s, i,j):
ans+=1
print(ans)
| 0 | null | 72,228,657,789,078 | 272 | 110 |
H=int(input())
x=0
while True:
x+=1
if 2**x>H:
x-=1
break
ans=0
for i in range(x+1):
ans+=2**i
print(ans)
|
from collections import Counter
n=int(input())
s=list(input())
cnt = Counter(s)
rn=cnt['R']
gn=cnt['G']
bn=n-rn-gn
ans=bn*gn*rn
if n>2:
for x in range(n-2):
y=(n-1-x)//2
for i in range(1,y+1):
if (not s[x]==s[x+i]) & (not s[x]==s[x+i+i]) & (not s[x+i]==s[x+i+i]):
ans-=1
print(ans)
else:
print(0)
| 0 | null | 58,276,137,338,034 | 228 | 175 |
from math import gcd
mod = 1000000007
n = int(input())
counter = {}
zeros = 0
for i in range(n):
a, b = map(int, input().split())
if (a == 0 and b == 0):
zeros += 1
continue
g = gcd(a, b)
a //= g
b //= g
if (b < 0):
a = -a
b = -b
if (b == 0 and a < 0):
a = -a
counter[(a, b)] = counter.get((a, b), 0)+1
counted = set()
ans = 1
for s, s_count in counter.items():
if s not in counted:
if s[0] > 0 and s[1] >= 0:
t = (-s[1], s[0])
else:
t = (s[1], -s[0])
t_count = counter.get(t, 0)
now = pow(2, s_count, mod)-1
now += pow(2, t_count, mod)-1
now += 1
ans *= now
ans %= mod
counted.add(s)
counted.add(t)
print((ans - 1 + zeros) % mod)
|
S = list(input())
left = [0]*(len(S)+1)
right = [0]*(len(S)+1)
for i in range(len(S)):
if S[i] == '<':
left[i+1] += 1+left[i]
for i in range(len(S)-1,-1,-1):
if S[i] == '>':
right[i] = right[i+1]+1
ans = [0]*(len(S)+1)
for i in range(len(S)+1):
ans[i] = max(left[i],right[i])
print(sum(ans))
| 0 | null | 88,570,768,409,248 | 146 | 285 |
import sys
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = I()
print(a[K -1 ])
|
n, k = map(int, input().split())
argList = list(map(int, input().split()))
print(sum([h >= k for h in argList]))
| 0 | null | 114,453,874,505,052 | 195 | 298 |
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
*a, = map(int, input().split())
s = [0]*(n+1)
for i in range(len(a)):
s[i+1] = s[i] + a[i]
for i in range(len(s)):
s[i] = (s[i] - i)%k
from collections import defaultdict
cnt = defaultdict(int)
left = 0
right = k-1
if right > n:
right = n
for i in range(right+1):
cnt[s[i]] += 1
ans = 0
while left < right:
ans += cnt[s[left]]-1
if right == n:
cnt[s[left]] -= 1
left += 1
else:
cnt[s[left]] -= 1
left += 1
right += 1
cnt[s[right]] += 1
print(ans)
|
def shaku(K,lists):
ans=0
SUMS=0
index=0
for l in range(len(lists)):
while index < l or index< len(lists) and SUMS +lists[index] < K:
SUMS += lists[index]
index+= 1
ans += index-l
SUMS -= lists[l]
return ans
n,k=map(int,input().split())
lists=list(map(int,input().split()))
uselist=[0 for i in range(n+1)]
for i in range(n):
uselist[i+1]=(uselist[i]+lists[i])
anslist=[0 for i in range(n+1)]
for j in range(1,n+1):
anslist[j]=(uselist[j]-j)%k
dic={}
for i in range(n+1):
if anslist[i] in dic.keys():
dic[anslist[i]].append(i+1)
else:
dic[anslist[i]]=[1+i]
#answerに答えを格納することにする
answer=0
for lis in dic.values():
sublis=[lis[0]]
for a in range(1,len(lis)):
sublis.append(lis[a]-lis[a-1])
P=shaku(k,sublis)
for some in lis:
if some<k:
answer-=1
answer+=P
print(answer)
| 1 | 137,584,989,197,978 | null | 273 | 273 |
from collections import defaultdict
N, P = map(int, input().split())
S = input()
"""
S = "s0 s1 ... s(N-1)"に対して"sl s(l+1) ... s(r-1)"が素数Pで割り切れるかを考える。
これはa_i := int("si s(i+1) ... s(N-1)")と定めることで、
(a_l - a_r) / 10^{N-r} ¥cong 0 (mod P)
と定式化できる。
(整数関連の区間の問題は後ろからの累積和が相性良さそう。頭からの累積を考えたのが敗因な気がする)
Pが2でも5でもない場合は、上式は
a_l - a_r ¥cong 0 (mod P)
に同値であるから、各a_iのmod Pでの値を辞書にまとめておけば良さそう。
Pが2, 5のいずれかの場合は偶然チェックが簡単なので解ける。
"""
ans = 0
if P == 2:
for i in range(N):
a = int(S[i])
if a % 2 == 0:
ans += i + 1
elif P == 5:
for i in range(N):
a = int(S[i])
if a == 0 or a == 5:
ans += i + 1
else:
S += "0" # 上の定式化の都合上、r = Nのケースが必要なので
d = defaultdict(int)
r = 0
d[0] += 1
for i in range(N - 1, -1, -1):
"""
ここでS[i:]を毎回Pで割るとTLEする(桁の大きい演算はやはり負担が大きいのか?)
(a_i % P)をi = N, N-1,...の降順に求めていくことを考えれば、
前の計算結果が使える、特に繰り返し二乗法が使えるのでだいぶ早くなるみたい。
"""
r += int(S[i]) * pow(10, N - i - 1, P)
r %= P
d[r] += 1
for num in d.values():
ans += num * (num - 1) // 2
print(ans)
|
import sys
n = int(input())
for i in range(1, 46300):
if n*25/27 <= i < (n+1)*25/27:
print(i)
sys.exit()
print(":(")
| 0 | null | 92,311,114,849,590 | 205 | 265 |
import math
n=int(input())
XY=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
for j in range(i+1,n):
disx=XY[i][0]-XY[j][0]
disy=XY[i][1]-XY[j][1]
dis=math.sqrt(disx**2+disy**2)
ans+=dis
print(2*ans/n)
|
a=[list(map(int,input().split()))for i in range(int(input()))]
b=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in a:
b[i[0]-1][i[1]-1][i[2]-1] += i[3]
f=0
for i in b:
if f:print('#'*20)
else:f=1
for j in i:
print('',*j)
| 0 | null | 74,835,017,153,530 | 280 | 55 |
def main():
x = int(input())
cnt = x // 100
m, M = cnt * 100, cnt * 105
if m <= x <= M:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
|
X = int(input())
for i in range(105, 100, -1):
while True:
if X % 100 < (X-i) % 100:
break
else:
X = X-i
if X < 0: X = 1
print(1 if X % 100 == 0 else 0)
| 1 | 127,539,879,626,368 | null | 266 | 266 |
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sumA = [0]
sumB = [0]
tmp = 0
answer = 0
st = 0
for i in range(N):
tmp = tmp + A[i]
sumA.append(tmp)
tmp = 0
for i in range(M):
tmp = tmp + B[i]
sumB.append(tmp)
for i in range(N, -1, -1):
booktmp = 0
for j in range(st, M + 1):
if sumA[i] + sumB[j] <= K:
booktmp = i + j
else:
st = j
break
answer = max(answer, booktmp)
if j == M:
break
print(answer)
|
def main():
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
total_T_in_A = [0] * (N+1)
total_T_in_B = [0] * (M+1)
for i in range(1, N+1):
total_T_in_A[i] = total_T_in_A[i-1] + A[i-1]
for i in range(1, M+1):
total_T_in_B[i] = total_T_in_B[i-1] + B[i-1]
result = 0
for i in range(N+1):
# A から i 冊読むときにかかる時間
i_A_T = total_T_in_A[i]
if K < i_A_T:
continue
if K == i_A_T:
result = max(result, i)
continue
rem_T = K - i_A_T
# total_T_in_B は累積和を格納した、ソート済の配列
# B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
first = total_T_in_B[1]
last = total_T_in_B[M]
if rem_T < first:
result = max(result, i)
continue
if last <= rem_T:
result = max(result, i + M)
continue
# assume that first <= rem_T <= last
first = 1
last = M
while first < last:
if abs(last - first) <= 1:
break
mid = (first + last) // 2
if rem_T < total_T_in_B[mid]:
last = mid
else:
first = mid
result = max(result, i + first)
print(result)
main()
| 1 | 10,826,666,758,708 | null | 117 | 117 |
mf = 0
while True:
m,f,r = [int(i) for i in input().strip().split()]
if m==f==r==-1 : break
mf = m+f
if m*f<0 or mf<30 : print("F")
elif mf<50 and r<50 : print("D")
elif mf<65 : print("C")
elif mf<80 : print("B")
elif mf>=80 : print("A")
else: print("F")
|
s = list(input().split())
print('Yes' if len(set(s)) == 2 else 'No')
| 0 | null | 34,529,272,388,016 | 57 | 216 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
print(10 - int(input()) // 200)
if __name__ == '__main__':
main()
|
from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
d = 0
if A[0][0]=="#":
d += 1
que = deque([(0,0,d)])
hist = [[H*W for _ in range(W)] for _ in range(H)]
hist[0][0] = d
while que:
i,j,d = que.popleft()
if j+1<W and A[i][j+1]==A[i][j]:
if hist[i][j+1]>d:
hist[i][j+1] = d
que.append((i,j+1,d))
elif j+1<W and A[i][j+1]!=A[i][j]:
if hist[i][j+1]>d+1:
hist[i][j+1] = d+1
que.append((i,j+1,d+1))
if i+1<H and A[i+1][j]==A[i][j]:
if hist[i+1][j]>d:
hist[i+1][j] = d
que.append((i+1,j,d))
elif i+1<H and A[i+1][j]!=A[i][j]:
if hist[i+1][j]>d+1:
hist[i+1][j] = d+1
que.append((i+1,j,d+1))
m = hist[H-1][W-1]
print((m+1)//2)
| 0 | null | 27,863,739,624,688 | 100 | 194 |
n = int(input())
l = list(range(0,n+1))
print(sum([i for i in l if i % 3 != 0 and i % 5 != 0]))
|
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
k = ni()
a = [0]*(10**6+1)
a[1] = 7%k
for i in range(2,k+1):
a[i] = (a[i-1]*10+7)%k
for i in range(1,k+1):
if a[i]==0:
print(i)
exit()
print(-1)
| 0 | null | 20,586,584,899,008 | 173 | 97 |
# abc161_c.py
# https://atcoder.jp/contests/abc161/tasks/abc161_c
# C - Replacing Integer /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点
# 問題文
# 青木君は任意の整数 xに対し、以下の操作を行うことができます。
# 操作: xを x と Kの差の絶対値で置き換える。
# 整数 Nの初期値が与えられます。この整数に上記の操作を 0 回以上好きな回数行った時にとりうる Nの最小値を求めてください。
# 制約
# 0≤N≤1018
# 1≤K≤1018
# 入力は全て整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N K
# 出力
# 操作を 0回以上好きな回数行った時にとりうる Nの最小値を出力せよ。
# 入力例 1
# 7 4
# 出力例 1
# 1
# 最初、 N=7です。
# 1回操作を行うと、N は |7−4|=3となります。
# 2回操作を行うと、N は |3−4|=1となり、これが最小です。
# 入力例 2
# 2 6
# 出力例 2
# 2
# 1回も操作を行わなかった場合の N=2が最小です。
# 入力例 3
# 1000000000000000000 1
# 出力例 3
# 0
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
# N = int(lines[0])
N, K = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
tmp = N % K
result = min(tmp, K-tmp)
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['7 4']
lines_export = [1]
if pattern == 2:
lines_input = ['2 6']
lines_export = [2]
if pattern == 3:
lines_input = ['1000000000000000000 1']
lines_export = [0]
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
|
S = input()
ans = 0
for i in range(int(len(S) / 2)):
if S[i] != S[-1-i]:
ans += 1
print(ans)
| 0 | null | 79,968,061,184,340 | 180 | 261 |
import math
import sys
x=input()
x0=x.split()
a=int(x0[0])
b=int(x0[1])
n=int(x0[2])
b0=n%b
b1=0
q1=0
if b==1:
print(0)
sys.exit()
for i in range(1,math.floor(n/b)+1):
b1=b*i-1
q1=max(q1,math.floor(a*b1/b)-a*math.floor(b1/b))
q2=math.floor(a*b0/b)-a*math.floor(b0/b)
print(max(q1,q2))
|
input()
xs = input().split()
print(' '.join(list(map(str, reversed(xs)))))
| 0 | null | 14,597,228,608,800 | 161 | 53 |
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)
|
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
tmp = 0
ans = 0
for num in A:
ans += tmp * num % MOD
tmp += num
print(ans%MOD)
| 1 | 3,839,646,223,798 | null | 83 | 83 |
#セグ木
from collections import deque
def f(L, R): return L|R # merge
def g(old, new): return old^new # update
zero = 0 #零元
class segtree:
def __init__(self, N, z):
self.M = 1
while self.M<N: self.M *= 2
self.dat = [z] * (self.M*2-1)
self.ZERO = z
def update(self, x, idx, l=0, r=-1):
if r==-1: r = self.M
idx += self.M-1
self.dat[idx] = g(self.dat[idx], x)
while idx > 0:
idx = (idx-1)//2
self.dat[idx] = f(self.dat[idx*2+1], self.dat[idx*2+2])
def query(self, a, b=-1, idx=0, l=0, r=-1):
if r==-1: r = self.M
if b==-1: b = self.M
q = deque([])
q.append([l, r, 0])
ret = self.ZERO
while len(q):
tmp = q.popleft()
L = tmp[0]
R = tmp[1]
if R<=a or b<=L: continue
elif a<=L and R<=b:
ret = f(ret, self.dat[tmp[2]])
else:
q.append([L, (L+R)//2, tmp[2]*2+1])
q.append([(L+R)//2, R, tmp[2]*2+2])
return ret
n = int(input())
s = list(input())
q = int(input())
seg = segtree(n+1, 0)
for i in range(n):
num = ord(s[i]) - ord("a")
seg.update((1<<num), i)
for _ in range(q):
a, b, c = input().split()
b = int(b) - 1
if a == "1":
pre = ord(s[b]) - ord("a")
now = ord(c) - ord("a")
seg.update((1<<pre), b)
seg.update((1<<now), b)
s[b] = c
else:
q = seg.query(b, int(c))
bin(q).count("1")
print(bin(q).count("1"))
|
day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
d = input()
print(7 - day.index(d))
| 0 | null | 97,327,693,453,968 | 210 | 270 |
word = raw_input()
text = []
while True:
raw = raw_input()
if raw == "END_OF_TEXT":
break
text += raw.lower().split()
print(text.count(word))
# print(text.lower().split().count(word))
|
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 2019
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')
S = input()
N = len(S)
d = defaultdict(int)
d[0] += 1
# nums = [0]*(N+1)
m = 0
last = 0
dd = 1
for i in range(N):
m += int(S[N-i-1])*dd
m %= MOD
# val = (int(S[i])*m + nums[i])%MOD
# cnt += d[val]
dd = (dd*10)%MOD
d[m] += 1
cnt = 0
for i, v in d.items():
cnt += v*(v-1)//2
print(cnt)
| 0 | null | 16,419,668,092,800 | 65 | 166 |
# -*-coding:utf-8
def main():
while True:
n, x = map(int, input().split())
if ((n == 0) and (x == 0)):
break
count = 0
for i in range(1, n+1):
for j in range(1, n+1):
for k in range(1, n+1):
if((i<j) and (j<k) and i+j+k == x):
count += 1
print(count)
if __name__ == '__main__':
main()
|
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
def input():
x=sys.stdin.readline()
return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
K,N,M=len(B),len(A),len(B[0])
return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
N,size=len(v),len(M)
return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
n,m=len(M),len(M[0])
return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
mod = 1000000007
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
s = input()
K= int(input())
#N, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
keta=len(s)
dp=[[[0,0] for _ in range(K+1)] for _ in range(keta+1)]
#dp[i][j][k]前からi桁目まで決め、j個の条件を満たす桁を含み、k=1:i文字目まで一致 k=0:対象の数以下
dp[0][0][0]=1
for i in range(0,keta):
ni=i+1
nd=int(s[i])
for j in range(0,K+1):
for k in range(0,2):
for d in range(10):
nj=j
nk=k
if d!=0:nj+=1
if nj>K:continue
if k==0:
if d>nd:break
elif d<nd:nk=1
dp[ni][nj][nk]+=dp[i][j][k]
if K<=keta:
ans=dp[keta][K][1]+dp[keta][K][0]
else:
ans=0
#与えられた数未満で条件を満たすもの+与えられた数が条件を満たす場合1
print(ans)
#print(dp)
if __name__ == "__main__":
main()
| 0 | null | 38,524,719,486,930 | 58 | 224 |
_, _, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
xyc = [tuple(map(int, input().split())) for i in range(M)]
print(min([min(A)+min(B)]+[A[x-1]+B[y-1]-c for x, y, c in xyc]))
|
A, B, M = map(int, input().split())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
m = []
for n in range(M):
m.append([int(s) for s in input().split()])
minValue = min(a) + min(b)
for i in range(M):
discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2]
if discountPrice < minValue:
minValue = discountPrice
print(minValue)
| 1 | 54,349,062,474,762 | null | 200 | 200 |
"""
i - j = A[i] + A[j]
> i - A[i] = j + A[j]
i > j
"""
from collections import defaultdict
N = int(input())
high = list(map(int, input().split()))
ans = 0
calc = defaultdict(int)
for i in range(1, N+1):
ans += calc[i - high[i-1]]
calc[i + high[i-1]] += 1
print(ans)
|
L,R,d=map(int,input().split())
ans=0
for i in range(L,R+1):
if i%d==0:
ans+=1
print(ans)
| 0 | null | 16,881,058,303,552 | 157 | 104 |
import math
n = int(raw_input())
def func(i, ox1, oy1, ox2, oy2):
if i != n:
nx1 = ox1 + (ox2 - ox1) / 3
ny1 = oy1 + (oy2 - oy1) / 3
nx2 = ox1 + (ox2 - ox1) * 2 / 3
ny2 = oy1 + (oy2 - oy1) * 2 / 3
if nx1 < nx2:
if ny1 == ny2:
nx3 = nx1 + (nx2 - nx1) / 2
ny3 = ny1 + (nx2 - nx1) * math.sqrt(3) / 2
elif ny1 < ny2:
nx3 = ox1
ny3 = ny2
elif ny1 > ny2:
nx3 = ox2
ny3 = ny1
elif nx1 > nx2:
if ny1 == ny2:
nx3 = nx1 + (nx2 - nx1) / 2
ny3 = ny1 - (nx1 - nx2) * math.sqrt(3) / 2
elif ny1 < ny2:
nx3 = ox2
ny3 = ny1
elif ny1 > ny2:
nx3 = ox1
ny3 = ny2
func(i+1, ox1, oy1, nx1, ny1)
func(i+1, nx1, ny1, nx3, ny3)
func(i+1, nx3, ny3, nx2, ny2)
func(i+1, nx2, ny2, ox2, oy2)
elif i == n:
print(str(ox1) + str(" ") + str(oy1))
func(0, 0.0, 0.0, 100.0, 0.0)
print(str(100) + str(" ") + str(0))
|
#(63)距離
import math
x1,y1,x2,y2=map(float,input().split())
a=abs(x2-x1)
b=abs(y2-y1)
c=math.sqrt(a**2+b**2)
print('{:.8f}'.format(c))
| 0 | null | 147,231,688,112 | 27 | 29 |
A = int(input())
B = int(input())
if (A==1 and B ==2) or (A==2 and B==1):
print('3')
elif (A==1 and B==3) or (A==3 and B==1):
print('2')
elif (A==2 and B==3) or (A==3 and B==2):
print('1')
|
M1,D1 = [ int(i) for i in input().split() ]
M2,D2 = [ int(i) for i in input().split() ]
print("1" if M1 != M2 else "0")
| 0 | null | 117,742,290,703,850 | 254 | 264 |
a, b = map(int, input().split())
x = a // 0.08
y = b // 0.10
x, y = int(x), int(y)
minv = min(x, y)
maxv = max(x, y)
ans = []
for i in range(minv, maxv+2):
if int(i * 0.08) == a and int(i * 0.1) == b:
ans.append(i)
if len(ans) == 0:
print(-1)
else:
print(min(ans))
|
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
a_rev = a[::-1]
ok, ng = 1, 200001
while ng-ok > 1:
x = (ok+ng)//2
num = 0
cur = 0
for i in range(n-1, -1, -1):
while cur < n and a[i] + a[cur] >= x:
cur += 1
num += cur
if num < m:
ng = x
else:
ok = x
just = ok
ans = 0
larger_cnt = 0
cur = 0
a_cum = [0]
for i in range(n):
a_cum.append(a_cum[-1] + a[i])
for i in range(n):
while cur < n and a[i] + a_rev[cur] <= just:
cur += 1
larger_cnt += n - cur
ans += (n - cur) * a[i] + a_cum[n - cur]
ans += just * (m - larger_cnt)
print(ans)
| 0 | null | 82,072,614,036,336 | 203 | 252 |
import sys
read = sys.stdin.read
def main():
N, K = map(int, read().split())
dp1 = [0] * (K + 1)
dp2 = [0] * (K + 1)
dp1[0] = 1
for x in map(int, str(N)):
dp1, dp1_prev = [0] * (K + 1), dp1
dp2, dp2_prev = [0] * (K + 1), dp2
for j in range(K, -1, -1):
if j > 0:
dp2[j] = dp2_prev[j - 1] * 9
if x != 0:
dp2[j] += dp1_prev[j - 1] * (x - 1)
dp2[j] += dp2_prev[j]
if x != 0:
dp2[j] += dp1_prev[j]
if x != 0:
if j > 0:
dp1[j] = dp1_prev[j - 1]
else:
dp1[j] = dp1_prev[j]
print(dp1[K] + dp2[K])
return
if __name__ == '__main__':
main()
|
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
l = list(map(int, input().split()))
if (l[0] == l[1] != l[2]):
print("Yes")
elif (l[0] == l[2] != l[1]):
print("Yes")
elif (l[0] != l[1] == l[2]):
print("Yes")
else:
print("No")
| 0 | null | 72,161,056,681,118 | 224 | 216 |
n,k=map(int,input().split());s=set(range(1,-~n))
for _ in range(k):
input();s-=set(map(int,input().split()))
print(len(s))
|
X,Y = map(int,input().split())
ans='No'
for i in range(0,X+1):
#print(i)
if i * 2 + (X - i) * 4 == Y and X>=i:
ans = 'Yes'
break
print(ans)
| 0 | null | 19,030,281,115,648 | 154 | 127 |
text = input()
times = int(input())
for i in range(times):
function = input().split()
word = text[int(function[1]):int(function[2])+1]
if function[0] == "print":
print(word)
elif function[0] == "reverse":
word_reverse = word[::-1]
text = text[:int(function[1])] + word_reverse + text[int(function[2])+1:]
elif function[0] == "replace":
text = text[:int(function[1])] + function[3] + text[int(function[2])+1:]
|
N = int(input())
Alst = list(map(int, input().split()))
Blst = [0]*(N+1)
num = 0
for i in Alst:
num = num + Blst[i]
Blst[i] += 1
for i in Alst:
k = Blst[i] -1
print(num - k)
| 0 | null | 24,997,769,192,366 | 68 | 192 |
# AOJ ITP1_9_A
def numinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
# ※大文字と小文字を区別しないので注意!!!!
# 全部大文字にしちゃえ。
def main():
W = input().upper() # 大文字にする
line = ""
count = 0
while True:
line = input().split(" ")
if line[0] == "END_OF_TEXT": break
for i in range(len(line)):
word = line[i].upper()
if W == word: count += 1
print(count)
if __name__ == "__main__":
main()
|
import sys
w=input().upper()
c=0
for s in sys.stdin:
if "END_OF_TEXT" in s:
break
c += str(s).upper().split().count(w)
print(c)
| 1 | 1,795,589,106,278 | null | 65 | 65 |
x=input()
x=x*x*x
print(x)
|
N=input()
print("ABC" if N=="ARC" else "ARC")
| 0 | null | 12,274,258,692,190 | 35 | 153 |
A=int(input())
B=int(input())
print(6-(A+B))
|
def main():
h, n = map(int, input().split())
a = [int(x) for x in input().split()]
if h > sum(a):
print('No')
else:
print('Yes')
if __name__ == '__main__':
main()
| 0 | null | 94,111,644,341,220 | 254 | 226 |
a,b,c,d=map(int,input().split())
if (b<0 and c>0) or (a>0 and d<0):
print(max(a*c,a*d,b*c,b*d))
else:
print(max(0,a*c,a*d,b*c,b*d))
|
a, b, c, d = map(int, input().split())
v1 = a * c
v2 = a * d
v3 = b * c
v4 = b * d
print(max(v1, v2, v3, v4))
| 1 | 3,055,260,579,492 | null | 77 | 77 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def cut(x):
cut_count = 0
for i in range(n):
cut_count += (a[i]-1)//x
return cut_count
l = 0
r = 10**9
while r-l > 1:
mid = (l+r)//2
if k >= cut(mid):
r = mid
else:
l = mid
print(r)
|
import math
N, K=map(int,input().split())
A=list(map(int,input().split()))
def judge(ans,K,A):
cut=0
for i in range(len(A)):
cut+=(A[i]-1)//ans
if cut>K:
return False
else:
return True
ansp=max(A)
ansm=0
ans=(ansp+ansm)//2
d=1
while ansp-ansm>d:
if judge(ans,K,A):
ansp=ans
else:
ansm=ans
ans=(ansp+ansm)//2
print(ansp)
| 1 | 6,499,698,392,992 | null | 99 | 99 |
asd=input()
dfg=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
print(dfg[dfg.index(asd)+1])
|
A, B, C = [int(x) for x in input().split()]
if len({A, B, C}) == 2:
print('Yes')
else:
print('No')
| 0 | null | 80,461,740,955,540 | 239 | 216 |
while 1:
x = raw_input()
if x == '0':
break
s = 0
for i in xrange(len(x)):
s += int(x[i])
print s
|
while True:
l=list(input())
if l==["0"]:
break
print(sum(map(int,l)))
| 1 | 1,549,772,815,580 | null | 62 | 62 |
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()
def addAll(end):
return (end * (end + 1)) // 2
total = 0
index = 0
while len(s) > index:
leftCount = 0
rightCount = 0
while len(s) > index and s[index] == "<":
leftCount += 1
index += 1
while len(s) > index and s[index] == ">":
rightCount += 1
index += 1
maxCount = max(leftCount, rightCount)
minCount = min(leftCount, rightCount)
total += addAll(maxCount) + addAll(max(minCount - 1, 0))
print(total)
| 1 | 155,895,059,032,098 | null | 285 | 285 |
n = int(input())
a = int(n**0.5+1)
ans = [0]*n
for x in range(1, a):
for y in range(1, a):
for z in range(1, a):
if x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
ans[x**2 + y**2 + z**2 + x*y + y*z + z*x -1] += 1
[print(i) for i in ans]
|
x,y,z=map(int,input().split())
count=0
for i in range(x,y+1):
if(i%z==0):
count+=1
print(count)
| 0 | null | 7,740,210,479,584 | 106 | 104 |
s, t = input().split()
d = {}
d[s] , d[t] = map(int, input().split())
d[input()]-=1
for i in d.values(): print(i, end = ' ')
|
n, x, m = [int(x) for x in input().split()]
A = [x]
while len(A) < n:
a = (A[-1] * A[-1]) % m
if a not in A:
A.append(a)
else:
i = A.index(a)
loop_len = len(A) - i
print(sum(A[:i]) + sum(A[i:]) * ((n - i) // loop_len) + sum(A[i:i + ((n - i) % loop_len)]))
break
else:
print(sum(A))
| 0 | null | 37,585,797,225,688 | 220 | 75 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
a = LIST()
q = INT()
count = [0]*(10**5+1)
for x in a:
count[x] += 1
ans = 0
for i in range(10**5+1):
ans += i * count[i]
for i in range(q):
b, c = MAP()
ans += (c - b) * count[b]
count[c] += count[b]
count[b] = 0
print(ans)
|
r = int(input())
a = (44/7)*r
print(a)
| 0 | null | 21,658,467,570,090 | 122 | 167 |
numz = input()
count = 0
numz_pair = numz.split(" ")
numz_pair = list(map(int, numz_pair))
for i in range(len(numz_pair)):
if numz_pair[i] <= 9:
count = count + 1
else:
print(-1)
break
if count == len(numz_pair):
print(numz_pair[0]*numz_pair[1])
|
import math
import fpformat
r=0.0
r=input()
print fpformat.fix(r*r*math.pi,6),fpformat.fix(r*2*math.pi,6)
| 0 | null | 79,079,992,359,368 | 286 | 46 |
n = int(input())
s = set()
for i in range(n):
a,b = input().strip().split()
if a == 'insert':
s.add(b)
if a == 'find':
if b in s:
print('yes')
else:
print('no')
|
n = int(input())
a,b = map(int, input().split())
F = True
while a<=b:
if a%n == 0:
print('OK')
F = False
break
a += 1
if F:
print('NG')
| 0 | null | 13,297,801,351,902 | 23 | 158 |
n = int(input())
p = [input().split() for i in range(n)]
x = input()
ans = 0
f = False
for l in p:
if f:
ans+=int(l[1])
if l[0]==x:
f = True
print(ans)
|
N = int(input())
music = []
for _ in range(N):
s, t = map(str, input().split())
music.append([s, int(t)])
number = input()
ans = 0
flag = False
for i in range(N):
if flag:
ans += music[i][1]
elif number == music[i][0]:
flag = True
print(ans)
| 1 | 96,954,943,944,650 | null | 243 | 243 |
from functools import reduce
N = int(input())
A = [int(x) for x in input().split()]
SUM=reduce(lambda a, b: a^b, A)
[print(SUM^A[i]) for i in range(N)]
|
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
A = list(ma())
tot = 0
for a in A:
tot = tot^a
ans = []
for a in A:
ans.append(tot^a)
print(*ans)
| 1 | 12,445,925,429,444 | null | 123 | 123 |
combined = input().split(" ")
s = int(combined[0])
w = int(combined[1])
if w >= s:
print("unsafe")
else:
print("safe")
|
N = int(input())
music_list = [input().split(' ') for i in range(N)]
X = input()
sleep_switch = False
total_time = 0
for music in music_list:
if not sleep_switch:
if music[0] == X:
sleep_switch = True
else:
total_time += int(music[1])
print(total_time)
| 0 | null | 63,018,561,566,322 | 163 | 243 |
num = int(input())
s = list(map(int, input().split()))
cnt = 0
def merge(A, left, mid, right):
global cnt
L = A[left:mid] + [10**9 + 1]
R = A[mid:right] + [10**9 + 1]
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += right - left
def merge_sort(A, left, right):
if (left + 1) < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(s, 0, num)
print(*s)
print(cnt)
|
def main():
s=input()
ans=0
for i in range(0,int(len(s)/2)):
if s[i]!=s[-1*(i+1)]:
ans+=1
print(ans)
main()
| 0 | null | 59,786,624,515,892 | 26 | 261 |
from sys import stdin, stdout
n, m = map(int, stdin.readline().strip().split())
if m>=n:
print('unsafe')
else:
print('safe')
|
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def main():
N=ii()
up = []
down = []
for _ in range(N):
S = input()
h = 0
b = 0
for s in S:
if s=='(':
h += 1
else:
h -= 1
b = min(b, h)
#
if h>=0:
up.append((h, b))
else:
down.append((h, b))
#
up.sort(key=lambda t: t[1], reverse=True)
down.sort(key=lambda t: t[0]-t[1], reverse=True)
H = 0
for h, b in up:
if H+b>=0:
H += h
else:
print(No)
return
for h, b in down:
if H+b>=0:
H += h
else:
print(No)
return
#
if H == 0:
print(Yes)
else:
print(No)
main()
| 0 | null | 26,414,144,743,060 | 163 | 152 |
def main() :
n = int(input())
lst = [int(i) for i in input().split()]
print(" ".join(map(str, lst)));
for i in range(1,n) :
for j in reversed(range(i+1)) :
if j == 0 :
break
elif lst[j] < lst[j-1]:
lst[j], lst[j-1] = lst[j-1], lst[j]
print(" ".join(map(str, lst)))
if __name__ == '__main__' :
main()
|
import sys
input = sys.stdin.readline
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort()
ans = 0
if N & 1:
l = AB[N//2][0]
AB.sort(key=lambda x: x[1])
ans = AB[N // 2][1] - l + 1
else:
l = (AB[N // 2][0], AB[N // 2 - 1][0])
AB.sort(key=lambda x: x[1])
r = (AB[N // 2][1], AB[N // 2 - 1][1])
ans = sum(r) - sum(l) + 1
print(ans)
| 0 | null | 8,711,554,962,136 | 10 | 137 |
import numpy as np
from numba import njit
@njit
def f(a):
n = len(a)
cnt = 0
for i in range(n):
for j in range(i + 1, n):
for k in range(j + 1, n):
if a[k] < a[i] + a[j]:
cnt += 1
return cnt
n = int(input())
a = np.array(input().split(), dtype=np.int32)
a.sort()
print(f(a))
|
import sys
input = sys.stdin.readline
# D - Triangles
def binary_search(i, j):
global N
left = j
right = N
while right - left > 1:
mid = (left + right) // 2
if is_match(mid, i, j):
left = mid
else:
right = mid
return left
def is_match(mid, i, j):
global L
a = L[i]
b = L[j]
c = L[mid]
if b < c + a and c < a + b:
return True
else:
return False
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
k = binary_search(i, j)
if k > j and k < N:
ans += k - j
print(ans)
| 1 | 171,777,729,144,714 | null | 294 | 294 |
h,w,k = map(int,input().split())
s = [list(map(int,input())) for _ in range(h)]
ans = h*w
for div in range(1<<(h-1)):
row = 0
S = [[0]*w]
S[row] = [s[0][i] for i in range(w)]
for i in range(1,h):
if 1&(div>>i-1):
row += 1
S.append([s[i][j] for j in range(w)])
else:
S[row] = [S[row][j]+s[i][j] for j in range(w)]
count = [0]*(row+1)
ans_ = row
a = True
for i in range(w):
for j in range(row+1):
if S[j][i] > k:
a = False
break
count[j] += S[j][i]
if count[j] > k:
ans_+=1
count = [0]*(row+1)
for l in range(row+1):
count[l] += S[l][i]
break
if ans_ >= ans or a==False:
break
if a:
ans = min(ans,ans_)
print(ans)
|
i = 1
a = []
while True:
x = input()
if x == 0:
break
a.append(x)
for i in range(len(a)):
print 'Case ' + str(i+1) + ': ' + str(a[i])
| 0 | null | 24,321,805,649,170 | 193 | 42 |
def gcd(aa,bb):
while bb!=0:
r=bb
bb=aa%bb
aa=r
return aa
a,b=map(int,raw_input().strip().split())
#print a,b
print gcd(a,b)
|
a,b=sorted(list(map(int, input().split())))
m=b%a
while m>=1:
b=a
a=m
m=b%a
print(a)
| 1 | 7,917,779,750 | null | 11 | 11 |
MAX_ARRAY_SIZE = 100000
class Queue:
array = [None] * MAX_ARRAY_SIZE
start = end = 0
def enqueue(self, a):
assert not self.isFull(), "オーバーフローが発生しました。"
self.array[self.end] = a
if self.end + 1 == MAX_ARRAY_SIZE:
self.end = 0
else:
self.end += 1
def dequeue(self):
assert not self.isEmpty(), "アンダーフローが発生しました。"
if (self.start + 1) == MAX_ARRAY_SIZE:
self.start = 0
return self.array[MAX_ARRAY_SIZE - 1]
else:
self.start += 1
return self.array[self.start - 1]
def isEmpty(self):
return self.start == self.end
def isFull(self):
return self.start == (self.end + 1) % MAX_ARRAY_SIZE
n, q = list(map(lambda x: int(x), input().strip().split()))
queue = Queue()
for i in range(n):
queue.enqueue(input().strip().split())
sum_time = 0
while not queue.isEmpty():
name, time = queue.dequeue()
if int(time) <= q:
sum_time += int(time)
print(name + ' ' + str(sum_time))
else:
queue.enqueue([name, str(int(time) - q)])
sum_time += q
|
def koch(d,p0,p1):
#終了条件
if d == n:
return
#内分点:s,t
s=[(2*p0[0]+p1[0])/3,(2*p0[1]+p1[1])/3]
t=[(2*p1[0]+p0[0])/3,(2*p1[1]+p0[1])/3]
#正三角形の頂点:u
u=[(p0[0]+p1[0])/2-(p1[1]-p0[1])*(3**(1/2)/6),(p1[1]+p0[1])/2+(p1[0]-p0[0])*(3**(1/2)/6)]
koch(d+1,p0,s)
print(*s)
# point.append(s)
koch(d+1,s,u)
print(*u)
# point.append(u)
koch(d+1,u,t)
print(*t)
# point.append(t)
koch(d+1,t,p1)
p0=[0,0]
p1=[100,0]
n=int(input())
print(*p0)
koch(0,p0,p1)
print(*p1)
| 0 | null | 87,147,199,640 | 19 | 27 |
n,a,b=map(int,input().split())
print(min(n%(a+b),a)+n//(a+b)*a)
|
N, A, B = map(int, input().split())
ans = 0
roop = int(N / (A + B))
# print(roop)
padding = N % (A + B)
if padding >= A:
ans += roop * A + A
else:
ans += roop * A + padding
print(ans)
| 1 | 55,471,220,271,420 | null | 202 | 202 |
# https://atcoder.jp/contests/abc145/tasks/abc145_d
X, Y = list(map(int, input().split()))
MOD = int(1e9 + 7)
def combination(n, r, mod=MOD):
def modinv(a, mod=MOD):
return pow(a, mod-2, mod)
# nCr with MOD
r = min(r, n - r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
# 1回の移動で3増えるので,X+Yは3の倍数 (0, 0) start
if (X + Y) % 3 != 0:
ans = 0
print(0)
else:
# X+Yは3の倍数
# (+1, +2)をn回,(+2, +1)をm回実行
# n + 2m = X
# 2n + m = Y
# 3 m = 2 X - Y
# m = (2 X - Y) // 3
# n = X - 2 * m
m = (2 * X - Y) // 3
n = X - 2 * m
if m < 0 or n < 0:
print(0)
else:
print(combination(m + n, m, MOD))
|
import math
I=list(map(int,input().split()))
X=(2*I[1]-I[0])//3
Y=(2*I[0]-I[1])//3
n=X+Y
r=X
if (X<0 or Y<0 or (I[0]+I[1])%3!=0):
print(0)
exit()
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
print(cmb(n, r, p))
| 1 | 150,196,703,852,380 | null | 281 | 281 |
A, B = map(str, input().split())
A=int(A)
B=int(B[0]+B[2]+B[3])
print(A*B//100)
|
from decimal import *
import math
a, b = map(str, input().split())
print(math.floor(Decimal(a)*Decimal(b)))
| 1 | 16,524,485,177,648 | null | 135 | 135 |
from collections import deque
def bfs(s):
visit[i] = 1
q = deque()
q.append(s)
while q:
p = q.popleft()
for j in G[p]:
if not visit[j]:
visit[j] = 1
q.append(j)
return
n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
G[a].append(b)
G[b].append(a)
visit = [0] * (n + 1)
ans = -1
for i in range(1, n + 1):
if not visit[i]:
bfs(i)
ans += 1
print(ans)
|
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = map(int, input().split())
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def bfs(cnt, lis):
nextvisit = []
for j in lis:
for item in nextcity[j]:
if sgn[item] == 0:
nextvisit.append(item)
sgn[item] = cnt
if nextvisit:
bfs(cnt, nextvisit)
return None
else:
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
bfs(cnt, [k])
print(cnt -1)
| 1 | 2,293,198,092,592 | null | 70 | 70 |
H = int(input())
W = int(input())
N = int(input())
longer = H
if longer < W:
longer = W
print(((N-1)//longer)+1)
|
h,w,n = int(input()),int(input()),int(input())
ans = 0
s = 0
while s < n:
s += max(h,w)
ans += 1
print(ans)
| 1 | 89,220,926,499,924 | null | 236 | 236 |
s = input()
t = input()
n = len(s) - len(t)
l = len(t)
res = 0
for i in range(n+1):
cnt = 0
for j in range(l):
if s[i+j] == t[j]:
cnt += 1
res = max(res, cnt)
print(l - res)
|
S=input()
T=input()
s=len(S)
t=len(T)
A=[]
for i in range(s-t+1):
word=S[i:i+t]
a=0
for j in range(t):
if word[j]==T[j]:
a+=1
else:
a+=0
A.append(t-a)
print(min(A))
| 1 | 3,709,052,581,888 | null | 82 | 82 |
def distance(x, y, p):
"""returns Minkowski's distance of vactor x and y if p > 0.
if p == 0, returns Chebyshev distance
>>> d = distance([1, 2, 3], [2, 0, 4], 1)
>>> print('{:.6f}'.format(d))
4.000000
>>> d = distance([1, 2, 3], [2, 0, 4], 2)
>>> print('{:.6f}'.format(d))
2.449490
>>> d = distance([1, 2, 3], [2, 0, 4], 3)
>>> print('{:.6f}'.format(d))
2.154435
>>> d = distance([1, 2, 3], [2, 0, 4], 0)
>>> print('{:.6f}'.format(d))
2.000000
"""
if p == 0:
return max([abs(a-b) for (a, b) in zip(x, y)])
else:
return sum([abs(a-b) ** p for (a, b) in zip(x, y)]) ** (1/p)
def run():
dim = int(input()) # flake8: noqa
x = [int(i) for i in input().split()]
y = [int(j) for j in input().split()]
print(distance(x, y, 1))
print(distance(x, y, 2))
print(distance(x, y, 3))
print(distance(x, y, 0))
if __name__ == '__main__':
run()
|
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
def main():
N, K = ril()
A = ril()
l = 1
r = 1000000000
while l < r:
m = (l + r) // 2
k = 0
for a in A:
k += (a - 1) // m
if k <= K:
r = m
else:
l = m + 1
print(r)
if __name__ == '__main__':
main()
| 0 | null | 3,327,539,967,918 | 32 | 99 |
a = list(map(int, input().split()))
for i in range(1,len(a)):
v = a[i]
j = i - 1
while j >= 0 and a[j] > v:
a[j+1] = a[j]
j -= 1
a[j+1] = v
print("{} {} {}".format(a[0],a[1],a[2]))
|
N = int(input())
ans = [0] * (N + 1)
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 100):
n = x**2 + y**2 + z**2 + x*y + y*z + z*x
if n <= N:
ans[n] += 1
print(*ans[1:], sep="\n")
| 0 | null | 4,206,375,885,668 | 40 | 106 |
import math
x1,y1,x2,y2=map(float,input().split())
print(round(math.sqrt((x1-x2)**2+(y1-y2)**2),7))
|
N = int(input())
lis = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
def dfs(ans, keep, n):
if n == N + 1:
print(ans)
else:
for i in range(keep):
dfs(ans + lis[i], max(keep, i + 2), n + 1)
dfs('', 1, 1)
| 0 | null | 26,191,008,897,568 | 29 | 198 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.