code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import itertools
n = int(input())
S = list(input())
L = [k for k, v in itertools.groupby(S)]
print(len(L)) | d,t,s=map(int,input().split())
if(d<=t*s): print("Yes")
else: print("No") | 0 | null | 86,661,102,260,040 | 293 | 81 |
arr = [[[0 for i1 in range(10)] for i2 in range(3)] for i3 in range(4)]
count=input()
for l in range(int(count)):
b,f,r,v=input().split()
arr[int(b)-1][int(f)-1][int(r)-1]+=int(v)
first_b = arr[0]
second_b = arr[1]
third_b = arr[2]
fourth_b= arr[3]
for m in range(3):
for n in range(10):
print(" "+str(first_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(second_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(third_b[m][n]),end="")
print()
print("#"*20)
for m in range(3):
for n in range(10):
print(" "+str(fourth_b[m][n]),end="")
print() | # coding: utf-8
N = 10
h = []
for n in range(N):
h.append(int(input()))
h = sorted(h, reverse = True)
for i in range(3):
print(h[i]) | 0 | null | 556,030,122,130 | 55 | 2 |
x = input()
print(int(x)*int(x)*int(x)) | from sys import stdin
def main():
for l in stdin:
n, x = map(int, l.split(' '))
if 0 == n == x:
break
print(len(num_sets(n, x)))
def num_sets(n, x):
num_sets = []
for i in range(1, n-1):
for j in [m for m in range(i+1, n)]:
k = x - (i+j)
if n < k:
continue
if k <= j:
break
num_sets.append((i, j, k))
return num_sets
if __name__ == '__main__': main() | 0 | null | 793,471,169,594 | 35 | 58 |
import sys
#fin = open("test.txt", "r")
fin = sys.stdin
n, m = map(int, fin.readline().split())
A = [[] for i in range(n)]
for i in range(n):
A[i] = list(map(int, fin.readline().split()))
b = [0 for i in range(m)]
for i in range(m):
b[i] = int(fin.readline())
c = [0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i] += A[i][j] * b[j]
for i in range(n):
print(c[i]) | ichi = input().split()
n = int(ichi[0])
m = int(ichi[1])
a = [[0 for j in range(m)] for i in range(n)]
for i in range(n):
input_a = input().split()
for j in range(m):
a[i][j] = int(input_a[j])
b = []
for i in range(m):
b.append(int(input()))
for i in range(n):
c=0
for j in range(m):
c += a[i][j] * b[j]
print(c) | 1 | 1,180,563,264,920 | null | 56 | 56 |
n,m = map(int, input().split())
h = list(map(int, input().split()))
l = [1]*n
for i in range(m):
a,b = map(int, input().split())
if h[a - 1] <= h[b - 1]:
l[a - 1] = 0
if h[b - 1] <= h[a - 1]:
l[b - 1] = 0
print(sum(l))
| def mapt(fn, *args):
return tuple(map(fn, *args))
def main():
n, m = mapt(int, input().split(" "))
h = mapt(int, input().split(" "))
ok = [True for i in range(n)]
for i in range(m):
a, b = mapt(int, input().split(" "))
a = a-1
b = b-1
if h[a] <= h[b]: ok[a] = False
if h[b] <= h[a]: ok[b] = False
print(sum(ok))
main() | 1 | 25,118,369,686,112 | null | 155 | 155 |
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
s, w = map(int, input().split())
if s > w:
print('safe')
else :
print("unsafe")
| n = -100
i = 1
while n != 0:
n = int(raw_input())
if n != 0:
print 'Case %d: %d' %(i,n)
i = i + 1 | 0 | null | 14,958,291,063,418 | 163 | 42 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
# 丸太がすべてxの長さ以下になる回数を出し、それがK回以下か判定する
def f(x):
now = 0
for i in range(N):
now += (A[i]-1)//x
return now <= K
l = 0
r = 10**9
while r-l > 1:
mid = (r+l)//2
if f(mid):
r = mid
else:
l = mid
print(r) | H, W, K = map(int, input().split())
S = [''] * H
for i in range(H):
S[i] = input()
A = [[0] * W] * H
bg = 1
inflg = 0
outcnt = 1
for i in range(H):
if '#' not in S[i]:
if inflg == 0:
outcnt += 1
else:
A[i] = A[i-1]
print(" ".join(str(k) for k in A[i]))
else:
inflg += 1
for j in range(S[i].find('#')):
A[i][j] = bg
for j in range(S[i].find('#'),W):
if S[i][j] == '#':
A[i][j] = bg
bg += 1
else:
A[i][j] = A[i][j-1]
if inflg == 1:
for s in range(outcnt):
print(" ".join(str(k) for k in A[i]))
else:
print(" ".join(str(k) for k in A[i]))
| 0 | null | 75,323,112,723,180 | 99 | 277 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
X=I()
if X>=30:
print("Yes")
else:
print("No")
main()
| N=int(input())
S=list(map(str,input()))
ans=1
for i in range(N-1):
if S[i]!=S[i+1]:
ans+=1
print(ans) | 0 | null | 87,877,883,723,808 | 95 | 293 |
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
if i % 2 == 0 and A[i] % 2 == 1:
ans += 1
print(ans) | import math
a, b, deg = map(float, raw_input().split(" "))
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(deg)))
L = a + b + c
s = (a + b + c) / 2.0
S = math.sqrt(s*(s-a)*(s-b)*(s-c))
h = 2 * S / a
print(str(S) + " " + str(L) + " " + str(h)) | 0 | null | 3,994,618,548,462 | 105 | 30 |
N = int(input())
Up = []
Down = []
for _ in range(N):
S = input()
L = [0]
mi = 0
now = 0
for __ in range(len(S)):
if S[__] == '(':
now += 1
else:
now -= 1
mi = min(mi, now)
if now > 0:
Up.append((mi, now))
else:
Down.append((mi - now, mi, now))
Up.sort(reverse=True)
Down.sort()
now = 0
for i, j in Up:
if now + i < 0:
print('No')
exit()
else:
now += j
for _, i, j in Down:
if now + i < 0:
print('No')
exit()
else:
now += j
if now == 0:
print('Yes')
else:
print('No')
| s = str(input())
MOD = 2019
m = 0
digit = 1
mods = [1] + [0] * 2018
for a in s[::-1]:
m = (m + digit * int(a)) % MOD
mods[m] += 1
digit = digit * 10 % MOD
ans = 0
for x in mods:
ans += x * (x - 1) // 2
print(ans) | 0 | null | 27,386,103,689,090 | 152 | 166 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
A = inpl()
B = inpl()
aa = 0
bb = 0
i = 0
for tmp in itertools.permutations(range(1,n+1)):
i += 1
if list(tmp) == A:
aa = i
if list(tmp) == B:
bb = i
print(abs(aa - bb)) | from itertools import permutations
n = int( input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a = [i for i in range(1,n+1)]
x = list(permutations(a,n))
y = x.index(p)
z = x.index(q)
print(abs(y-z))
| 1 | 100,732,378,623,360 | null | 246 | 246 |
from math import log10
while True:
try:
a, b = map(int, raw_input().split())
print(int(log10(a+b)) + 1)
except EOFError:
break | from math import log10 as log
from sys import stdin
A = []
for po in stdin:
S = list(map(int,po.split()))
A.append(int(log(S[0]+S[1])+1))
for i in A:
print(i) | 1 | 141,395,060 | null | 3 | 3 |
import sys
line = sys.stdin.readline()
print(line[0:3])
| r = input()
print(r[0:3]) | 1 | 14,712,783,637,510 | null | 130 | 130 |
X,Y,Z = map(str, input().split())
ans = [Z,X,Y]
print(" ".join(ans)) | a,b,c = map(int,input().split())
tmp = a
a = b
b = tmp
tmp = a
a = c
c = tmp
print(a,b,c) | 1 | 38,049,106,294,290 | null | 178 | 178 |
K,N=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]+K-A[-1]
for i in range(N-1):
ans=max(ans,A[i+1]-A[i])
print(K-ans)
| k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + k)
dist = [a[i + 1] - a[i] for i in range(n)]
print(sum(dist) - max(dist))
| 1 | 43,130,083,933,388 | null | 186 | 186 |
n = int(input())
alist = list(map(int,input().split()))
numb = [0]*n
for i in range(n):
numb[alist[i]-1] = i+1
for i in range(n):
print(numb[i],end=(' ')) | n=int(input())
s=list(map(int,input().split()))
p=[0]*n
for i in range(n):
p[s[i]-1]=i+1
print(*p) | 1 | 180,771,719,446,348 | null | 299 | 299 |
lines = int(input())
mini = int(input())
maxi = -1000000000
for i in range(1,lines):
s = int(input())
maxi = max(maxi,s - mini)
mini = min(s,mini)
print(maxi) | n = int(raw_input())
maxprofit = -2 * 10 ** 9
minval = int(raw_input())
for _ in xrange(n-1):
R = int(raw_input())
maxprofit = max(maxprofit, R-minval)
minval = min(minval, R)
print maxprofit | 1 | 12,544,027,592 | null | 13 | 13 |
a,b=input().split(' ')
if int(a)<=100 and int(b)<=100:
print(int(a)*int(b))
else:
pass | h, a = map(int,input().split())
print(h//a + min(h%a,1))
| 0 | null | 46,336,058,439,554 | 133 | 225 |
N = int(input())
li = [[0]*9 for i in range(9)]
counter = 0
for i in range(1,N+1):
I = str(i)
fast = int(I[0])
last = int(I[-1])
if not last==0:
li[fast-1][last-1] += 1
for i in range(9):
for k in range(9):
counter += li[i][k]*li[k][i]
print(counter) | s = input()
l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
i = 7-l.index(s)
print(i) | 0 | null | 109,789,011,381,920 | 234 | 270 |
n, k = map(int, input().split()); m = 998244353; a = []
for i in range(k): a.append(list(map(int, input().split())))
b = [0]*n; b.append(1); c = [0]*n; c.append(1)
for i in range(1, n):
d = 0
for j in range(k): d = (d+c[n+i-a[j][0]]-c[n+i-a[j][1]-1])%m
b.append(d); c.append(c[-1]+d)
print(b[-1]%m) | import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, K = NMI()
LR = list(sorted([NLI() for _ in range(K)]))
dp = [0 for _ in range(N)]
dp[0] = 1
cumsum = [0 for _ in range(N+1)]
cumsum[0] = 0
cumsum[1] = 1
for n in range(1,N):
for k in range(K):
r = n-LR[k][0]
l = n-LR[k][1]
if r < 0:
continue
else:
l = max(0,l)
dp[n] += cumsum[r+1]-cumsum[l]
dp[n] = dp[n]%MOD2
cumsum[n+1] = (dp[n] + cumsum[n])%MOD2
print(dp[-1])
if __name__ == '__main__':
main() | 1 | 2,710,944,276,222 | null | 74 | 74 |
N,A,B=map(int,input().split())
if N == (N//(A+B))*(A+B):
print(N-(N//(A+B))*(B))
elif (N//(A+B))*(A+B)<N <= (N//(A+B))*(A+B)+A:
print(N-(N//(A+B))*(B))
else:
print((N//(A+B)+1)*(A))
| N, A, B = map(int, input().split())
q, r = divmod(N, A + B)
ans = 0
ans += q * A
ans += min(r, A)
print(ans) | 1 | 55,592,203,917,832 | null | 202 | 202 |
h, w, k = map(int, input().split())
S = [list(input()) for i in range(h)]
A = []
cnt = 1
for i in range(h):
Ai = []
if S[i].count('#') == 0:
A.append(Ai)
continue
flag = False
for j in range(w):
if S[i][j] == '#':
if flag:
cnt += 1
flag = True
Ai.append(cnt)
A.append(Ai)
cnt += 1
l = 0
for i in range(h):
if A[i] != []:
for j in range(l, i):
A[j] = A[i]
l = i + 1
for j in range(l, h):
A[j] = A[l - 1]
for i in range(h):
print(*A[i])
| import sys
import bisect
import itertools
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
a.sort()
cor_v = -1
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
p = n
for v in a:
p = bisect.bisect_left(a, bin_v - v, 0, p)
cost += n - p
if cost > m:
break
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = [0] + list(itertools.accumulate(a))
c = 0
t = 0
for v in a:
p = bisect.bisect_left(a, cor_v - v)
c += n - p
t += acm[-1] - acm[p] + v * (n - p)
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
| 0 | null | 125,881,531,391,680 | 277 | 252 |
# -*- coding: utf-8 -*-
def main():
n = int(input())
keihin_set = set()
for i in range(n):
s = input()
if not s in keihin_set:
keihin_set.add(s)
print(len(keihin_set))
if __name__ == "__main__":
main() |
def main():
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, k = map(int, input().split())
mod = 1000000007
def make_fact(n):
fact = [1]*(n+1)
ifact = [1]*(n+1)
for i in range(1, n+1):
fact[i] = fact[i-1]*i % mod
ifact[n] = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
ifact[i-1] = ifact[i]*i % mod
return fact, ifact
fact, ifact = make_fact(n)
def comb(n, k):
if k < 0 or k > n: return 0
return fact[n]*ifact[k]*ifact[n-k] % mod
ans = 0
if k > n-1:
k = n-1
for i in range(k+1):
ans = (ans + comb(n, i) * comb(n-1, i))% mod
print(ans)
main() | 0 | null | 48,419,836,584,450 | 165 | 215 |
score = list(map(int,input().split()))
kaisu = 1
hp = score[0]
while hp > score[1]:
kaisu += 1
hp -= score[1]
print(kaisu) | N,P = map(int,input().split())
S = input()
def solve(S,N,P):
if P == 2:
ans = 0
for i in range(N):
if int(S[i])%P == 0:
ans += i+1
return ans
if P == 5:
ans = 0
for i in range(N):
if int(S[i])%P == 0:
ans += i+1
return ans
S = S[::-1]
mod_list = [0]*P
mod_list[0] = 1
mod = P
tmp = 0
for i in range(N):
tmp = (tmp + int(S[i])*pow(10,i,mod))%mod
mod_list[tmp] += 1
ans = 0
for i in mod_list:
ans += i*(i-1)//2
return ans
print(solve(S,N,P)) | 0 | null | 67,360,767,227,904 | 225 | 205 |
#!/usr/bin/env python3
N, M = list(map(int, input().split()))
h_list = list(map(int, input().split()))
h_dict = {i + 1: h for i, h in enumerate(h_list)}
h_set = set(h_dict.keys())
no_list = []
for _ in range(M):
a, b = list(map(int, input().split()))
if h_dict[a] == h_dict[b]:
no_list.append(a)
no_list.append(b)
elif h_dict[a] > h_dict[b]:
no_list.append(b)
else:
no_list.append(a)
no_set = set(no_list)
ans = len(h_set - no_set)
print(ans)
| n,m = map(int, input().split())
ans = 0
#辺を取り除くことはabのセットとなっている要素から取り除くことと等価。頂点を消すのではない。
h_list = list(map(int, input().split()))
c = 0
max_list = [0]*(n+1)
for i in range(m):
a,b = map(int, input().split())
max_list[a] = max(max_list[a],h_list[b-1])
max_list[b] = max(max_list[b],h_list[a-1])
for i in range(1,n+1):
if h_list[i-1] > max_list[i]:
ans += 1
print(ans)
| 1 | 24,998,662,462,060 | null | 155 | 155 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
K = II()
A, B = MI()
for i in range(A, B+1):
if i % K == 0:
print('OK')
return
print('NG')
if __name__ == '__main__':
solve()
| N = int(input())
C = input()
r_n = 0
ans = 0
for c in C:
if c == 'R':
r_n += 1
for i in range(r_n):
if C[i] == 'W':
ans += 1
print(ans) | 0 | null | 16,418,046,686,730 | 158 | 98 |
N, K = map(int, input().split())
A = list(map(lambda x:int(x)-1, input().split()))
cnts = [None] * N
pos = 0
cnt = 0
while cnt < K:
if cnts[pos] != None:
loop_size = cnt - cnts[pos]
cnt += ((K-cnt-1) // loop_size) * loop_size
cnts = [None] * N
cnts[pos] = cnt
pos = A[pos]
cnt += 1
print(pos+1)
| # カウントと踏破フラグをもっておくと二度目の踏破でループの長さが分かりそう
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
count_arr = [0] * n
count = 0
now = 0
loop_length = -1
while True:
if count == k:
print(now + 1)
exit()
if count_arr[now] != 0:
loop_length = count - count_arr[now] + 1
break
count += 1
count_arr[now] = count
now = a[now]
# 真の残り回数
rest = (k - count) % loop_length
# 既にゴールしてると見る場合
if rest == 0:
print(now + 1)
exit()
while rest > 0:
rest -= 1
if rest == 0:
break
now = a[now]
print(a[now] + 1)
# 727202214173249352 | 1 | 22,866,406,469,632 | null | 150 | 150 |
N, K, C = map(int, input().split())
S = input()
L, R = [], []
i = 0
while len(L) < K:
if S[i] == "o":
L.append(i)
i += C+1
else:
i += 1
i = N-1
while len(R) < K:
if S[i] == "o":
R.append(i)
i -= C+1
else:
i -= 1
R = R[::-1]
for i in range(K):
if L[i] == R[i]:
print (L[i]+1) | mod = 10**9+7
n,k = map(int,input().split())
ans = 0
for i in range(k,n+2):
ans += (i*n-i*(i-1)+1)%mod
ans %=mod
print(ans) | 0 | null | 36,772,300,867,800 | 182 | 170 |
# coding: utf-8
import sys
def merge(A, left, mid, right):
global count
L = A[left:mid]
R = A[mid:right]
L.append(sys.maxsize)
R.append(sys.maxsize)
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
count += 1
def mergeSort(A, left, right):
if left+1 < right:
mid = int((left + right)/2);
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
n = int(input().rstrip())
A = list(map(int,input().rstrip().split()))
count = 0
mergeSort(A, 0, n)
print(" ".join(map(str,A)))
print(count)
| n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = 0
def q(k):
if A[k] < A[i] + A[j]:
return True
else:
return False
for i in range(n):
for j in range(i + 1, n):
l = j
r = n
while r - l > 1:
mid = (l + r) // 2
if q(mid):
l = mid
else:
r = mid
ans += (l - j)
print(ans)
| 0 | null | 85,665,222,541,400 | 26 | 294 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
x=I()
a=x%100
b=x//100
if a>b*5:
print("0")
else:
print("1") | import sys
input = sys.stdin.readline
def main():
S, T = input().split()
A, B = map(int, input().split())
U = input().strip()
print(A-1, B) if S == U else print(A, B-1)
if __name__ == '__main__':
main()
| 0 | null | 99,290,773,140,082 | 266 | 220 |
s = input()
print("ARC" if s[1] == "B" else "ABC") | import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n,a,b = inpm()
def pow_k(x, n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K = K * x % mod
x *= x % mod
n = n // 2 % mod
return K * x
ret = (pow_k(2,n) - 1) % mod
modinv_table = [-1] * (max(a,b)+1)
modinv_table[1] = 1
for i in range(2, max(a,b)+1):
modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
def binomial_coefficients(n, k):
ans = 1
for i in range(k):
ans *= n-i
ans *= modinv_table[i + 1]
ans %= mod
return ans
aa = binomial_coefficients(n,a) % mod
bb = binomial_coefficients(n,b) % mod
ret = (ret - aa - bb) % mod
print(ret) | 0 | null | 44,981,106,496,830 | 153 | 214 |
while 1:
x = raw_input()
if x == '0':
break
s = 0
for i in xrange(len(x)):
s += int(x[i])
print s | while 1:
x = input()
if x == "0":
break
kei = 0
for i in x:
kei += int(i)
print(kei) | 1 | 1,575,650,885,898 | null | 62 | 62 |
n,m,k = map(int,input().split())
MOD = 998244353
FAC = [1]
INV = [1]
for i in range(1,n+1):
FAC.append((FAC[i-1]*i) % MOD)
INV.append(pow(FAC[-1],MOD-2,MOD))
def nCr(n,r):
return FAC[n]*INV[n-r]*INV[r]
ans = 0
for i in range(k+1):
ans += nCr(n-1,i)*m*pow(m-1,n-i-1,MOD)
ans %= MOD
print(ans) | # nikkei2019-2-qualA - Sum of Two Integers
def main():
N = int(input())
ans = (N - 1) // 2
print(ans)
if __name__ == "__main__":
main() | 0 | null | 87,977,553,115,748 | 151 | 283 |
class SegmentTree():
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
built(array) := arrayを初期値とするセグメント木を構築する O(N)。
update(i, val) := i番目の要素をvalに変更する。
get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
"""
def __init__(self, n, op, e):
"""要素数、二項演算、単位元を引数として渡す
例) 区間最小値 SegmentTree(n, min, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def built(self, array):
"""arrayを初期値とするセグメント木を構築する"""
for i in range(self.n):
self.node[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def update(self, i, val):
"""i番目の要素をvalに変更する"""
i += self.size
self.node[i] = val
while i > 1:
i >>= 1
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res_l, res_r = self.e, self.e
while l < r:
if l & 1:
res_l = self.op(res_l, self.node[l])
l += 1
if r & 1:
r -= 1
res_r = self.op(self.node[r], res_r)
l, r = l >> 1, r >> 1
return self.op(res_l, res_r)
n, m = map(int, input().split())
s = input()
INF = 10 ** 18
st = SegmentTree(n + 1, min, INF)
st.update(n, 0)
for i in range(n)[::-1]:
if s[i] == "1":
continue
tmp = st.get_val(i + 1, min(i + 1 + m, n + 1)) + 1
st.update(i, tmp)
if st.get_val(0, 1) >= INF:
print(-1)
exit()
ans = []
ind = 0
for i in range(n + 1):
if st.get_val(ind, ind + 1) - 1 == st.get_val(i, i + 1):
ans.append(i - ind)
ind = i
print(*ans) | N, M, K = map(int, input().split())
mod = 998244353
inv = [0,1]
for i in range(2, N):
inv.append((-inv[mod%i]*(mod//i))%mod)
if N == 1:
print(M)
exit()
m = [1]
s = 1
for _ in range(N-1):
s = s*(M-1)%mod
m.append(s)
ncombi = [1]
c = 1
for k in range(K):
c = c*(N-1-k)*inv[k+1]
c %= mod
ncombi.append(c)
ans = 0
for k in range(K+1):
ans = ans + m[-k -1]*ncombi[k]
ans %= mod
ans = ans*M%mod
print(ans) | 0 | null | 80,976,434,013,152 | 274 | 151 |
#<ABC151>
#<A>
s = input()
s = ord(s)
s = s + 1
print(chr(s))
| C = input()
次の英単語 = ord(C)+1
print(chr(次の英単語))
| 1 | 92,482,573,204,450 | null | 239 | 239 |
x,y=map(int, input().split())
a = int(x * y)
b=int(2*x+2*y)
#print(x,y)
print(a,b) | n = raw_input()
a = n.split(" ")
b = int(a[0])
c = int(a[1])
print b*c ,(b+c)*2 | 1 | 301,600,292,810 | null | 36 | 36 |
#coding:utf-8
import itertools
r = range(1,10)
for (x,y) in itertools.product(r,r):
print('{}x{}={}'.format(x,y,x*y)) | # -*- coding: utf-8 -*-
#https://mathtrain.jp/tyohukuc
n, m, k = map(int,input().split())
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 998244353
N = n+1 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
ans = 0
beki = [1,m-1]
for i in range(2,N+1):
beki.append(((beki[-1]*(m-1)) % p))
for x in range(k+1):
ans += m * beki[n-x-1] %p * cmb(n-1,x,p) %p
ans = ans % p
print(ans)
| 0 | null | 11,579,992,795,376 | 1 | 151 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
mod = 10**9+7
ans = 0
for i in range(K, N+2):
ans += (N+(N-i+1))*i//2-(i*(i-1)//2)+1
ans %= mod
print(ans) | n=int(input())
a = list(map(int,input().split()))
# oを選択 xを非選択とする 左から見て
# oxoxoxoxoxo に x を1つか2つ挿入することを考える
# 状態を4つ設定 (最後がxかoか)(挿入ずみのxの数)の形式でやる
#a=[1,2,3,4,5,6,7]
#n=len(a)
x0,x1,x2,o0,o1,o2=a[0],-10**18,0,-10**18,a[1],-10**18
for i in a[2:]:
x0,x1,x2,o0,o1,o2=o0,max(o1,x0),max(o2,x1),x0+i,x1+i,x2+i
if n%2==0:
print(max(x0,x1,o1))
else:
print(max(x1,x2,o2)) | 0 | null | 35,364,566,061,162 | 170 | 177 |
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
class Fibonacci(object):
memo = [1, 1]
def get_nth(self, n):
if n < len(Fibonacci.memo):
return Fibonacci.memo[n]
# print('fib({0}) not found'.format(n))
for i in range(len(Fibonacci.memo), n+1):
result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
Fibonacci.memo.append(result)
# print('fib({0})={1} append'.format(i, result))
return Fibonacci.memo[n]
if __name__ == '__main__':
# ??????????????\???
num = int(input())
# ?????£??????????????°????¨????
#f = Fibonacci()
#result = f.get_nth(num)
result = fib(num+1)
# ???????????????
print('{0}'.format(result)) | f=[1,1]
for _ in range(2,45):f+=[sum(f[-2:])]
print(f[int(input())])
| 1 | 2,019,588,380 | null | 7 | 7 |
def resolve():
c = input()
ans = chr(ord(c) + 1)
print(ans)
resolve() | chs = 'abcdefghijklmnopqrstuvwxyz'
s = input()
for i,c in enumerate(chs):
if s == c:
print(chs[i+1])
break | 1 | 92,031,088,146,790 | null | 239 | 239 |
print('Yes' if len(set(map(int, input().split()))) == 2 else 'No')
| arr = list(map(int, input().split()))
arr.sort()
if (arr[0] == arr[1]) and (arr[2] != arr[1]):
print("Yes")
elif (arr[1] == arr[2]) and (arr[0] != arr[1]):
print("Yes")
else:
print("No") | 1 | 68,381,027,657,140 | null | 216 | 216 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
''' ?????¢??¢?´¢ '''
# n??????????´??????????????????????q????????¢?´¢????????£?????´???
# ?¨??????????O(qn)
def linear_search(S, T):
count = 0
for t in T:
if t in S:
count += 1
return count
if __name__ == '__main__':
NS = int(input())
S = list(map(int, input().split()))
NT = int(input())
T = list(map(int, input().split()))
print(linear_search(S, T)) | a,b = map(int,input().split())
for i in range(1,100000):
x = i*8
y = i*10
if x//100 == a and y//100 == b:
print(i)
exit()
print(-1) | 0 | null | 28,125,766,893,328 | 22 | 203 |
def main():
s,w = map(int, input().split())
if w>=s: print("unsafe")
else: print("safe")
main()
| from fractions import gcd
a, b = map(int, raw_input().split())
print gcd(a, b) | 0 | null | 14,631,076,711,722 | 163 | 11 |
# -*- coding: utf-8 -*-
N,M,K = list(map(int, input().rstrip().split()))
#-----
# Calculate the Factorial and it's Inverse Element
fact = [0]*(N+1)
fact_inv = [0]*(N+1)
inv = [0]*(N+1)
mod = 998244353
fact[0] = fact[1] = 1
fact_inv[0] = fact_inv[1] = 1
inv[1] = 1
for i in range(2, N+1):
fact[i] = (fact[i-1] * i) % mod
inv[i] = mod - ( inv[mod%i] * (mod // i) ) % mod
fact_inv[i] = ( fact_inv[i-1] * inv[i] ) % mod
#-----
# Calculate (M-1) raised to the power of "0 to N-1"
pow_M1 = [0]*N
pow_M1[0] = 1
for i in range(1, N):
pow_M1[i] = ( pow_M1[i-1] * (M-1) ) % mod
#-----
ans = 0
for i in range(K+1):
comb = ( fact[N-1] * fact_inv[i] * fact_inv[N-1-i] ) % mod
ans += ( comb * M * pow_M1[N-i-1] ) % mod
ans %= mod
print(ans)
| from heapq import heappush, heappop
N, K, C = map(int, input().split())
S = input()
if C == 0 :
if K == S.count('o') :
for i, s in enumerate(S) :
if s == 'o' :
print(i + 1)
else :
N += 2
S = 'x' + S + 'x'
dpL = [0] * N
dpR = [0] * N
for l in range(1, N) :
r = N - 1 - l
dpL[l] = max(dpL[l - 1], int(S[l] == 'o'))
dpR[r] = max(dpR[r + 1], int(S[r] == 'o'))
if l - C - 1 >= 0 and S[l] == 'o' :
dpL[l] = max(dpL[l], dpL[l - C - 1] + 1)
if r + C + 1 < N and S[r] == 'o' :
dpR[r] = max(dpR[r], dpR[r + C + 1] + 1)
h = []
for r in range(C + 1) :
heappush(h, (-dpR[r], r))
for l in range(1, N) :
r = l - 1 + C + 1
if r < N :
cost = dpL[l - 1] + dpR[r]
else :
cost = dpL[l - 1]
heappush(h, (-cost, r))
while h[0][1] <= l :
heappop(h)
if -h[0][0] < K and S[l] == 'o' :
print(l) | 0 | null | 31,891,528,310,850 | 151 | 182 |
while True:
s = input()
if s == "-":
exit()
m = int(input())
for i in range(m):
h = int(input())
s = s[h:] + s[:h]
print(s)
| while 1:
m, f, r = map(int, input().split())
s = m + f
if m == -1 and f == -1 and r == -1:
break
elif m == -1 or f == -1 or s < 30:
print("F")
elif s >= 80:
print("A")
elif s >= 65 and s < 80:
print("B")
elif s >= 50 and s < 65:
print("C")
elif s >= 30 and s < 50:
if r < 50:
print("D")
else:
print("C")
| 0 | null | 1,570,950,328,992 | 66 | 57 |
li = []
for i, s in enumerate(input()):
if s == "\\":
li.append([i, 0])
elif s == "/":
if li:
if li[-1][1] == 0:
li[-1][1] = i - li[-1][0]
else:
for j in range(len(li) - 1, -1, -1):
if li[j][1] == 0:
li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
break
ans = []
for a in li:
if a[1] != 0:
ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)
| n = int(input())
l = list(map(int, input().split()))
c = 0
for i in l:
if i%2 == 0:
if i%3 != 0 and i%5 != 0:
c += 1
break
print("DENIED" if c > 0 else "APPROVED") | 0 | null | 34,484,363,196,328 | 21 | 217 |
n=int(input())
li=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
val=dic.get(li[i],-1)
if val==-1:
dic[li[i]]=1
else:
dic[li[i]]=val+1
ans+=li[i]
q=int(input())
for i in range(q):
a,b=map(int,input().split())
val=dic.get(a,-1)
if val==-1 or val==0:
print(ans)
else:
nb=dic.get(b,-1)
if nb==-1:
dic[b]=val
else:
dic[b]=val+nb
ans+=(b-a)*val
dic[a]=0
print(ans)
| n=int(input())
A=list(map(int,input().split()) )
q=int(input())
B=[]
C=[]
a_sum = sum(A)
counter = [0]*10**5
for a in A:
counter[a-1] += 1
for i in range(q):
b,c = map(int,input().split())
a_sum += (c-b) * counter[b-1]
counter[c-1]+=counter[b-1]
counter[b-1]=0
print(a_sum)
| 1 | 12,230,136,791,682 | null | 122 | 122 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
s = input()
cnt = 0
for i in range(len(s)//2):
if s[i] != s[-1-i]:
cnt += 1
print(cnt) | S = input()
ans = 0
for i in range(0,len(S)//2):
if S[i] != S[len(S)-1-i]:
ans += 1
print(ans) | 1 | 120,306,789,188,300 | null | 261 | 261 |
a= int(input())
h = a//3600
m = (a%3600)//60
s = (a%3600)%60
print('%d:%d:%d' % (h, m, s))
| def main():
A = int(input())
B = int(input())
print(6-(A+B))
main()
| 0 | null | 55,672,971,121,510 | 37 | 254 |
A,B,C,K = map(int,input().split())
if K-A > 0:
if K-A-B > 0:
print(A-(K-A-B))
else:
print(A)
else:
print(K) | c = 0
def merge(A, l, m, r):
global c
L = A[l:m]
L.append(1e10)
R = A[m:r]
R.append(1e10)
i, j = 0, 0
for k in range(l, r):
c += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def sort(A, l, r):
if r-l > 1:
m = (l+r)//2
sort(A, l, m)
sort(A, m, r)
merge(A, l, m, r)
N = int(input())
A = list(map(int, input().split()))
sort(A, 0, N)
print(" ".join(map(str, A)))
print(c)
| 0 | null | 10,891,119,869,620 | 148 | 26 |
N = int(input())
S = input()
ans = 0
for i in range(10):
for j in range(10):
for k in range(10):
tmp = 0
for l, value in enumerate(S):
if tmp == 0:
if value == str(i):
tmp = 1
elif tmp == 1:
if value == str(j):
tmp = 2
elif tmp == 2:
if value == str(k):
ans += 1
break
print(ans) | n=int(input())
if n%2==1:
print("0")
exit()
count=0
for i in range(1,30):
count+=n//(2*5**i)
print(count) | 0 | null | 122,257,216,489,760 | 267 | 258 |
from collections import deque
def main():
H,W=map(int,input().split())
S=[]
for i in range(H):
s=input()
S.append(s)
G=[]
for i in range(H):
for j in range(W):
tmp=[]
if S[i][j]=="#":
G.append(tmp)
continue
if i-1>=0:
if S[i-1][j]==".":
tmp.append((i-1)*W+j)
if i+1<=H-1:
if S[i+1][j]==".":
tmp.append((i+1)*W+j)
if j-1>=0:
if S[i][j-1]==".":
tmp.append(i*W+j-1)
if j+1<=W-1:
if S[i][j+1]==".":
tmp.append(i*W+j+1)
G.append(tmp)
res=0
for start in range(H*W):
dist = 0
v = [-1 for _ in range(H * W)]
que=deque([])
que.append(start)
v[start]=dist
while len(que)>0:
next_index=que.popleft()
next=G[next_index]
for i in next:
if v[i]==-1:
que.append(i)
v[i]=v[next_index]+1
if max(v)>=res:
res=max(v)
print(res)
if __name__=="__main__":
main()
| def main():
A = input()
ans = chr(ord(A) + 1)
print(ans)
main() | 0 | null | 93,362,601,104,544 | 241 | 239 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
A, B = map(int, readline().split())
if (A <= 9) & (B <= 9):
print(A * B)
else:
print(-1)
if __name__ == '__main__':
main()
| if __name__ == '__main__':
a, b = map(int, input().split())
if 1 <= a <= 9 and 1 <= b <= 9:
print(a * b)
else:
print(-1)
| 1 | 158,189,152,358,862 | null | 286 | 286 |
def isPrime(n):
if n==2 or n==3:
return True
elif n%2==0:
return False
else:
i = 2
while i**2 <= n:
if n%i == 0:
return False
i += 1
return True
r = []
n = int(input())
for i in range(n):
p = int(input())
if isPrime(p):
if p not in r:
r.append(p)
print(len(r)) | N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
C = []
maA = max(A) + N -1
for k in range(N):
if A[k] + k <= maA:
B.append(A[k]+k)
if -A[k] + k >0:
C.append(-A[k]+k)
B.sort()
C.sort()
c = 0
b = 0
while b < len(B) and c < len(C):
if B[b] == C[c]:
s = 0
t = 0
j = float('inf')
k = float('inf')
for j in range(b, len(B)):
if B[b] == B[j]:
s += 1
else:
break
for k in range(c, len(C)):
if C[c] == C[k]:
t +=1
else:
break
ans += s*t
b = j
c = k
continue
elif B[b] > C[c]:
c += 1
else:
b += 1
#print(B)
#print(C)
print(ans)
| 0 | null | 13,043,306,415,634 | 12 | 157 |
# swag
from collections import deque
class SWAG_Stack():
def __init__(self, F):
self.stack1 = deque()
self.stack2 = deque()
self.F = F
self.len = 0
def push(self, x):
if self.stack2:
self.stack2.append((x, self.F(self.stack2[-1][1], x)))
else:
self.stack2.append((x, x))
self.len += 1
def pop(self):
if not self.stack1:
while self.stack2:
x, _ = self.stack2.pop()
if self.stack1:
self.stack1.appendleft((x, self.F(x, self.stack1[0][1])))
else:
self.stack1.appendleft((x, x))
self.stack1.popleft()
self.len -= 1
def sum_all(self):
if self.stack1 and self.stack2:
return self.F(self.stack1[0][1], self.stack2[-1][1])
elif self.stack1:
return self.stack1[0][1]
elif self.stack2:
return self.stack2[-1][1]
else:
raise IndexError
n,m = map(int, input().split())
s = input()
stack = SWAG_Stack(min)
stack.push((0,n))
turn = [-1]*(n+1)
turn[-1] = 0
for i in range(n-1, -1, -1):
if s[i] == "1":
stack.push((float("inf"), i))
else:
cost, ind = stack.sum_all()
if cost == float("inf"):
break
turn[i] = cost+1
stack.push((cost+1, i))
if stack.len > m:
stack.pop()
# print(turn)
if turn[0] == -1:
print(-1)
exit()
prev_turn=turn[0]
prev_ind = 0
ans = []
for i in range(1, n+1):
if prev_turn-turn[i] == 1:
ans.append(i-prev_ind)
prev_ind = i
prev_turn = turn[i]
print(*ans)
| N,M=map(int,input().split())
S,r,s=input(),[],N
for _ in range(2*N):
if S[s]=='1':
s+=1
else:
if N-s:
r.append(N-s)
N,s=s,max(0,s-M)
print(*[-1] if s else r[::-1]) | 1 | 138,959,568,762,972 | null | 274 | 274 |
a, b, c, d = map(int, input().split())
cnt1 = 0
cnt2 = 0
while c > 0:
c -= b
cnt1 += 1
while a > 0:
a -= d
cnt2 += 1
if cnt1 <= cnt2:
print('Yes')
else:
print('No') | nums = input().split()
area = int(nums[0]) * int(nums[1])
length_cirle = int(nums[0]) * 2 + int(nums[1]) * 2
print(str(area) + " " + str(length_cirle))
| 0 | null | 14,968,707,993,372 | 164 | 36 |
N,K=map(int,input().split())
List = list(map(int, input().split()))
INF = 10000000000
expList = [INF]*1001
def expectationF(num):
if expList[num] == INF:
exp = 0
for i in range(1,num+1):
exp += i/num
expList[num] = exp
return expList[num]
res = 0
mid = 0
midList=[]
for i in range(N):
if i>=1:
midList.append(expectationF(List[i])+midList[i-1])
else:
midList.append(expectationF(List[i]))
m=K-1
for j in range(N-m):
if j == 0:
mid = midList[j+m]
else:
mid = midList[j+m]- midList[j-1]
res = max(res,mid)
print(res) | 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,666,990,816,732 | null | 223 | 223 |
n = int(input())
A = list(map(int, input().split()))
ans = 0
cumsum = 0
for i in range(n-1):
cumsum += A[n-i-1]
ans += (A[n-i-2] * cumsum)
ans %= 1000000007
print(ans) | n = int(input())
a, b = map(int, input().split())
i = 0
ans = "NG"
while i <= b:
if i >= a and i % n == 0:
ans = "OK"
i += n
print(ans)
| 0 | null | 15,100,234,750,430 | 83 | 158 |
def main():
A, B = map(int,input().split())
print( A * B if (A // 10 == 0) & (B // 10 == 0) else -1)
return 0
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():
A, B = map(int, readline().split())
if A < 10 and B < 10:
print(A * B)
else:
print(-1)
return
if __name__ == '__main__':
main()
| 1 | 158,234,363,325,232 | null | 286 | 286 |
def insertion_sort(arr):
print(" ".join(map(str, arr)))
for i in range(1,len(arr)):
j = i
while arr[j] < arr[j-1] and j > 0:
arr[j-1], arr[j] = arr[j], arr[j-1]
j -= 1
print(" ".join(map(str, arr)))
input()
arr = list(map(int, input().split()))
insertion_sort(arr)
| from collections import Counter
word = input()
count = 0
while True:
text = input()
if text == 'END_OF_TEXT':
break
count += Counter(text.lower().split())[word.lower()]
print(count) | 0 | null | 907,828,270,960 | 10 | 65 |
ans=0
for i,j in zip(input(),input()):
if i!=j:ans+=1
print(ans) | def linearSearch(A, n, key):
i = 0
A.append(key)
while (A[i] != key):
i += 1
del A[n]
return i != n
if __name__ == '__main__':
n = int(input())
L = list(map(int, input().split()))
q = int(input())
Key = list(map(int, input().split()))
cnt = 0
for i in range(q):
if (linearSearch(L, n, Key[i])):
cnt += 1
print(cnt)
| 0 | null | 5,324,553,375,680 | 116 | 22 |
minute = int(input())
print('{}:{}:{}'.format(minute // 3600, (minute % 3600) // 60, (minute % 3600) % 60))
| #!/usr/bin/python3
import sys
from collections import Counter
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = [int(x) for x in input().split()]
c = Counter(a)
def c2(n):
return n * (n - 1) // 2
ans = sum(c2(v) for v in c.values())
def add(x):
global ans
ans -= c2(c[x])
c[x] += 1
ans += c2(c[x])
def remove(x):
global ans
ans -= c2(c[x])
c[x] -= 1
ans += c2(c[x])
for x in a:
remove(x)
print(ans)
add(x) | 0 | null | 23,980,306,608,642 | 37 | 192 |
# -*- coding: utf-8 -*-
import sys
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
A_list.sort(key=lambda x: -abs(x))
A_plus = []
A_minus = []
mod = 10**9 + 7
for val in A_list:
if val >= 0:
A_plus.append(val)
else:
A_minus.append(val)
ans = 1
cnt = 0
i_p = 0 # index of A_plus
i_m = 0 # index of A_minus
while (cnt < K):
if (K - cnt) == 1:
if i_p < len(A_plus):
ans *= A_plus[i_p]
ans %= mod
cnt += 1
i_p += 1
break
else:
ans2 = 1
for i in range( len(A_list)-K, len(A_list) ):
ans2 *= A_list[i]
ans2 %= mod
print(ans2)
return
if (i_m + 1) < len(A_minus):
if (i_p + 1) < len(A_plus):
if abs( A_plus[i_p] * A_plus[i_p + 1] ) > abs( A_minus[i_m] * A_minus[i_m + 1] ):
ans *= A_plus[i_p]
cnt += 1
i_p += 1
else:
ans *= (A_minus[i_m] * A_minus[i_m + 1])
cnt += 2
i_m += 2
else:
ans *= (A_minus[i_m] * A_minus[i_m + 1])
cnt += 2
i_m += 2
else:
ans *= A_plus[i_p]
cnt += 1
i_p += 1
ans %= mod
print(ans)
return
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
A, B = map(int, readline().split())
if (A <= 9) & (B <= 9):
print(A * B)
else:
print(-1)
if __name__ == '__main__':
main()
| 0 | null | 83,590,642,739,142 | 112 | 286 |
X = input()
l = len(X)
m = l//2
if (X == 'hi'*m):
print("Yes")
else:
print("No") | s = input().split("hi")
f = 0
for i in s:
if i != "":
f = 1
break
if f == 0:
print("Yes")
else:
print("No") | 1 | 53,223,490,133,032 | null | 199 | 199 |
x, k, d = map(int, input().split())
cur = x
numTimes = x // d
if numTimes == 0:
cur -= d
k -= 1
else:
numTimes = min(abs(numTimes), k)
if x < 0:
numTimes *= -1
cur -= numTimes * d
k -= numTimes
if k % 2 == 0:
print(abs(cur))
else:
result = min(abs(cur - d), abs(cur + d))
print(result) | X,K,D = map(int,input().split())
ans = 0
if X == 0:
if K % 2 == 0:
ans = 0
else:
ans = D
if X > 0:
if K*D <= X:
ans = X - K*D
else:
n = X // D
if X % D != 0:
n += 1
if (K - n) % 2 == 0:
ans = abs(X-D*n)
else:
ans = abs(X-D*(n-1))
if X < 0:
if K*D + X <= 0:
ans = abs(K*D+X)
else:
n = -X // D
if -X % D != 0:
n += 1
if (K-n) % 2 == 0:
ans = abs(X+n*D)
else:
ans = abs(X+(n-1)*D)
print(ans) | 1 | 5,262,484,914,802 | null | 92 | 92 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n,t=map(int,input().split())
d1=[[0]*t for i in range(n+1)]
d2=[[0]*t for i in range(n+1)]
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(1,n+1):
a=ab[i-1][0]
b=ab[i-1][1]
for j in range(t):
if j<a:
d1[i][j]=d1[i-1][j]
else:
d1[i][j]=max(d1[i][j],d1[i-1][j],d1[i-1][j-a]+b)
a,b=ab[n-i]
for j in range(t):
if j<a:
d2[n-i][j]=d2[n-i+1][j]
else:
d2[n-i][j]=max(d2[n-i][j],d2[n-i+1][j],d2[n-i+1][j-a]+b)
ans=0
for i in range(1,n+1):
b=ab[i-1][1]
for j in range(t):
ans=max(ans,b+d1[i-1][j]+d2[i][t-1-j])
print(ans) | import math
r = float(raw_input())
s = r * r * math.pi
l = 2 * r * math.pi
print '%f %f' %(s,l) | 0 | null | 76,452,267,007,470 | 282 | 46 |
import math
x1,y1,x2,y2 = map(float,input().split(" "))
print("{:.5f}".format(math.sqrt((x2-x1)**2 + (y2-y1)**2)))
| import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
n = ni()
a = na()
b = []
for i in range(n):
b.append((a[i],i))
b.sort(reverse=True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
x,y = b[i-1]
for j in range(i+1):
left = dp[i-1][j-1] + x*abs(y-j+1) if j > 0 else -1
right = dp[i-1][j] + x*abs(n-i+j-y) if j < i else -1
dp[i][j] = max(left,right)
print(max(dp[-1])) | 0 | null | 16,991,272,183,238 | 29 | 171 |
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15,
2, 2, 5, 4, 1, 4, 1, 51]
index = input()
index = int(index)
print(list[index-1])
| #!/usr/bin/python3
# -*- coding:utf-8 -*-
def main():
k = int(input()) - 1
li = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')
print(li[k])
if __name__=='__main__':
main()
| 1 | 50,125,256,813,992 | null | 195 | 195 |
h=int(input())
w=int(input())
n=int(input())
print(-(-n//max(h,w))) | n = int(input())
titles = []
times = []
for i in range(n):
title,m = input().split()
titles.append(title)
times.append(int(m))
print(sum(times[titles.index(input())+1:])) | 0 | null | 92,618,231,867,798 | 236 | 243 |
S = list(input())
if S[-1] == S[-2] and S[-3] == S[-4]:
print("Yes")
else:
print("No")
| #!/usr/bin/env python3
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def solve(s: str):
if s[2] == s[3] and s[4] == s[5]:
print(YES)
else:
print(NO)
return
def main():
s = sys.stdin.readline().strip() # type: str
solve(s)
if __name__ == '__main__':
main()
| 1 | 42,010,940,406,260 | null | 184 | 184 |
import math
A, B, H, M = map(int, input().split())
c = math.cos(math.radians(360 - abs(30 * H + 0.5 * M - 6 * M)))
X_2 = A ** 2 + B ** 2 - 2 * A * B * c
X = math.sqrt(X_2)
print(X) | A, B, H, M = map(int,input().split())
import numpy as np
theta_h=2*np.pi*(H/12 + M/720)#rad
theta_m=2*np.pi*M/60#rad
theta=min((max(theta_h, theta_m)-min(theta_h, theta_m)), 2*np.pi-(max(theta_h, theta_m)-min(theta_h, theta_m)))
print(np.sqrt(A**2 + B**2 - 2*np.cos(theta)*A*B)) | 1 | 19,976,766,550,784 | null | 144 | 144 |
n = int(input())
mod = 10**9+7
ls = list(map(int,input().split()))
di = [i**2 for i in ls]
print((((sum(ls)**2)-(sum(di)))//2)%mod) | import sys
if __name__ == '__main__':
a, b, c = map(int, input().split())
print(c, a, b)
| 0 | null | 20,828,813,450,590 | 83 | 178 |
inf = 10**9 + 7
def merge(A, left, mid, right):
cnt = 0
L = A[left:mid]
R = A[mid:right]
L.append(inf)
R.append(inf)
i, j = 0, 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += 1
return cnt
def merge_sort(A, left, right):
cnt = 0
if left + 1 < right:
mid = (left + right) // 2
cnt += merge_sort(A, left, mid)
cnt += merge_sort(A, mid, right)
cnt += merge(A, left, mid, right)
return cnt
n = int(input())
*A, = map(int, input().split())
cnt = merge_sort(A, 0, n)
print(*A)
print(cnt)
| INFTY = 1000000001
def merge(A, left, mid, right):
global cnt
L = A[left:mid]
R = A[mid:right]
L.append(INFTY)
R.append(INFTY)
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt += 1
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
n = int(input())
S = list(map(int, input().split()))
cnt = 0
merge_sort(S, 0, len(S))
print(*S)
print(cnt)
| 1 | 110,914,542,012 | null | 26 | 26 |
from sys import stdin
import math
import re
import queue
input = stdin.readline
MOD = 1000000007
def solve():
N,A,B = map(int, input().split())
if(abs(A - B)%2 == 0):
print(abs(A-B)//2)
return
print(min(A-1,N-B)+1+(B-A-1)//2)
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
def solve():
n, a, b = inl()
if (b - a) % 2 == 0:
return (b - a) // 2
k = min(a - 1, n - b)
return k + 1 + (b - a) // 2
print(solve())
| 1 | 109,281,128,419,552 | null | 253 | 253 |
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
a=LI()
A=0
for elem in a:
A^=elem
ans=[A^elem for elem in a]
print(*ans) | import numpy as np
import sys
readline = sys.stdin.readline
N = int(input())
A = np.array(readline().split(), np.int64)
all_xor = 0
for a in A:
all_xor = all_xor^a
for a in A:
xor = all_xor^a
print(xor, end = ' ') | 1 | 12,382,997,124,550 | null | 123 | 123 |
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))
import numpy as np
Q = np.cumsum(P)
R = np.pad(Q,K,'constant', constant_values=0)[:N]
a = np.argmax(Q-R)
ans = 0
for i in range(K):
ans += (1.00+P[a-i])/2.00
print(ans) | #C - Average Length
import math
import itertools
N = int(input())
town = []
for i in range(N):
x,y = map(int,input().split())
town.append((x,y))
def dist(A,B):
return math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2)
route = list(itertools.permutations(town))
tot = 0
for i in route:
for j in range(len(i)-1):
tot += dist(i[j],i[j+1])
ave = tot/len(route)
print(ave) | 0 | null | 111,728,473,581,468 | 223 | 280 |
from math import sin, cos, radians, sqrt
a, b, C = map(float, input().split())
rad = radians(C)
h = b * sin(rad)
print(a * h / 2)
print(a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(rad)))
print(h)
| import math, re
a, b, c = [int(n) for n in re.split(r"\s+", input().strip())]
h = b * math.sin(c * math.pi / 180)
S = a * h / 2
L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(c * math.pi / 180)) + a + b
print("%f %f %f" % (S, L, h))
| 1 | 175,512,686,738 | null | 30 | 30 |
h = int(input())
layer = 0
branch_set = 0
while True :
if h > 1 :
h //= 2
layer += 1
continue
else :
break
for i in range(0, layer) :
branch_set += 2 ** i
print(branch_set + 2**layer)
| import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
val+=a[K+i]
val-=a[i]
max_val=max(val,max_val)
print(max_val/2+K*0.5) | 0 | null | 77,741,116,777,798 | 228 | 223 |
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
c = input()
if c == 'AC':
c0 += 1
elif c == 'WA':
c1 += 1
elif c == 'TLE':
c2 += 1
else:
c3 += 1
print(f'AC x {c0}')
print(f'WA x {c1}')
print(f'TLE x {c2}')
print(f'RE x {c3}')
| n = int(input())
a = map(int, input().split())
cnt = 0
for i, v in enumerate(a):
if (i+1) % 2 == 1 and v % 2 == 1:
cnt+=1
print(cnt) | 0 | null | 8,192,449,267,310 | 109 | 105 |
N = int(input())
A = list(map(int, input().split()))
S = [0]
for i in range(N):
S.append(A[i] + S[i])
ans = float('inf')
for i in range(1, N):
ans = min(ans, abs((S[i] - S[0]) - (S[N] - S[i])))
print(ans)
| import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
import numpy as np
def main():
n=II()
A=LI()
A=np.array(A)
B=np.cumsum(A)
C=np.cumsum(A[::-1])
#print(B,C)
D=abs(B[:-1]-C[:-1][::-1])
#print(D)
print(np.min(D))
if __name__ == "__main__":
main()
| 1 | 142,080,746,301,328 | null | 276 | 276 |
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]
for a in A:
B[a-1] += 1
s = 0
for b in B:
s += b * (b-1) // 2
for a in A:
print(s - (B[a-1]-1)) | from collections import Counter
n = int(input())
A = list(map(int,input().split()))
Acount = Counter(A)
total = 0
for key in Acount.keys():
total += Acount[key] * (Acount[key] - 1) // 2
for i in range(n):
tmp = total
tmp -= Acount[A[i]]*(Acount[A[i]]-1) // 2
tmp += (Acount[A[i]]-1)*(Acount[A[i]]-2) // 2
print(tmp) | 1 | 47,736,606,054,448 | null | 192 | 192 |
from collections import namedtuple
import math
Co = namedtuple('Co', 'x y')
def f(i, n, l, r):
if i >= n:
return
il = Co(x=(1/3 * r.x + (1 - 1/3) * l.x), y=(1/3 * r.y + (1 - 1/3) * l.y))
ir = Co(x=(2/3 * r.x + (1 - 2/3) * l.x), y=(2/3 * r.y + (1 - 2/3) * l.y))
trix = 1/2 * (ir.x + il.x - math.sqrt(3) * ir.y + math.sqrt(3) * il.y)
triy = 1/2 * (math.sqrt(3) * ir.x - math.sqrt(3) * il.x + ir.y + il.y)
trico = Co(trix, triy)
f(i+1, n, l, il)
print(il.x, il.y)
f(i+1, n, il, trico)
print(trico.x, trico.y)
f(i+1, n, trico, ir)
print(ir.x, ir.y)
f(i+1, n, ir, r)
if __name__ == '__main__':
n = int(input())
print(0, 0)
f(0, n, Co(0,0), Co(100,0))
print(100, 0)
| import math
def koch_kurve(n, p1=[0, 0], p2=[100, 0]):
if n == 0: return
s, t, u = make_edge_list(p1, p2)
koch_kurve(n-1, p1, s)
# print(s)
# print(s)
print(" ".join([ str(i) for i in s ]))
koch_kurve(n-1, s, u)
print(" ".join([ str(i) for i in u ]))
koch_kurve(n-1, u, t)
print(" ".join([ str(i) for i in t ]))
koch_kurve(n-1, t, p2)
def make_edge_list(p1, p2):
sx = 2 / 3 * p1[0] + 1 / 3 * p2[0]
sy = 2 / 3 * p1[1] + 1 / 3 * p2[1]
# s = (sx, sy)
s = [sx, sy]
tx = 1 / 3 * p1[0] + 2 / 3 * p2[0]
ty = 1 / 3 * p1[1] + 2 / 3 * p2[1]
t = [tx, ty]
theta = math.radians(60)
ux = math.cos(theta) * (tx - sx) - math.sin(theta) * (ty - sy) + sx
uy = math.sin(theta) * (tx - sx) + math.cos(theta) * (ty - sy) + sy
u = [ux, uy]
return s, t, u
n = int(input())
print("0 0")
koch_kurve(n)
print("100 0")
| 1 | 126,065,768,682 | null | 27 | 27 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
if S[2] == S[3] and S[4] == S[5]:
print('Yes')
else:
print('No') | # import math
N = int(input())
# Nが奇数の場合は-2していくと全て奇数になるので答えは0
# Nが偶数の場合を検討するべし
# Nが偶数の場合、明らかに2の倍数より5の倍数の方が少ないので5の倍数がいくつかで考える
if (N % 2 == 1):
print(0)
exit()
bunbo = 0
sum_5 = 0
while (10 * 5 ** bunbo) <= N:
sum_5 += N // (10 * 5**bunbo)
bunbo += 1
print(sum_5)
| 0 | null | 79,066,091,948,550 | 184 | 258 |
#!/usr/bin/env python3
import collections as cl
import sys
def comb(n, r, mod=10 ** 9 + 7):
r = min(r, n-r)
upper = 1
for i in range(n, n-r, -1):
upper = (upper * i) % mod
lower = 1
for i in range(1, r+1):
lower = (lower * i) % mod
lower_inv = pow(lower, mod - 2, mod)
return (upper * lower_inv) % mod
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 main():
n, a, b = MI()
ttl = pow(2, n, 10**9+7) - 1
a_ttl = comb(n, a)
b_ttl = comb(n, b)
print((ttl - a_ttl - b_ttl) % (10**9+7))
main()
| for i in xrange(1, 10):
for j in xrange(1, 10):
print '%dx%d=%d'%(i,j,i*j) | 0 | null | 33,002,027,672,110 | 214 | 1 |
import math
import sys
import itertools
from collections import deque
# import numpy as np
def main():
S = sys.stdin.readline()
len_S = len(S)
index = 0 # 操作しているSのインデックス
DOWN = [] # 下り文字をスタック
POOL = [] # 水たまりごとの面積
area = 0 # 総面積
for s in S:
if s == '\\':
DOWN.append(index)
elif s == '/' and len(DOWN) > 0:
pool_start = DOWN.pop()
pool_end = index
tmp_area = pool_end - pool_start
area += tmp_area
while True:
if len(POOL) == 0:
break
if POOL[-1]['start'] > pool_start and POOL[-1]['end'] < pool_end:
tmp_area += POOL[-1]['area']
POOL.pop()
else:
break
POOL.append({'start': pool_start, 'end': pool_end, 'area': tmp_area})
index += 1
print(area)
if len(POOL) > 0:
print(len(POOL), end=" ")
for i in range(len(POOL)-1):
print(POOL[i]['area'], end=" ")
print(POOL[-1]['area'])
else:
print(0)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
N, M = map(int, input().split())
if M%2:
cnt = 0
for i in range(1, M//2 + 1):
cnt += 1
print(i, M + 2 - i)
print(M + 1 + i, 2*M + 2 - i)
i = cnt + 1
print(i, M + 2 - i)
else:
for i in range(1, M//2 + 1):
print(i, M + 2 - i)
print(M + 1 + i, 2*M + 2 - i) | 0 | null | 14,480,111,120,800 | 21 | 162 |
N,X,Y =map(int,input().split())
count = [0] * (N-1)
for i in range(1,N):
for j in range(i+1,N+1):
dist = min(j-i, abs(X-i)+1+abs(Y-j))
count[dist-1] +=1
print("\n".join(map(str,count))) | N,X,Y = map(int,input().split())
from collections import deque
INF = 1000000000
ans = [0]*(N-1)
def rep(sv,dist):
que = deque()
def push(v,d):
if (dist[v] != INF): return
dist[v] = d
que.append(v)
push(sv,0)
while(que):
v = que.popleft()
d = dist[v]
if v-1 >= 0:
push(v-1, d+1)
if v+1 < N:
push(v+1, d+1)
if v == X-1:
push(Y-1, d+1)
#逆に気を付ける
if v == Y-1:
push(X-1, d+1)
for i in range(N):
dist = [INF]*N
rep(i,dist)
# print(dist)
for d in dist:
if d-1 == -1:continue
ans[d-1] += 1
for an in ans:
print(an//2)
# print(ans)
| 1 | 44,101,878,184,672 | null | 187 | 187 |
N, K = map(int, input().split())
mod = pow(10, 9)+7
Cmax = ((N+N-K+1)*K)//2
Cmin = ((K-1)*K)//2
ans = 1
for i in range(K, N+1):
ans = (ans+Cmax-Cmin+1)
Cmin += i
Cmax += (N-i)
print(ans % mod)
| n,k = map(int,input().split())
ans = 1
y = sum(list(range(n-k+2,n+1)))
j = n - k + 1
for i in range(k,n+1):
x = (1+(i-1))*(i-1)//2
y += j
j -= 1
ans += y - x + 1
ans %= 10 ** 9 + 7
print(ans) | 1 | 33,281,890,062,548 | null | 170 | 170 |
a=input()
print("A" if a.isupper() else "a") | a = input()
if str.isupper(a):
print('A')
elif str.islower(a):
print('a') | 1 | 11,353,074,075,038 | null | 119 | 119 |
n,m=list(map(int,input().split()))
s=input()
a=[0]*(n+1)
a[0]=1
for i in range(1,n+1):
if s[i]=='1':
continue
for j in range(max(0,i-m),i):
if s[j]=='1':
continue
if a[j]>0:
break
a[i]=i-j
ans=''
cur=n
while cur>0:
d=a[cur]
cur-=d
if d==0:
print(-1)
exit(0)
ans=str(d)+' '+ans
print(ans[:-1]) | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
class SegTree:
"""
セグメント木
1.update: i番目の値をxに更新する
2.query: 区間[l, r)の値を得る
"""
def __init__(self, n, func, intv, A=[]):
"""
:param n: 要素数(0-indexed)
:param func: 値の操作に使う関数(min, max, add, gcdなど)
:param intv: 要素の初期値(単位元)
:param A: 初期化に使うリスト(オプション)
"""
self.n = n
self.func = func
self.intv = intv
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [self.intv] * (n2 << 1)
# 初期化の値が決まっている場合
if A:
# 1段目(最下段)の初期化
for i in range(n):
self.tree[n2+i] = A[i]
# 2段目以降の初期化
for i in range(n2-1, -1, -1):
self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 0:
i >>= 1
self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])
def query(self, a, b):
"""
[a, b)の値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
l = a + self.n2
r = b + self.n2
s = self.intv
while l < r:
if r & 1:
r -= 1
s = self.func(s, self.tree[r])
if l & 1:
s = self.func(s, self.tree[l])
l += 1
l >>= 1
r >>= 1
return s
def get(self, i):
""" 一点取得 """
return self.tree[i+self.n2]
def all(self):
""" 全区間[0, n)の取得 """
return self.tree[1]
N, M = MAP()
S = input()
dp = SegTree(N+1, min, INF)
dp.update(N, 0)
for i in range(N-1, -1, -1):
# ゲームオーバーマスには遷移できない
if S[i] == '1':
continue
mn = dp.query(i+1, min(N+1, i+M+1))
if mn != INF:
dp.update(i, mn+1)
# 辿り着けない
if dp.get(0) == INF:
print(-1)
exit()
cnt = dp.get(0)
cur = 0
prev = -1
ans = []
for i in range(1, N+1):
if dp.get(i) == INF:
continue
# 手数が変わる場所でなるべく手前に飛ぶ
if dp.get(i) != cnt:
prev = cur
cur = i
ans.append(cur-prev)
cnt = dp.get(i)
print(*ans)
| 1 | 138,620,152,756,738 | null | 274 | 274 |
N = int(input())
A = tuple(map(int, input().split(' ')))
MOD = 10 ** 9 + 7
zeros = [0] * 60
ones = [0] * 60
for a in A:
for i, bit in enumerate(reversed(format(a, '060b'))):
if bit == '0':
zeros[i] += 1
else:
ones[i] += 1
base = 1
ans = 0
for i in range(len(zeros)):
ans += zeros[i] * ones[i] * base
ans %= MOD
base *= 2
base %= MOD
print(ans)
| import sys
input = sys.stdin.readline
MOD = pow(10, 9) + 7
n = int(input())
a = list(map(int, input().split()))
m = max(a)
num = [0] * 61
for x in a:
for j in range(61):
if (x >> j) & 1:
num[j] += 1
s = 0
#print(num)
for i in range(61):
s += (n - num[i]) * num[i] * pow(2, i, MOD) % MOD
print(s % MOD) | 1 | 122,974,487,901,342 | null | 263 | 263 |
n=int(input())
ps=[0 for j in range(n+1)]
for i in range(n):
p,d,*vs=[int(j) for j in input().split()]
ps[p]=vs
dist=[-1 for i in range(n+1)]
d=0
queue=[1]
while queue:
pos=queue.pop(0)
if dist[pos] == -1:
dist[pos]=d
for i in ps[pos]:
if dist[i]==-1:
queue.append(i)
dist[i]=dist[pos]+1
for i in range(1,n+1):
print(i,dist[i])
|
def BFS(s = 0):
Q.pop(0)
color[s] = 2
for j in range(len(color)):
if A[s][j] == 1 and color[j] == 0:
Q.append(j)
color[j] = 1
d[j] = d[s] + 1
if len(Q) != 0:
BFS(Q[0])
n = int(raw_input())
A = [0] * n
for i in range(n):
A[i] = [0] * n
for i in range(n):
value = map(int, raw_input().split())
u = value[0] - 1
k = value[1]
nodes = value[2:]
for j in range(k):
v = nodes[j] - 1
A[u][v] = 1
color = [0] * n
Q = [0]
d = [-1] * n
d[0] = 0
BFS(0)
for i in range(n):
print(str(i + 1) + " " + str(d[i])) | 1 | 3,804,062,052 | null | 9 | 9 |
X,N=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(1,102):
if i not in p:
if abs(X-i)<abs(X-ans):
ans=i
print(ans)
| def p_has_value_x(p:list, x:int):
for item in p:
if int(item) == x:
return True
return False
def solve(p: list, x:int) -> int:
if not p_has_value_x(p, x):
return x
pos = 1
while True:
aim_value = x - pos
if aim_value <= 0:
return aim_value
if not p_has_value_x(p, aim_value):
return aim_value
aim_value = x + pos
if not p_has_value_x(p, aim_value):
return aim_value
pos += 1
x, n = map(int, input().split())
if n == 0:
print(x)
else:
p = input().split()
print(solve(p, x))
| 1 | 14,013,705,005,598 | null | 128 | 128 |
x1,y1,x2,y2=list(map(float,input().split()))
d=((x1-x2)**2+(y1-y2)**2)**0.5
print(d) | x1, y1, x2, y2 = map(float, input().split())
print(((y2-y1)**2 + (x2-x1)**2)**(1/2))
| 1 | 156,563,241,340 | null | 29 | 29 |
import itertools
while True:
n,x = map(int,input().split(" "))
if n == 0 and x == 0:
break
#データリスト作成
data = [m for m in range(1,n+1)]
data_cmb = list(itertools.combinations(data,3))
#検証
res = [ret for ret in data_cmb if sum(ret) == x]
print(len(res))
| # coding: utf-8
def getint():
return int(input().rstrip())
def main():
n = getint()
values = []
for i in range(n):
values.append(getint())
maxv = values[1] - values[0]
minv = values[0]
for j in range(1,n):
maxv = max(maxv, values[j]-minv)
minv = min(minv, values[j])
print(maxv)
if __name__ == '__main__':
main() | 0 | null | 664,557,370,000 | 58 | 13 |
A,B,C,D = [int(x) for x in input().split()]
if A % D == 0 :
takahashi = A // D
else:
takahashi = A // D + 1
if C % B == 0 :
aoki = C // B
else:
aoki = C // B + 1
if takahashi >= aoki:
print('Yes')
else:
print('No') | def main():
a, b, c, d = map(int, input().split())
if c % b == 0:
e = c // b
else:
e = c // b + 1
if a % d == 0:
f = a // d
else:
f = a // d + 1
if e > f:
ans = "No"
else:
ans = "Yes"
print(ans)
if __name__ == "__main__":
main()
| 1 | 29,777,716,299,868 | null | 164 | 164 |
class BIT:
def __init__(self,n):
self.s = [0]*(n+1)
self.n = n
def add(self,val,idx):
while idx < self.n+1:
self.s[idx] = self.s[idx] + val
idx += idx&(-idx)
return
def get(self,idx):
res = 0
while idx > 0:
res = res + self.s[idx]
idx -= idx&(-idx)
return res
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(input())
S = [ord(s) - ord('a') for s in input()[:-1]]
bits = [BIT(n) for i in range(26)]
for i,s in enumerate(S):
bits[s].add(1,i+1)
Q = int(input())
ans = []
for _ in range(Q):
flag,x,y = input().split()
if flag == "1":
i = int(x)
c = ord(y) - ord('a')
bits[S[i-1]].add(-1,i)
bits[c].add(1,i)
S[i-1] = c
else:
l = int(x)
r = int(y)
res = 0
for i in range(26):
res += (bits[i].get(r) > bits[i].get(l-1))
ans.append(str(res))
print("\n".join(ans)) | x = list(map(int , input().split()))
s = set()
for i in x:
if i not in s:
s.add(i)
if len(s) == 2:
print('Yes')
else:
print('No') | 0 | null | 65,284,458,124,328 | 210 | 216 |
index = 0
inputs = []
while True:
index += 1
x = input()
if x == '0':
break
else:
inputs.append("Case {}: {}".format(index, x))
print("\n".join(inputs)) | a, b = input().split()
if (len(a) >1) or (len(b) >1):
print(-1)
else:
print(int(a)*int(b)) | 0 | null | 79,393,057,792,048 | 42 | 286 |
N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
R = [0] * N
for i in range(N):
R[i] = set()
for i in range(M):
A[i], B[i] = list(map(int, input().split()))
R[A[i]-1].add(B[i]-1)
R[B[i]-1].add(A[i]-1)
stack = set()
visited = set()
max_groups = 0
for i in range(N):
if not i in visited:
stack.add(i)
groups = 0
while True:
current = stack.pop()
visited.add(current)
groups += 1
stack |= (R[current] - visited)
if not stack:
break
max_groups = max(max_groups,groups)
print(max_groups) | n,m = map(int,input().split())
a = [1]*(n+1)
b = [0]*(n+1)
for i in range(m):
x,y = map(int,input().split())
u = x
while a[u]==0:
u = b[u]
v = y
while a[v]==0:
v = b[v]
if u!=v:
b[v] = u
b[y] = u
b[x] = u
a[u] += a[v]
a[v] = 0
print(max(a)) | 1 | 3,969,158,279,812 | null | 84 | 84 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(1,min(K+1,45)):
B = [0]*N
for i in range(N):
l = max(0,i-A[i])
r = min(N-1,i+A[i])
B[l] += 1
if r+1 < N:
B[r+1] -= 1
for i in range(1,N):
B[i] += B[i-1]
A = B
print(*A) | N, K = map(int, input().split())
A = [int(i) for i in input().split()]
for _ in range(K):
flg = True
imos = [0]*(N+1)
for i in range(N):
imos[max(0, i-A[i])] += 1
imos[min(N, i+A[i]+1)] -= 1
A = [0]*N
c = 0
for i in range(N):
c += imos[i]
A[i] = c
if c != N:
flg = False
if flg is True:
print(*([N]*N), sep=' ')
exit()
print(*A)
| 1 | 15,450,877,492,578 | null | 132 | 132 |
N=int(input())
s=input()
count=0
for i in range(0,10):
if str(i) in s[:-2]:
index_1=s.index(str(i))
for j in range(0,10):
if str(j) in s[index_1+1:-1]:
index_2=s[index_1+1:-1].index(str(j))+index_1+1
for k in range(0,10):
if str(k) in s[index_2+1:]:
count+=1
print(count)
| N = int(input())
S = input()
ans = 0
for i in range(1000):
res = str(i).zfill(3)
cnt = 0
p = res[cnt]
for s in S:
if p == s:
cnt += 1
if cnt == 3:
ans += 1
break
p = res[cnt]
print(ans) | 1 | 128,105,637,765,060 | null | 267 | 267 |