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
|
---|---|---|---|---|---|---|
dict = {}
n = int(raw_input())
for _ in xrange(n):
com, word = raw_input().split()
if com == "insert":
dict[word] = True
else:
if word in dict:
print "yes"
else:
print "no"
|
n = int(input())
D = set()
for _ in range(n):
q, s = map(str, input().split())
if q == 'insert':
D.add(s)
elif q == 'find':
if s in D:
print('yes')
else:
print('no')
| 1 | 78,261,899,870 | null | 23 | 23 |
import math
import sys
readline = sys.stdin.readline
def main():
h1, m1, h2, m2, k = map(int, readline().rstrip().split())
print((max(0, (h2 - h1) * 60 + (m2 - m1) - k)))
if __name__ == '__main__':
main()
|
(r1,g1,b1)=input().split()
(r,g,b)=(int(r1),int(g1),int(b1))
k=int(input())
flg=0
for i in range(k):
if not g > r :
g *= 2
elif not b > g:
b *= 2
if ( b > g > r):
print ("Yes")
else:
print ("No")
| 0 | null | 12,432,324,782,640 | 139 | 101 |
def mlt(): return map(int, input().split())
x, a, b = mlt()
dp = [0 for n in range(x)]
for n in range(1, x+1):
for k in range(n+1, x+1):
d1 = k-n
d2 = abs(a-n)+1+abs(b-k)
ds = min(d1, d2)
dp[ds] += 1
print(*dp[1:], sep='\n')
|
n,k=map(int,input().split())
def find_power(n,mod):
# 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである)
powlist=[0]*(n+1)
powlist[0]=1
powlist[1]=1
for i in range(2,n+1):
powlist[i]=powlist[i-1]*i%(mod)
return powlist
def find_inv_power(n):
#0!からn!までの逆元を素数10**9+7で割ったあまりリストを作る関数
powlist=find_power(n,10**9+7)
check=powlist[-1]
first=1
uselist=[0]*(n+1)
secondlist=[0]*30
secondlist[0]=check
secondlist[1]=check**2
for i in range(28):
secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
a=format(10**9+5,"b")
for j in range(30):
if a[29-j]=="1":
first=(first*secondlist[j])%(10**9+7)
uselist[n]=first
for i in range(n,0,-1):
uselist[i-1]=(uselist[i]*i)%(10**9+7)
return uselist
mod=10**9+7
a=find_power(4*10**5+100,mod)
b=find_inv_power(4*10**5+100)
def combi(n,r,mod):
if n<r:
return 0
elif n>=r:
return (a[n]*b[r]*b[n-r])%(mod)
if n<=k:
K=combi(2*n-1,n-1,mod)
print(K)
else:
K=combi(2*n-1,n-1,mod)
for i in range(k+1,n):
K-=combi(n-1,n-i-1,mod)*combi(n,i,mod)
print(K%mod)
| 0 | null | 55,789,273,676,752 | 187 | 215 |
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
ans = 0
di = defaultdict(int)
for i, a in enumerate(A):
ans += di[i+1 - a]
di[i+1 + a] += 1
print(ans)
|
import bisect
def main2():
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(len(L) - 2):
for j in range(i + 1, len(L) - 1):
ab = L[i] + L[j]
r = bisect.bisect_left(L, ab)
l = j + 1
ans += r - l
print(ans)
if __name__ == "__main__":
main2()
| 0 | null | 99,058,045,012,928 | 157 | 294 |
c=input().split(" ")
print(c[1]+c[0])
|
import sys
S,T = input().split()
if not ( S.islower() and T.islower() ): sys.exit()
if not ( 1 <= len(S) <= 100 and 1 <= len(S) <= 100 ): sys.exit()
print(T,S,sep='')
| 1 | 103,220,079,083,106 | null | 248 | 248 |
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------
n, a, b = inpl()
l = n // (a + b)
m = n % (a + b)
print(a * l + min(m, a))
# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)
|
s = input()
n = len(s)
kotae = "x"*n
print(kotae)
| 0 | null | 64,282,636,773,680 | 202 | 221 |
N, K = map(int, input().split())
A = list()
for i in range(K):
input()
A.extend(list(map(int, input().split())))
print(N - len(set(A)))
|
n, k = map(int, input().split())
treat_array = [0]*n
for i in range(k):
d = int(input())
for j in map(int, input().split()):
treat_array[j-1] += 1
ans = 0
for i in range(n):
if treat_array[i] == 0:
ans += 1
print(ans)
| 1 | 24,592,319,598,788 | null | 154 | 154 |
n = int(input())
a = list(map(int, input().split()))
p = sorted([(x, i) for i, x in enumerate(a)], reverse=True)
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for s in range(1, n+1):
for x in range(s+1):
y = s-x
if x > 0:
dp[x][y] = max(dp[x][y], dp[x-1][y] + abs(p[s-1][1] - x + 1) * p[s-1][0])
if y > 0:
dp[x][y] = max(dp[x][y], dp[x][y-1] + abs(n-y - p[s-1][1]) * p[s-1][0])
print(max(dp[x][n-x] for x in range(n+1)))
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
N = int(input())
A = [(i, v) for i, v in enumerate(map(int, input().split()))]
values = [[0] * (N + 1) for _ in range(N + 1)]
A.sort(key=lambda x:-x[1])
for i, (p, v) in enumerate(A):
for j in range(i + 1):
left = abs((p - j) * v)
right = abs((N - 1 - (i - j) - p) * v)
values[i + 1][j + 1] = max(values[i][j] + left, values[i + 1][j + 1])
values[i + 1][j] = max(values[i][j] + right, values[i + 1][j])
print(max(values[-1]))
if __name__ == '__main__':
main()
| 1 | 33,481,742,756,252 | null | 171 | 171 |
from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
x = [0] * (N + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
y = [(x[i] - i) % K for i in range(N + 1)]
ctr = defaultdict(int)
ans = 0
for j in range(N + 1):
ans += ctr[y[j]]
ctr[y[j]] += 1
if j - K + 1 >= 0:
ctr[y[j - K + 1]] -= 1
print(ans)
|
import collections
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
d = collections.defaultdict(int)
prefix = [0]
for i in range(N):
prefix.append(prefix[-1] + A[i])
ans = 0
for j in range(N+1):
v = (prefix[j] - j) % K
ans += d[v]
d[v] += 1
if j >= K-1:
d[(prefix[j-K+1] - (j-K+1)) % K] -= 1
# print(ans)
return ans
if __name__ == '__main__':
print(main())
| 1 | 137,736,702,706,472 | null | 273 | 273 |
N = int(input())
stone = input()
R = stone.count('R')
ans = stone.count('W', 0, R)
print(ans)
|
# -*- coding: utf-8 -*-
import sys
def main():
N = int( sys.stdin.readline() )
c_list = list(sys.stdin.readline().rstrip())
num_R = c_list.count("R")
cnt = 0
for i in range(num_R):
if c_list[i] == "W":
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 1 | 6,300,466,990,276 | null | 98 | 98 |
A = []
for i in range(3):
A.append(list(map(int, input().split())))
B = [[0 for i in range(3)] for j in range(3)]
N = int(input())
for i in range(N):
b = int(input())
for j in range(3):
for k in range(3):
if A[j][k] == b:
B[j][k] = 1
c = []
for i in range(3):
c.append(B[i][0] & B[i][1] & B[i][2])
c.append(B[0][i] & B[1][i] & B[2][i])
c.append(B[0][0] & B[1][1] & B[2][2])
c.append(B[0][2] & B[1][1] & B[2][0])
if sum(c) > 0:
print("Yes")
else:
print("No")
|
#!/usr/bin/env python3
from pprint import pprint
import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
n = int(input())
x = input()
x_pc = x.count('1')
x_pc_plus = x_pc + 1
x_pc_minus = x_pc - 1
# 2 ** i % x_pc_plus, 2 ** i % x_pc_minus を予め計算しておく
r_plus_list = [pow(2, i, x_pc_plus) for i in range(n+1)]
r_minus_list = [0] * (n+1)
if x_pc_minus > 0:
r_minus_list = [pow(2, i, x_pc_minus) for i in range(n+1)]
x = x[::-1]
r_plus = 0
r_minus = 0
for i in range(n):
if x[i] == '1':
r_plus += r_plus_list[i]
r_minus += r_minus_list[i]
for i in range(n-1, -1, -1):
if x[i] == '0':
diff = (r_plus + r_plus_list[i]) % x_pc_plus
elif x_pc_minus >= 1:
diff = (r_minus - r_minus_list[i]) % x_pc_minus
else:
print(0)
continue
ans = 1
while diff > 0:
diff = diff % bin(diff).count('1')
ans += 1
print(ans)
| 0 | null | 34,158,317,907,030 | 207 | 107 |
a,b= input().split()
print(str(min(int(a),int(b)))*int(str(max(int(a),int(b)))))
|
# coding: utf-8
a, b = input().split()
aaa = ""
bbb = ""
for i in range(int(b)):
aaa += a
for i in range(int(a)):
bbb += b
if aaa > bbb:
print(bbb)
else:
print(aaa)
| 1 | 84,165,081,942,172 | null | 232 | 232 |
haveTrumps = [[0 for i in range(13)] for j in range(4)]
allCards = int(input())
for i in range(0, allCards):
cardType, cardNum = input().split()
if cardType == "S":
haveTrumps[0][int(cardNum) - 1] = 1
elif cardType == "H":
haveTrumps[1][int(cardNum) - 1] = 1
elif cardType == "C":
haveTrumps[2][int(cardNum) - 1] = 1
elif cardType == "D":
haveTrumps[3][int(cardNum) - 1] = 1
for i in range(0, 4):
for j in range(0, 13):
if haveTrumps[i][j] == 0:
if i == 0:
print("S ", end="")
elif i == 1:
print("H ", end="")
elif i == 2:
print("C ", end="")
elif i == 3:
print("D ", end="")
print("{0}".format(j + 1))
|
import sys
#f = open("test.txt", "r")
f = sys.stdin
num_rank = 14
s_list = [False] * num_rank
h_list = [False] * num_rank
c_list = [False] * num_rank
d_list = [False] * num_rank
n = f.readline()
n = int(n)
for i in range(n):
[suit, num] = f.readline().split()
num = int(num)
if suit == "S":
s_list[num] = True
elif suit == "H":
h_list[num] = True
elif suit == "C":
c_list[num] = True
else:
d_list[num] = True
for i in range(1, num_rank):
if not s_list[i]:
print("S " + str(i))
for i in range(1, num_rank):
if not h_list[i]:
print("H " + str(i))
for i in range(1, num_rank):
if not c_list[i]:
print("C " + str(i))
for i in range(1, num_rank):
if not d_list[i]:
print("D " + str(i))
| 1 | 1,034,056,998,400 | null | 54 | 54 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M = map(int, readline().split())
ans = (N + M) * (N + M - 1) // 2 - N * M
print(ans)
return
if __name__ == '__main__':
main()
|
all = [x for x in range(1,53)]
N = int(input())
i = 1
while i <= N:
M, num = input().split()
num = int(num)
if M == 'S':
all.remove(num)
elif M == 'H':
all.remove(num+13)
elif M == 'C':
all.remove(num+26)
elif M == 'D':
all.remove(num+39)
i += 1
sN = 52 - N
for j in range(sN):
if all[j] // 13 == 0 or (all[j] // 13 == 1 and all[j] % 13 == 0):
print("S {}".format(all[j]))
elif all[j] // 13 == 1 or (all[j] // 13 == 2 and all[j] % 13 == 0):
print("H {}".format(all[j]-13))
elif all[j] // 13 == 2 or (all[j] // 13 == 3 and all[j] % 13 == 0):
print("C {}".format(all[j]-26))
else:
print("D {}".format(all[j]-39))
| 0 | null | 23,201,326,134,802 | 189 | 54 |
import math
H = int(input())
l = math.log(H,2)
ll = math.floor(l)+1
ans = 2 ** ll -1
print(ans)
|
def main():
s, w = map(int, input().split(" "))
if s <= w:
print("unsafe")
else:
print("safe")
if __name__ == "__main__":
main()
| 0 | null | 54,720,483,737,920 | 228 | 163 |
a, b = map(int,input().split())
if a > b:
a, b = b, a
print(str(a) * b)
|
N,M = map(int,input().split())
print((str(N)*M,str(M)*N)[N > M])
| 1 | 84,263,425,844,926 | null | 232 | 232 |
def main():
mod=998244353
n,k=map(int,input().split())
region=[]
for _ in range(k):
a,b=map(int,input().split())
region.append((a,b))
#dp[i]はマスiに行く方法の個数
#workにdp[i-1]からの増減分を保持
dp=[0]*(n+1)
work=[0]*(n+1)
#initialize
for j in region:
if 1+j[0]<=n:
work[1+j[0]]+=1
if 1+j[1]+1<=n:
work[1+j[1]+1]-=1
for i in range(2,n+1):
dp[i]=dp[i-1]+work[i]
dp[i]%=mod
for j in region:
if i+j[0]<=n:
work[i+j[0]]+=dp[i]
work[i+j[0]]%=mod
if i+j[1]+1<=n:
work[i+j[1]+1]-=dp[i]
work[i+j[1]+1]%=mod
print(dp[n])
main()
|
M=998244353
f=lambda:[*map(int,input().split())]
n,k=f()
lr=[f() for _ in range(k)]
dp=[0]*n
dp[0]=1
S=[0]
for i in range(1,n):
S+=[S[-1]+dp[i-1]]
for l,r in lr:
dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)]
dp[i]%=M
print(dp[-1])
| 1 | 2,738,244,179,200 | null | 74 | 74 |
N = int(input())
S = [input() for _ in range(N)]
res = {}
for s in S:
if s in res:
res[s] += 1
else:
res[s] = 1
max_ = max(res.values())
ans = []
for k in res:
if res[k] == max_:
ans.append(k)
ans.sort()
for a in ans:
print(a)
|
n = int(input())
memo = {}
for _ in range(n):
s = input()
try:
memo[s] += 1
except KeyError:
memo[s] = 1
m = max(memo.values())
print(*sorted([ i for i, j in memo.items() if j == m]), sep='\n')
| 1 | 70,301,219,682,890 | null | 218 | 218 |
N=int(input())
DP=[0]*(N+1)
def fin(n):
if DP[n]!=0:
return DP[n]
if n<=1:
DP[n]=1
return DP[n]
else:
DP[n]=fin(n-1)+fin(n-2)
return DP[n]
print(fin(N))
|
F = {}
def fib(n):
global F
if n < 0:
print("error")
exit()
if n < 2:
F[n] = 1
return F[n]
# F[n] = fib(n-1) + fib(n-2)
F[n] = F[n-1] + F[n-2]
return F[n]
n = int(input())
#print(fib(n))
#n = int(input())
#print(fib(n))
#fib(44)
for i in range(n+1):
result = fib(i)
print(result)
# print(F[i])
| 1 | 1,822,394,662 | null | 7 | 7 |
def resolve():
H, W, K = map(int, input().split())
G = [list(input()) for _ in range(H)]
ans = [[None] * W for _ in range(H)]
cnt = 1
for h in range(H):
for w in range(W):
if G[h][w] == "#":
ans[h][w] = cnt
cnt += 1
# 左から右
for h in range(H):
for w in range(1, W):
if ans[h][w] is None:
if ans[h][w - 1] is not None:
ans[h][w] = ans[h][w - 1]
# 右から左
for h in range(H):
for w in range(W - 1)[::-1]:
if ans[h][w] is None:
if ans[h][w + 1] is not None:
ans[h][w] = ans[h][w + 1]
# 上から下
for h in range(1, H):
for w in range(W):
if ans[h][w] is None:
ans[h][w] = ans[h - 1][w]
# 下から上
for h in range(H - 1)[::-1]:
for w in range(W):
if ans[h][w] is None:
if ans[h + 1][w] is not None:
ans[h][w] = ans[h + 1][w]
for h in range(H):
print(*ans[h])
if __name__ == "__main__":
resolve()
|
H,W,K = map(int,input().split())
s=[list(input()) for i in range(H)]
area=[[0 for _ in range(W)] for _ in range(H)]
st_num=[0]*H
st_pos=[[] for _ in range(H)]
for i in range(H):
for j in range(W):
if s[i][j]=="#":
st_num[i] += 1
st_pos[i].append(j)
upper=0
cnt=0
for i in range(H):
if st_num[i]==0:
upper=min(upper,i)
else:
cnt+=1
#左の余白
if st_pos[i][0]>0:
for p in range(upper,i+1):
for q in range(st_pos[i][0]):
area[p][q]=cnt
#左端のいちごから右端のいちご左まで
for j in range(st_num[i]-1):
for p in range(upper,i+1):
for q in range(st_pos[i][j],st_pos[i][j+1]):
area[p][q]=cnt
cnt+=1
#右端のいちごから右
for p in range(upper,i+1):
for q in range(st_pos[i][-1],W):
area[p][q]=cnt
upper = i+1
if upper!=H: #下端のいちごよりも下の領域
for p in range(upper,H):
for q in range(W):
area[p][q]=area[upper-1][q]
for i in area:
print(*i)
| 1 | 144,330,719,890,528 | null | 277 | 277 |
a, b = map(int, input().split())
def base10to(n, b):
if (int(n/b)):
return base10to(int(n/b), b) + str(n%b)
return str(n%b)
print(len(base10to(a,b)))
|
K=int(input())
x=7
c=1
visited={7}
while x%K:
x*=10
x+=7
x%=K
c+=1
z=x%K
if z in visited:
print(-1)
exit()
visited.add(x%K)
print(c)
| 0 | null | 35,154,660,298,628 | 212 | 97 |
import sys
n = int(input())
for i in range(1,10):
for j in range(1,10):
if i * j == n :
print('Yes')
sys.exit()
print('No')
|
n,a,b=map(int,input().split())
mod=10**9+7
def power_func(a,n,mod):
bi=str(format(n,"b"))
res=1
for i in range(len(bi)):
res=(res*res)%mod
if bi[i]=='1':
res=(res*a)%mod
return res
def cmb1(x,y,mod):
l=1
for g in range(x+1-y,x+1):
l*=g
l%=mod
for k in range(1,y+1):
l*=power_func(k,mod-2,mod)
l%=mod
return l
return ans
ans=power_func(2,n,mod)-1
ans1=cmb1(n,a,mod)
ans2=cmb1(n,b,mod)
print((ans-ans1-ans2)%mod)
| 0 | null | 112,459,660,128,832 | 287 | 214 |
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,k = ma()
A = lma()
s = [0]*(n+1)
l = [0]*(n+1)
for i in range(n):
s[i+1]=(s[i]+A[i])%k
l[i+1]=(s[i+1]-(i+1))%k
ans = 0
co = collections.Counter(l[:min(n+1,k)])
for num,cnt in co.items():
ans+=cnt*(cnt-1)//2
for i in range(k,n+1):
co[l[i-k]]-=1
ans+=co[l[i]]
co[l[i]]+=1
print(ans)
|
import bisect
def solve(n, k, a):
s = [0] * (n+1)
for i in range(n):
s[i+1] = s[i] + a[i]
D = {}
for i in range(n+1):
p = (s[i] - i) % k
if not p in D:
D[p] = []
D[p].append(i)
res = 0
for vs in D.values():
m = len(vs)
for j, vj in enumerate(vs):
i = bisect.bisect_left(vs, vj+k) - 1
res += i - j
return res
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, k, a))
| 1 | 137,137,338,283,360 | null | 273 | 273 |
l = input().split()
print(l.index("0") + 1)
|
from itertools import accumulate
n = int(input())
song= []
time = []
for i in range(n):
s, t = input().split()
song.append(s)
time.append(int(t))
time_acc = list(accumulate(time))
x = input()
print(time_acc[n - 1] - time_acc[song.index(x)])
| 0 | null | 55,040,748,077,458 | 126 | 243 |
def resolve():
N = int(input())
X = input()
if N == 1:
if X.count("1"):
print(0)
else:
print(1)
return True
base_1_count = X.count("1")
if base_1_count == 0:
for _ in range(N):
print(1)
return True
X_int = int(X, 2)
X_int_p = X_int%(base_1_count + 1)
# RE 対策
if base_1_count == 1:
for i in range(N):
if X[i] == "1":
print(0)
else:
if i == N - 1:
Xi = X_int_p + 1
else:
Xi = X_int_p
count = 1
while Xi != 0:
Xi %= bin(Xi).count("1")
count += 1
print(count)
return True
X_int_m = X_int%(base_1_count - 1)
for i in range(N):
# 初期値計算を高速にやる
if X[i] == "1":
temp_1_count = base_1_count-1
pow_2 = pow(2, N-i-1, base_1_count-1)
if X_int_m <= pow_2:
Xi = X_int_m - pow_2 + base_1_count-1
else:
Xi = X_int_m - pow_2
else:
temp_1_count = base_1_count+1
Xi = X_int_p + pow(2, N-i-1, base_1_count+1)
while Xi >= base_1_count+1:
Xi %= base_1_count+1
# print("1_c={0}".format(temp_1_count))
if temp_1_count == Xi:
print(1)
continue
count = 1
while Xi != 0:
num_of_1 = bin(Xi).count("1")
Xi %= num_of_1
count += 1
print(count)
if __name__ == "__main__":
resolve()
|
import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
def fast_expo(x,y,m):
res=1
while(y):
if(y&1):
res*=x
res%=m
x*=x
x%=m
y>>=1
return res
dp=defaultdict(int)
dp[1]=1
dp[2]=1
for i in range(3,200001):
k=i
cnt=0
while(k):
if(k%2): cnt+=1
k>>=1
dp[i]=dp[i%cnt]+1
n=ii()
a=ip()
a=a[::-1]
c=a.count('1')
min_1=0
max_1=0
for i in range(n):
if(a[i]=='1'):
if(c-1!=0):
min_1+=fast_expo(2,i,c-1)
min_1%=(c-1)
max_1+=fast_expo(2,i,c+1)
max_1%=(c+1)
ans=[]
for i in range(n):
if(a[i]=='1'):
if(c-1==0):
ans.append(0)
else:
ans.append(dp[(min_1-fast_expo(2,i,c-1)+(c-1))%(c-1)]+1)
else:
ans.append(dp[(max_1+fast_expo(2,i,c+1))%(c+1)]+1)
ans=ans[::-1]
for i in ans:
print(i)
| 1 | 8,251,280,390,888 | null | 107 | 107 |
n,k = map(int,input().split())
li = []
for i in range(k) :
gomi = input()
[li.append(int(j)) for j in input().split()]
st = set(li)
print(n - len(st))
|
N, K = map(int, input().split())
people = []
for i in range(K):
_ = input()
a = list(map(int, input().split()))
people += a
print(N - len(set(people)))
| 1 | 24,688,037,047,388 | null | 154 | 154 |
n = input()
K = int(input())
L = len(n)
dp = [[[0] * (K + 2) for _ in range(2)] for __ in range(L + 1)]
dp[0][1][0] = 1
for i in range(L):
d = int(n[i])
for j in [0, 1]:
for k in range(K + 1):
if j == 0:
dp[i + 1][j][k] += dp[i][j][k]
dp[i + 1][j][k + 1] += dp[i][j][k] * 9
else:
if d > 0:
dp[i + 1][0][k] += dp[i][j][k]
dp[i + 1][0][k + 1] += dp[i][j][k] * (d - 1)
dp[i + 1][1][k + 1] += dp[i][j][k]
else:
dp[i + 1][1][k] += dp[i][j][k]
print(dp[L][0][K] + dp[L][1][K])
|
N = int(input())
S = str(N)
m = len(S)
K = int(input())
#dp[i][j][k]: 上からi桁目までに0以外がj個あって、Nと一致しているならばk=0
dp = [[[0] * 2 for _ in range(4)] for _ in range(m+1)]
dp[0][0][0] = 1
for i in range(m): #i=0は架空の桁に相当。
for j in range(4):
for k in range(2):
#dp[i][j][k]という状態が次の桁でどこに遷移するかを考える。遷移先のni,nj,nkを決定する。
nd = int(S[i]) #Nのi桁目。1桁目はS[0]。
for d in range(10): #dというのが今の桁(i+1)の値
ni = i+1 #今の桁
nj = j
nk = k
if d != 0: #もし今の桁が0でなければjは一つ増える。
nj += 1
if nj > K: #もしnjが許容値のKを超えたら無視。
continue
if k == 0: #ここまで完全一致の時
if d > nd: #今の桁がNのi桁目より大きいつまりNを超えているので無視。
continue
elif d < nd: #今の桁がNのi桁目より小さいなら完全一致ではないのでnk=1と変更。
nk = 1
dp[ni][nj][nk] += dp[i][j][k]
ans = dp[m][K][0] + dp[m][K][1]
print(ans)
| 1 | 76,147,758,225,862 | null | 224 | 224 |
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
A, B = map(int, input().split())
print(int(A*B))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
|
import sys
input = sys.stdin.readline
A,B = list(map(int,input().split()))
print(A*B)
| 1 | 15,805,256,529,594 | null | 133 | 133 |
thp, tak, ahp, aak = map(int, input().split())
judge = 0
while thp > 0 and ahp > 0:
if judge == 0:
ahp -= tak
judge = 1
else:
thp -= aak
judge = 0
if thp <= 0:
print("No")
else:
print("Yes")
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque
def main():
a,b,c,d = map(int, input().split())
while True:
c -= b
if c<= 0:
print("Yes")
exit()
a -= d
if a <= 0:
print("No")
exit()
if __name__=="__main__":
main()
| 1 | 29,648,925,778,608 | null | 164 | 164 |
a,b=map(int, input().split())
c=list(map(int, input().split()))
l =[]
ans = 0
def abc(n):
return (n+1)/2
cb = list(map(abc,c))
s = sum(cb[:b])
l.append(s)
for i in range(b,a):
s = s - cb[i-b] + cb[i]
l.append(s)
L = sorted(l)
print(L[-1])
|
n, k = map(int,input().split())
p = list(map(int,input().split()))
mu = [(a+1)/2 for a in p]
maxsum = sum(mu[:k])
now = maxsum
left = 0
right = k
while right<n:
now = now+mu[right]-mu[left]
if maxsum<now:
maxsum = now
left += 1
right += 1
print(maxsum)
| 1 | 74,871,574,114,030 | null | 223 | 223 |
N = int(input())
if(N%1000 != 0):
print(1000-(N%1000))
else:print(0)
|
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
n = ini()
ans = n % 1000
print(0 if ans == 0 else 1000 - ans)
| 1 | 8,471,045,092,802 | null | 108 | 108 |
import numpy as np
import itertools as it
H,W,N = [int(i) for i in input().split()]
dat = np.array([list(input()) for i in range(H)], dtype=str)
emp_r = ["." for i in range(W)]
emp_c = ["." for i in range(H)]
def plot(dat, dict):
for y in dict["row"]:
dat[y,:] = emp_r
for x in dict["col"]:
dat[:,x] = emp_c
return dat
def is_sat(dat):
count = 0
for y in range(W):
for x in range(H):
if dat[x, y] == "#":
count += 1
if count == N:
return True
else:
return False
# def get_one_idx(bi, digit_num):
# tmp = []
# for j in range(digit_num):
# if (bi >> j) == 1:
# tmp.append()
# plot(dat, dict={"row": [], "col":[0, 1]})
combs = it.product([bin(i) for i in range(2**H-1)], [bin(i) for i in range(2**W-1)])
count = 0
for comb in combs:
rows = comb[0]
cols = comb[1]
rc_dict = {"row": [], "col": []}
for j in range(H):
if (int(rows, 0) >> j) & 1 == 1:
rc_dict["row"].append(j)
for j in range(W):
if (int(cols, 0) >> j) & 1 == 1:
rc_dict["col"].append(j)
dat_c = plot(dat.copy(), rc_dict)
if is_sat(dat_c):
count += 1
print(count)
|
h, w, k = map(int, input().split())
c = [list(input()) for i in range(h)]
ans = 0
for i in range(1 << h):
for j in range(1 << w):
black = 0
for x in range(h):
for y in range(w):
if (i >> x) & 1:
continue
if (j >> y) & 1:
continue
if c[x][y] == '#':
black += 1
if black == k:
ans += 1
print(ans)
| 1 | 9,015,336,558,172 | null | 110 | 110 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def inp():
return int(input())
def inps():
return input().rstrip()
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10
# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque
# ---------------------------------------
s = inps()
print("ARC" if s == "ABC" else "ABC")
|
print('A%sC'%'BR'[input()<'AR'])
| 1 | 24,163,041,384,020 | null | 153 | 153 |
N,K = map(int,input().split())
a = list(map(int,input().split()))
for i in range(1,N-K+1):
if a[K+i-1]>a[i-1]:
print("Yes")
else:
print("No")
|
from bisect import bisect_left
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
# a<b<c として、aとbを固定する
# 残る条件は c<a+b のみ
# aとbの固定方法がO(N^2), cの二分探索がO(logN)、結局O(N^2logN)
# 二分探索は事前にソートが必要
# ex. 2, 4(a), 4, 7(b), | 8, 9, 9 | (ここにa+b=11が挿入される), 12, 14
# cとして適切なのは8,9,9の3通り
# bisect_rightだとa+bが存在した時にバグる
for ai in range(n):
for bi in range(ai + 1, n):
ans += bisect_left(l, l[ai] + l[bi]) - bi - 1
print(ans)
| 0 | null | 89,526,675,310,760 | 102 | 294 |
S,W = map(int,input().split())
if S<=W:
print('unsafe')
else: print('safe')
|
s,w = map(int,input().split())
print("safe") if s > w else print("unsafe")
| 1 | 29,186,414,866,658 | null | 163 | 163 |
_ = input()
s = input()
if len(s) % 2 == 1:
print("No")
exit(0)
if s[:len(s) // 2] == s[len(s) // 2:]:
print("Yes")
else:
print("No")
|
import sys
(row, column) = sys.stdin.readline().rstrip('\r\n').split(' ')
row = int(row)
column = int(column)
a = []
b = []
c = []
for ii in range(row):
a.append([int(x) for x in input().rstrip('\r\n').split(' ')])
for ii in range(column):
b.append(int(input().rstrip('\r\n')))
for ii in range(len(a)):
work = 0
for jj in range(len(a[ii])):
work += a[ii][jj] * b[jj]
c.append(work)
for cc in c:
print(cc)
| 0 | null | 74,009,813,452,832 | 279 | 56 |
def az15():
n = input()
xs = map(int,raw_input().split())
xs.reverse()
for i in range(0,len(xs)):
print xs[i],
az15()
|
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if n==1:
print(a[0]*2)
exit()
from bisect import bisect_left,bisect_right
#幸福度がx以上がm以上か?
def f(x):
global n,a
ret=0
for i in range(n):
ret+=(n-bisect_left(a,x-a[i]))
return ret
l,r=-1,10**6
while l+1<r:
k=l+(r-l)//2
if f(k)>=m:
l=k
else:
r=k
#print(l,r)
#print(f(l),f(r))
if f(r)>=m:
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,r-a[i]))
ans+=(n-bisect_right(a,r-a[i]))*a[i]
print(2*ans+(m-co)*r)
else:
co,ans=0,0
for i in range(n):
co+=(n-bisect_right(a,l-a[i]))
ans+=(n-bisect_right(a,l-a[i]))*a[i]
print(2*ans+(m-co)*l)
| 0 | null | 54,730,133,818,500 | 53 | 252 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
class Edge:
def __init__(self, to, id):
self.to = to
self.id = id
N = int(input())
graph = {}
ans = [0] * (N-1)
def dfs(v, c=-1, p=-1):
global graph, ans
k = 1
for edge in graph[v]:
nv = edge.to
if nv == p:continue
if k == c:k += 1
ans[edge.id] = k
dfs(nv, k, v)
k += 1
def main():
global N, graph, ans
for i in range(N):
graph[i] = set()
for i in range(N-1):
a, b = map(int, input().split())
graph[a-1].add(Edge(b-1, i))
graph[b-1].add(Edge(a-1, i))
color_count = 0
for i in range(N):
color_count = max(color_count, len(graph[i]))
dfs(0, 0, -1)
print(color_count)
for x in ans:
print(x)
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
def round_robin_scheduling(process_name, process_time, q):
result = []
elapsed_time = 0
while len(process_name) > 0:
# print process_name
# print process_time
if process_time[0] <= q:
elapsed_time += process_time[0]
process_time.pop(0)
result.append(process_name.pop(0) + ' ' + str(elapsed_time))
else:
elapsed_time += q
process_name.append(process_name.pop(0))
process_time.append(process_time.pop(0) - q)
return result
if __name__ == '__main__':
N, q = map(int, raw_input().split())
process_name, process_time = [], []
for i in xrange(N):
process = raw_input().split()
process_name.append(process[0])
process_time.append(int(process[1]))
# N, q = 5, 100
# process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
# process_time = [150, 80, 200, 350, 20]
result = round_robin_scheduling(process_name, process_time, q)
for i in xrange(len(result)):
print result[i]
| 0 | null | 67,844,423,743,122 | 272 | 19 |
import math
N = int(input())
a = math.ceil(N / 1000)
b = 1000*a - N
print(b)
|
from collections import defaultdict
import numpy as np
def main():
s = input()
n = len(s)
d = np.zeros(2019,np.int64)
ans = 0
num = 0
pow10 = 1
d[0] = 1
for i in reversed(range(n)):
pow10 = pow10 * 10 % 2019
num += int(s[i]) * pow10
#print(num, num % 2019, i)
mod = num % 2019
ans += d[mod]
d[mod] += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 19,568,270,878,130 | 108 | 166 |
n, k = map(int, input().split())
a = n % k
if a <= k/2:
print(a)
else:
print(k-a)
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
node_count = [0] * (N+1)
for i, a in enumerate(A[::-1]):
if i == 0:
node_count[N] = a
continue
node_count[N-i] = node_count[N-i+1] + a
can_build = True
for i, a in enumerate(A):
if i == 0:
if N > 0 and a > 0:
can_build = False
break
if N == 0 and a > 1:
can_build = False
break
node_count[0] = min(node_count[0], 1)
continue
if (i < N and a >= node_count[i-1]*2) or (i == N and a > node_count[i-1]*2):
can_build = False
break
node_count[i] = min(node_count[i], node_count[i-1]*2-A[i-1]*2)
if can_build:
ans = sum(node_count)
else:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 29,059,597,821,032 | 180 | 141 |
a,b=map(int,input().split())
if(b%2==0):
if(2*a<=b<=4*a):
print("Yes")
else:
print("No")
else:
print("No")
|
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
a,b,n=map(int, input().split())
if b<=n:
n=b-1
print(((a*n)//b) - (a*(n//b)))
if __name__ == '__main__':
main()
| 0 | null | 21,068,342,482,860 | 127 | 161 |
from functools import reduce
x,y=list(map(int,input().split()))
mod = 10 ** 9 + 7
if (2 * y - x) % 3 != 0 or (2 * x - y) % 3 != 0:
print("0")
exit()
a,b = (2 * y - x) // 3, (2 * x - y) // 3
r = max(a,b)
if min(a,b) < 0:
print("0")
else:
numerator = reduce(lambda x, y: x * y % mod, range(a + b - r + 1, a + b + 1))
denominator = reduce(lambda x, y: x * y % mod, range(1 , r + 1))
print(numerator * pow(denominator, mod - 2, mod) % mod)
|
n = int(input())
s, t = map(str, input().split())
ans = ''
for a, b in zip(s, t):
ans += a+b
print(ans)
| 0 | null | 130,416,790,670,368 | 281 | 255 |
import math
num1 = int(input())
num2 = math.floor(num1 / 1.08)
num3 = math.ceil(num1 / 1.08)
end = False
if math.floor(math.floor(num1 / 1.08) * 1.08) == num1:
print(math.floor(num1 / 1.08))
end = True
elif math.floor(math.ceil(num1 / 1.08) * 1.08) == num1 and end == False:
print(math.ceil(num1 / 1.08))
else:
print(':(')
|
n = int(input())
import math
a = n*100/108
b = (n*100+100)/108
ans = math.ceil(a) if math.ceil(a) < b else ":("
print(ans)
| 1 | 125,947,169,686,820 | null | 265 | 265 |
x, k, d = map(int, input().split())
cur = abs(x)
rem = k
cnt = min(cur // d, k)
cur = cur - d * cnt
rem = rem - cnt
if rem > 0:
if rem % 2 == 1:
cur = cur - d
ans = abs(cur)
print(ans)
|
X,K,D = map(int,input().split())
X = abs(X)
ans = 0
if X>=D and D*K<=X:
ans = X - D*K
if X>=D and D*K>X:
K=K-int(X/D)
X=X%D
if K%2==0:
ans=X
else:
ans = abs(X-D)
if X<D:
if K%2==0:
ans = X
else:
ans = abs(X-D)
print(ans)
| 1 | 5,249,903,912,750 | null | 92 | 92 |
s=input()
if s<='Z':print('A')
else:print('a')
|
if input().isupper():
print('A')
else:
print('a')
| 1 | 11,421,731,142,080 | null | 119 | 119 |
n = int(input())
a = list(map(int, input().split()))
a = [(i, j) for i, j in enumerate(a, start=1)]
a.sort(key=lambda x: x[1])
a = [str(i) for i, j in a]
print(' '.join(a))
|
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
for i, a in enumerate(A):
ans[a-1] = i + 1
print(' '.join(map(str, ans)))
| 1 | 180,343,121,532,030 | null | 299 | 299 |
import sys
S = input()
if S == "ABC":
print("ARC")
sys.exit()
else:
print("ABC")
sys.exit()
|
A=input()
if A=='ABC':
print('ARC')
else:
print('ABC')
| 1 | 24,101,864,346,842 | null | 153 | 153 |
x,y=map(int,input().split())
for i in range(0,x+1):
if(2*i+4*(x-i)==y):
print("Yes")
exit()
print("No")
|
S = input()
if S == 'ABC':
answer = 'ARC'
elif S == 'ARC':
answer = 'ABC'
else:
answer = '入力間違い【ABC】【ARC】を入力'
print(answer)
| 0 | null | 18,892,114,051,248 | 127 | 153 |
# coding:UTF-8
import sys
def resultSur97(x):
return x % (1000000000 + 7)
if __name__ == '__main__':
# ------ 入力 ------#
# 1行入力
n = int(input()) # 数字
# a = input() # 文字列
# aList = list(map(int, input().split())) # スペース区切り連続数字
# aList = input().split() # スペース区切り連続文字列
# aList = [int(c) for c in input()] # 数字→単数字リスト変換
# 定数行入力
x = n
# aList = [int(input()) for _ in range(x)] # 数字
# aList = [input() for _ in range(x)] # 文字
aList = [list(map(int, input().split())) for _ in range(x)] # スペース区切り連続数字(行列)
# aList = [input().split() for _ in range(x)] # スペース区切り連続文字
# aList = [[int(c) for c in input()] for _ in range(x)] # 数字→単数字リスト変換(行列)
# スペース区切り連続 数字、文字列複合
# aList = []
# for _ in range(x):
# aa, bb = input().split()
# a.append((int(aa), bb))
# ------ 処理 ------#
zmin = aList[0][0] + aList[0][1]
zmax = aList[0][0] + aList[0][1]
wmin = aList[0][0] - aList[0][1]
wmax = aList[0][0] - aList[0][1]
for i in range(len(aList)):
x = aList[i][0]
y = aList[i][1]
z = x + y
w = x - y
if z < zmin:
zmin = z
if z > zmax:
zmax = z
if w < wmin:
wmin = w
if w > wmax:
wmax = w
disMax = max(zmax-zmin, wmax-wmin)
# ------ 出力 ------#
print("{}".format(disMax))
# if flg == 0:
# print("YES")
# else:
# print("NO")
|
def main():
n = int(input())
L = []
for _ in range(n):
x,l = map(int,input().split())
L.append([x+l,x-l])
L.sort()
cnt = 0
right = -10**9
for r,l in L:
if right <= l:
cnt += 1
right = r
print(cnt)
main()
| 0 | null | 46,774,773,516,922 | 80 | 237 |
import math
r = float(input())
print('%.6f %.6f' %(math.pi*r**2, math.pi*2*r))
|
s=input().split('S')
print(len(max(s)))
| 0 | null | 2,798,453,071,040 | 46 | 90 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
class UnionFindPathCompression():
def __init__(self, n):
self.parents = list(range(n))
self.rank = [1]*n
self.size = [1]*n
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
px = self.find(x)
py = self.find(y)
if px == py:
return
else:
if self.rank[px] < self.rank[py]:
self.parents[px] = py
self.size[py] += self.size[px]
else:
self.parents[py] = px
self.size[px] += self.size[py]
#ランクの更新
if self.rank[px] == self.rank[py]:
self.rank[px] += 1
N,M = map(int,input().split())
ufpc = UnionFindPathCompression(N)
for i in range(M):
a,b = map(int,input().split())
ufpc.union(a-1,b-1)
ans = 0
for i in range(N-1):
if ufpc.find(i) != ufpc.find(i+1):
ufpc.union(i,i+1)
ans += 1
print(ans)
|
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)
| 1 | 2,266,984,348,272 | null | 70 | 70 |
def selection_sort(A, N):
cnt = 0
for i in range(N):
min_j = i
for j in range(i, N):
if A[j] < A[min_j]:
min_j = j
if i != min_j:
A[i], A[min_j] = A[min_j], A[i]
cnt += 1
return A, cnt
N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))
A, cnt = selection_sort(A, N)
string = list(map(str, A))
print(' '.join(string))
print(cnt)
|
#python2.7
N=input()
A=map(int,raw_input().split())
num=0
for i in range(N):
minj=i
for j in range(N-i):
if A[j+i] < A[minj]:
minj=j+i
if i != minj:
A[i],A[minj]=A[minj],A[i]
num+=1
for m in range(N-1):
print str(A[m]),
print A[N-1]
print num
| 1 | 20,087,515,940 | null | 15 | 15 |
x,y=map(int,input().split())
ans=0
if x<=3:
ans+=(4-x)*100000
if y<=3:
ans+=(4-y)*100000
if ans==600000:
ans=1000000
print(ans)
|
H, W, M = map(int, input().split())
row=[0]*H #x座標を入れるっちゅうかカウント
col=[0]*W #y座標を入れる
mat=[] #座標を入れる
for i in range(M):
h, w = map(int, input().split())
row[h-1]+=1
col[w-1]+=1
mat.append((h-1,w-1))
r=max(row)
c=max(col)
rr=[1 if row[i]==r else 0 for i in range(H)] #maxな列のインデックス
cc=[1 if col[i]==c else 0 for i in range(W)] #maxな行のインデックス
x=0 #maxな列と行の交差点にある爆弾の個数をカウント
for k in mat:
if rr[k[0]]==1 and cc[k[1]]==1:
x+=1
if sum(rr)*sum(cc)==x: #行と列の全ての交差点に爆弾があれば-1する
print(r+c-1)
else:
print(r+c)
| 0 | null | 72,695,215,612,308 | 275 | 89 |
n = int(input())
a = list(map(int, input().split()))
x = 0
for a_i in a:
x ^= a_i
for a_i in a:
print(x ^ a_i)
|
from enum import IntEnum
class Direction(IntEnum):
NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
class Dice:
"""Dice class implements the structure of a dice
having six faces.
"""
def __init__(self, v1, v2, v3, v4, v5, v6):
self.top = 1
self.heading = Direction.NORTH
self.values = [v1, v2, v3, v4, v5, v6]
def to_dice_axis(self, d):
return (d - self.heading) % 4
def to_plain_axis(self, d):
return (self.heading + d) % 4
def roll(self, d):
faces = [[(2, Direction.NORTH), (6, Direction.NORTH),
(6, Direction.WEST), (6, Direction.EAST),
(6, Direction.SOUTH), (5, Direction.SOUTH)],
[(4, Direction.EAST), (4, Direction.NORTH),
(2, Direction.NORTH), (5, Direction.NORTH),
(3, Direction.NORTH), (4, Direction.WEST)],
[(5, Direction.SOUTH), (1, Direction.NORTH),
(1, Direction.EAST), (1, Direction.WEST),
(1, Direction.SOUTH), (2, Direction.NORTH)],
[(3, Direction.WEST), (3, Direction.NORTH),
(5, Direction.NORTH), (2, Direction.NORTH),
(4, Direction.NORTH), (3, Direction.EAST)]]
f, nd = faces[self.to_dice_axis(d)][self.top-1]
self.top = f
self.heading = self.to_plain_axis(nd)
def value(self):
return self.values[self.top-1]
def run():
values = [int(v) for v in input().split()]
dice = Dice(*values)
for d in input():
if d == 'N':
dice.roll(Direction.NORTH)
if d == 'E':
dice.roll(Direction.EAST)
if d == 'S':
dice.roll(Direction.SOUTH)
if d == 'W':
dice.roll(Direction.WEST)
print(dice.value())
if __name__ == '__main__':
run()
| 0 | null | 6,375,941,825,188 | 123 | 33 |
word_1 = [i for i in map(str,input())]
count =0
word_2 = [i for i in map(str,input())]
for key,item in enumerate(word_1):
if not item == word_2[key]:
count += 1
print(count)
|
s = list(input())
t = list(input())
cnt = 0
for x,y in zip(s,t):
if x != y:
cnt += 1
print(cnt)
| 1 | 10,433,907,666,038 | null | 116 | 116 |
H,A = (int(x) for x in input().split())
print(H//A+(H%A>0))
|
H, A = map(int, input().split())
print(H//A + (H%A != 0))
| 1 | 76,750,141,444,180 | null | 225 | 225 |
a,b,c = map(int,input().split())
cnt = 0
for d in range(a,b+1):
if c%d==0: cnt+=1
print(cnt)
|
number_list=[int(i) for i in input().split()]
counter=0
for r in range(number_list[0],number_list[1]+1):
if number_list[2]%r==0:
counter+=1
print(counter)
| 1 | 570,827,058,752 | null | 44 | 44 |
# コッホ曲線 Koch curve
import math
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return str(self.x) + " " + str(self.y)
def Koch(p1, p2, n):
if n == 0:
print(p1)
else:
s = Point(p1.x * 2 / 3 + p2.x * 1 / 3, p1.y * 2 / 3 + p2.y * 1 / 3)
u = Point(p1.x / 2 + p2.x / 2 + p1.y * r3 / 6 - p2.y * r3 / 6, p1.y / 2 + p2.y / 2 + p2.x * r3 / 6 - p1.x * r3 / 6)
t = Point(p1.x * 1 / 3 + p2.x * 2 / 3, p1.y * 1 / 3 + p2.y * 2 / 3)
Koch(p1, s, n - 1)
Koch(s, u, n - 1)
Koch(u, t, n - 1)
Koch(t, p2, n - 1)
r3 = math.sqrt(3)
start = Point(0, 0)
goal = Point(100, 0)
n = int(input())
Koch(start, goal, n)
print(goal)
|
from math import cos,sin, pi
n = int(input())
def koch(n, l, r):
if n == 0:
return
s = ((2*l[0] + r[0])/3, (2*l[1] + r[1])/3)
t = ((l[0] + 2*r[0])/3, (l[1] + 2*r[1])/3)
u = ((t[0] - s[0]) * cos(pi/3) - (t[1] - s[1]) * sin(pi/3) + s[0],
(t[0] - s[0]) * sin(pi/3) + (t[1] - s[1]) * cos(pi/3) + s[1])
koch(n - 1, l, s)
print(s[0], s[1])
koch(n - 1, s, u)
print(u[0], u[1])
koch(n - 1, u, t)
print(t[0], t[1])
koch(n - 1, t, r)
print(0, 0)
koch(n, (0, 0), (100, 0))
print(100, 0)
| 1 | 123,640,670,580 | null | 27 | 27 |
def main():
import sys
asa = sys.stdin.readline
n = int(input())
s = list(map(int, asa().split()))
q = int(input())
t = list(map(int, asa().split()))
c = 0
s.append(0)
for i in t: # tの中のiを探索
j = 0
s[n] = i
while s[j] != i:
j += 1
if j < n:
c += 1
print(c)
if __name__ == '__main__':
main()
|
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
C = 0
for i in range(Q):
if T[i] in S:
C+=1
print(C)
| 1 | 67,397,490,080 | null | 22 | 22 |
# coding: utf-8
a = int(input())
b = int(input())
if a + b == 3:
print("3")
elif a + b == 4:
print("2")
else:
print("1")
|
A = int(input())
B = int(input())
ans = 6-A-B
print(ans)
| 1 | 110,839,398,522,908 | null | 254 | 254 |
A, B, C = map(int, input().split())
if A+B+C >= 22:
print('bust')
elif A+B+C <=21:
print('win')
|
# -*- coding: utf-8 -*-
import sys
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
cnt = Counter(A)
sum = 0
for n in cnt.values():
sum += n*(n-1)//2
for a in A:
print(sum-cnt[a]+1)
| 0 | null | 83,360,936,481,668 | 260 | 192 |
x = int(input(""))
if (x >= 1) or (x <= 100):
num = x ** 3
print(num, end="\n")
else:
pass
|
x=input()
y=int(x)
print(y*y*y)
| 1 | 277,260,022,820 | null | 35 | 35 |
import math
L,R,d = map(int, input().strip().split())
x=math.ceil(L/d)
y=math.floor(R/d)
print(y-x+1)
|
def main():
L, R, d = map(int, input().split())
ans = R//d - (L-1)//d
print(ans)
if __name__ == "__main__":
main()
| 1 | 7,544,025,584,650 | null | 104 | 104 |
n, k = map(int, input().split())
A = []
A_dup = []
cnt = 0
for i in range(k):
input()
# A.append(list(map(int, input().split())))
A_dup += list(map(int, input().split()))
A_eldup = list(set(A_dup))
for i in range(1, n+1):
if i not in A_eldup:
cnt += 1
print(cnt)
|
N=int(input())
C=input()
W=0
R=C.count("R")
ans=R
for i in range(N):
if C[i]=="R":
R-=1
else:
W+=1
if ans>max(W,R):
ans=max(W,R)
print(ans)
| 0 | null | 15,515,161,453,092 | 154 | 98 |
H1,M1,H2,M2,K = (int(x) for x in input().split())
Wake = 60*H1+M1
Sleep = 60*H2+M2
Activate = Sleep - Wake
CanStudy = Activate - K
print(int(CanStudy))
|
n = int(input())
a = list(map(int, input().split()))
que = [-1, -1, -1]
ans = 1
for i in range(n):
if que[0]+1 == a[i]:
if que[0] == que[1] and que[0] == que[2]:
ans *= 3
ans %= (10**9 + 7)
elif que[0] == que[1]:
ans *= 2
ans %= (10**9 + 7)
que[0] = a[i]
elif que[1]+1 == a[i]:
if que[1] == que[2]:
ans *= 2
ans %= (10**9 + 7)
que[1] = a[i]
elif que[2]+1 == a[i]:
que[2] = a[i]
else:
ans = 0
break
print(ans)
| 0 | null | 73,759,141,567,248 | 139 | 268 |
#coding: utf-8
#ALDS1_1D
import sys
n=int(raw_input())
minv=float("inf")
maxv=float("-inf")
for i in xrange(1,n+1):
r=int(raw_input())
maxv=max(maxv,r-minv)
minv=min(minv,r)
print maxv
|
n=int(input())
ar=3
sv=[0]*(10**6+2)
for i in range(2,len(sv)):
if not sv[i]:
sv[i]=i
for j in range(2*i,len(sv),i):
sv[j]=i
def di(x):
an=1
if sv[x]==x:
return 2
while x>1:
ct=0;cr=sv[x]
while x%cr==0:
ct+=1;x//=cr
an*=(ct+1)
return an
for i in range(4,n+1):
ar=ar+di(i-1)
if n==2:
ar=1
print(ar)
| 0 | null | 1,317,372,977,088 | 13 | 73 |
n = int(input())
s = input()
if n%2 != 0:
ans = 'No'
else:
ans = 'Yes'
for i in range(n//2):
if s[i] != s[i+n//2]:
ans = 'No'
print(ans)
|
N = int(input())
S = input()
if N % 2 == 1:
print("No")
else:
if S[:N // 2] == S[N // 2:]:
print("Yes")
else:
print("No")
| 1 | 146,510,075,392,372 | null | 279 | 279 |
import sys
import collections
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=998244353
#+++++
def main():
n = int(input())
#b , c = tin()
#s = input()
al = lin()
if al[0] != 0:
return 0
if al.count(0) != 1:
return 0
alc = collections.Counter(al)
mm = max(alc.keys())
b = alc.keys()
b=list(b)
b.sort()
if list(range(mm+1)) != b:
#pa('rrrr')
return 0
v = 1
p=1
for k in range(1, mm+1):
num = alc[k]
add = pow(p, num, mod)
v *= add
v %= mod
p = num
return v
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
from collections import deque
def bfs(x):
for v in graph[x]:
if dist[v] != -1:
continue
dist[v] = dist[x] + 1
queue.append(v)
if len(queue) == 0:
return
bfs(queue.popleft())
N = int(input())
graph = []
for _ in range(N):
graph.append(list(map(lambda x: int(x)-1, input().split()))[2:])
dist = [-1] * N
queue = deque()
dist[0] = 0
bfs(0)
for i in range(N):
print("{} {}".format(i+1, dist[i]))
| 0 | null | 77,469,200,806,788 | 284 | 9 |
ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
k+=(s*int(S[a-i-1]))
k%=mod
s*=10
s%=mod
if k in c:
c[k]+=1
else:
c[k]=1
for i in c:
ans+=c[i]*(c[i]-1)//2
print(ans)
|
n = int(input())
a = input().split()
money = 1000
stock = 0
pivot = []
upflag = 0
dnflag = 1
if(int(a[1]) - int(a[0]) > 0): # initial
stock = int(money // (int(a[0])))
money = int(money % (int(a[0])))
upflag = 1
dnflag = 0
for i in range(n-2): # i=0,1,,,,n-3 (for n=7, n-3=4)
if(int(a[i+1]) == int(a[i])):
if((int(a[i+2]) - int(a[i+1]) < 0) and upflag == 1): # i+1 is local max so that to sell stock
money = money + stock * (int(a[i+1]))
stock = 0
upflag = 1
dnflag = 0
elif((int(a[i+2]) - int(a[i+1]) > 0) and dnflag == 1): # i+1 is local min so that to sell stock
stock = int(money // (int(a[i+1])))
money = int(money % (int(a[i+1])))
upflag = 0
dnflag = 1
elif(int(a[i+1]) - int(a[i]) > 0):
upflag = 1
if(int(a[i+2]) - int(a[i+1]) < 0): # i+1 is local max so that to sell stock
money = money + stock * (int(a[i+1]))
stock = 0
upflag = 0
elif(int(a[i+1]) - int(a[i]) < 0):
dnflag = 1
if(int(a[i+2]) - int(a[i+1]) > 0): # i+1 is local min so that to buy stock
stock = int(money // (int(a[i+1])))
money = int(money % (int(a[i+1])))
dnflag = 0
if(int(a[n-1]) - int(a[n-2]) > 0): # sell @ final
money = money + stock * (int(a[n-1]))
elif(int(a[n-1]) - int(a[n-2]) == 0):
if(upflag == 1):
money = money + stock * (int(a[n-1]))
print(money)
| 0 | null | 18,966,814,277,280 | 166 | 103 |
S=input()
count=[0]
s=0
for i in range(3):
if S[i]=='R':
if i==2 or S[i+1]=='S':
s=s+1
count.append(s)
s=0
else:
s=s+1
print(max(count))
|
import sys
def input(): return sys.stdin.readline().rstrip()
class SegTree:
X_unit = 0
def __init__(self, N, X_f=min):
self.N = N
self.X = [self.X_unit] * (N + N)
self.X_f = X_f
def build(self, seq):
for i, x in enumerate(seq, self.N):
self.X[i] = x
for i in range(self.N - 1, 0, -1):
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def set_val(self, i, x):
i += self.N
self.X[i] = x
while i > 1:
i >>= 1
self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
def fold(self, L, R):
L += self.N
R += self.N
vL = self.X_unit
vR = self.X_unit
while L < R:
if L & 1:
vL = self.X_f(vL, self.X[L])
L += 1
if R & 1:
R -= 1
vR = self.X_f(self.X[R], vR)
L >>= 1
R >>= 1
return self.X_f(vL, vR)
def orr(x, y):
return x | y
def main():
N = int(input())
S = input()
S = list(map(lambda c: 2**(ord(c) - ord('a')), list(S)))
Q = int(input())
seg = SegTree(N, orr)
seg.build(S)
for _ in range(Q):
num, x, y = input().split()
if num == '1':
seg.set_val(int(x)-1, 2**(ord(y) - ord('a')))
else:
bits=seg.fold(int(x)-1, int(y))
print(sum(map(int, list(bin(bits))[2:])))
if __name__ == '__main__':
main()
| 0 | null | 33,661,605,819,140 | 90 | 210 |
import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
def fast_expo(x,y,m):
res=1
while(y):
if(y&1):
res*=x
res%=m
x*=x
x%=m
y>>=1
return res
dp=defaultdict(int)
dp[1]=1
dp[2]=1
for i in range(3,200001):
k=i
cnt=0
while(k):
if(k%2): cnt+=1
k>>=1
dp[i]=dp[i%cnt]+1
n=ii()
a=ip()
a=a[::-1]
c=a.count('1')
min_1=0
max_1=0
for i in range(n):
if(a[i]=='1'):
if(c-1!=0):
min_1+=fast_expo(2,i,c-1)
min_1%=(c-1)
max_1+=fast_expo(2,i,c+1)
max_1%=(c+1)
ans=[]
for i in range(n):
if(a[i]=='1'):
if(c-1==0):
ans.append(0)
else:
ans.append(dp[(min_1-fast_expo(2,i,c-1)+(c-1))%(c-1)]+1)
else:
ans.append(dp[(max_1+fast_expo(2,i,c+1))%(c+1)]+1)
ans=ans[::-1]
for i in ans:
print(i)
|
s = int(input())
if s == 1:
print(0)
elif s == 0:
print(1)
| 0 | null | 5,580,838,414,140 | 107 | 76 |
s = input()
ans = 0
a = []
for i in s:
if i == 'R':
ans += 1
else :
ans = 0
a.append(ans)
print(max(a))
|
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict
n=IN()
a=LI()
ans=0
for i in range(n):
ans^=a[i]
for i in range(n):
print(ans^a[i],end=" ")
| 0 | null | 8,706,712,172,740 | 90 | 123 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
s = ins()
print("ABC" if s == "ARC" else "ARC")
|
x = input()
if x=='ABC':
print('ARC')
else:
print('ABC')
| 1 | 24,206,003,306,462 | null | 153 | 153 |
N,K = map(int,input().split())
a = N%K
print(min(a,K-a))
|
INF = 10**18
def solve(n, a):
# 現在の位置 x 選んだ個数 x 直前を選んだかどうか
dp = [{j: [-INF, -INF] for j in range(i//2-1, (i+1)//2 + 1)} for i in range(n+1)]
dp[0][0][False] = 0
for i in range(n):
for j in dp[i].keys():
if (j+1) in dp[i+1]:
dp[i+1][j+1][True] = max(dp[i+1][j+1][True], dp[i][j][False] + a[i])
if j in dp[i+1]:
dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][False])
dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][True])
return max(dp[n][n//2])
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
| 0 | null | 38,318,963,074,208 | 180 | 177 |
n,k=map(int,input().split())
A=[0]*k
mod=10**9+7
def power(a,x): #a**xの計算
T=[a]
while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
T.append(T[-1]**2%mod)
b=bin(x) #xを2進数表記にする
ans=1
for i in range(len(b)-2):
if int(b[-i-1])==1:
ans=ans*T[i]%mod
return ans
for i in range(k):
cnt=power(k//(k-i),n)
now=(k-i)*2
while now<=k:
cnt-=A[now-1]
now+=k-i
A[k-i-1]=cnt
ans=0
for i in range(k):
ans+=(i+1)*A[i]%mod
ans%=mod
print(ans)
|
n,k=map(int,input().split())
mod=pow(10,9)+7
ans=[0]*(k+1)
# gcdがkiとなる数列。すべてがkiの倍数でかつ少なくとも一つkiを含む
for ki in range(k,0,-1):
a=k//ki
ans[ki]=pow(a,n,mod)
i=2
while i*ki<=k:
ans[ki]-=ans[i*ki]
i+=1
b=0
for ki in range(1,k+1):
b+=(ans[ki]*ki)%mod
b%=mod
print(b)
| 1 | 36,674,320,156,740 | null | 176 | 176 |
import math
r = float(input())
print((r**2)*math.pi,r*2*math.pi)
|
pai = 3.141592653589793
r = float(input())
s = pai * r ** 2
l = 2 * pai * r
print(s, l)
| 1 | 640,423,074,538 | null | 46 | 46 |
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def resolve():
h1,m1,h2,m2,k = mi()
res = convert(h2,m2) - convert(h1,m1) - k
print(res)
def convert(h,m):
return h*60 + m
if __name__ == "__main__":
resolve()
|
k=int(input())
s="ACL"
for i in range(k):
print(s,end="")
| 0 | null | 10,087,512,617,842 | 139 | 69 |
print(str(int(input())**3))
|
n = int(input())
*a, = map(int, input().split())
ans = 1000
for i, j in zip(a, a[1:]):
if i<j:
ans = ans//i*j + ans%i
print(ans)
| 0 | null | 3,788,869,346,990 | 35 | 103 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
s,t = input().split()
print(''.join([s[i] + t[i] for i in range(n)]))
|
N, K = map(int, input().split())
Max = [0]
Min = [0]
for i in range(1, N+2):
Max.append(N-i+1+Max[i-1])
Min.append(i-1+Min[i-1])
A = [mx-mn+1 for mx,mn in zip(Max,Min)]
B =[0]
for i in range(N+1):
B.append(B[i]+A[i+1])
print((B[N+1]-B[K-1])%(10**9+7))
| 0 | null | 72,526,445,127,410 | 255 | 170 |
def chess(h,w):
o = ""
for i in range(h):
if i%2:
if w%2: o+= ".#"*(w/2)+".\n"
else: o+= ".#"*(w/2)+"\n"
else:
if w%2: o+= "#."*(w/2)+"#\n"
else: o+= "#."*(w/2)+"\n"
print o
while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
chess(h,w)
|
def resolve():
n=int(input())
print((n-1)//2)
resolve()
| 0 | null | 76,692,367,863,426 | 51 | 283 |
N = int(input())
A = list(map(int,input().split()))
X = 0
for i in range(N):
X = X^A[i]
ans = []
for i in range(N):
temp = X^A[i]
ans.append(temp)
print(*ans)
|
n = int(input())
a_ls = list(map(int, input().split()))
s_ls = [0] * n
Sum = 0
for i in range(n):
Sum = Sum ^ a_ls[i]
for i in range(n):
s_ls[i] = Sum ^ a_ls[i]
print(*s_ls)
| 1 | 12,468,154,733,008 | null | 123 | 123 |
N = int(input())
from collections import Counter
c = Counter()
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
n = x*x + y*y + z*z + x*y + y*z + z*x
c[n] += 1
for i in range(1,N+1):
print(c[i])
|
n=int(input())
from collections import defaultdict
def factorization(n):
arr = defaultdict(int)
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr[i]+=cnt
if temp!=1:
arr[temp]=1
if arr==[]:
arr[n]=1
return arr
l=factorization(n)
ans=0
for v in l.values():
i=1
while i<=v:
ans+=1
v-=i
i+=1
print(ans)
| 0 | null | 12,425,992,581,812 | 106 | 136 |
a=int(input())
if a==11 or a==13 or a==17 or a==19 or a==22 or a==23 or a==26 or a==29 or a==31 or a==33 or a==34 or a==37 or a==38 or a==39 or a==41 or a==43 or a==44 or a==46 or a==47 or a==50 or a==51 or a==52 or a==53 or a==55 or a==57 or a==58 or a==59 or a==60 or a==61 or a==62 or a==65 or a==66 or a==67 or a==68 or a==69 or a==70 or a==71 or a==73 or a==74 or a==75 or a==76 or a==77 or a==78 or a==79 or a==80 or a>=82:
print("No")
else:
print("Yes")
|
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
n = int(input())
ans = 0
for i in range(1,n):
ans += (n-1)//i
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 81,235,648,845,420 | 287 | 73 |
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
N,M=map(int,input().split())
if M%2==0:
for i in range(M//2):
print(i+1,M-i)
for i in range(M//2):
print(M+i+1,2*M-i+1)
else:
for i in range(M//2):
print(i+1,M-i)
for i in range(M//2+1):
print(M+i+1,2*M-i+1)
|
# -*- coding: utf-8 -*-
"""
D - Knight
https://atcoder.jp/contests/abc145/tasks/abc145_d
"""
import sys
def modinv(a, m):
b, u, v = m, 1, 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= m
return u if u >= 0 else u + m
def solve(X, Y):
MOD = 10**9 + 7
if (X + Y) % 3:
return 0
n = (X - 2 * Y) / -3.0
m = (Y - 2 * X) / -3.0
if not n.is_integer() or not m.is_integer() or n < 0 or m < 0:
return 0
n, m = int(n), int(m)
x1 = 1
for i in range(2, n + m + 1):
x1 = (x1 * i) % MOD
x2 = 1
for i in range(2, n+1):
x2 = (x2 * i) % MOD
for i in range(2, m+1):
x2 = (x2 * i) % MOD
ans = (x1 * modinv(x2, MOD)) % MOD
return ans
def main(args):
X, Y = map(int, input().split())
ans = solve(X, Y)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 0 | null | 89,304,712,387,488 | 162 | 281 |
N = int(input())
if N%2==1:
ans = 0
else:
n = N//10
ans = n
k = 1
while 5**k<=n:
ans += n//(5**k)
k += 1
print(ans)
|
N = int(input())
import sys
if N & 1:
print(0)
sys.exit()
ans = 0
N //= 2
while N != 0:
ans += N // 5
N //= 5
print(ans)
| 1 | 116,015,628,479,718 | null | 258 | 258 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
lr = [None]*n
for i in range(n):
x,l = map(int, input().split())
lr[i] = (x-l, x+l)
lr.sort(key=lambda x: x[1])
ans = 0
c = -10**10
for l,r in lr:
if c<=l:
ans += 1
c = r
print(ans)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
m = map(int,read().split())
xl = zip(m,m)
c = [(x-l,x+l) for x,l in xl]
from operator import itemgetter
c.sort()
c.sort(key=itemgetter(1))
ans = 1
chk = c[0][1]
for i,j in c:
if i >= chk:
ans +=1
chk = j
print(ans)
| 1 | 89,731,357,479,480 | null | 237 | 237 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
num1 = a[0]
num2 = 0
while num1 % 2 == 0:
num1 //= 2
num2 += 1
gc = 2 ** num2
b = []
for i in a:
if i % gc != 0 or (i // gc) % 2 == 0:
print(0)
exit()
else:
b.append(i // gc)
from fractions import gcd
lcm = 1
for i in b:
lcm = (lcm * i) // gcd(lcm, i)
ans = m // (lcm * (gc // 2))
ans = (ans + 1) // 2
print(ans)
|
N = int(input())
A = [int(temp) for temp in input().split()]
cou = 0
for mak in range(1,N) :
for j in range(mak,N)[ : : -1] :
if A[j] < A[j - 1] :
tem = int(A[j])
A[j] = int(A[j - 1])
A[j - 1] = int(tem)
cou = cou + 1
A = [str(temp) for temp in A]
print(' '.join(A))
print(cou)
| 0 | null | 50,834,457,219,520 | 247 | 14 |
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
i_l=[]
j_l=[]
for i in range(n):
i_l.append(i+a[i])
j_l.append(i-a[i])
ci=Counter(i_l)
cl=Counter(j_l)
ans=0
for k,v in ci.items():
ans+=v*cl[k]
print(ans)
|
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
X, Y = [], []
for i in range(N):
X.append(i + 1 + A[i])
Y.append(i + 1 - A[i])
XL = Counter(X)
c = 0
for y in Y:
c += XL.get(y, 0)
print(c)
| 1 | 26,013,902,285,630 | null | 157 | 157 |
N = int(input())
S = input()
ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]
all = len(ris) * len(gis) * len(bis)
cnt = 0
for i in range(N):
for j in range(i+1, N):
k = 2*j - i
if 0 <= k < N:
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
ans = all - cnt
print(ans)
|
row = input().split()
row = [ int(i) for i in row]
print(row[0] * row[1], 2 * (row[0] + row[1]))
| 0 | null | 18,112,935,436,388 | 175 | 36 |
S = input()
N = len(S)
ans = 0
for i in range(len(S) // 2):
if S[i] != S[N - i - 1]:
ans += 1
print(ans)
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = input()
n = len(s)
ans = 0
for i in range(n//2):
if s[i] != s[-(i+1)]:
ans += 1
print(ans)
| 1 | 120,187,133,889,706 | null | 261 | 261 |
import sys
from collections import deque
n = int(sys.stdin.readline().strip())
edges = [[] for _ in range(n)]
for _ in range(n):
tmp = list(map(int, sys.stdin.readline().strip().split(" ")))
for node in tmp[2:]:
edges[tmp[0] - 1].append(node-1)
# print(edges)
distance = [0] * n
q = deque()
q.append((0, 0))
visited = set()
while q:
node, d = q.popleft()
# print(node, d)
if node in visited:
continue
distance[node] = d
visited.add(node)
for next in edges[node]:
# print("next", next)
q.append((next, d + 1))
for i, d in enumerate(distance):
if i == 0:
print(1, 0)
else:
print(i + 1, d if d > 0 else -1)
|
def main():
n = int(input())
A,B = [],[]
for i in range(n):
a,b = map(int,input().split())
A.append(a)
B.append(b)
if n%2==1:
a_ = sorted(A)[(n-1)//2]
b_ = sorted(B)[(n-1)//2]
print(b_-a_+1)
else:
A,B = sorted(A),sorted(B)
a_ = (A[n//2]+A[n//2-1])/2
b_ = (B[n//2]+B[n//2-1])/2
print(int(2*(b_-a_))+1)
if __name__ == "__main__":
main()
| 0 | null | 8,707,290,690,862 | 9 | 137 |
n,m=map(int,input().split())
lst=[[]for i in range(n)]
for i in range(n):
lst[i]=list(map(int,input().split()))
lst2=[[]*1 for i in range(m)]
for i in range(m):
lst2[i]=int(input())
for i in range(n):
x=0
for j in range(m):
x=x+lst[i][j]*lst2[j]
print("%d"%(x))
|
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
N = int(input())
if N % 2 == 0:
print(0.5)
else:
print(1.0-((N-1)//2.0)/N)
| 0 | null | 88,895,795,194,080 | 56 | 297 |
mod = 1000000007
def mod_cmb(n: int, k: int, p: int) -> int:
if n < 0 or k < 0 or n < k: return 0
if n == 0 or k == 0: return 1
if (k > n - k):
return mod_cmb(n, n - k, p)
c = d = 1
for i in range(k):
c *= (n - i)
d *= (k - i)
c %= p
d %= p
return c * pow(d, -1, p) % p
def main():
n, a, b = map(int, input().split())
ans = pow(2, n, mod) - 1
tmp_a = mod_cmb(n , a, mod)
tmp_b = mod_cmb(n , b, mod)
print((ans-tmp_a-tmp_b)%mod)
if __name__ == '__main__':
main()
|
N = int(input())
block = list(map(int,input().split()))
a = 1
for i in block:
if i == a:
a += 1
if a==1:
print(-1)
else:
print(len(block)-a+1)
| 0 | null | 90,922,069,948,930 | 214 | 257 |
def main():
str1, str2 = input().rstrip().split(' ')
str1_quantity, str2_quantity = (int(i) for i in input().rstrip().split(' '))
chosen_ball_str = input().rstrip()
if str1 == chosen_ball_str:
str1_quantity -= 1
else:
str2_quantity -= 1
print('{} {}'.format(str1_quantity, str2_quantity))
if __name__ == '__main__':
main()
|
nums = input().split()
a = int(nums[0])
b = int(nums[1].replace('.', ''))
result = str(a * b)
if len(result) < 3:
print(0)
else:
print(result[:-2])
| 0 | null | 44,331,337,771,148 | 220 | 135 |
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = R[0]
R.pop(0)
for i in R:
if profit < i - mn:
profit = i - mn
if 0 > i - mn:
mn = i
elif mn > i:
mn = i
print(profit)
|
N = input()
R = [int(raw_input()) for _ in xrange(N)]
S = [0 for i in xrange(N)]
S[N-1] = R[N-1]
for i in xrange(N-2, -1, -1):
S[i] = max(R[i], S[i+1])
ans = float('-inf')
for i in xrange(N-1):
ans = max(ans, S[i+1]-R[i])
print ans
| 1 | 13,534,855,230 | null | 13 | 13 |
K, N = map(int, input().split())
nums = list(map(int, input().split()))
before = 0
max_n = 0
for num in nums:
dist = num - before
max_n = max(max_n, dist)
before = num
max_n = max(max_n, K-nums[-1]+nums[0])
print(K-max_n)
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,t = list(map(int, input().split()))
ab = [None]*n
for i in range(n):
ab[i] = tuple(map(int, input().split()))
ab.sort()
dp = [[0]*(t) for _ in range(n)]
for i in range(1, n):
a,b = ab[i-1]
for j in range(t-1, 0, -1):
dp[i][j] = dp[i-1][j]
if j>=a and dp[i][j]<dp[i-1][j-a]+b:
dp[i][j] = dp[i-1][j-a]+b
ans = max((dp[i][t-1] + ab[i][1]) for i in range(n))
print(ans)
| 0 | null | 97,448,745,636,870 | 186 | 282 |
N,K = map(int,input().split())
n = N - K * (N//K)
n = min(n, abs(n-K))
print(n)
|
l=input("").split(" ")
n=int(l[0])
k=int(l[1])
s=n%k
ss=k-s
if(s<ss):
print(s)
else:
print(ss)
| 1 | 39,333,238,216,680 | null | 180 | 180 |
N = int(input())
for i in range(10):
pay = (i + 1) * 1000
if(pay >= N):
break
if(pay < N):
print("たりません")
else:
print(pay - N)
|
print(['ABC', 'ARC'][input() == 'ABC'])
| 0 | null | 16,231,548,404,448 | 108 | 153 |
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
def main():
N = in_n()
ans = []
def dfs(s):
if len(s) == N:
ans.append(s)
return
maxs = max(map(ord, s))
for i in range(ord('a'), maxs + 2):
dfs(s + chr(i))
dfs('a')
print('\n'.join(sorted(ans)))
if __name__ == '__main__':
main()
|
def dfs(s, ub, n):
if len(s) == n:
print(s)
else:
ch = "a"
while ord(ch) < ord(ub):
dfs(s + ch, ub, n)
ch = chr(ord(ch) + 1)
ub = chr(ord(ub) + 1)
dfs(s + ch, ub, n)
def solve(n):
dfs("", "a", n)
n = int(input())
solve(n)
| 1 | 52,655,908,791,490 | null | 198 | 198 |
n,m,l = map(int,input().split())
A = list()
B = list()
for i in range(n):
A.append(list(map(int,input().split())))
for i in range(m):
B.append(list(map(int,input().split())))
for i in range(n):
C = list()
for j in range(l):
sum = 0
for k in range(m):
sum += A[i][k] * B[k][j]
C.append(sum)
print(" ".join(list(map(str,C))))
|
N, M, L = map(int, raw_input().split())
nm = [map(int, raw_input().split()) for n in range(N)]
ml = [map(int, raw_input().split()) for m in range(M)]
for n in range(N):
col = [0] * L
for l in range(L):
for m in range(M):
col[l] += nm[n][m] * ml[m][l]
print ' '.join(map(str, col))
| 1 | 1,434,329,185,340 | null | 60 | 60 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.