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
|
---|---|---|---|---|---|---|
N = int(input())
ans = 0
for a in range(1, 10 ** 6 + 1):
for b in range(1, 10 ** 6 + 1):
if a * b >= N:
break
ans += 1
print(ans)
| n=int(input())
a=list(map(int,input().split()))
a.sort()
am=max(a)
dp=[[True,0] for _ in range(am+1)]
count=0
for i in a:
if dp[i][0]==False:
continue
else:
if dp[i][1]==1:
dp[i][0]=False
count-=1
else:
dp[i][1]=1
count+=1
for j in range(2*i,am+1,i):
dp[j][0]=False
print(count) | 0 | null | 8,447,542,077,440 | 73 | 129 |
s=input()
num=s.count("R")
if num==2:
if s=="RSR":
ans=1
else:
ans=2
else:
ans=num
print(ans) | # -*- coding: utf-8 -*-
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
dic = {s:a, t:b}
dic[u] = dic[u] - 1
print(dic[s], dic[t]) | 0 | null | 38,612,340,363,718 | 90 | 220 |
A,B = map(int,input().split())
if A<=9 and B<=9:print(A*B)
else : print(-1) | import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
inf=10**9
h,w=MI()
ss=[SI() for _ in range(h)]
cc=[[0]*w for _ in range(h)]
if ss[0][0]=="#":cc[0][0]=1
for i in range(h):
for j in range(w):
if (i,j)==(0,0):continue
u=l=inf
if i-1>=0:
u=cc[i-1][j]
if ss[i][j]=="#" and ss[i-1][j]==".":u+=1
if j-1>=0:
l=cc[i][j-1]
if ss[i][j]=="#" and ss[i][j-1]==".":l+=1
cc[i][j]=min(u,l)
print(cc[h-1][w-1])
main() | 0 | null | 103,398,104,425,590 | 286 | 194 |
h,w=map(int,input().split())
field=[list(input()) for i in range(h)]
ans=[[0 for i in range(w)]for j in range(h)]
if field[0][0]=='#':
ans[0][0]=1
def black(i,j,f):
if f==1:
if field[i][j]=='#' and field[i-1][j]=='.':
return 1
else:
return 0
else:
if field[i][j]=='#' and field[i][j-1]=='.':
return 1
else:
return 0
for i in range(h):
for j in range(w):
if i==0 and j==0:
continue
elif i==0:
ans[i][j]=ans[i][j-1]+black(i,j,2)
elif j==0:
ans[i][j]=ans[i-1][j]+black(i,j,1)
else:
ans[i][j]=min(ans[i-1][j]+black(i,j,1),ans[i][j-1]+black(i,j,2))
print(ans[-1][-1]) | import sys
def input(): return sys.stdin.readline().rstrip()
import math
X = int(input())
ans = False
money = 100
year = 0
while money < X:
money += money // 100
year += 1
print(year)
| 0 | null | 38,211,034,537,170 | 194 | 159 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = []
for i in range(k,n):
ans.append(a[i] - a[i-k])
for j in ans:
if j > 0:
print('Yes')
else:
print('No') | N = int(input())
arr = list(map(int, input().split()))
s = 0
for i in range(N):
s ^= arr[i]
for i in range(N):
arr[i] ^= s
print(' '.join(map(str, arr))) | 0 | null | 9,868,770,813,648 | 102 | 123 |
(h, n), *m = [[*map(int, i.split())] for i in open(0)]
dp = [0] * 20001
for i in range(1, h + 1):
dp[i] = min(dp[i-a]+b for a, b in m)
print(dp[h])
| A = [[[0 for r in range(10)] for f in range(3)] for b in range(4)] # A[b][f][r]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().split())
A[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print(' %d' %(A[b][f][r]), end='')
print('')
if b < 3:
print('#'*20) | 0 | null | 41,232,982,191,020 | 229 | 55 |
n = int(input())
m = [[0 for j in range(n)] for i in range(n)]
color = [0 for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
time = [0]
def dfs(u):
color[u] = 1
time[0] += 1
d[u] = time[0]
for i in range(n):
if m[u][i] == 1 and color[i] == 0:
dfs(i)
color[u] = 2
time[0] += 1
f[u] = time[0]
def main():
for i in range(n):
data = list(map(int, input().split()))
for j in range(2, len(data)):
m[data[0]-1][data[j]-1] = 1
for i in range(n):
if color[i] == 0:
dfs(i)
for i in range(n):
print(i+1, d[i], f[i])
if __name__ == '__main__':
main()
| # coding: utf-8
# Your code here!
n = int(input())
M = []
for i in range(n):
adj = list(map(int,input().split()))
if adj[1] == 0:
M += [[]]
else:
M += [adj[2:]]
time = 1
ans = [[j+1,0,0] for j in range(n)] # id d f
while True:
for i in range(n):
if ans[i][1] == 0:
stack = [i]
ans[i][1] = time
time += 1
break
elif i == n-1:
for k in range(n):
print(*ans[k])
exit()
while stack != []:
u = stack[-1]
if M[u] != []:
for i in range(len(M[u])):
v = M[u][0]
M[u].remove(v)
if ans[v-1][1] == 0:
ans[v-1][1] = time
stack.append(v-1)
time += 1
break
else:
stack.pop()
ans[u][2] = time
time += 1
| 1 | 2,847,913,198 | null | 8 | 8 |
stations = input()
if 'A' in stations and 'B' in stations:
print('Yes')
else:
print('No') | S = input()
if S[0] == S[1] == S[2]:
print("No")
else:
print("Yes") | 1 | 54,721,597,788,028 | null | 201 | 201 |
n,k,c = list(map(int, input().split()))
s = list(input())
l = []
r = []
i = 0
while i < n and len(l) <= k:
if s[i] == "o":
l.append(i)
i += (c + 1)
else:
i += 1
i = n-1
while i >= 0 and len(r) <= k:
if s[i] == "o":
r.append(i)
i -= (c+1)
else:
i -= 1
i = 0
while i < k:
if l[i] == r[k-1-i]:
print(l[i]+1)
i += 1
| def main():
N, K, C = map(int, input().split())
S = input()
L, R = [-C], [N + C]
i, k = 0, 0
while i < N and k < K:
if S[i] == 'o':
L.append(i)
k += 1
i += C
i += 1
L.append(N)
i, k = N - 1, 0
while 0 <= i and k < K:
if S[i] == 'o':
R.append(i)
k += 1
i -= C
i -= 1
R.append(N)
l = 0
for i, s in enumerate(S):
if s == 'x':
continue
r = K - l
if R[r] <= i or R[r] - L[l] < C:
print(i + 1)
if L[l + 1] == i:
l += 1
main()
| 1 | 40,514,273,675,360 | null | 182 | 182 |
n,m=map(int,input().split())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
a[i]+=[sum(a[i])]
print(*a[i])
a=list(zip(*a[::-1]))
for i in range(m):print(sum(a[i]),end=' ')
print(sum(a[m]))
| n, m = map(int, input().split())
a = []
b = []
for i in range(n):
a += [list(map(int, input().split()))]
a[i] += [sum(a[i])]
for i in range(m+1):
b += [sum(x[i] for x in a)]
a += [b]
for i in range(n+1):
print(*a[i])
| 1 | 1,341,283,075,868 | null | 59 | 59 |
n = int(input())
l = [input() for i in range(n)]
d = {k: 0 for k in ['AC', 'WA', 'TLE', 'RE']}
for s in l:
d[s] += 1
for s in ['AC', 'WA', 'TLE', 'RE']:
print('{} x {}'.format(s, d[s])) | # Aizu Problem ITP_1_11_A: Dice I
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def do_roll(dice, roll):
d1, d2, d3, d4, d5, d6 = dice
if roll == 'E':
return [d4, d2, d1, d6, d5, d3]
elif roll == 'W':
return [d3, d2, d6, d1, d5, d4]
elif roll == 'N':
return [d2, d6, d3, d4, d1, d5]
elif roll == 'S':
return [d5, d1, d3, d4, d6, d2]
else:
assert False, "We should never reach this point!"
dice = [int(_) for _ in input().split()]
for roll in input().strip():
dice = do_roll(dice, roll)
print(dice[0]) | 0 | null | 4,494,155,658,872 | 109 | 33 |
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
a += A[i]
Asum.append(a)
for i in range(M):
b += B[i]
Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
if Asum[i] > K:
break
while Asum[i] + Bsum[j] > K:
j -= 1
res = max(res,i+j)
print(res) | from collections import deque
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
da = deque()
i = 0
tmpK = 0
while tmpK <= K and i < N:
tmpK += A[i]
da.append(A[i])
i += 1
# 一冊多い場合がある
if (tmpK > K):
i -= 1
tmpK -= da.pop()
# Bを増やしていく
db = deque()
j = 0
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
tmptot = i+j
while len(da) > 0:
tmpK -= da.pop()
i -= 1
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
if tmptot < i+j:
tmptot = i+j
print(tmptot) | 1 | 10,871,993,775,612 | null | 117 | 117 |
n = int(input())
aas = list(map(int, input().split()))
res = 0
pre = aas[0]
for i in range(1,len(aas)):
if pre > aas[i]:
res += pre - aas[i]
else:
pre = aas[i]
print(res) | def main():
N, A = int(input()), list(map(int, input().split()))
ans = 0
for idx in range(1, N):
if A[idx] < A[idx - 1]:
diff = A[idx - 1] - A[idx]
ans += diff
A[idx] = A[idx - 1]
print('{}'.format(ans))
if __name__ == '__main__':
main()
| 1 | 4,573,428,391,968 | null | 88 | 88 |
K = int ( input().strip() ) ;
print ( "ACL" * K ) ;
| def main():
n = int(input())
c = input()
r = 0
for i in range(n):
if c[i]=='R':
r += 1
ans = 0
for i in range(r):
if c[i]=='W':
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 4,256,478,543,900 | 69 | 98 |
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x]) #経路圧縮
return par[x]
def same(x,y):
return find(x) == find(y)
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return 0
par[x] = y
size[y] = size[x] + size[y]
size[x] = 0
N,M = map(int,input().split())
par = [ i for i in range(N+1)]
size = [1 for _ in range(N+1)]
for _ in range(M):
a,b = map(int,input().split())
unite(a,b)
A = size.count(0)
print(N-A-1) | a, b = map(int, input().split())
c = a - (2 * b)
print(c if c >= 0 else 0) | 0 | null | 84,832,598,032,350 | 70 | 291 |
class Node(object):
def __init__(self, key=None):
self.key = key
self.prev = None
self.next = None
class DoublyLinkedList(object):
def __init__(self):
self.first = Node()
self.first.prev = self.first
self.first.next = self.first
def insert(self, key):
x = Node(key)
x.next = self.first.next
self.first.next.prev = x
self.first.next = x
x.prev = self.first
def search(self, key):
cur = self.first.next
while cur != self.first and cur.key != key:
cur = cur.next
return cur
def delete(self, key):
self.delete_node(self.search(key))
def delete_node(self, node):
if node == self.first:
return
else:
node.prev.next = node.next
node.next.prev = node.prev
def delete_first(self):
self.delete_node(self.first.next)
def delete_last(self):
self.delete_node(self.first.prev)
if __name__ == "__main__":
import sys
input = sys.stdin.readline # faster input
linklist = DoublyLinkedList()
n = int(input())
for _ in range(n):
inputs = input().rstrip()
if inputs[0] == 'i':
linklist.insert(inputs[7:])
elif inputs[6] == 'F':
linklist.delete_first()
elif inputs[6] == 'L':
linklist.delete_last()
else:
linklist.delete(inputs[7:])
result = []
cur = linklist.first.next
while cur != linklist.first:
result.append(cur.key)
cur = cur.next
print(' '.join(result))
| from collections import deque
n = int(input())
d = deque()
for i in range(n):
c = input()
if ' ' in c:
c, num = c.split()
if c == 'insert':
d.appendleft(num)
elif c == 'delete' and num in d:
d.remove(num)
else:
if c == 'deleteFirst' and d:
d.popleft()
elif c == 'deleteLast' and d:
d.pop()
print(' '.join(d))
| 1 | 50,758,022,068 | null | 20 | 20 |
n, m = map(int, input().split())
temp = list(['?'] * n)
# print(temp)
if (m == 0):
if (n == 1):
ans = 0
else:
ans = '1' + '0' * (n - 1)
else:
for _ in range(m):
s, c = map(int, input().split())
if (s == 1 and c == 0 and n >= 2):
print(-1)
exit()
else:
pass
if (temp[s-1] == '?'):
temp[s - 1] = str(c)
elif (temp[s - 1] == str(c)):
pass
else:
print(-1)
exit()
if (temp[0] == '?'):
temp[0] = '1'
ans01 = ''.join(temp)
ans = ans01.replace('?', '0')
print(ans)
| import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
N,M = mint()
C = []
for _ in range(M):
s,c = mint()
C.append([s,c])
for x in range(10**(N-1)-(N==1),10**N):
x = str(x)
if all([x[s-1]==str(c) for s,c in C]):
print(x)
exit()
print(-1) | 1 | 60,638,016,243,468 | null | 208 | 208 |
# D - Coloring Edges on Tree
import sys
sys.setrecursionlimit(10 ** 5)
N = int(input())
G = [[] for _ in range(N)]
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
G[a].append((b, i))
G[b].append((a, i))
ans = [-1] * (N - 1)
def dfs(key, color=-1, parent=-1):
k = 1
for i in range(len(G[key])):
if G[key][i][0] == parent:
continue
if color == k:
k += 1
ans[G[key][i][1]] = k
dfs(G[key][i][0], k, key)
k += 1
dfs(0)
print(max(ans))
for a in ans:
print(a)
| import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline
n=int(input())
#初期値が0の辞書
from collections import defaultdict
tree = defaultdict(lambda: set([]))
color={}
key=[]
for _ in range(n-1):
a,b=map(int,input().split())
tree[a-1].add(b-1)
tree[b-1].add(a-1)
color[(a-1,b-1)]=0
key.append((a-1,b-1))
checked=[0]*n
cnt=0
def DEF(parent_color,node_no):
global color,checked,tree,cnt
checked[node_no]=1
cnt=max(cnt,parent_color)
i=1
#print("node_no",node_no)
for item in tree[node_no]:
if checked[item]==0:
if i==parent_color:
i+=1
color[(min(item,node_no),max(item,node_no))]=i
DEF(i,item)
i+=1
DEF(0,1)
print(cnt)
for item in key:
print(color[item])
| 1 | 136,325,028,244,810 | null | 272 | 272 |
#!/usr/bin/env python3
l = int(input())
q = l / 3
print(q ** 3)
| n = int(input())
a = n//3
b = n%3
if b == 1:
print((a+1/3)**3)
elif b==2:
print((a+2/3)**3)
else:
print(a**3) | 1 | 46,908,059,201,442 | null | 191 | 191 |
import sys
import bisect
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
l = L[i] + L[j]
p = bisect.bisect_left(L, l)
# print(p)
ans += p - j - 1
print(ans) | k = int(input())
ok = False
for i in range(1, k+1):
if i == 1:
a = 7 % k
else:
anext = (a * 10 + 7) % k
a = anext
if a == 0:
print(i)
ok = True
break
if not ok:
print(-1)
| 0 | null | 89,332,494,695,780 | 294 | 97 |
N,K,S = [int(hoge) for hoge in input().split()]
import math
#累積和数列であって、Ar-Al=Sを満たすものが丁度K個ある
if S==10**9:
print(*([S]*K + [27]*(N-K)))
elif S:
print(*([S]*K + [S+1]*(N-K)))
else:
ans = []
while 1:
if K==2:
ans +=[0,1,0]
break
for R in range(N):
if (R+1)*(R+2)//2 > K:break
print(K)
if K==0:break
ans += [0]*R+[1]
K = K - R*(R+1)//2
print(ans + [1]*(N-len(ans))) | N, K, S = map(int, input().split())
if S == 10**9:
ans = [1]*N
else:
ans = [S+1] * N
for i in range(K):
ans[i] = S
print(" ".join(map(str, ans))) | 1 | 91,193,812,440,012 | null | 238 | 238 |
#!/usr/bin/env python3
def main():
s = input()
t = input()
ans = float("inf")
add = 0
for j in range(len(s) - len(t) + 1):
tans = 0
for i in range(len(t)):
if s[i + add] == t[i]:
pass
else:
tans += 1
add += 1
ans = min(ans, tans)
print(ans)
main()
| #from sys import stdin
#input = stdin.readline
#inputRstrip = stdin.readline().rstrip
#x = input().rstrip()
#n = int(input())
#a,b,c = input().split()
#a,b,c = map(int, input().split())
ST = [input() for i in range(2)]
S = ST[0]
T = ST[1]
ans = len(T)
for i in range(len(S) - len(T) + 1):
count = len(T)
for j in range(len(T)):
if(T[j] == S[i + j]):
count -= 1
if(ans > count):
ans = count
print(ans) | 1 | 3,663,940,498,400 | null | 82 | 82 |
N, K = [int(v) for v in input().strip().split(" ")]
A = [int(v) for v in input().strip().split(" ")]
for i in range(N - K):
if A[i+K] > A[i]:
print("Yes")
else:
print("No") | MOD = 10**9 + 7
N, K = map(int, input().split())
dp = [0 for _ in range(K + 1)]
res = 0
for i in range(1, K + 1)[::-1]:
dp[i] += pow(K // i, N, MOD)
for j in range(1, K // i):
dp[i] -= dp[i * (j + 1)]
res += i * dp[i]
res %= MOD
print(res) | 0 | null | 22,042,812,897,468 | 102 | 176 |
n,m=map(int,input().split())
a =map(int,input().split())
x = sum(a)
if x > n:
print('-1')
else:
print(n-x) | def main():
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
U = []
for i, t in enumerate(T):
if t == 'r':
if i-K >= 0:
if U[i-K] == 'p':
U.append('rs')
continue
U.append('p')
ans += P
elif t == 's':
if i-K >= 0:
if U[i-K] == 'r':
U.append('sp')
continue
U.append('r')
ans += R
else:
if i-K >= 0:
if U[i-K] == 's':
U.append('rp')
continue
U.append('s')
ans += S
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 69,564,876,885,530 | 168 | 251 |
n=int(input())
k="ACL"
print(k*n) | N=int(input())
base = ["ACL"]*N
print("".join(base)) | 1 | 2,174,466,886,110 | null | 69 | 69 |
N, X, M = map(int, input().split())
tmp = X
seq = []
ans = 0
for i in range(N):
if X in seq:
break
seq.append(X)
X = (X ** 2) % M
ans = sum(seq[:min(N, len(seq))])
N -= len(seq)
if N < 1:
print(ans)
exit()
i = seq.index(X)
l = len(seq) - i
ans += sum(seq[i:]) * (N//l)
N %= l
ans += sum(seq[i:i+N])
print(ans)
| from sys import exit
def main():
N = int(input())
S = input()
middle = int(N / 2)
if middle == 0 or N % 2 != 0:
print('No')
exit()
for i in range(middle):
if S[i] != S[i + middle]:
print('No')
exit()
print('Yes')
main() | 0 | null | 75,137,441,742,188 | 75 | 279 |
N, u, v = map(int, input().split())
u, v = u-1, v-1
ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
#%%
roots = [[] for _ in range(N)]
for AB in ABs:
roots[AB[0]].append(AB[1])
roots[AB[1]].append(AB[0])
#BFS
def BFS(roots, start):
from collections import deque
seen = [-1 for _ in range(N)]
seen[start] = 0
todo = deque([start])
while len(todo) > 0:
checking = todo.pop()
for root in roots[checking]:
if seen[root] == -1:
seen[root] = seen[checking] +1
todo.append(root)
return seen
from_u = BFS(roots, u)
from_v = BFS(roots, v)
from collections import deque
todo = deque([u])
max_distance = from_v[u]
position = u
seen = [False for _ in range(N)]
seen[u] = True
while len(todo) > 0:
checking = todo.pop()
for root in roots[checking]:
if from_u[root] < from_v[root] and seen[root] == False:
seen[root] = True
todo.append(root)
if max_distance < from_v[root]:
max_distance = from_v[root]
position = root
print(max_distance-1) | import math
H, W = map(int, input().split())
ans = int(H / 2) * W
if (H % 2) == 1:
ans += math.ceil(W / 2)
if H == 1 or W == 1:
ans = 1
print(ans) | 0 | null | 84,488,921,948,850 | 259 | 196 |
a, op, b = input().split()
a = int(a)
b = int(b)
L = []
while op != "?":
L.append([a, b, op])
a, op, b = input().split()
a = int(a)
b = int(b)
for (a, b, op) in L:
if op == "+":
print(str(a + b))
elif op == "-":
print(str(a - b))
elif op == "*":
print(str(a * b))
else:
print(str(a // b)) | while True:
a, op, b = input().split()
a, b = int(a), int(b)
if op == '?':
quit()
else:
if op == '+':
result = a+b
elif op == '-':
result = a-b
elif op == '*':
result = a*b
elif op == '/':
result = int(a/b)
print(result) | 1 | 677,537,561,540 | null | 47 | 47 |
n = int(input())
C = list(input())
a, b = 0, 0
for i in range(n):
if C[i] == "R":
a += 1
ans = max(a, b)
for i in range(n):
if C[i] == "R":
a -= 1
else:
b += 1
tmp = max(a, b)
ans = min(ans, tmp)
print(ans) | a = input ()
numbers = map(int,raw_input().split())
numbers.reverse()
print ' '.join(map(str,numbers)) | 0 | null | 3,650,653,040,382 | 98 | 53 |
def main():
n, m = map(int, input().split())
if n%2:
for i in range(m):
print(i+1, n-i)
else:
for i in range(m):
if n-2*i-1 > n//2:
print(i+1, n-i)
else:
print(i+1, n-i-1)
if __name__ == "__main__":
main() | n = int(input())
S = ['']*n
T = []
for i in range(n):
S[i] = input()
S.sort()
if n == 1:
print(S[0])
exit()
cnt = 1
mxcnt = 1
for i in range(n-1):
if S[i] == S[i+1]:
cnt += 1
else:
cnt = 1
mxcnt = max(mxcnt,cnt)
cnt = 1
for i in range(n-1):
if S[i] == S[i+1]:
cnt += 1
else:
cnt = 1
if cnt == mxcnt:
T.append(S[i])
if mxcnt == 1:
T.append(S[-1])
for t in T:
print(t) | 0 | null | 49,258,546,598,210 | 162 | 218 |
s = input()
l = ["x" for i in range(len(s))]
print("".join(l)) | #n=int(input())
#a,b,n=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())
print("".join(s[0:3]))
| 0 | null | 43,551,901,777,680 | 221 | 130 |
N=int(input())
ans=""
check="abcdefghijklmnopqrstuvwxyz"
while N!=0:
N-=1
ans+=check[N%26]
N=N//26
print(ans[::-1])
"""
while N>0:
N-=1
ans+=chr(ord("a")+ N%26)
N//=26
print(ans[::-1])
"""
| N = int(input())
ans = ""
while N > 0:
N -=1
ans = chr(ord("a") + (N%26)) + ans
N //= 26
print(ans) | 1 | 11,886,476,472,460 | null | 121 | 121 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#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
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
ln = len(input())
print('x'*ln)
| print(''.join(['x' for _ in range(len(input()))])) | 1 | 72,937,942,893,012 | null | 221 | 221 |
import collections
def prime_factorize(n):
a = []
while n%2 == 0:
a.append(2)
n//=2
f =3
while f*f <= n:
if n%f == 0:
a.append(f)
n//=f
else:
f +=2
if n != 1:
a.append(n)
return a
# N-1の約数を数える
N = int(input())
factor = collections.Counter(prime_factorize(N-1))
K = 1
for i in list(factor.values()):
K *= i+1
K -=1
for f in range(2, int(N**0.5)+1):
n = N
if n%f != 0:
continue
while n%f ==0:
n//=f
if n%f ==1 or n==1:
K+=1
#最後は自分自身を加える。
K +=1
print(K) | import numpy
a,b,x=map(int,input().split())
V=a*a*b
if x<=V/2:
y=2*x/b/a
theta=numpy.arctan(b/y)
print(theta*360/2/numpy.pi)
else:
x=V-x
y=2*x/a/a
theta=numpy.arctan(y/a)
print(theta*360/2/numpy.pi)
| 0 | null | 102,111,025,230,144 | 183 | 289 |
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')
N=INT()
nodes=[[] for i in range(N)]
for i in range(N):
l=LIST()
u=l[0]
l=l[2:]
for v in l:
nodes[u-1].append(v-1)
nodes[u-1].sort()
ans=[[0]*2 for i in range(N)]
visited=[False]*N
time=0
def rec(u):
if visited[u]:
return
visited[u]=True
global time
time+=1
ans[u][0]=time
for v in nodes[u]:
rec(v)
time+=1
ans[u][1]=time
for i in range(N):
rec(i)
for i in range(N):
d,f=ans[i]
print(i+1, d, f)
| n = int(input())
from collections import deque
graph = [deque([]) for _ in range(n+1)]
for _ in range(n):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
arrive = [-1 for i in range(n+1)]
finish = [-1 for i in range(n+1)]
times = 0
def dfs(v):
global times
times += 1
arrive[v] = times
stack = [v]
while stack:
v = stack[-1]
if graph[v]:
w = graph[v].popleft()
if arrive[w] == -1:
times += 1
arrive[w] = times
stack.append(w)
else:
times += 1
finish[v] = times
stack.pop()
return
for i in range(n):
if arrive[i+1] == -1:
dfs(i+1)
for j in range(n):
tmp = [j+1, arrive[j+1], finish[j+1]]
print(*tmp)
| 1 | 2,656,111,484 | null | 8 | 8 |
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 01:55:56 2020
@author: liang
"""
import math
N = int(input())
key = int(math.sqrt(N))
ans = 10**12
for i in reversed(range(1,key+1)):
if N%i == 0:
ans = i-1 + N//i -1
break
print(ans) | s = input()
q = int(input())
flag = True
head = '' # 最終的に先頭に追加されている文字
end = '' # 最終的に末尾に追加されている文字
for i in range(q):
que = [i for i in input().split()]
if que[0] == '1':
flag ^= True # Trueなら通常,Falseは反転状態
elif que[0] == '2' and flag is True:
if que[1] == '1':
head = que[2] + head
elif que[1] == '2':
end = end + que[2]
elif que[0] == '2' and flag is False:
if que[1] == '1':
end = end + que[2]
elif que[1] == '2':
head = que[2] + head
s = head+s+end
if flag is False:
s = s[::-1]
print(s) | 0 | null | 109,891,766,881,292 | 288 | 204 |
def main():
X = int(input())
fifth_power = [x ** 5 for x in range(201)]
for i in range(len(fifth_power)):
p = fifth_power[i]
q1 = abs(X - p)
q2 = abs(X + p)
if q1 in fifth_power:
if p + q1 == X:
print(fifth_power.index(p), -fifth_power.index(q1))
elif p - q1 == X:
print(fifth_power.index(p), fifth_power.index(q1))
return 0
if q2 in fifth_power:
print(fifth_power.index(q2), fifth_power.index(p))
return 0
main() | x = int(input())
for i in range(243):
for j in range(243):
if (i-121)**5 - (j-121)**5 == x:
print(i-121,j-121)
exit() | 1 | 25,493,297,354,190 | null | 156 | 156 |
from collections import deque
INF = 1e9
def BFS(n, adj):
d = [INF] * N
d[0] = 0
next_v = deque([0]) # ?¬??????????????????????
while next_v:
u = next_v.popleft()
for v in adj[u]:
if d[v] == INF:
d[v] = d[u] + 1
next_v.append(v)
return d
N = int(input())
Adj = [None] * N
for i in range(N):
u, k, *vertex = [int(i)-1 for i in input().split()]
Adj[u] = vertex
distance = BFS(N, Adj)
for i, di in enumerate(distance, start = 1):
if di == INF:
print(i, -1)
else:
print(i, di) | from collections import deque
def main():
while que:
v, d = que.popleft()
for nv in G[v]:
nv -= 1
if D[nv] == -1:
D[nv] = D[v] + 1
que.append((nv, D[nv]))
for i in range(N):
print(i+1, D[i])
if __name__ == "__main__":
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
ipts = [int(ipt) for ipt in input().split()]
G[ipts[0]-1] = ipts[2:]
D = [-1]*N
D[0] = 0
que = deque()
que.append((0, 0))
main()
| 1 | 3,822,490,970 | null | 9 | 9 |
h, n = map( int, input().split() )
a = []
b = []
for _ in range( n ):
a_i, b_i = map( int, input().split() )
a.append( a_i )
b.append( b_i )
dp = [ float( "Inf" ) ] * ( h + 1 )
# dp[ d ] = dを与える最小マナ
dp[ 0 ] = 0
for i in range( h ):
for j in range( n ):
update_index = min( i + a[ j ], h )
dp[ update_index ] = min( dp[ update_index ], dp[ i ] + b[ j ] )
print( dp[ h ] ) | def main():
h, n = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("inf")]*(2*10**4+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
p, a, b = i+1, arr[i][0], arr[i][1]
for j in range(2*10**4+1):
if j < a:
dp[p][j] = dp[p-1][j]
else:
if dp[p][j-a] + b < dp[p-1][j]:
dp[p][j] = dp[p][j-a] + b
else:
dp[p][j] = dp[p-1][j]
print(min(dp[-1][h:2*10**4+1]))
if __name__ == "__main__":
main()
| 1 | 81,018,305,762,832 | null | 229 | 229 |
N = int(input())
xyp = []
xym = []
for _ in range(N):
x, y = map(int, input().split())
xyp.append(x+y)
xym.append(x-y)
xyp.sort()
xym.sort()
print(max(xyp[-1] - xyp[0], xym[-1] - xym[0])) | N = int(input())
a = []
b = []
for i in range(N):
x,y = (list(map(int,input().split())))
a.append(x+y)
b.append(x-y)
a.sort()
b.sort()
ans = max(a[-1]-a[0],b[-1]-b[0])
print(ans)
| 1 | 3,385,683,388,508 | null | 80 | 80 |
input_list = [int(num) for num in input().split()]
D = input_list[0]
T = input_list[1]
S = input_list[2]
if D/S <= T:
print("Yes")
else:
print("No") | D,T,S=map(int,input().split())
if 1<=D<=10000 and 1<=T<=10000 and 1<=S<=10000:
if (D/S)>T:
print("No")
else:
print("Yes") | 1 | 3,555,905,511,188 | null | 81 | 81 |
N=int(input())
L=list(map(int,input().split()))
A=1
if 0 in L:
print(0)
exit()
for i in range(N):
A=A*L[i]
if 10**18<A:
print(-1)
exit()
if 10**18<A:
print(-1)
else:
print(A) | import numpy as np
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
ans = 0
for i in range(N):
ans *= A[i]
if ans > 1000000000000000000:
ans = -1
break
print(ans)
| 1 | 16,132,664,197,860 | null | 134 | 134 |
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
N,P=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()
if P in (2,5):
ans=0
for i,x in enumerate(S):
if int(x)%P==0:
ans+=i+1
print ans
else:
L=[int(S)%P]
for i,x in enumerate(S):
L.append((L[-1]-int(x)*pow(10,N-1-i,P))%P)
ans=0
D=defaultdict(lambda: 0)
for i in range(N,-1,-1):
x=L[i]
ans+=D[x]
D[x]+=1
print ans
| def solve():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
res = 0
for i in range(N):
if int(S[i]) % P == 0:
res += i + 1
print(res)
else:
res = 0
count = [0] * P
r = 0
for i in range(N-1, -1, -1):
r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P
if r == 0: res += 1
res += count[r]
count[r] += 1
print(res)
if __name__ == '__main__':
solve()
| 1 | 58,311,373,883,488 | null | 205 | 205 |
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
import math
f = (a1-b1)*t1
s = (a2-b2)*t2
if f == -s:
print("infinity")
elif (f>0 and f+s>0) or (f<0 and f+s<0):
print(0)
elif f//(-(f+s)) == math.ceil(f/(-(f+s))):
print(f//(-(f+s))*2)
else:
print(f//(-(f+s))*2+1) | T1,T2=[int(i) for i in input().split()]
A1,A2=[int(i) for i in input().split()]
B1,B2=[int(i) for i in input().split()]
if((B1-A1)*((B1-A1)*T1+(B2-A2)*T2)>0):
print(0);
exit();
if((B1-A1)*T1+(B2-A2)*T2==0):
print("infinity")
exit();
ans=(abs((B1-A1)*T1)//abs((B1-A1)*T1+(B2-A2)*T2))*2+1
if(abs((B1-A1)*T1)%abs((B1-A1)*T1+(B2-A2)*T2)==0):
ans-=1
print(ans)
| 1 | 131,829,570,310,020 | null | 269 | 269 |
from math import *
a,b,c = map(int,raw_input().split())
sinc = sin(radians(c))
cosc = cos(radians(c))
S = 0.5 * a * b * sinc
L = a+b+sqrt(a**2+b**2-2*a*b*cosc)
h = b*sinc
print S
print L
print h | import math
a, b, C = map(int, input().split())
C = math.radians(C)
S = a * b * math.sin(C) * 0.5
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
L = a + b + c
h = 2 * S / a
print(S, L, h)
| 1 | 181,229,455,862 | null | 30 | 30 |
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
a,b,c = inm()
k = inn()
x = 0
while b<=a:
b *= 2
x += 1
while c<=b:
c *= 2
x += 1
print('Yes' if x<=k else 'No')
| n = int(input())
a = input()
s=list(map(int,a.split()))
q = int(input())
a = input()
t=list(map(int,a.split()))
i = 0
for it in t:
if it in s:
i = i+1
print(i) | 0 | null | 3,489,224,043,900 | 101 | 22 |
def f(input1):
if input1 >= 30:
return 'Yes'
return 'No'
if __name__ == "__main__":
input1 = int(input())
print(f(input1)) | n,m = map(int,raw_input().split(" "))
a = []
for i in range(0,n):
b = map(int,raw_input().split(" "))
a.append(b)
for j in range(0,m):
k = input()
for i in range(0,n):
a[i][j] = a[i][j] * k
for i in range(0,n):
s = 0
for j in range(0,m):
s = s + a[i][j]
print str(s) | 0 | null | 3,421,919,204,864 | 95 | 56 |
MOD = 998244353
N,K = map(int,input().split())
l = []
dp = [0]*N
sdp = [0]*(N+1)
for i in range(K):
L,R = map(int,input().split())
l.append([L,R])
dp[0] = 1
sdp[1] = 1
for i in range(1,N):
for L, R in l:
dp[i] += sdp[max(0,i - L+1)] - sdp[max(0,i - R)]
dp[i] %= MOD
sdp[i+1] = sdp[i] + dp[i]
sdp[i+1] %= MOD
print(dp[N-1]) | MOD = 998244353
N, K = list(map(int, input().split()))
dp = [0] * (N+1)
dp[1] = 1
LR = []
for i in range(K):
l, r = list(map(int, input().split()))
LR.append([l, r])
for i in range(2, N+1):
dp[i] = dp[i-1]
for j in range(K):
l, r = LR[j]
dp[i] += dp[max(i-l, 0)] - dp[max(i-r-1, 0)]
dp[i] %= MOD
print((dp[N]-dp[N-1]) % MOD) | 1 | 2,715,473,358,042 | null | 74 | 74 |
N, K = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
P2 = [(((P[i]+1)) / 2) for i in range(N)]
# i番目は1~P[i]の値を出す
# P[i]が大きいものからK個選んで期待値を求める
# 幅が最大のところを見つける
s = 0
init = 0
for i in range(K):
s += P2[i]
tmp = s
for i in range(1, N-K+1):
tmp = tmp - P2[i-1] + P2[i+K-1]
if s < tmp:
s = tmp
init = i
print(s) | n, k = map(int, input().split())
p = list(map(int, input().split()))
e = [(p[i]+1)/2 for i in range(n)]
tmp = sum(e[:k])
ans = tmp
for i in range(n-k):
tmp += (e[i+k]-e[i])
ans = max(ans, tmp)
print(ans) | 1 | 74,710,483,329,874 | null | 223 | 223 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
error_print(e - s, 'sec')
return ret
return wrap
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD
@mt
def slv(N, K):
ans = 0
M = 10**9 + 7
C = Combination(N*2+1, M)
def H(n, r):
return C(n+r-1, r)
K = min(N-1, K)
for k in range(K+1):
m = N - k
t = C(N, k) * H(m, k)
ans += t
ans %= M
return ans
def main():
N, K = read_int_n()
print(slv(N, K))
if __name__ == '__main__':
main()
| 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, k = map(int, readline().split())
COM_MAX = n
fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1
for i in range(2, COM_MAX + 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
def com(n, r):
if n < 0 or r < 0 or n < r:
return 0
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD
ans = 0
for r in range(min(n, k + 1)):
ans = (ans + com(n, r) * com(n - 1, r)) % MOD
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 67,521,809,503,360 | null | 215 | 215 |
array = []
x = input()
while x != "0":
array.append(x)
x = input()
for i, x in enumerate(array):
print("Case %d: %s" % (i + 1, x))
| import sys
i = 1
for line in sys.stdin.readlines():
x = line.strip()
if x != "0":
print("Case {}: {}".format(i, x))
i += 1 | 1 | 495,265,395,782 | null | 42 | 42 |
def main():
N = input()
if "7" in N: return "Yes"
return "No"
if __name__ == '__main__':
print(main())
| import re
S = input()
rds = list(map(lambda x: len(x), re.findall('R{1,}', S)))
print(max(rds)) if rds else print(0)
| 0 | null | 19,691,316,127,616 | 172 | 90 |
def scan(s):
m = 0
a = 0
for c in s:
if c == '(':
a += 1
elif c == ')':
a -= 1
m = min(m, a)
return m, a
def key(v):
m, a = v
if a >= 0:
return 1, m, a
else:
return -1, a - m, a
N = int(input())
S = [input() for _ in range(N)]
c = 0
for m, a in sorted([scan(s) for s in S], reverse=True, key=key):
if c + m < 0:
c += m
break
c += a
if c == 0:
print('Yes')
else:
print('No')
| import sys
from functools import reduce
n=int(input())
s=[input() for i in range(n)]
t=[2*(i.count("("))-len(i) for i in s]
if sum(t)!=0:
print("No")
sys.exit()
st=[[t[i]] for i in range(n)]
for i in range(n):
now,mi=0,0
for j in s[i]:
if j=="(":
now+=1
else:
now-=1
mi=min(mi,now)
st[i].append(mi)
now2=sum(map(lambda x:x[0],filter(lambda x:x[1]>=0,st)))
v,w=list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st))
v.sort(reverse=True,key=lambda z:z[1])
w.sort(key=lambda z:z[0]-z[1],reverse=True)
#print(now2)
for vsub in v:
if now2+vsub[1]<0:
print("No")
sys.exit()
now2+=vsub[0]
for wsub in w:
if now2+wsub[1]<0:
print("No")
sys.exit()
now2+=wsub[0]
print("Yes") | 1 | 23,687,557,600,658 | null | 152 | 152 |
s = input()
if '7' in s:
print("Yes")
else:
print("No")
| n,m = map(int,input().split())
if(n % 2 == 0):
d = n // 2 - 1
c = 0
i = 1
while(d > 0):
print(i,i+d)
d -= 2
i += 1
c += 1
if(c == m):exit()
d = n // 2 - 2
i = n // 2 + 1
while(d > 0):
print(i,i+d)
d -= 2
i += 1
c += 1
if(c == m):exit()
else:
for i in range(m):
print(i+1,n-i)
| 0 | null | 31,399,389,935,650 | 172 | 162 |
def main():
X = int(input())
i = 1
while True:
if i * X % 360 == 0:
print(i)
break
i += 1
main() | import sys
x = int(input())
ans = 2
while(True):
if x*ans % 360 == 0:
print(ans)
sys.exit()
ans +=1 | 1 | 13,207,928,647,420 | null | 125 | 125 |
def main():
num = list(map(int,input().split()))
if num[0]>2*num[1]:
print(num[0]-2*num[1])
else:
print(0)
main() | import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
a, b = geta(int)
print(max(0, a - 2 * b))
if __name__ == "__main__":
main() | 1 | 166,512,206,280,398 | null | 291 | 291 |
N, M = map(int, input().split())
parent = [-1] * N
def get_group_root(x):
if parent[x] < 0:
return x
return get_group_root(parent[x])
for i in range(0, M):
A, B = map(int, input().split())
A -= 1
B -= 1
groupA = get_group_root(A)
groupB = get_group_root(B)
if groupA == groupB:
continue
elif parent[groupA] < parent[groupB]:
parent[groupB] = A
parent[groupA] -= 1
else:
parent[groupA] = B
parent[groupB] -= 1
def check(x):
return x < 0
print(sum(list(map(check, parent))) - 1)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return S().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
self.total += w
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
def interval_sum(self, i, j): # i <= x < j の区間
return self.sum(j - 1) - self.sum(i - 1) if i else self.sum(j - 1)
n = I()
s = list(S())
q = I()
D = defaultdict(lambda:BIT(n))
for j in range(n):
D[s[j]].add(j, 1)
for _ in range(q):
qi, i, c = LS()
if qi == "1":
i = int(i) - 1
D[s[i]].add(i, -1)
D[c].add(i, 1)
s[i] = c
else:
l, r = int(i) - 1, int(c)
ret = 0
for k in range(97, 123):
if D[chr(k)].interval_sum(l, r):
ret += 1
print(ret)
| 0 | null | 32,210,678,133,880 | 70 | 210 |
import math
lrd=input().split()
l=int(lrd[0])
r=int(lrd[1])
d=int(lrd[2])
a=math.ceil(l/d)
b=math.floor(r/d)
print(b-a+1)
| s = input()
flg = True
while len(s) > 0:
if s.startswith("hi"):
s = s[2::]
else:
flg = False
break
if flg:
print("Yes")
else:
print("No") | 0 | null | 30,473,781,857,088 | 104 | 199 |
import sys
def display(inp):
s = len(inp)
for i in range(s):
if i!=len(inp)-1:
print("%d" % inp[i], end=" ")
else:
print("%d" % inp[i], end="")
print("")
line = sys.stdin.readline()
size = int(line)
line = sys.stdin.readline()
inp = []
for i in line.split(" "):
inp.append(int(i))
display(inp)
for i in range(1,size):
if inp[i]!=size:
check = inp.pop(i)
for j in range(i):
if check<inp[j]:
inp.insert(j,check)
break
if j==i-1:
inp.insert(j+1,check)
break
display(inp) | def insertion_sort(A, N):
yield A
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
# 右にずらす
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
yield A
N = int(input())
A = list(map(int, input().split()))
for li in insertion_sort(A, N):
print(*li)
| 1 | 5,586,319,822 | null | 10 | 10 |
if __name__ == "__main__":
T = input()
ans = T
ans = ans.replace("P?", 'PD')
ans = ans.replace("??", 'PD')
ans = ans.replace("?D", 'PD')
ans = ans.replace("?", 'D')
print(ans) | s=input()
sp=s.replace("?","P")
sd=s.replace("?","D")
d= sd.count('D')+sd.count('DP')
p= sp.count('D')+sp.count('DP')
if d < p:
print(sp)
else:
print(sd)
| 1 | 18,569,754,126,708 | null | 140 | 140 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans = k
elif a + b >= k:
ans = a
else:
ans = a + ((k - a - b) * (-1))
print(ans)
| a, b, c, k = map(int, input().split())
count = 0
if a < k:
count += a
if a+b < k:
count -= k-a-b
else:
count = k
print(count) | 1 | 21,968,052,435,260 | null | 148 | 148 |
a, b = map(int, raw_input().split())
print "%d %d %.6f"%(a/b, a%b, a*1.0/b) | a,b = input().split()
a = int(a)
b = int(b)
d = a // b
r = a % b
f = a / b
f = "{0:.8f}".format(f)
fmt = "{v} {c} {n}"
s = fmt.format(v = d,c = r,n = f)
print(s) | 1 | 592,337,789,410 | null | 45 | 45 |
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
a = l()
if n % 2 == 0:
po = [a[i] for i in range(n)]
for i in range(n-3,-1,-1):
po[i] += po[i+2]
ans = sum(a[0::2])
ans = max(ans,sum(a[1::2]))
co = 0
for i in range(0,n,2):
if i+1 <= n-1:
ans = max(ans,co+po[i+1])
else:
ans = max(ans,co)
co += a[i]
print(ans)
else:
po = [a[i] for i in range(n)]
mi = [-Max for i in range(n)]
for i in range(n-3,-1,-1):
po[i] += po[i+2]
ans = sum(a[1::2])
ans = max(ans,sum(a[0::2]) - a[-1])
#print(ans)
l1 = [-Max for i in range(n)]
for i in range(n):
if i != n-1:
l1[i] = po[i+1]
"""
co = 0
for i in range(0,n,2):
if i != n-1:
l1[i] = co + po[i+1]
else:
l1[i] = co
co += a[i]
co = 0
for i in range(1,n,2):
if i != n-1:
l1[i] = co + po[i+1]
else:
l1[i] = co
co += a[i]
"""
for i in range(n-1,-1,-1):
if i == n-1:
continue
elif i == n-2:
mi[i] = l1[i]
else:
mi[i] = max(mi[i+2]+a[i],l1[i])
l1 = mi
"""
for i in range(n-1,-1,-1):
if i <= n-3:
mi[i] = min(mi[i+2],a[i])
else:
mi[i] = a[i]
print(mi)
"""
l2 = [-Max for i in range(n)]
for i in range(n-1,-1,-1):
l2[i] = po[i]
#print(l1)
#print(l2)
co = 0
for i in range(0,n,2):
if i + 2 <= n-1:
#print(ans,co+l1[i+1],co+l2[i+2])
ans = max(ans,co+l1[i+1],co+l2[i+2])
elif i+1 <= n-1:
ans = max(ans,co+l1[i+1])
else:
ans = max(ans,co)
co += a[i]
co = 0
#print(ans)
for i in range(1,n,2):
#print(ans,co+l1[i+1])
ans = max(ans,co+po[i+1])
#ans = max(ans,co+l1[i+1])
co += a[i]
#print("po:"+str(mi[1]))
print(ans)
| 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")
import bisect
N = int(input())
a = [0] + list(map(int, input().split()))
o = [a[2*i+1] for i in range(N//2)]
o = list(itertools.accumulate(o))
dp = [0 for i in range(N+1)]
dp[0] = dp[1] = 0
dp[2] = max(a[1], a[2])
if N > 2: dp[3] = max([a[1], a[2], a[3]])
if N > 3:
for i in range(4, N+1):
if i % 2 == 0:
dp[i] = max(dp[i-2] + a[i], o[(i-3)//2] + a[i-1])
else:
dp[i] = max([dp[i-2] + a[i], dp[i-3] + a[i-1], o[(i-2)//2] ])
print(dp[N])
| 1 | 37,354,428,960,552 | null | 177 | 177 |
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
ans = n - sum(a)
if ans < 0:
ans = -1
print(ans) | import sys
def main():
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
b = [0] * (10 ** 6)
ans = 0
for i in range(n):
if i - a[i] > 0:
ans += b[i - a[i]]
if i + a[i] < 10 ** 6:
b[i + a[i]] += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 29,126,598,145,740 | 168 | 157 |
import math
def solve():
N = int(input())
A = list(map(int, input().split()))
if(N == 0 and A[0] == 1):
print(1)
return
leaf_list = [0] * (N+1)
for d in range(N, -1 , -1):
if(d == N):
leaf_list[d] = (A[d],A[d])
else:
Min = math.ceil(leaf_list[d+1][0]/2) + A[d]
Max = leaf_list[d+1][1] + A[d]
leaf_list[d] = (Min,Max)
if(not(leaf_list[0][0] <= 1 and leaf_list[0][1] >= 1)):
print(-1)
return
node_list = [0] * (N+1)
node_list[0] = 1
for d in range(1, N+1):
node_list[d] = min((node_list[d-1] - A[d-1]) * 2, leaf_list[d][1])
print(sum(node_list))
solve() | import math
import itertools
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
n = int(input())
distances = []
for _ in range(n):
points = list(map(int, input().split()))
distances.append(points)
total = 0
routes = list(itertools.permutations(range(n), n))
for route in routes:
distance = 0
for index in range(len(route)-1):
idx1 = route[index]
idx2 = route[index+1]
distance += math.sqrt((distances[idx1][0] - distances[idx2][0]) ** 2 + (distances[idx1][1] - distances[idx2][1]) ** 2)
total += distance
print(total / len(routes))
| 0 | null | 83,470,229,545,560 | 141 | 280 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A-B)
if d-(V-W)*T<=0:
print("YES")
else:
print("NO") | import sys
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
sys.exit()
a_b_dist = abs(a-b)
v_w_dist = abs(v-w)
if v_w_dist * t < a_b_dist:
print('NO')
sys.exit()
print('YES')
| 1 | 15,149,404,762,822 | null | 131 | 131 |
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():
S = readline().strip()
ans = 0
n = len(S) // 2
for i in range(n):
if S[i] != S[-1 - i]:
ans += 1
print(ans)
return
if __name__ == '__main__':
main()
| S=input()
if len(S)%2==0:
S_mae=S[:len(S)//2]
S_ushiro=S[len(S)//2:]
else:
S_mae=S[:len(S)//2+1]
S_ushiro=S[len(S)//2:]
ans=0
for i in range(len(S_mae)):
if S_mae[-i-1]!=S_ushiro[i]:
ans += 1
print(ans)
| 1 | 120,325,514,051,200 | null | 261 | 261 |
n, m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ans = -1
for i in range(1000):
s_i = str(i)
if len(s_i) == n and all(int(s_i[s-1])==c for s,c in sc):
ans = i
break
print(ans) | def main():
A = int(input())
B = int(input())
print(6-(A+B))
main()
| 0 | null | 85,946,891,024,940 | 208 | 254 |
n=int(input())
a=list(map(int,input().split()))
score=0
mod=10**9+7
b=sum(a)
for i in range(0,n-1):
b-=a[i]
score+=a[i]*b
print(score%mod) | k = int(input())
ans = 1
a = 7 % k
while a != 0:
ans += 1
a = (10*a + 7) % k
if ans == 10**6:
ans = -1
break
print(ans) | 0 | null | 5,007,295,297,060 | 83 | 97 |
s = input()
t = input()
ls = len(s)
lt = len(t)
ret = lt
for i in range(ls+1 - lt):
diff = 0
for j in range(lt):
diff += (t[j] != s[i+j])
if diff == 0:
ret = diff
break
if diff < ret:
ret = diff
print(ret) | s=input()
t=input()
ans=int(len(s))
for i in range(len(s)-len(t)+1):
now=int(0)
for j in range(len(t)):
if s[i+j]!=t[j]:
now+=1
ans=min(now,ans)
print(ans) | 1 | 3,671,243,408,800 | null | 82 | 82 |
n = int(raw_input())
a = map(int, raw_input().split())
print "%d %d %d" % (min(a), max(a), sum(a)) | n = int(input())
a = list(map(int, input().split()))
ans = []
ans.append(min(a))
ans.append(max(a))
ans.append(sum(a))
print(" ".join(map(str, ans)))
| 1 | 730,214,964,892 | null | 48 | 48 |
a,b,c=map(int,input().split())
if 4*a*b<(c-a-b)*(c-a-b) and c-a-b>=0:
print("Yes")
else:
print("No") | a,b,c= map(int,input().split())
if c>a+b and 4*a*b<(c-a-b)*(c-a-b):
print('Yes')
else:
print('No') | 1 | 51,522,605,539,580 | null | 197 | 197 |
towers = [
[[0 for i in range(10)] for j in range(3)] for k in range(4)
]
floor = 3
n = int(input())
for i in range(n):
b,f,r,v = list(map(int,input().split()))
towers[b-1][f-1][r-1] += v
for b in towers:
for f in b:
for r in f:
print(' ' + str(r), end='')
print('')
if floor:
print('#'*20)
floor -= 1 | n = input()
arr = [map(int,raw_input().split()) for _ in range(n)]
tou = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for line in arr:
b,f,r,v = line
tou[b-1][f-1][r-1] = tou[b-1][f-1][r-1] + v
for i in range(4):
for j in range(3):
print ' '+' '.join(map(str,tou[i][j]))
if i < 3 :
print '#'*20 | 1 | 1,100,842,971,140 | null | 55 | 55 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
S = input()
K = int(input())
import functools
@functools.lru_cache(None)
def rec(i, k, is_same):
if k == 0:
return 1
if i == 0:
if k >= 2:
return 0
if is_same == 1:
return int(S[len(S) - i - 1])
else:
return 9
res = 0
a = int(S[len(S) - i - 1])
if is_same == 1:
for x in range(a + 1):
if x == a and x == 0:
res += rec(i - 1, k, 1)
elif x == 0:
res += rec(i - 1, k, 0)
elif x == a:
res += rec(i - 1, k - 1, 1)
else:
res += rec(i - 1, k - 1, 0)
else:
for x in range(10):
if x == 0:
res += rec(i - 1, k, 0)
else:
res += rec(i - 1, k - 1, 0)
return res
n = len(S)
res = rec(n - 1, K, 1)
print(res) | 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()))
s = input()
n = len(s)
K = inp()
dp = [[[0 for i in range(5)] for j in range(2)] for k in range(n+1)]
# dp[i][j][k] j:0 kaku j:1 mikaku , k:kosuu
dp[0][1][0] = 1
for i,x in enumerate(s):
x = int(x)
for k in range(4):
dp[i+1][0][k] += dp[i][0][k]
dp[i+1][0][k+1] += dp[i][0][k]*9 + dp[i][1][k]*max(0,(x-1))
if x != 0:
dp[i+1][0][k] += dp[i][1][k]
dp[i+1][1][k+1] = dp[i][1][k]
if k == 0: dp[i+1][1][k] = 0
else:
dp[i+1][1][k] = dp[i][1][k]
for j in range(2):
dp[i+1][j][k] %= mod
# print(dp[i+1][0])
# print(dp[i+1][1])
# print()
print(dp[-1][0][K] + dp[-1][1][K])
| 1 | 76,042,386,319,604 | null | 224 | 224 |
nd = list(map(int, input().split()))
N = nd[0]
D = nd[1]
ans = 0
for i in range(N):
x = list(map(int, input().split()))
if x[0] ** 2 + x[1] ** 2 <= D ** 2:
ans += 1
print(ans)
| import numpy as np
N, D = map(int,input().split())
count = 0
for _ in range(N):
x,y = map(int,input().split())
distance = np.sqrt(x**2 + y**2)
if distance <= D:
count += 1
print(count)
| 1 | 5,870,572,204,832 | null | 96 | 96 |
from collections import *
n, p = map(int, input().split())
s = list(map(int, input()))
if 10%p==0:
r = 0
for i in range(n):
if s[i]%p==0:
r += i+1
print(r)
exit()
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
v += int(i)*k
v %= p
r += c[v]
c[v] += 1
k *= 10
k %= p
print(r)
| n = int(input())
s = [input().split() for i in range(n)]
b = sum([int(s[i][1]) for i in range(n)])
x = input()
c = 0
for i in range(n):
c+=int(s[i][1])
if s[i][0] == x:
break
print(b-c) | 0 | null | 77,218,656,793,058 | 205 | 243 |
N=int(input())
A=list(map(int,input().split()))
flg=True
for i in A:
if i%2==0:
if i%3==0 or i%5==0:
pass
else:
flg=False
break
else:
pass
if flg:
print("APPROVED")
else:
print("DENIED") | n = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 'APPROVED'
for i in a:
if i % 2 == 0:
if i % 3 != 0 and i % 5 != 0:
ans = 'DENIED'
break
print(ans) | 1 | 69,088,902,765,168 | null | 217 | 217 |
import math
from numba import jit
k=int(input())
@jit
def f():
ans=0
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
g=math.gcd(math.gcd(a,b),c)
ans+=g
return ans
print(f())
| import math
K = int(input())
ans = 0
for i in range(1, K+1):
for j in range(1, i+1):
for k in range(1, j+1):
gcd = math.gcd(i, math.gcd(j, k))
if i == j == k:
ans += gcd
elif i != j and j != k:
ans += 6 * gcd
else:
ans += 3 * gcd
print(ans) | 1 | 35,490,405,585,028 | null | 174 | 174 |
import sys
(a, b ,c) = [int(i) for i in input().split(' ')]
x = a
cnt = 0
while x <= b:
if (c % x == 0) : cnt+=1
x += 1
else:
print(cnt) | def az8():
xs = map(int,raw_input().split())
a,b = xs[0],xs[1]
print (a/b),(a%b), "%5f"%(float(a)/b)
az8() | 0 | null | 570,059,870,808 | 44 | 45 |
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)) |
n=int(input())
s,t=map(str, input().split())
a=[]
for i in range(n):
a.append(s[i]+t[i])
a = "".join(a)
print(a) | 1 | 111,950,701,373,058 | null | 255 | 255 |
N, M = map(int, input().split())
C = [-1] * 3
for i in range(M):
s, c = map(int, input().split())
if C[s - 1] == -1:
C[s - 1] = c
else:
if C[s - 1] != c:
print(-1)
exit()
if N == 1 and (M == 0 or (M == 1 and C[0] == 0)):
print(0)
exit()
for i in range(10 ** (N - 1), 10 ** N):
si = str(i)
flg = True
for j in range(N):
if C[j] != -1 and si[j] != str(C[j]):
flg = False
break
if flg:
print(i)
exit()
print(-1)
| N=int(input())
s=list()
t=list()
st=[]
for i in range(N):
st.append(input().split())
X=input()
ans=0
count=False
for j in range(N):
if count:
ans+=int(st[j][1])
if st[j][0]==X:
count=True
print(ans) | 0 | null | 79,057,969,803,680 | 208 | 243 |
n=int(input())
s=0
for i in range(1,n+1):
if(i%3!=0 and i%5!=0):
s=s+i
print(s)
| import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
n=INT()
ans=0
for i in range(1,n+1):
if i%3==0 or i%5==0:
pass
else:
ans+=i
print(ans)
if __name__ == '__main__':
do() | 1 | 34,879,031,387,420 | null | 173 | 173 |
print(6.28318530717958623200*int(input())) | #
# author sidratul Muntaher
# date: Aug 19 2020
#
n = int(input())
from math import pi
print(pi* (n*2))
| 1 | 31,496,315,207,510 | null | 167 | 167 |
n, m = map(int, input().split())
a = [int(s) for s in input().split()]
days = n - sum(a)
print(days) if days >= 0 else print(-1) | input = raw_input()
input = int(input)
ans = input**3
print ans | 0 | null | 16,017,107,246,350 | 168 | 35 |
import sys
from operator import add
(r, c) = [int(i) for i in sys.stdin.readline().split()]
s = [0] * (c + 1)
for i in range(r):
l = [int(i) for i in sys.stdin.readline().split()]
l.append(sum(l))
print(" ".join([str(i) for i in l]))
s = map(add, s, l)
print(" ".join([str(i) for i in s])) | from collections import Counter
N = int(input())
S = input()
cnt = Counter(S)
ans = cnt['R']*cnt['G']*cnt['B']
#まずansに要請1を満たす(i, j, k)の組の数を入れておき,ここから,要請2を満たさないものを除いていく。
for i in range(N-2):
for j in range(i+1, N-1):
k = j + (j - i)
#kは j - i = k - j を満たす。ただし,(i, j, k)が要請1を満たしているとは限らない。
if k < N:
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans) | 0 | null | 18,775,737,928,740 | 59 | 175 |
s = input()
n = len(s)
ans = 0
sub = 0
judge = False
for i in range(n-1, -1, -1):
key = int(s[i])+sub
if key <= 4:
ans += key
sub = 0
elif key == 5:
ans += 5
if i == 0:
sub = 0
elif int(s[i-1]) <= 4:
sub = 0
else:
sub = 1
else:
ans += 10-key
sub = 1
ans += sub
print(ans) | N = int(input())
L = list(map(int, input().split()))
import copy
U = copy.copy(L)
for i in range (0, N):
L[i]+=(i+1)
U[i]= -U[i]+(i+1)
L = sorted(L)
U = sorted(U)
import bisect
count = 0
for i in range (0, N):
count+= bisect.bisect_right(U, L[i])-bisect.bisect_left(U, L[i])
print(count) | 0 | null | 48,713,004,717,680 | 219 | 157 |
x = int(input())
h500 = x // 500
h5 = (x%500) //5
print(h500 * 1000 + h5* 5) | N, K = [int(x) for x in input().split()]
R, S, P = [int(x) for x in input().split()]
T = input()
point = {'r':P, 's':R, 'p':S}
win = [False] * N
total = 0
for i in range(N):
if i < K or T[i] != T[i - K] or win[i - K] == False:
total += point[T[i]]
win[i] = True
print(total) | 0 | null | 74,734,820,236,188 | 185 | 251 |
N, S = map(int, input().split())
A_array = list(map(int, input().split()))
mod = 998244353
a = 1
arr2 = [1]
ans = 0
for i in range(N):
a = a * 2 % mod
arr2.append(a)
dp = [0] * (S + 1)
dp[0] = 1
for i, a in enumerate(A_array):
# print(dp)
if S - a >= 0:
ans = (ans + dp[S - a] * arr2[N - 1 - i]) % mod
for j in range(S, -1, -1):
dp[j] = (2 * dp[j] + (dp[j - a] if (j - a) >= 0 else 0)) % mod
print(ans)
| import sys
def input(): return sys.stdin.readline().strip()
from functools import lru_cache
sys.setrecursionlimit(10**9)
mod = 998244353
def main():
N, S = map(int, input().split())
A = list(map(int, input().split()))
"""
再帰の計算式自体は合っていた!
メモ化再帰とdpで計算量は変わらないはずだが、取りあえずdpで書き直してみる。
"""
dp = [[0] * (S + 1) for _ in range(N)] # dp[n][s] = (N=n, S=sに対する問題の解)
dp[0][0] = 1
for n in range(1, N): dp[n][0] = (dp[n - 1][0] * 2 + 1) % mod
for s in range(1, S + 1): dp[0][s] = 1 if s == A[0] else 0
for n in range(1, N):
for s in range(1, S + 1):
dp[n][s] = (dp[n - 1][s] * 2 + dp[n - 1][s - A[n]]) if s >= A[n] else dp[n - 1][s] * 2
if A[n] == s: dp[n][s] += 1
dp[n][s] %= mod
print(dp[N - 1][S])
if __name__ == "__main__":
main()
| 1 | 17,551,218,136,902 | null | 138 | 138 |
import sys
def main():
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
accum=[0]*n
accum[0]=a[0]
d=dict()
ans=0
for i in range(1,n):
accum[i]+=a[i]+accum[i-1]
accum=[0]+accum
for j in range(n+1):
if j-k>=0:
d[(accum[j-k]-(j-k))%k]-=1
if (accum[j]-j)%k not in d:
d[(accum[j]-j)%k]=1
else:
ans+=d[(accum[j]-j)%k]
d[(accum[j]-j)%k]+=1
#print(d)
return print(ans)
if __name__=='__main__':
main() | n=int(input())
s='*'+input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(1,n+1):
for j in range(i,n+1):
k=2*j-i
if k>n:
continue
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
cnt+=1
print(r*g*b-cnt) | 0 | null | 86,851,992,260,136 | 273 | 175 |
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
INF = 10**12
N, M, L = map(int, input().split())
A = []; B = []; C = []
for i in range(M):
a, b, c = map(int, input().split())
A.append(a - 1); B.append(b - 1); C.append(c)
A = np.array(A); B = np.array(B); C = np.array(C)
graph = csr_matrix((C, (A, B)), (N, N))
d = floyd_warshall(graph, directed=False)
d[d <= L] = 1
d[d > L] = INF
d = floyd_warshall(d, directed=False)
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
if d[s - 1][t - 1] != INF:
print(int(d[s - 1][t - 1]) - 1)
else:
print(- 1) | # coding: utf-8
n, m = map(int, input().split())
matrixA = []
vectorB = []
for i in range(n):
matrixA.append(list(map(int, input().split())))
for i in range(m):
vectorB.append(int(input()))
for i in range(n):
num = 0
for j in range(m):
num += matrixA[i][j] * vectorB[j]
print(num)
| 0 | null | 87,774,886,175,860 | 295 | 56 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
n = II()
aa = np.array(MII())
ans = 0
for i in range(60):
cnt1 = int((aa&1).sum())
ans += cnt1*(n-cnt1)*(2**i)
aa >>= 1
print(ans%MOD)
if __name__ == '__main__':
main() | #coding:utf-8
N = int(input())
taro = 0
hanako = 0
for i in range(N):
strs = input().split()
if strs[0] > strs[1]:
taro += 3
elif strs[0] < strs[1]:
hanako += 3
else:
taro+=1
hanako+=1
print(str(taro) + " " + str(hanako)) | 0 | null | 62,456,165,785,340 | 263 | 67 |
N=int(input())
a=list(map(int,input().split()))
a_all=0
for i in range(N):
a_all^=a[i]
ans=[]
for j in range(N):
ans.append(a_all^a[j])
print(*ans) | a = [int(v) for v in input().rstrip().split()]
r = 'bust' if sum(a) >= 22 else 'win'
print(r)
| 0 | null | 65,658,352,937,320 | 123 | 260 |
def main():
num = [int(input()) for i in range(2)]
print(6-num[0]-num[1])
main() | a, b = int(input()), int(input())
if 1 not in [a, b]:
print(1)
elif 2 not in [a, b]:
print(2)
else:
print(3) | 1 | 110,805,148,410,208 | null | 254 | 254 |
N=int(input())
zls=[0 for _ in range(N)]
wls=[0 for _ in range(N)]
for i in range(N):
x,y=[int(s) for s in input().split()]
zls[i]=x+y
wls[i]=x-y
print(max([max(zls)-min(zls),max(wls)-min(wls)])) | import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import deque
import bisect
from decimal import *
from functools import reduce
def main():
N = I()
Dots = defaultdict()
xpyp = []
xpyn = []
xnyp = []
xnyn = []
for i in range(N):
x, y = MI()
Dots[i] = (x, y)
xpyp.append(x + y)
xpyn.append(x - y)
xnyp.append(- x + y)
xnyn.append(- x - y)
xpyp_max = max(xpyp) - min(xpyp)
xpyn_max = max(xpyn) - min(xpyn)
xnyp_max = max(xnyp) - min(xnyp)
xnyn_max = max(xnyn) - min(xnyn)
print(max(xpyp_max, xpyn_max, xnyp_max, xnyn_max))
if __name__ == "__main__":
main()
| 1 | 3,443,091,021,660 | null | 80 | 80 |
A, B, C, K = map(int, input().split())
count_A = 0
count_B = 0
count_C = 0
count = 0
if A >= K:
count_A += K
else: # A < K
K -= A
count_A += A
if B >= K:
count_B += K
else:
K -= B
count_B += B
count_C += K
print(count_A - count_C)
| from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
a, b = map(int, input().split())
if a >= b:
ans = str(b)*a
else:
ans = str(a)*b
print(int(ans)) | 0 | null | 52,996,360,036,100 | 148 | 232 |
mod = 1000000007
def ff(a, b):
ans = 1
while b:
if b & 1: ans = ans * a % mod
b >>= 1
a = a * a % mod
return ans
n=int(input())
print(((ff(10,n)-2*ff(9,n)+ff(8,n))%mod+mod)%mod)
| n = int(input())
mod = 10**9+7
a = pow(10,n,mod)
b = pow(9,n,mod)
c = pow(9,n,mod)
d = pow(8,n,mod)
print((a-b-c+d)%mod) | 1 | 3,198,717,109,178 | null | 78 | 78 |
from collections import deque
import copy
h,w=map(int,input().split())
Inf=float('inf')
maze1=[]
for _ in range(h):
s=list(input())
for u in range(w):
if s[u]=='.':
s[u]=Inf
maze1.append(s)
def maze_solve(maze,sy,sx):
qu=deque([[sy,sx]])
maze[sy][sx]=0
while qu:
y,x=qu.popleft()
T=maze[y][x]
for i in ([1,0],[-1,0],[0,1],[0,-1]):
ny=y+i[0]
nx=x+i[1]
if 0<=ny<=h-1 and 0<=nx<=w-1 and maze[ny][nx]!='#':
if maze[ny][nx]>T+1:
maze[ny][nx]=T+1
qu.append([ny,nx])
ans=-Inf
for i in range(h):
for j in range(w):
if maze[i][j]!='#' and maze[i][j]!=Inf:
ans=max(ans,maze[i][j])
return ans
ans=-Inf
for i in range(h):
for j in range(w):
if maze1[i][j]!='#':
maze2=copy.deepcopy(maze1)
ans=max(ans,maze_solve(maze2,i,j))
print(ans) | # A - Takoyaki
from math import ceil
n, x, t = map(int, input().split())
print(ceil(n / x) * t)
| 0 | null | 49,226,939,574,008 | 241 | 86 |
mod_val = 10**9+7
n, k = map(int, input().split())
factorials = [1]*(n+1) # values 0 to n
for i in range(2, n+1):
factorials[i] = (factorials[i-1]*i)%mod_val
def mod_binomial(a, b):
numerator = factorials[a]
denominator = (factorials[b]*factorials[a-b])%mod_val
invert = pow(denominator, mod_val-2, mod_val)
return (numerator*invert)%mod_val
partial = 0
# m is number of rooms with no people
for m in range(min(k+1, n)):
# m places within n to place the 'no people' rooms
# put n-(n-m) people in n-m rooms (n-m) must be placed to be non-empty
partial = (partial + (mod_binomial(n, m) * mod_binomial(n-1, m))%mod_val)%mod_val
print(partial) | def is_much_money(num_of_coin, yen):
if num_of_coin * 500 >= yen:
return "Yes"
else:
return "No"
if __name__ == "__main__":
num_of_coin, yen = input().split()
judgement = is_much_money(int(num_of_coin), int(yen))
print(judgement) | 0 | null | 82,661,858,543,998 | 215 | 244 |
pay = int(input())
if pay % 1000 == 0:
print(0)
else:
print(1000 - pay % 1000) | S = input()
T = input()
def count_diff(s, t):
N = 0
for i, j in zip(s, t):
if i != j:
N += 1
return N
ns = len(S)
nt = len(T)
res = nt
for i in range(ns - nt + 1):
sub = S[i:i+nt]
a = count_diff(sub, T)
if a < res:
res = a
print(res) | 0 | null | 6,085,385,042,320 | 108 | 82 |
mod=10**9+7
x,y=map(int,input().split())
if (x+y)%3!=0:
print(0)
exit()
a=min(x,y)
b=max(x,y)
if 2*a<b:
print(0)
exit()
k=(x+y)//3
left_x=2*k
left_y=k
r=left_x-x
def factorialmod(n,mod):
ans=1
for i in range(2,n+1):
ans*=i
ans%=mod
return ans
fac_k=factorialmod(k,mod)
fac_k_r=factorialmod(k-r,mod)
fac_r=factorialmod(r,mod)
bunbo=fac_k_r*fac_r%mod
print(fac_k*pow(bunbo,mod-2,mod)%mod) | x,y = map(int,input().split())
if (x+y)%3!=0:print(0);exit()
mod = 10**9+7
n = (x+y)//3
m = min(x-n,y-n)
frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r):
if n<0 or r<0 or n<r: return 0
r = min(r,n-r)
return frac[n]*finv[n-r]*finv[r]%mod
print(nCr(n,m)%mod) | 1 | 149,785,813,858,320 | null | 281 | 281 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.