code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
a, b, k = map(int, input().split())
x = min(a, k)
a -= x
k -= x
y = min(b, k)
b -= y
print(str(a),str(b)) | def main():
A, B, K = map(int, input().split())
if A - K > 0:
print(A - K, B)
elif B + A - K > 0:
print(0, B + A - K)
else:
print(0, 0)
main()
| 1 | 104,329,877,437,018 | null | 249 | 249 |
N = int(input())
ls = []
for i in range(N):
s = input().split()
ls.append(s)
X = input()
ans = 0
mode = 0
for i in range(N):
if ls[i][0] == X:
mode = 1
else:
if mode == 1:
ans += int(ls[i][1])
print(ans) | S=str(input())
a=S.count('hi')
if a*2==len(S):
print('Yes')
else:
print("No") | 0 | null | 75,195,330,568,458 | 243 | 199 |
m1,_ = map(int,input().split())
m2,_ = map(int,input().split())
if m1 < m2:
print(1)
else:
print(0) |
r=int(input())
print(int(pow(r,2))) | 0 | null | 134,885,083,481,148 | 264 | 278 |
n = input()
l = [int(i) for i in input().split()]
print(' '.join([str(min(l)),str(max(l)),str(sum(l))])) | #!/usr/bin/env python3
def main():
A1, A2, A3 = map(int, input().split())
A=A1+A2+A3
if A >=22:
ans='bust'
else:
ans='win'
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 60,079,085,854,070 | 48 | 260 |
import itertools
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
c_p = 0
c_q = 0
count = 0
for i in itertools.permutations(sorted(p),len(p)):
if p == list(i):
c_p = count
if q == list(i):
c_q = count
count += 1
print(abs(c_p - c_q)) | from itertools import permutations
from bisect import bisect
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = tuple(permutations(range(1, n + 1), n))
print(abs(bisect(l, p) - bisect(l, q))) | 1 | 100,303,117,265,340 | null | 246 | 246 |
from functools import reduce
from fractions import gcd
mod = 10**9 + 7
n, *A = map(int, open(0).read().split())
if len(A) == 1:
print(1)
else:
l = reduce(lambda x, y: x*y // gcd(x, y), A) % mod
s = 0
for a in A:
s += l * pow(a, mod-2, mod)
s %= mod
print(s) | import math
T_1, T_2 = map(int, input().split())
A_1, A_2 = map(int, input().split())
B_1, B_2 = map(int, input().split())
ans = 0
if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2:
print("infinity")
else:
# 速いほうをAと仮定
if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2:
A_1, A_2, B_1, B_2 = B_1, B_2, A_1, A_2
if A_1 < B_1:
sa_12 = T_1 * A_1 + T_2 * A_2 - (T_1 * B_1 + T_2 * B_2) # 1サイクルでできる差
sa_1 = -T_1 * A_1 + T_1 * B_1 # T_1でできる差
if sa_1 % sa_12 == 0:
ans = int((sa_1 / sa_12)*2)
else:
kari = math.ceil(sa_1 / sa_12)
ans = (kari-1)*2+1
print(ans)
| 0 | null | 109,610,447,102,878 | 235 | 269 |
s,t=input().split();print(t+s) | S, T = input().split()
ans = T + S
print(ans) | 1 | 103,294,347,999,810 | null | 248 | 248 |
n=int(input())
arr=list(map(int,input().split()))
xors = 0
for val in arr: #あらかじめすべての要素のxorを求めておく
xors^=val #(ai xor aj = bi xor bj)となるのですべてのxorを合わせると、b0^b1^b2^...^bn
ans=[]
for i in range(n): #各aiについて、ai xor (すべての要素のxor)がi番目に書かれた値に等しい
ans.append(xors^arr[i])
print(*ans) | n=int(input())
a=list(map(int,input().split()))
temp=a[0]
for i in range(n-1):
temp=temp^a[i+1]
for i in range(n):
print(temp^a[i]) | 1 | 12,469,186,259,730 | null | 123 | 123 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
a[0] = (a[0]-1)%k
for i in range(1,n):
a[i] = (a[i]+a[i-1]-1)%k
ans = 0
b = {0:1}
for i in range(n):
if i>0:
b[a[i-1]] = b.get(a[i-1],0) + 1
if i>=k:
b[a[i-k]] -= 1
if i==k-1:
b[0] -= 1
ans += b.get(a[i],0)
print(ans) | from math import gcd
N=int(input())
A = list(map(int,input().split()))
val = A[0]
for i in range(1,N):
val = gcd(val,A[i])
if val > 1:
print("not coprime")
exit()
D = [i for i in range(max(A)+1)]
p = 2
while(p*p<=max(A)):
if D[p]==p:
for i in range(2*p,len(D),p):
if D[i]==i:
D[i]=p
p+=1
prime = set()
for a in A:
tmp=D[a]
L=set()
while(a>1):
a=a//tmp
L.add(tmp)
tmp=D[a]
#print(L)
for l in L:
if l in prime:
#print(D)
#print(prime)
print("setwise coprime")
exit()
else:
prime.add(l)
#print(D)
#print(prime)
print("pairwise coprime") | 0 | null | 71,027,531,156,798 | 273 | 85 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
S, W = map(int, input().split())
if W >= S:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
main()
| n=int(input())
R=[]
for _ in range(n):
x,l=map(int,input().split())
R.append([x-l,x+l])
R=sorted(R,key=lambda x:x[1])
ans=n
for i in range(1,n):
if R[i][0]<R[i-1][1]:
ans-=1
R[i][1]=R[i-1][1]
print(ans) | 0 | null | 59,395,692,225,252 | 163 | 237 |
text = ''
while(True):
try:
text += input().lower()
except:
break
count = [0 for i in range(26)]
for c in text:
if c < 'a' or c > 'z':
continue
count[ord(c) - ord('a')] += 1
for i, c in enumerate(count):
print('{0} : {1}'.format(chr(i + ord('a')), c)) | alphabet = 'abcdefghijklmnopqrstuvwxyz'
from collections import defaultdict
import sys
adict = defaultdict(int)
for l in sys.stdin:
for c in l.lower():
adict[c] += 1
for k in alphabet:
print('%s : %i' %(k, adict[k])) | 1 | 1,658,191,999,156 | null | 63 | 63 |
s = str(input())
sm = 0
for c in s:
sm += int(c)
if sm % 9 == 0:
print('Yes')
else:
print('No') | N = input()
answer = 0
for keta in N:
answer = (answer + int(keta))%9
if not answer:
print("Yes")
else:
print("No")
| 1 | 4,441,341,194,140 | null | 87 | 87 |
import math
import itertools
k = int(input())
l = list(range(1,k+1))
y = list(itertools.combinations_with_replacement(l,3))
n = len(y)
t = 0
for i in range(n):
a = y[i][0]
b = y[i][1]
c = y[i][2]
d = math.gcd(math.gcd(a,b),c)
if a != b != c:
t += d * 6
elif a == b == c:
t += d
else:
t += d * 3
print(t) | n = int(input())
a = list(map(int, input().split()))
for n in a:
if n % 2 == 0:
if not n % 3 == 0 and not n % 5 == 0:
print("DENIED")
break
else:
print("APPROVED") | 0 | null | 52,370,216,846,080 | 174 | 217 |
n = int(input())
Taro = 0
Hanako = 0
for i in range(n):
x = 0
t,h = input().split()
for j in range(min(len(t),len(h))):
if t == h:
Hanako += 1
Taro += 1
x = 1
break
if ord(t[j:j+1]) > ord(h[j:j+1]):
Taro += 3
x = 1
break
if ord(t[j:j+1]) < ord(h[j:j+1]):
Hanako += 3
x = 1
break
if x == 0:
if len(t) > len(h):
Taro += 3
elif len(t) < len(h):
Hanako += 3
print("{} {}".format(Taro,Hanako)) | from collections import Counter
s = input()
n = len(s)
dp = [0]
mod = 2019
a = 0
for i in range(n):
a = a + int(s[n-i-1]) * pow(10, i, mod)
a %= mod
dp.append(a%mod)
ans = 0
c = Counter(dp)
for value in c.values():
ans += value * (value-1) / 2
print(int(ans)) | 0 | null | 16,422,760,046,252 | 67 | 166 |
# -*- coding: utf-8 -*-
list = map(int, raw_input().split())
W = list[0]
H = list[1]
x = list[2]
y = list[3]
r = list[4]
if (x-r) >= 0 and (y-r) >= 0 and (x+r) <= W and (y+r) <= H:
print "Yes"
else:
print "No" | W,H,x,y,r = map(int,input().split())
if x >= r and x <= W-r and y >= r and y <= H-r:
print('Yes')
else:
print('No')
| 1 | 459,244,300,958 | null | 41 | 41 |
n = int(input())
al = list(map(int, input().split()))
num_cnt = {}
c_sum = 0
for a in al:
num_cnt.setdefault(a,0)
num_cnt[a] += 1
c_sum += a
ans = []
q = int(input())
for _ in range(q):
b,c = map(int, input().split())
num_cnt.setdefault(b,0)
num_cnt.setdefault(c,0)
diff = num_cnt[b]*c - num_cnt[b]*b
num_cnt[c] += num_cnt[b]
num_cnt[b] = 0
c_sum += diff
ans.append(c_sum)
for a in ans:
print(a) | import sys , math
from bisect import bisect
N=int(input())
alp="abcdefghijklmnopqrstuvwxyz"
R=[]
i=1
tot = 0
while tot < 1000000000000001:
tar = 26**i
tot+=tar
R.append(tot+1)
i+=1
keta = bisect(R , N)+1
if keta == 1:
print(alp[N-1])
sys.exit()
ans = ""
M = N - R[keta - 1]
for i in range(keta):
j = keta - i - 1
ind = M // (26**j)
M -= ind * (26**j)
ans+=alp[ind]
print(ans) | 0 | null | 12,134,373,890,940 | 122 | 121 |
str = input()
n = int(input())
for i in range(n):
args = input().split()
command = args[0]
s = int(args[1])
e = int(args[2])
if command == 'print':
print(str[s:e + 1])
if command == 'reverse':
str = str[0:s] + str[s:e + 1][::-1] + str[e + 1:]
if command == 'replace':
str = str[0:s] + args[3] + str[e + 1:] |
string = [str(i) for i in input()]
for _ in range(int(input())):
n = input().split()
order = n.pop(0)
if order == 'replace':
string = string[:int(n[0])] + \
[i for i in n[2]] + string[int(n[1])+1:]
elif order == 'reverse':
string = string[:int(n[0])] + \
string[int(n[0]):int(n[1])+1][::-1] + \
string[int(n[1])+1:]
else :
out = string[ int(n[0]) : int(n[1])+1 ]
print(''.join(out)) | 1 | 2,078,509,978,972 | null | 68 | 68 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
m = 0
for a in A:
if a >= sum(A) / (4 * M):
m += 1
print('Yes') if m >= M else print('No') | n, t = map(int, input().split())
ab = []
for _ in range(n):
ab.append(list(map(int, input().split())))
ab.sort(key=lambda x:x[0])
dp = [-1]*(t+1)
dp[0] = 0
for a, b in ab:
tmp = dp[:]
for i in range(t):
if dp[i] >= 0 and dp[i]+b > tmp[min(i+a, t)]:
tmp[min(i+a, t)] = dp[i]+b
dp = tmp
print(max(dp)) | 0 | null | 94,757,693,705,470 | 179 | 282 |
# author: Taichicchi
# created: 19.09.2020 00:06:44
import sys
K = int(input())
a = 7 % K
for k in range(K + 2):
if a == 0:
print(k + 1)
break
a = (a * 10 + 7) % K
else:
print(-1)
| #dp[n][t]=max(dp[n-1][t],dp[n-1][t-A[n]]+B[n])
#dp[0][t]=0, dp[n][0]=0,0<=t<=T+max(B)-1, 0<=n<=N
def solve():
N, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
dp = [[0]*(T+3000) for _ in range(N+1)]
for n in range(1,N+1):
for t in range(1,T+X[n-1][0]):
dp[n][t]=dp[n-1][t]
if t>=X[n-1][0]:
dp[n][t]=max(dp[n][t],dp[n-1][t-X[n-1][0]]+X[n-1][1])
ans = max(dp[N])
return ans
print(solve()) | 0 | null | 78,576,896,600,520 | 97 | 282 |
import sys
for line in sys.stdin:
list = line.split()
print len(str(eval(list[0])+eval(list[1]))) | while 1:
try:
line = raw_input()
except EOFError:
break
arr = map((lambda x: int(x)), line.split())
print len(str(arr[0]+arr[1])) | 1 | 120,619,202 | null | 3 | 3 |
#!/usr/bin/env python3
import sys
def solve(S: str):
print(S[0:3])
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
solve(S)
if __name__ == '__main__':
main()
| S=input()
nick_name=S[0:3]
print(nick_name) | 1 | 14,733,198,530,710 | null | 130 | 130 |
import math
N = int(input())
count = 0
for A in range(1, N):
for B in range(1, math.ceil(N/A)):
if A * B < N:
count += 1
print(count) | N = int(input())
A = list(map(int,input().split()))
b = 1
c = 0
if A.count(0) != 0:
print(0)
else:
for i in range(N):
b = b * A[i]
if b > 10 ** 18:
c = 1
break
if c == 0:
print(b)
else:
print(-1) | 0 | null | 9,275,103,717,100 | 73 | 134 |
i=1
k=1
for k in range(1,10):
for i in range(1,10):
print(str(k)+"x"+str(i)+"="+str(k*i)) | for i in range(1, 10):
for j in range(1, 10):
print(f"{i}x{j}={i * j}")
| 1 | 124,820 | null | 1 | 1 |
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys
sys.setrecursionlimit(10**6)
def bfs(s,n,node):
#頂点が探索済みかどうかのチェック配列
check=[False for _ in range(n)]
check[s]=True
#次見る頂点を格納するキュー
queue=deque([s])
visited_num=1
#問題固有の配列
#color_check=[[True for _ in range(l)] for _ in range(n)]
color=[-1 for _ in range(n)]
color[s]=0
while visited_num<n:
#グラフが全連結ではない場合
if len(queue)==0:
#空配列を返す
#現状までの計算済み配列を返してもいいと思う
return color
now_vertex=queue.popleft()
#インデックスがない場合は
for next_vertex in node[now_vertex]:
if check[next_vertex]==True:
continue
queue.append(next_vertex)
check[next_vertex]=True
#問題固有の計算
color[next_vertex]=color[now_vertex]+1
visited_num+=1
return color
#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))
#n=int(input())
#n,m=input_list()
#a=input_list()
s=input()
ans=0
s=[i if i!="?" else "D" for i in s]
print("".join(s)) | raw_data = input()
data = raw_data.replace('?', 'D')
print(data) | 1 | 18,367,764,520,200 | null | 140 | 140 |
from bisect import bisect_left
N=int(input())
y=list(map(int, input().split()))
y.sort()
ans=0
for i in range(N-2):
for j in range(i+1, N-1):
tmp=y[i]+y[j]
ans+=bisect_left(y,tmp)-j-1
print(ans)
| S = input()
T = input()
min_dist = 10**10
for i in range(len(S) - len(T) + 1):
for k in range(len(T)):
dist = 0
for s, t in zip(S[i:i + len(T)], T):
if s != t:
dist += 1
if dist >= min_dist:
break
min_dist = min(dist, min_dist)
if min_dist == 0:
print(0)
exit()
print(min_dist)
| 0 | null | 87,635,715,417,098 | 294 | 82 |
# coding=utf-8
inputs = raw_input().rstrip().split()
nums = [int(x) for x in inputs]
print ' '.join([str(x) for x in sorted(nums)]) | a = list(map(int, input().split()))
a.sort()
print(a[0], a[1], a[2])
| 1 | 418,371,701,888 | null | 40 | 40 |
from typing import List
class Info:
def __init__(self, arg_start, arg_end, arg_area):
self.start = arg_start
self.end = arg_end
self.area = arg_area
if __name__ == "__main__":
LOC: List[int] = []
POOL: List[Info] = []
all_symbols = input()
loc = 0
total_area = 0
for symbol in all_symbols:
if symbol == '\\':
LOC.append(loc)
elif symbol == '/':
if len(LOC) == 0:
continue
tmp_start = int(LOC.pop())
tmp_end = loc
tmp_area = tmp_end - tmp_start
total_area += tmp_area
while len(POOL) > 0:
# \ / : (tmp_start, tmp_end)
# \/ : (POOL[-1].start, POOL[-1].end)
if tmp_start < POOL[-1].start and POOL[-1].end < tmp_end:
tmp_area += POOL[-1].area
POOL.pop()
else:
break
POOL.append(Info(tmp_start, tmp_end, tmp_area))
else:
pass
loc += 1
print(f"{total_area}")
print(f"{len(POOL)}", end="")
while len(POOL) > 0:
print(f" {POOL[0].area}", end="")
POOL.pop(0)
print()
| import sys
def read_heights():
current = 0
heights = [current]
for c in sys.stdin.read().strip():
current += {
'/': 1,
'\\': -1,
'_': 0
}[c]
heights.append(current)
return heights
heights = read_heights()
height_index = {}
for i, h in enumerate(heights):
height_index.setdefault(h, []).append(i)
flooded = [False] * len(heights)
floods = []
# search from highest points
for h in sorted(height_index.keys(), reverse=True):
indexes = height_index[h]
for i in range(len(indexes) - 1):
start = indexes[i]
stop = indexes[i + 1]
if start + 1 == stop or flooded[start] or flooded[stop]:
continue
if any(heights[j] >= h for j in range(start + 1, stop)):
continue
# flood in (start..stop)
floods.append((start, stop))
for j in range(start, stop):
flooded[j] = True
floods.sort()
areas = []
for start, stop in floods:
area = 0
top = heights[start]
for i in range(start + 1, stop + 1):
h = heights[i]
area += top - h + (heights[i - 1] - h) * 0.5
areas.append(int(area))
print(sum(areas))
print(' '.join([str(v) for v in [len(areas)] + areas]))
| 1 | 59,817,678,324 | null | 21 | 21 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]
ans_kouho = [min(a)+min(b)] + [a[x-1]+b[y-1]-c for x, y, c in xyc]
print(min(ans_kouho))
| from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
def readInts():
return list(map(int,input().split()))
def main():
a,b,m = readInts()
A = readInts()
B = readInts()
ans = float('inf')
for i in range(m):
x,y,c = readInts()
x -=1
y -=1
ans = min(ans,A[x] + B[y] - c)
# Aの商品の中で1番最小のやつを買うだけでもいいかもしれない
# Bの商品の中で1番最小のやつを買うだけでもいいかもしれない
ans = min(ans,min(A) + min(B))
print(ans)
if __name__ == '__main__':
main()
| 1 | 54,148,772,476,430 | null | 200 | 200 |
# -*- coding: utf-8 -*-
N = int(raw_input())
A = map(str, raw_input().split())
B = A[:]
for i in range(N):
for j in range(N-1, i, -1):
if int(A[j][1]) < int(A[j-1][1]):
A[j], A[j-1] = A[j-1], A[j]
bubble = " ".join(A)
for i in range(N):
minj = i
for j in range(i, N):
if int(B[j][1]) < int(B[minj][1]):
minj = j
B[i], B[minj] = B[minj], B[i]
select = " ".join(B)
print bubble
print "Stable"
print select
if bubble == select:
print "Stable"
else:
print "Not stable" | def select(S):
for i in range(0, n):
minj = i
for j in range(i, n):
if int(S[j][1]) < int(S[minj][1]):
minj = j
(S[i], S[minj]) = (S[minj], S[i])
return S
def bubble(B):
flag = True
while flag:
flag = False
for j in reversed(range(1, n)):
if int(B[j][1]) < int(B[j-1][1]):
(B[j-1], B[j]) = (B[j], B[j-1])
flag = True
return B
def isStable(inA, out):
for i in range(0, n):
for j in range(i+1, n):
for a in range(0, n):
for b in range(a+1, n):
if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
return "Not stable"
return "Stable"
n = int(input())
A = input().split(' ')
B = bubble(A[:])
print(" ".join(B))
print(isStable(A, B))
S = select(A[:])
print(" ".join(S))
print(isStable(A, S)) | 1 | 23,970,847,480 | null | 16 | 16 |
N = int(input())
A = sorted(map(lambda x: (int(x[1]), x[0]),
enumerate(input().split())), reverse=True)
V = [0]
for i in range(N-1):
a, p = A[i]
s = i+1
V2 = [None]*(s+1)
for t in range(s+1):
v = 0
if t > 0:
v = V[t-1] + a*abs(p-(t-1))
if t < s:
v = max(V[t] + a*abs(p-(N-s+t)), v)
V2[t] = v
V = V2
a, p = A[-1]
for i in range(N):
V[i] += a*abs(p-i)
print(max(V))
| data = list(map(int,input().split()))
if(data[0] < data[1]): data[0],data[1] = data[1],data[0]
def gcd(x,y):
return x if y == 0 else gcd(y,x%y)
print(gcd(data[0],data[1]))
| 0 | null | 16,804,727,032,490 | 171 | 11 |
input()
data = input().split()
data.reverse()
print(' '.join(data)) | N = int(input())
S,T = input().split()
ans = ["a"]*(N*2)
for i in range(N) :
ans[2*i] = S[i]
ans[2*i+1] = T[i]
print(''.join(ans)) | 0 | null | 56,388,547,975,616 | 53 | 255 |
from queue import Queue
def isSafe(row, col):
return row >= 0 and col >= 0 and row<h and col<w and mat[row][col] != '#'
def bfs(row, col):
visited = [[False]*w for _ in range(h)]
que = Queue()
dst = 0
que.put([row, col, 0])
visited[row][col] = True
moves = [[-1, 0],[1, 0], [0, -1], [0, 1]]
while not que.empty():
root = que.get()
row, col, dst = root
for nrow, ncol in moves:
row2 = row + nrow
col2 = col + ncol
if isSafe(row2, col2) is True and visited[row2][col2] is False:
visited[row2][col2] = True
que.put([row2, col2, dst+1])
return dst
h, w = map(int, input().split())
mat = [input() for _ in range(h)]
ans = 0
for row in range(h):
for col in range(w):
if mat[row][col] == '.':
ans = max(ans, bfs(row, col))
print(ans)
| N,M = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
DP = [i for i in range(N+1)]
for m in range(1,M):
coin = C[m]
for total in range(1, N+1):
if total - coin >= 0:
DP[total] = min(DP[total], DP[total - coin] + 1)
print(DP[-1])
| 0 | null | 47,260,824,082,238 | 241 | 28 |
def base_10_to_n(x, n):
ans = []
while x > 0:
x -= 1
ans.append(str(x % n + 1))
x //= n
return ans[::-1]
a = base_10_to_n(int(input()), 26)
ans1 = ''
for i in a:
ans1 += chr(ord('a') + int(i) - 1)
print(ans1)
| def judge(m,f,r):
ret = 'F'
score = m + f
if -1 in (m,f): pass
elif score >= 80: ret = 'A'
elif score >= 65: ret = 'B'
elif score >= 50: ret = 'C'
elif score >= 30:
ret = 'D'
if r >= 50:ret = 'C'
return ret
while True:
m,f,r=map(int,input().split())
if m==f==r==-1: break
print(judge(m,f,r)) | 0 | null | 6,601,247,660,630 | 121 | 57 |
N,M=map(int, input().split())
print("Yes" if N==M else "No") | import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7
a, b, x = rm()
x /= a
if a*b / 2 >= x:
a = 2*x / b
print(90 - math.degrees(math.atan(a/b)))
else:
x = a*b - x
b = 2*x / a
print(math.degrees(math.atan(b/a)))
| 0 | null | 122,697,133,271,790 | 231 | 289 |
import math
R=float(input())
print(2.0*R*math.pi) | R = int(input())
print((R * 2) * 3.14) | 1 | 31,501,957,842,110 | null | 167 | 167 |
for a in range(1,10):
for b in range(1,10):
print("%dx%d=%d" % (a,b,a*b)) | m = input()
c = m[-1]
if c == 's':
print(m+'es')
else:
print(m+'s') | 0 | null | 1,177,584,219,348 | 1 | 71 |
string = raw_input()
for _ in xrange(input()):
order = raw_input().split()
a, b = map(int, order[1:3])
if order[0] == 'print':
print string[a:b+1]
elif order[0] == 'reverse':
# string = string[:a] + string[b:a-1:-1] + string[b+1:]
string = string[:a] + string[a:b+1][::-1] + string[b+1:]
elif order[0] == 'replace':
string = string[:a] + order[3] + string[b+1:] | in_str = raw_input()
q = input()
for i in xrange(q):
order = raw_input().split()
a = int(order[1])
b = int(order[2])+1
if order[0] == "print":
print in_str[a:b]
if order[0] == "reverse":
temp_str = in_str[a:b]
in_str = in_str[:a] + temp_str[::-1] + in_str[b:]
if order[0] == "replace":
in_str = in_str[:a] + order[3] + in_str[b:] | 1 | 2,103,335,723,690 | null | 68 | 68 |
a, b = input().split()
print(a * int(b) if a < b else b * int(a)) | a,b = input().split()
A = a*int(b)
B = b*int(a)
print(A if A<B else B)
| 1 | 84,288,485,128,800 | null | 232 | 232 |
import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
import string
def main():
H,W = i_map()
dy_dx=[[1,0],[0,1],[-1,0],[0,-1]]
rc=[input() for i in range(H)]
ans = 0
for sy in range(H):
for sx in range(W):
if rc[sy][sx] == "#":
continue
dist=[[-1 for _ in range(W)] for _ in range(H)]
dist[sy][sx] = 0
d=deque()
d.append([sx,sy])
while d:
nx, ny = d.popleft()
for dy,dx in dy_dx:
y,x = ny+dy,nx+dx
if 0<=y<H and 0<=x<W and rc[y][x] != "#" and dist[y][x] == -1:
dist[y][x] = dist[ny][nx] + 1
d.append([x,y])
ans = max(ans, max(list(itertools.chain.from_iterable(dist))))
print(ans)
if __name__=="__main__":
main()
| n = input()
m = 0
for i in range(len(n)):
m += int(n[i])
m %= 9
if m == 0:
print("Yes")
else:
print("No") | 0 | null | 49,698,560,188,606 | 241 | 87 |
from collections import deque
d = deque()
n = int(input())
for i in range(n):
s = input()
if s == "deleteFirst":
d.popleft()
elif s == "deleteLast":
d.pop()
elif s[:6] == "insert":
d.appendleft(int(s[7:]))
else:
delkey = int(s[7:])
if delkey in d:
d.remove(delkey)
print(" ".join(map(str,d)))
| class Node:
def __init__(self,key):
self.key = key
self.prev = None
self.next = None
class DoublyLinkedList:
def __init__(self):
self.nil = Node(None)
self.nil.prev = self.nil
self.nil.next = self.nil
def insert(self,key):
new = Node(key)
new.next = self.nil.next
self.nil.next.prev = new
self.nil.next = new
new.prev = self.nil
def listSearch(self,key):
cur = self.nil.next
while cur != self.nil and cur.key != key:
cur = cur.next
return cur
def deleteNode(self, t):
if t == self.nil:
return
t.prev.next = t.next
t.next.prev = t.prev
def deleteFirst(self):
self.deleteNode(self.nil.next)
def deleteLast(self):
self.deleteNode(self.nil.prev)
def deleteKey(self, key):
self.deleteNode(self.listSearch(key))
if __name__ == '__main__':
import sys
input = sys.stdin.readline
n = int(input())
d = DoublyLinkedList()
for _ in range(n):
c = input().rstrip()
if c[0] == "i":
d.insert(c[7:])
elif c[6] == "F":
d.deleteFirst()
elif c[6] =="L":
d.deleteLast()
else:
d.deleteKey(c[7:])
ans = []
cur = d.nil.next
while cur != d.nil:
ans.append(cur.key)
cur = cur.next
print(" ".join(ans))
| 1 | 48,582,716,800 | null | 20 | 20 |
A,B,C,D,E=map(int,input().split())
if A==0 :
print(1)
elif B==0:
print(2)
elif C==0:
print(3)
elif D==0:
print(4)
else :
print(5)
| x = list(map(int, input().split()))
for i in range(len(x)):
if x[i] == 0:
print(i+1)
break
else:
continue | 1 | 13,341,402,045,280 | null | 126 | 126 |
n = int(input())
a = list(map(int, input().split()))
count = {}
for i in range(len(a)):#番号と身長を引く
minus = (i+1) - a[i]
if minus in count:
count[minus] += 1
else:
count[minus] = 1
total = 0
for i in range(len(a)):
plus = a[i] + (i+1)
if plus in count:
total += count[plus]
print(total)
| import sys
import math
sys.setrecursionlimit(10**9)
def main():
N = int(input())
A = list(map(int,input().split()))
dic = [{},{}]
counted = [set(),set()]
def count(x,type):
type = type - 1
if x <= 0:
return
if not x in counted[type]:
dic[type][x] = 1
counted[type].add(x)
else:
dic[type][x] += 1
for i in range(N):
type1 = (i+1)-A[i]
type2 = (i+1)+A[i]
count(type1,1)
count(type2,2)
ans = 0
# print(dic,counted)
for index,cnt in dic[0].items():
if index in counted[1]:
ans += cnt * dic[1][index]
print(ans)
if __name__ == "__main__":
main() | 1 | 26,130,146,082,820 | null | 157 | 157 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
''' ??????????????? '''
# ????????????????????°?????????N(N-1)/2????????§???
# ?¨???????:O(n^2)
def selection_sort(A, N):
swap_num = 0 # ???????????°
for i in range(N):
minj = i
for j in range(i, N, 1):
if A[j] < A[minj]:
minj = j
# swap
if i != minj:
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
swap_num += 1
return (A, swap_num)
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
# A = [5, 2, 4, 6, 1, 3]
# N = len(A)
array_sorted, swap_num = selection_sort(A, N)
print(' '.join(map(str, array_sorted)))
print(swap_num) | # -*- coding: utf-8 -*-
def selection_sort(seq, l):
cnt = 0
for head_i in range(l):
flag = False
min_i = head_i
for target_i in range(head_i+1, l):
if seq[target_i] < seq[min_i]:
min_i = target_i
flag = True
if flag:
seq[head_i], seq[min_i] = seq[min_i], seq[head_i]
cnt += 1
print(' '.join([str(n) for n in seq]))
print(cnt)
def to_int(v):
return int(v)
def to_seq(v):
return [int(c) for c in v.split()]
if __name__ == '__main__':
l = to_int(input())
seq = to_seq(input())
selection_sort(seq, l) | 1 | 19,264,589,090 | null | 15 | 15 |
import numpy as np
N = int(input())
X_low = N // 1.08
X_high = int(X_low + 1)
if np.floor(X_low * 1.08) == N:
print(X_low)
elif np.floor(X_high * 1.08) == N:
print(X_high)
else:
print(':(')
| N=int(input())
import math
X=math.ceil(N/1.08)
if int(X*1.08)==N:
print(X)
else:
print(':(') | 1 | 125,999,447,195,388 | null | 265 | 265 |
from collections import deque
from math import ceil
# n个怪物,d杀伤半径,a杀伤值
n, d, a = map(int, input().split())
ms = [map(int, input().split()) for i in range(n)]
ms = sorted([(pos, ceil(hp / a)) for pos, hp in ms])
bombs = deque()
ans = 0
valid_bomb = 0
for pos, hp in ms:
# 查看队列里的bomb是否对当前怪物有效
while bombs and bombs[0][0] < pos:
bomb_border, bomb_cnt = bombs.popleft()
valid_bomb -= bomb_cnt
# 还需新加多少bomb才能灭掉当前怪物
bomb_cnt = max(0, hp - valid_bomb)
valid_bomb += bomb_cnt
ans += bomb_cnt
# 新加的bomb放入队列
if bomb_cnt > 0:
bombs.append([pos + d * 2, bomb_cnt])
print(ans) | # imos解
n,d,a=map(int,input().split())
xh=[]
for i in range(n):
xx,hh=map(int,input().split())
xh.append([xx,hh])
xh.sort(key=lambda x:x[0])
xl=[x for x,h in xh]
# print(xh)
from math import ceil
from bisect import bisect_right
ans=0
damage=[0]*(n+1)
for i in range(n):
x,h=xh[i]
if damage[i]<h:
need=ceil((h-damage[i])/a)
right=x+2*d
# 爆発に巻き込まれる範囲の右端のindexを取得する
r_idx=bisect_right(xl,right)
# imosしながら爆発させる
damage[i]+=need*a
damage[r_idx]-=need*a
ans+=need
# imosの累積和を取る
damage[i+1]+=damage[i]
print(ans)
| 1 | 82,006,044,245,188 | null | 230 | 230 |
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]
ans = 100000
for i in range(2**H):
cnt = 0
temp = i
group = [0]*H
for j in range(H):
group[j] = cnt
if temp & 1:
cnt += 1
temp >>= 1
div = [0]*H
for j in range(W):
for k in range(H):
if div[group[k]] + S[k][j] > K:
cnt += 1
div = [0]*H
for l in range(H):
div[group[l]] += S[l][j]
if div[group[l]] > K:
cnt = 100000
break
else:
div[group[k]] += S[k][j]
ans = min(ans, cnt)
print(ans)
| # coding: utf-8
from itertools import combinations as combs
H,W,K = list(map(int, input().split()))
arr = []
for i in range(H):
arr.append(list(map(int, list(input()))))
def cut_sum(arr, x1, x2, y):
ret = 0
for i in range(x1, x2):
ret += arr[i][y]
return ret
row_idxes = list(range(1,H))
min_val = float('inf')
for n_rows in range(H):
for row_set in combs(row_idxes, n_rows):
count = len(row_set)
row_lines = [0] + list(row_set)+ [H]
col1, col2 = 0, 1
sums = [0] * (len(row_lines) - 1)
while col2 <= W:
row1 = 0
for box, row2 in enumerate(row_lines[1:]):
sums[box] += cut_sum(arr, row1, row2, col2-1)
if sums[box] > K:
if (col2 - col1) == 1:
count = float('inf')
break
count += 1
col1 = col2 - 1
col2 -= 1
sums = [0] * (len(row_lines) - 1)
break
row1 = row2
if count >= min_val:
break
col2 += 1
if min_val > count:
min_val = count
print(min_val) | 1 | 48,503,794,424,772 | null | 193 | 193 |
# coding:utf-8
class FLOOR:
def __init__(self):
self.room = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
class BUILD:
def __init__(self):
self.floor = [FLOOR(), FLOOR(), FLOOR()]
# 3??????10??¨?±????4?£?
all_rooms = [BUILD(), BUILD(), BUILD(), BUILD()]
# ??\???
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
all_rooms[b-1].floor[f-1].room[r-1] += v
for b in range(4):
for f in range(3):
display = []
for r in range(10):
display.append(str(all_rooms[b].floor[f].room[r]))
print(' ' + ' '.join(display))
if (b < 3):
print('#'*20) | import sys
buildings = tuple(i for i in range(4))
floors = tuple(i for i in range(3))
rooms = tuple(i for i in range(10))
occupant = [[[0 for r in rooms] for f in floors] for b in buildings]
n = input()
for line in sys.stdin:
b, f, r, v = map(int, line.split())
occupant[b - 1][f - 1][r - 1] += v
for b in buildings:
if b:
print('####################')
for f in floors:
print("", *occupant[b][f])
| 1 | 1,096,380,182,832 | null | 55 | 55 |
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
for i in range(M):
N -= A_list[i]
if N < 0:
print(-1)
break
if i == M-1:
print(N) | N=int(input())
A=list(map(int,input().split()))
t=[0]*N
for idx,i in enumerate(A):
t[i-1]=idx+1
print(*t) | 0 | null | 106,201,807,734,220 | 168 | 299 |
# -*- coding: utf-8 -*-
X = int(input())
# A**5 - (A-1)**5 = X = 10**9(Xの最大) となるAが
# Aの最大値となる(それ以上Aが大きくなると、Xは上限値を超える)
# → 最大となるAは120
for A in range(-120, 120 + 1):
for B in range(-120, 120):
if A**5 - B**5 == X:
print("{} {}".format(A, B))
exit() | from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N-K):
if A[i] < A[i+K]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 16,326,311,265,720 | 156 | 102 |
n = int(input())
s = str(input())
new_s = s[0]
for i in range(1,len(s)):
if s[i] == s[i-1]:
continue
else:
new_s += s[i]
print(len(new_s))
| n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
s = input()
if s == 'AC':
ac += 1
elif s == 'WA':
wa += 1
elif s == '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 | 89,525,590,579,832 | 293 | 109 |
def main():
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
# 集合的なら
# res = len(set(s) & set(p))
# print(res)
# 線形探索なら
cnt = 0
for i in t:
if i in s:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| A = []
b = []
row = 0
col = 0
row, col = map(int, raw_input().split())
A = [[0 for i in range(col)] for j in range(row)]
for i in range(row):
r = map(int, raw_input().split())
for index, j in enumerate(r):
A[i][index] = j
for i in range(col):
b.append(int(raw_input()))
for i in A:
ret = 0
for j,k in zip(i,b):
ret += j*k
print ret | 0 | null | 616,010,578,888 | 22 | 56 |
S = input()
q = int(input())
for i in range(q):
L = input().split()
a = int(L[1])
b = int(L[2])
slice1 = S[:a]
slice2 = S[a:b+1]
slice3 = S[b+1:]
if L[0] == 'print':
print(slice2)
elif L[0] == 'reverse':
S = slice1 + slice2[::-1] + slice3
elif L[0] == 'replace':
S = slice1 + L[3] + slice3 | n, m = map(int, raw_input().split())
A = []
b = []
for i in range(n):
A += [map(int, raw_input().split())]
for i in range(m):
b += [input()]
for i in range(n):
C = 0
for j in range(m):
C += A[i][j] * b[j]
print C | 0 | null | 1,622,351,545,792 | 68 | 56 |
N=int(input())
L=list(map(int,input().split()))
s=0
R=list()
for i in range(N):
s=s^L[i]
for i in range(N):
R.append(str(s^L[i]))
print(" ".join(R)) | # coding: utf-8
s = input()
ans = "x" * len(s)
print(ans)
| 0 | null | 42,782,789,661,852 | 123 | 221 |
n=list(input())
N=len(n)
k=int(input())
dp1=[[0 for i in range(k+1)] for j in range(N+1)]
dp2=[[0 for i in range(k+1)] for j in range(N+1)]
dp1[0][0]=1
for i in range(1,N+1):
x=int(n[i-1])
if i!=N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j-1]
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*(x-1)+dp2[i-1][j]+dp2[i-1][j-1]*9
elif i!=N and x==0:
for j in range(k+1):
if j==0:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]+dp2[i-1][j-1]*9
elif i==N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*x+dp2[i-1][j]+dp2[i-1][j-1]*9
else:
for j in range(k+1):
if j==0:
dp2[i][j]=dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]+dp2[i-1][j-1]*9
print(dp2[N][k]) | import math
n = int(input())
K = int(input())
def calk1(n):
if n == 0: return 0
m = int(math.log10(n))
num = m * 9
num += n//(10**m)
return num
def calk2(n):
m = int(math.log10(n))
num = m * (m - 1) // 2 * 9**2
num += (n//(10**m)-1) * m * 9
num += calk1(n - (n//(10**m)*10**m))
return num
def calk3(n):
m = int(math.log10(n))
num = m * (m - 1) * (m - 2) // 6 * 9**3
num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
num += calk2(n - (n//(10**m)*10**m))
return num
if n < 10 ** (K - 1): print(0)
else:
if K == 1: print(calk1(n))
elif K == 2: print(calk2(n))
else: print(calk3(n))
| 1 | 75,910,252,105,106 | null | 224 | 224 |
_, lis = input(), list(map(int, input().split()))
print("{} {} {}".format(min(lis), max(lis), sum(lis)))
| from math import gcd
K = int(input())
ans = 0
r = range(1, K+1)
for i in r:
for j in r:
for k in r:
ans += gcd(gcd(i, j), k)
print(ans)
| 0 | null | 18,233,802,465,284 | 48 | 174 |
x = input()
y = x.split(" ")
y = [int(z) for z in y]
w = y[0]
h = y[1]
x = y[2]
r = y[4]
y = y[3]
if (x <= w-r and x >= r) and (y <= h-r and y >= r):
print("Yes")
else:
print("No") | s=input()
t=input()
a = len(s)
b = len(t)
l = []
for i in range(a-b+1):
cnt = 0
c = s[i:i+b]
for x, y in zip(c, t):
if x != y:
cnt +=1
l.append(cnt)
print(min(l)) | 0 | null | 2,039,928,028,868 | 41 | 82 |
inData = int(input())
seqData = list(range(1,inData+1,1))
outData = [0] * inData
for thisData in seqData:
if thisData == inData:
if thisData%3 == 0 or thisData%10==3:
print(" "+str(thisData))
else:
for i in range(5):
i=i+1
over = 10 ** i
tmp = thisData/over
if int(tmp % 10) == 3:
print(" "+str(thisData))
break
else:
pass
print("")
else:
if thisData%3 == 0 or thisData%10==3:
print(" "+str(thisData), end = "")
else:
for i in range(5):
i=i+1
over = 10 ** i
tmp = thisData/over
if int(tmp % 10) == 3:
print(" "+str(thisData), end = "")
break
else:
pass
| n = int(raw_input())
s = ''
for i in range(1,n+1):
if (i % 3) == 0:
s = s + ' ' + str(i)
else:
x = i
while True:
if (x % 10) == 3:
s = s + ' ' + str(i)
break
x = x / 10
if x == 0:
break
print s | 1 | 931,723,608,768 | null | 52 | 52 |
a = int(input())
a-=1
cnt = 0
for i in range(1,a):
if i < a:
a -= 1
cnt += 1
else :
break
print (cnt) | #!/usr/bin/env python3
n = int(input())
print(int((n - 1) / 2) if n % 2 == 1 else int(n / 2) - 1)
| 1 | 153,471,659,261,158 | null | 283 | 283 |
n=int(input())
s=[]
t=[]
flag=0
ans=0
for i in range(n):
ss,tt=map(str,input().split())
s.append(ss)
t.append(int(tt))
x=input()
for i in range(n):
if s[i]==x:
flag=1
continue
if flag == 1:
ans+=t[i]
print(ans) | #coding:utf-8
#1_6_A 2015.4.1
input()
numbers = input().split()
numbers.reverse()
print(' '.join(numbers)) | 0 | null | 49,225,166,522,698 | 243 | 53 |
n,K = map(int, input().split())
mod = 10**9 + 7
def modcomb(n,a,mod):
cnt = 1
for i in range(a):
cnt *= (n-i)
cnt *= pow(i+1,mod-2,mod)
cnt %= mod
# print(cnt)
return cnt
def modconb(n,mod):
# テーブルを作る
fac = [0]*(n+1)
finv = [0]*(n+1)
inv = [0]*(n+1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,n+1):
fac[i] = fac[i-1]*i % mod
inv[i] = mod - inv[mod%i] * (mod//i) % mod
finv[i] = finv[i-1] * inv[i] %mod
return fac,finv
# return(fac[n]*(finv[k]*finv[n-k]%mod)%mod)
cnt = 0
if n-1 >= K:
fac1,finv1 = modconb(n,mod)
for k in range(K+1):
c1 = fac1[n]*(finv1[k]*finv1[n-k]%mod)%mod
c2 = fac1[n-1]*(finv1[k]*finv1[n-1-k]%mod)%mod
cnt += c1*c2
cnt %= mod
print(cnt%mod)
else:
cnt1 = modcomb(2*(n-1),n-1,mod)
cnt2 = modcomb(2*(n-1),n,mod)
ans = (cnt1+cnt2)%mod
print(ans) | MOD = 1000000007#い つ も の
n,k = map(int,input().split())
nCk = 1#nC0
ans = 1
if k > n-1:
k = n-1
for i in range(1,k+1,1):
nCk = (((nCk*(n-i+1))%MOD)*pow(i,1000000005,1000000007))%MOD
ans = (ans%MOD + ((((nCk*nCk)%MOD)*(n-i)%MOD)*pow(n,1000000005,1000000007)%MOD)%MOD)%MOD
print(ans)
| 1 | 67,109,039,453,536 | null | 215 | 215 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
ans = "APPROVED"
for i in range(n):
if (a[i] % 2 == 0):
if (a[i] % 3 == 0 or a[i] % 5 == 0):
pass
else:
ans = "DENIED"
break
print(ans)
| N = int(input())
A = list(map(int, input().split()))
even_numbers = [a for a in A if a % 2 == 0]
is_approved = all([even_num % 3 == 0 or even_num % 5 == 0 for even_num in even_numbers])
if is_approved:
print('APPROVED')
else:
print('DENIED')
| 1 | 68,948,273,996,480 | null | 217 | 217 |
import collections
N=int(input())
A=[x for x in input().split()]
c = collections.Counter(A)
for i in range(N):
print(c["{}".format(str(i+1))]) | LARGE = 10 ** 9 + 7
def solve(n, k):
# singular cases
if k == 0:
return 1
elif k == 1:
return n * (n - 1)
# pow
pow_mod = [1] * (n + 1)
for i in range(n):
pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
pow_mod_inv = [1] * (n + 1)
pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
for i in range(n - 1, 0, -1):
pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE
res = 0
for i in range(min(k, n - 1) + 1):
# find where to set 0
pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
# how to assign ones
assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
res += pick_zeros * assign_ones
res %= LARGE
return res
def main():
n, k = map(int, input().split())
res = solve(n, k)
print(res)
def test():
assert solve(3, 2) == 10
assert solve(200000, 1000000000) == 607923868
assert solve(15, 6) == 22583772
if __name__ == "__main__":
test()
main()
| 0 | null | 49,590,746,858,912 | 169 | 215 |
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
l = int(input())
print((l / 3) ** 3)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| L = int(input())
r = (L/3)**3
print(r)
| 1 | 46,787,361,649,600 | null | 191 | 191 |
N = int(input())
s = 0
for i in range(1,N+1):
if i%2 != 0:
s += 1
print(s/N) | import sys
w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
lines = sys.stdin.readline().rstrip()
if not lines:
break
words = lines.split( " " )
for i in range( len( words ) ):
if w == words[i].lower():
cnt += 1
print( cnt ) | 0 | null | 89,279,005,364,292 | 297 | 65 |
n, m = map(int,input().split())
a = list(map(int,input().split()))
total = sum(a)
popular = [x for x in a if x*4*m >= total]
if len(popular) >= m:
print("Yes")
else:
print("No")
| N, M = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = 0
for i in range(M):
if sum(a)%(M*4)== 0:
if a[i] >= int(sum(a)/(M*4)):
b += 1
if sum(a)%(M*4)!= 0:
if a[i] > int(sum(a)//(M*4)):
b += 1
if b == M:
print('Yes')
elif b < M:
print('No') | 1 | 38,608,053,742,102 | null | 179 | 179 |
n=int(input())
def dfs(s):
if len(s)==n:
print(s)
else:
for i in range(ord('a'),max(map(ord,list(s)))+2):
dfs(s+chr(i))
dfs('a') | x = int(input())
hap = x // 500
hap2 = (x - hap*500)//5
ans = hap*1000 + hap2*5
print(ans) | 0 | null | 47,472,962,285,308 | 198 | 185 |
N = int(input())
mod = 10**9+7
ans = pow(10, N, mod) - ((pow(9, N, mod) * 2) - pow(8, N, mod))
ans %= mod
print(ans)
| n = int(input())
mod = 10**9+7
ans = pow(10,n)
ans -= pow(9,n)*2
ans += pow(8,n)
print(ans%mod)
| 1 | 3,166,000,633,510 | null | 78 | 78 |
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in range(n)]
ab = [(x,y) for x,y in zip(a,b)]
from operator import itemgetter
ab = tuple(sorted(ab,key=itemgetter(0),reverse=True))
dp = [[-10**14]*(n+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
for j in range(i+2):
if j >= 1:
dp[i+1][j] = max(dp[i][j]+ab[i][0]*abs(ab[i][1]-(n-1-(i-j))),dp[i][j-1]+ab[i][0]*abs(ab[i][1]+1-j))
if j == 0:
dp[i+1][0] = dp[i][0] + ab[i][0]*abs(ab[i][1]-(n-1-i))
print(max(dp[n])) | import sys
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
input = sys.stdin.readline
n = int(input())
arr = list(map(int,input().split()))
arr = list(enumerate(arr))
arr.sort(reverse = True, key = lambda x:(x[1]))
dp = [[0 for c in range(n+1)] for r in range(n+1)]
ans = 0
for r in range(n+1):
st = r-1
for c in range(n+1-r):
if r==c==0:
pass
elif r-1<0:
dp[r][c] = dp[r][c-1] + ( arr[st][1] * abs((arr[st][0]+1) - (n+1-c)) )
elif c-1<0:
dp[r][c] = dp[r-1][c] + ( arr[st][1] * abs((arr[st][0]+1) - r) )
else:
dp[r][c] = max( dp[r-1][c] + ( arr[st][1] * abs((arr[st][0]+1) - r) ),
dp[r][c-1] + ( arr[st][1] * abs((arr[st][0]+1) - (n+1-c)) )
)
ans = max(ans, dp[r][c])
st += 1
print(ans) | 1 | 33,599,736,787,262 | null | 171 | 171 |
n,m = map(int,input().split())
memo2 = [False for i in range(n)]
memo = [0 for i in range(n)]
count1,count2 = 0,0
for i in range(m):
p,l = input().split()
p = int(p)-1
if memo2[p]:
continue
else:
if l == 'WA':
memo[p]+=1
else:
memo2[p] = True
count2 += 1
count1+=memo[p]
print(count2,count1) | n = int(input())
a = list(map(int,input().split()))
a.sort()
dp = [0]*(a[-1]+1)
for i in a:
for j in range(i, a[-1]+1, i):
dp[j] += 1
ans = 0
for i in a:
if dp[i]==1:
ans += 1
print(ans) | 0 | null | 54,127,805,472,048 | 240 | 129 |
N=int(input())
A=["a","b","c","d","e","f","g","h","i","j"]
L=[{}for i in range(N+1)]
L[1]["a"]=1
#print(L)
for i in range(2,N+1):
for j,k in L[i-1].items():
for l in range(k+1):
L[i][j+A[l]]=max(l+1,k)
#print(L[N])
ans=L[N].keys()
ans=list(ans)
ans.sort()
for i in range(len(ans)):
print(ans[i]) | from collections import deque
n = int(input())
q = deque(["a"])
# 最後に最新の文字数のセットだけ拾う
for i in range(n - 1):
next_q = deque()
for curr in q:
suffix = ord(max(curr)) + 1
for x in range(ord("a"), suffix + 1):
next_q.append(curr + chr(x))
q = next_q
print(*q, sep="\n") | 1 | 52,496,898,654,262 | null | 198 | 198 |
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
N,P = map(int,S().split())
S = LI2()
if P == 2 or P == 5: #10と素でない場合一番右の桁で決まる
ans = 0
for i in range(N):
if S[i] % P == 0:
ans += i+1
print(ans)
exit()
A = [0] #A[i] = 下i桁をPで割った余り
for i in range(1,N+1):
A.append((A[i-1]+pow(10,i,P)*S[N-i]) % P)
from collections import Counter
c = Counter(A)
B = c.values()
ans = 0
for i in B:
ans += (i*(i-1)//2)
print(ans) | def main():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += (i + 1)
print(ans)
exit()
sum_rem = [0] * N
sum_rem[0] = int(S[N - 1]) % P
ten = 10
for i in range(1, N):
a = (int(S[N - 1 - i]) * ten) % P
sum_rem[i] = (a + sum_rem[i - 1]) % P
ten = (ten * 10) % P
ans = 0
count = [0] * P
count[0] = 1
for i in range(N):
ans += count[sum_rem[i]]
count[sum_rem[i]] += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 57,919,876,699,090 | null | 205 | 205 |
while True:
h,w=map(int,input().split())
if(h==0):
break
for i in range(h):
for j in range(w):
print("#",end="")
print()
print()
| import sys
while True:
ins = input().split()
h = int(ins[0])
w = int(ins[1])
if h == 0 and w == 0:
break
for i in range(h):
for j in range(w-1):
sys.stdout.write("#")
print("#")
print("") | 1 | 773,097,749,468 | null | 49 | 49 |
a, b, k = map(int, input().split())
if a > k:
x = a - k
y = b
elif a + b > k:
x = 0
y = a + b - k
else:
x = 0
y = 0
print(int(x), int(y)) | # A - Connection and Disconnection
def count(s, c):
count_ = s.count(c*2)
while c*3 in s:
s = s.replace(c*3, c+'_'+c)
while c*2 in s:
s = s.replace(c*2, c+'_')
return min(count_, s.count('_'))
def get_startswith(s, c):
key = c
while s.startswith(key+c):
key += c
return len(key)
def get_endswith(s, c):
key = c
while s.endswith(key+c):
key += c
return len(key)
import string
S = input()
K = int(input())
lower = string.ascii_lowercase
ans = 0
if S[0] == S[-1:]:
start = get_startswith(S, S[0])
end = get_endswith(S, S[0])
if start == end == len(S):
print(len(S) * K // 2)
else:
ans = 0
ans += start // 2
ans += end // 2
ans += ((start + end) // 2) * (K - 1)
for c in lower:
ans += count(S[start:len(S)-end], c) * K
print(ans)
else:
for c in lower:
ans += count(S, c)
print(ans * K) | 0 | null | 140,032,672,931,242 | 249 | 296 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_D
def reverse(s, a, b):
s1 = s[0:a]
s2 = s[a:b+1]
s2 = s2[::-1]
s3 = s[b+1:len(string)]
return s1 + s2 + s3
def replace(s, a, b, p):
s1 = s[0:a]
s2 = p
s3 = s[b+1:len(string)]
return s1 + s2 + s3
string = input()
q = int(input())
for _ in range(q):
c = input().split()
if c[0] == "print":
print(string[int(c[1]):int(c[2])+1])
if c[0] == "reverse":
string = reverse(string, int(c[1]), int(c[2]))
if c[0] == "replace":
string = replace(string, int(c[1]), int(c[2]), c[3]) | s = input()
q = int(input())
for i in range(q):
command = input().split()
command[1] = int(command[1])
command[2] = int(command[2])
if command[0] == 'print':
print(s[command[1]:command[2]+1])
elif command[0] == 'reverse':
s = s[command[1]:command[2]+1][::-1].join([s[:command[1]], s[command[2]+1:]])
elif command[0] == 'replace':
s = command[3].join([s[:command[1]], s[command[2]+1:]]) | 1 | 2,084,570,734,916 | null | 68 | 68 |
#0除算
import math
def popcount(x):
s=0
y=int(math.log2(x))+2
for i in range(y):
if(x>>i)&1:
s+=1
return x%s
n=int(input())
x=input()[::-1]
#1がなんこ出るのか
c=x.count("1")
#c+1とc-1だけ考えれば良い
#c=1の時場合分け
#m[i][j]:2^iまで考えたときのmod(c+j-1)
if c!=1:
m=[[1%(c-1),1%(c+1)]]
for i in range(n-1):
m.append([(2*m[-1][0])%(c-1),(2*m[-1][1])%(c+1)])
l=[0,0]
for i in range(n):
if x[i]=="1":
l[0]+=m[i][0]
l[1]+=m[i][1]
l[0]%=(c-1)
l[1]%=(c+1)
else:
m=[[1%(c+1),1%(c+1)]]
for i in range(n-1):
m.append([(2*m[-1][0])%(c+1),(2*m[-1][1])%(c+1)])
l=[0,0]
for i in range(n):
if x[i]=="1":
l[0]+=m[i][0]
l[1]+=m[i][1]
l[0]%=(c+1)
l[1]%=(c+1)
#一個だけ変えたいので全体を求める
#最初以外はpopcount使って間に合う
ans=[0]*n
for i in range(n):
if x[i]=="1":
if c-1==0:
ans[i]=0
continue
p=(l[0]+(c-1)-m[i][0])%(c-1)
ans[i]+=1
while p!=0:
p=popcount(p)
ans[i]+=1
else:
p=(l[1]+m[i][1])%(c+1)
ans[i]+=1
while p!=0:
p=popcount(p)
ans[i]+=1
ans=ans[::-1]
for i in range(n):
print(ans[i])
| n,k,s = map(int,input().split())
ans = []
for i in range(k):
ans.append(str(s))
for j in range(n-k):
if s != 1000000000:
ans.append(str(s+1))
else:
ans.append(str(s-1))
print(' '.join(ans)) | 0 | null | 49,878,082,375,226 | 107 | 238 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
R, C, K = mapint()
dp = [[[0]*C for _ in range(R)] for _ in range(4)]
from collections import defaultdict
dic = [[0]*C for _ in range(R)]
for _ in range(K):
r, c, v = mapint()
dic[r-1][c-1] = v
for r in range(R):
for c in range(C):
v = dic[r][c]
for i in range(4):
if c!=0:
dp[i][r][c] = dp[i][r][c-1]
if r!=0:
dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
for i in range(2, -1, -1):
dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v)
ans = 0
for i in range(4):
ans = max(ans, dp[i][R-1][C-1])
print(ans)
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P *= -1
Q *= -1
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
S = (-P) // (P + Q)
T = (-P) % (P + Q)
if T != 0:
print(S * 2 + 1)
else:
print(S * 2)
| 0 | null | 68,756,096,294,970 | 94 | 269 |
while True:
m,f,r=map(int,input().split())
if m==-1 and f==-1 and r==-1:
break
if m==-1 or f==-1:
print('F')
elif m+f>=80:
print('A')
elif 80>(m+f)>=65:
print('B')
elif 65>(m+f)>=50 :
print('C')
elif 50>(m+f)>=30:
if r>=50:
print('C')
else:
print('D')
elif r>=50:
print('C')
elif m+f<30:
print('F')
else:
pass
| N = input()
flag = False
for i in range(len(N)):
if N[i] =="7":
flag =True
if flag:
print ("Yes")
else :
print ("No") | 0 | null | 17,910,387,866,272 | 57 | 172 |
N = int(input())
L = [i for i in range(1, N + 1) if i % 2 != 0]
A = len(L) / N
print(A) | import sys
x = sys.stdin.readline()
a_list = x.split(" ")
if int(a_list[0]) < int(a_list[1]) and int(a_list[1]) < int(a_list[2]):
print "Yes"
else:
print "No" | 0 | null | 88,708,183,050,400 | 297 | 39 |
n=int(input())
a=[input() for i in range(n)]
b=a.count("AC")
c=a.count("TLE")
d=a.count("WA")
e=a.count("RE")
print(f"AC x {b}")
print(f"WA x {d}")
print(f"TLE x {c}")
print(f"RE x {e}")
| def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n=int(input())
ar=[]
for _ in range(n):
ar.append(input())
from collections import Counter
c=Counter(ar)
print("AC x",c["AC"])
print("WA x",c["WA"])
print("TLE x",c["TLE"])
print("RE x",c["RE"]) | 1 | 8,773,607,053,760 | null | 109 | 109 |
n = int(input())
a = list(sorted(map(int,input().split())))[::-1]
ans = 0
for x in range(1,n):
ans += a[x//2]
print(ans) | N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
j = 1
for i in range(2,N):
ans += A[j]
if i % 2 == 1:
j += 1
print(ans) | 1 | 9,204,335,981,958 | null | 111 | 111 |
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M1 != M2 else 0) | n = int(input())
L = []
for _ in range(n):
L.append(int(input()))
def InsertionSort(L, n, g):
for i in range(n):
global cnt
v = L[i]
j = i - g
while j >= 0 and L[j] > v:
L[j+g] = L[j]
j -= g
cnt += 1
L[j+g] = v
def ShellSort(L, n):
gt = 1
g = []
while n >= gt:
g.append(gt)
gt = 3 * gt + 1
print(len(g))
g = g[::-1]
print(' '.join(str(x) for x in g))
for x in g:
InsertionSort(L, n, x)
print(cnt)
for i in L:
print(i)
cnt = 0
ShellSort(L, n)
| 0 | null | 62,453,987,604,398 | 264 | 17 |
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 02:42:25 2020
@author: liang
"""
"""
n進数問題
【原則】 大きな数の計算をしない
⇒ 1の桁から計算する
171-C いびつなn進数
27 -> a(26)a(1)となる
⇒先にa(1)だけもらってN%26とすることで解決
ASCII化 ord()
文字化 chr()
"""
N = int(input())
res = str()
while N > 0:
N -= 1 #"a"として予め設置
res += chr(ord("a") + N%26)
N //= 26
print(res[::-1]) | def solve(n):
ret = []
while n > 26:
if n % 26 == 0:
ret = [26] + ret
n = (n - 26) // 26
else:
ret = [n % 26] + ret
n = n // 26
ret = [n] + ret
return ret
n = int(input())
ans = ''.join([chr(ord('a') + i - 1) for i in solve(n)])
print(ans) | 1 | 12,005,536,816,572 | null | 121 | 121 |
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n, m = ns()
c = na()
dp = [INF for _ in range(n + 1)]
dp[0] = 0
for ci in c:
for i in range(n + 1 - ci):
dp[i + ci] = min(dp[i + ci], dp[i] + 1)
print(dp[n])
if __name__ == '__main__':
main()
| n,m=[int(j) for j in input().split()]
c=[int(j) for j in input().split()]
dp=[10**18]*(n+1)
dp[0]=0
for i in c:
for j in range(i,n+1):
dp[j]=min(dp[j],dp[j-i]+1)
print(dp[-1])
| 1 | 140,175,221,788 | null | 28 | 28 |
a,b=map(int,input().split())
print('Yes' if a==b else 'No') | n=input().split()
if int(n[0])==int(n[1]):
print("Yes")
else:
print("No") | 1 | 83,441,090,922,222 | null | 231 | 231 |
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
if debugmode:
print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True
n2 = [1 for _ in range(3010)]
for i in range(1, 3010):
n2[i] = n2[i - 1] * 2 % mod
n, s = MAP()
a = LIST()
dp = [[0 for _ in range(s + 1)] for _ in range(n)]
if s >= a[0]:
dp[0][a[0]] = 1
for i in range(1, n):
for j in range(1, min(s + 1, a[i])):
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= mod
if a[i] <= s:
dp[i][a[i]] = dp[i - 1][a[i]] * 2 + n2[i]
dp[i][a[i]] %= mod
for j in range(a[i] + 1, s + 1):
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i]]
dp[i][j] %= mod
print(dp[n - 1][s])
| def area_cal(input_fig):
stack = []
# area = [[面積計算が始まった位置, 面積],・・・]
area = []
total = 0
for i in range(len(input_fig)):
fig = input_fig[i]
if fig == "\\":
stack.append(i)
elif fig == "/" and stack:
j = stack.pop()
width = i - j
total += width
while area and area[-1][0] > j:
width += area[-1][1]
area.pop()
area.append([i,width])
return area, total
input_fig = input()
area, total = area_cal(input_fig)
print(total)
if area:
print(len(area),*list(zip(*area))[1])
else:
print(0)
| 0 | null | 8,776,673,305,142 | 138 | 21 |
N,K=map(int,input().split())
p=10**9 + 7
L_min,L_max=0,0
for i in range(K-1,N+1):
L_min+=i*(i+1)//2 - 1
L_max+=(N*(N+1)//2)-((N-i-1)*(N-i)//2)
ans = (L_max-L_min)%p
print(ans)
| first_line = input()
length = int(first_line)
second_line = input()
numbers_str = second_line.split()
result_list = numbers_str[::-1]
result = " ".join(result_list)
print(result)
| 0 | null | 17,123,714,108,758 | 170 | 53 |
def isprime(x):
if x==2:
return True
if x<2 or x&1==0:
return False
return pow(2,x-1,x)==1
cnt=0
n=int(input())
for i in range(n):
a=int(input())
if isprime(a):
cnt+=1
print(cnt) | a,b,c=map(int, input().split())
A=(b*c)
if A>a:
print('Yes')
elif A==a:
print('Yes')
else:
print('No') | 0 | null | 1,809,846,130,796 | 12 | 81 |
my_set = set()
n = int(input())
for _ in range(n):
command, dna = input().split()
if command == 'insert':
my_set.add(dna)
elif dna in my_set:
print('yes')
else:
print('no')
| n = int(input())
index = set()
for _ in range(n):
command, string = input().split()
if command == "insert":
index.add(string)
else:
if string in index:
print("yes")
else:
print("no")
| 1 | 77,980,231,020 | null | 23 | 23 |
debt=100000
week=input()
for i in range(week):
debt=debt*1.05
if debt%1000!=0:
debt=int(debt/1000)*1000+1000
print debt | import math
loan = 100000
n = int(input())
for i in range(n):
interest = math.ceil(loan * 0.05 / 1000) * 1000
loan += interest
print(loan) | 1 | 1,278,938,102 | null | 6 | 6 |
import numpy as np
S=input()
N=len(S)
mod=[0 for i in range(2019)]
mod2=0
ten=1
for i in range(N-1,-1,-1):
s=int(S[i])*ten
mod2+=np.mod(s,2019)
mod2=np.mod(mod2,2019)
mod[mod2]+=1
ten=(ten*10)%2019
ans=0
for i in range(2019):
k=mod[i]
if i==0:
if k>=2:
ans+=k*(k-1)//2+k
else:
ans+=k
else:
if k>=2:
ans+=k*(k-1)//2
print(ans) | from collections import Counter
S = input()
# S = "12345"*40000
N = len(S)
l = [0]*(N+1)
for i in range(N-1, -1, -1):
l[i] = (l[i+1] + pow(10, N-i, 2019) * int(S[i])) % 2019
# if i%10000 == 0:
# print(i)
# print(list(Counter(l).values()))
r = sum(m*(m-1)//2 for m in Counter(l).values())
print(r) | 1 | 30,817,048,921,376 | null | 166 | 166 |
n = int(input())
a = list(map(int, input().split()))
l = [0] * n
for i in range(n - 1):
if a[i] > 0:
l[a[i] - 1] += 1
for i in range(n):
print(l[i])
| n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for boss in a:
ans[boss-1] += 1
for sub in ans:
print(sub) | 1 | 32,486,800,245,670 | null | 169 | 169 |
N,K = list(map(int, input().split(" ")))
H = sorted(list(map(int, input().split(" "))), reverse=True)
Z = 0
R = 0
for n,e in enumerate(H):
if (n == K):
Z = n
break
elif (K >= len(H)):
Z = len(H)
break
for i in H[Z:]:
R += i
print(R)
| N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
for i in range(min(K, N)):
A[i] = 0
ans = sum(A)
print(ans) | 1 | 78,750,428,184,290 | null | 227 | 227 |
import sys
class Node:
def __init__(self, x):
self.x = x
def set_prev(self, prev):
self.prev = prev
def set_next(self, next):
self.next = next
class DoublelyLinkedList:
def __init__(self):
self.nil = Node(None)
self.nil.set_next(self.nil)
self.nil.set_prev(self.nil)
def insert(self, x):
new_elem = Node(x)
new_elem.set_next(self.nil.next)
new_elem.set_prev(self.nil)
self.nil.next.set_prev(new_elem)
self.nil.set_next(new_elem)
def list_search(self, x):
cur = self.nil.next
while cur != self.nil and cur.x != x:
cur = cur.next
return cur
def _delete(self, node):
node.prev.set_next(node.next)
node.next.set_prev(node.prev)
def delete_first(self):
self._delete(self.nil.next)
def delete_last(self):
self._delete(self.nil.prev)
def delete(self, x):
del_node = self.list_search(x)
if del_node.x is not None:
self._delete(del_node)
def main():
d_linked_list = DoublelyLinkedList()
for i in sys.stdin:
if 'insert' in i:
x = i[7:-1]
d_linked_list.insert(x)
elif 'deleteFirst' in i:
d_linked_list.delete_first()
elif 'deleteLast' in i:
d_linked_list.delete_last()
elif 'delete' in i:
x = i[7:-1]
d_linked_list.delete(x)
else:
pass
results = []
cur = d_linked_list.nil.next
while cur.x is not None:
results.append(cur.x)
cur = cur.next
print(*results)
if __name__ == "__main__":
main()
| N,K=map(int, input().split())
list=[]
while N>=K:
x=N%K
N=N//K
list.append(x)
list.append(N)
print(len(list))
| 0 | null | 32,266,338,882,260 | 20 | 212 |
def main():
N = input_int()
S = input()
count = 1
for i in range(1, N):
if S[i-1] != S[i]:
count += 1
print(count)
def input_int():
return int(input())
# def input_int_tuple():
# return map(int, input().split())
# def input_int_list():
# return list(map(int, input().split()))
main()
| g = input()
l = []
q = []
n = 0
for x in range(len(g)):
if g[x] == '\\':
if n:
l.append(n)
n = 0
if q:
q.append(-1)
q.append(x)
elif g[x] == '/':
if q:
while True:
p = q.pop()
if p == -1:
n += l.pop()
else:
break
n += x-p
else:
pass
if n:
l.append(n)
for j in range(l.count(0)):
l.remove(0)
print(sum(l))
print(len(l), *l) | 0 | null | 85,282,115,598,442 | 293 | 21 |
(X,N) = map(int,input().split())
if N == 0:
print(X)
else:
p = list(map(int,input().split()))
for i in range(N+1):
if (X - i) not in p:
print(X-i)
break
elif(X+i) not in p:
print(X+i)
break | x, n = map(int, input().split())
p = [int(s) for s in input().split()]
min_val = 101
for i in range(102):
if i not in p:
if abs(i - x) < min_val:
min_val = abs(i - x)
ans = i
print(ans) | 1 | 14,022,393,596,968 | null | 128 | 128 |
sec = int(input())
m, s = divmod(sec, 60)
h, m = divmod(m, 60)
print('%d:%d:%d' % (h, m, s)) | n=int(input())
a=[int(x) for x in input().split()]
mx=0
mae=a[0]
for i in a:
if i<mae:
mx=mx+mae-i
else:
mae=i
print(mx) | 0 | null | 2,457,997,545,670 | 37 | 88 |
n=int(input())
s=input()
flag=0
ans=0
for si in s:
if si=='A':
flag=1
elif si=='B' and flag==1:
flag=2
elif si=='C' and flag==2:
ans+=1
flag=0
else:
flag=0
print(ans)
| _ = input()
s = input()
x = s.count('ABC')
print(x) | 1 | 99,246,543,223,160 | null | 245 | 245 |
# coding=utf-8
def main():
n = input()
s = ''
for i in range(1, n + 1):
x = i
if x % 3 == 0:
s += ' ' + str(i)
continue
while x:
if x % 10 == 3:
s += ' ' + str(i)
break
x /= 10
print s
if __name__ == '__main__':
main() | n=input()
print "",
for i in xrange(1,n+1):
if i%3==0 or '3' in str(i):
print i, | 1 | 926,299,589,898 | null | 52 | 52 |
A,B=map(int,input().strip().split())
print(max(A-2*B,0)) | import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
A, B = map(int, input().split())
print(max(0, A - 2 * B)) | 1 | 166,334,680,527,300 | null | 291 | 291 |
A, B, K = map(int, input().split())
if A >= K:
print(str(A - K) + ' ' + str(B))
else:
print(str(0) + ' ' + str(max((B - (K - A)), 0)))
| A, B, K = [int(x) for x in input().split()]
if K <= A:
print(A - K, B)
else:
print(0, max(0, A + B - K)) | 1 | 103,907,184,141,312 | null | 249 | 249 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.