code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
A,B = input().split()
if len(A)==2 or len(B)==2:
print(-1)
exit(0)
print(int(A)*int(B)) | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
H,W=MI()
grid = [ST() for _ in range(H)]
N = H*W
edge = [[] for _ in range(N)]
def enc(h,w):
return h*W+w
# DP = [[[inf,inf] for _ in range(W)] for _ in range(H)]
# DP[0][0][0] = 0
DP = [[inf]*W for _ in range(H)]
DP[0][0] = int(grid[0][0] == "#")
for h in range(H):
for w in range(W):
if(h+1<H):
if(grid[h][w] == grid[h+1][w] or grid[h+1][w] == "."):
DP[h+1][w] = min(DP[h+1][w], DP[h][w])
else:
DP[h+1][w] = min(DP[h+1][w], DP[h][w] + 1)
if(w+1<W):
if(grid[h][w] == grid[h][w+1] or grid[h][w+1] == "."):
DP[h][w+1] = min(DP[h][w+1], DP[h][w])
else:
DP[h][w+1] = min(DP[h][w+1], DP[h][w] + 1)
print(DP[-1][-1])
if __name__ == '__main__':
main() | 0 | null | 103,975,492,826,940 | 286 | 194 |
N = int(input())
A = list(map(int, input().split()))
ans = 0
if N == 0:
if A[0] >= 2:
ans = -1
else:
ans = 1
if N >= 1 and A[0] >= 1:
ans = -1
if N >= 1:
node_num = {N: A[N]}
max_parent_num = {0: 1}
for i in range(1, N+1):
max_parent_num[i] = max_parent_num[i-1] * 2 - A[i]
for i in range(N, 0, -1):
if node_num[i] > A[i] + max_parent_num[i]:
ans = -1
break
#i-1 no parent wo tukuru
if node_num[i] <= max_parent_num[i-1]:
i_1_parent_num = node_num[i]
else:
i_1_parent_num = max_parent_num[i-1]
node_num[i-1] = i_1_parent_num + A[i-1]
if i == 1:
if node_num[i-1] != 1:
ans = -1
break
if ans == -1 or ans == 1:
print(ans)
else:
ans = sum(node_num.values())
print(ans) | 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 = int(readline())
S = readline().strip()
ans = 0
for i in range(N - 2):
if S[i : i + 3] == 'ABC':
ans += 1
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 59,265,850,870,656 | 141 | 245 |
import string
a=string.ascii_lowercase
A=string.ascii_uppercase
n=input()
if n in a :
print("a")
else :
print("A")
| ch = input()
if ch == 'a' or ch == 'b' or ch == 'c' or ch == 'd' or ch == 'e' or ch == 'f' or ch == 'g' or ch == 'h':
print('a')
elif ch == 'i' or ch == 'j' or ch == 'k' or ch == 'l' or ch == 'm' or ch == 'n' or ch == 'o':
print('a')
elif ch == 'p' or ch == 'q' or ch == 'r' or ch == 's' or ch == 't' or ch == 'u' or ch == 'v':
print('a')
elif ch == 'w' or ch == 'x' or ch == 'y' or ch == 'z':
print('a')
else:
print('A')
| 1 | 11,338,551,915,350 | null | 119 | 119 |
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
result = []
#
for bit in range(1<<n):
score = 0
#
for i in range((n)):
#
if bit & (1<<i):
score += a[i]
result.append(score)
for m_i in m:
if m_i in result:
print('yes')
else :
print('no')
| N, M, X = map(int, input().split())
book = [0] + [list(map(int, input().split())) for _ in range(N)]
ans = N * 10**5 + 1
for i in range(2**N):
read = [0] * (N+1)
rikai = [0] * (M+1)
cost = 0
for j in range(N):
read[j+1] = i%2
i //= 2
for j in range(1, N+1):
if read[j] == 1:
cost += book[j][0]
for k in range(1, M+1):
rikai[k] += book[j][k]
if min(rikai[1:]) >= X:
ans = min(ans, cost)
print(ans if ans != (N * 10**5 + 1) else -1)
| 0 | null | 11,182,611,906,970 | 25 | 149 |
a,b,c,k = map(int,input().split())
s = 0
if k <= a:
s = k
elif k <= a + b:
s = a
else:
s = a - (k - a - b)
print(s) | #ABC167
A,B,C,K=map(int,input().split())
#----------以上入力----------
if A > K:
print(K)
elif A+B >= K:
print(A)
else:
print(A-(K-A-B)) | 1 | 21,656,701,760,484 | null | 148 | 148 |
N,K=map(int,input().split())
A=sorted(map(int,input().split()))
M=10**9+7
t,b=A[K-1]-A[N-K],1
for i in range(1,N-K+1):
b=(b*(K-1+i)*pow(i,M-2,M))%M
t=(t+b*(A[K-1+i]-A[N-K-i]))%M
print(t)
| mod = pow(10,9)+7
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = A[::-1]
n= N
fac = [1]*(n+1)
inv = [1]*(n+1)
for i in range(1,n+1):
fac[i] = (fac[i-1]*i) % mod
inv[n] = pow(fac[n], mod-2, mod)
for i in range(n, 0, -1):
inv[i-1] = (inv[i]*i) % mod
def nCr(n,r):
if r < 1:
return 1
return (((fac[n] * inv[r])%mod) * inv[n-r]) % mod
counter_min=0
counter_max=0
for i in range(N-K+1): #i=0 1 2
counter_max += A[N-1-i] * nCr(N-1-i,K-1)
counter_min += B[N-1-i] * nCr(N-1-i,K-1)
print((counter_max-counter_min)%mod)
| 1 | 96,234,666,847,368 | null | 242 | 242 |
A, B, K = map(int, input().split())
Taka = max(A-K, 0)
if K <= A:
Aoki = B
else:
Aoki = max(0, B-(K-A))
print(Taka, Aoki) | A, B, K = map(int, input().split())
if A > K:
print(A-K, B)
else:
print(0, max(0, A+B-K)) | 1 | 104,443,474,780,612 | null | 249 | 249 |
n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]
mod=998244353
dp=[0]*(n+1)
csum=[0]*(n+2)
dp[0]=1
for i in range(n):
for j in range(k):
l,r=lr[j]
dp[i]+=csum[max(i+1-l,0)]-csum[max(i-r,0)]
dp[i]%=mod
csum[i+1]+=dp[i]+csum[i]
csum[i+1]%=mod
print(dp[n-1]) | H,N = map(int,input().split())
Q = []
for _ in range(N):
a,b = map(int,input().split())
Q.append((a,b))
INF = float("inf")
dp = [INF]*(H+1)
dp[0] = 0
for i in range(H+1):
for a,b in Q:
if i+a>=H:
dp[H] = min(dp[H],dp[i]+b)
else:
dp[i+a] = min(dp[i+a],dp[i]+b)
print(dp[-1]) | 0 | null | 42,163,639,259,250 | 74 | 229 |
import operator
from functools import reduce
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
positives = [a for a in A if a > 0]
negatives = [a for a in A if a < 0]
positive_cnt = len(positives)
negative_cnt = len(negatives)
zero_cnt = A.count(0)
if 2 * min(K // 2, negative_cnt // 2) + positive_cnt >= K:
ans = 1
positives.sort(key=lambda x: abs(x), reverse=True)
negatives.sort(key=lambda x: abs(x), reverse=True)
if K % 2 == 1:
ans *= positives.pop(0)
K -= 1
X = []
for pair in zip(*[iter(positives)] * 2):
X.append(reduce(operator.mul, pair, 1))
for pair in zip(*[iter(negatives)] * 2):
X.append(reduce(operator.mul, pair, 1))
X.sort(reverse=True)
ans *= reduce(lambda a, b: a * b % MOD, X[:K // 2], 1)
print(ans % MOD)
elif zero_cnt:
print(0)
else:
A.sort(key=lambda x: abs(x))
print(reduce(lambda a, b: a * b % MOD, A[:K], 1) % MOD)
| def solve():
can_positive = False
if len(P) > 0:
if k < n: can_positive = True
else: can_positive = len(M)%2 == 0
else: can_positive = k%2 == 0
if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k]
P.sort()
M.sort(reverse=True)
a = [P.pop()] if k%2 else [1]
while len(P) >= 2: a.append(P.pop() * P.pop())
while len(M) >= 2: a.append(M.pop() * M.pop())
return a[:1] + sorted(a[1:], reverse=True)[:(k-k%2)//2]
n, k = map(int, input().split())
P, M = [], []
for a in map(int, input().split()):
if a < 0: M.append(a)
else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)
| 1 | 9,443,790,807,230 | null | 112 | 112 |
score = list(map(int,input().split()))
kaisu = 1
hp = score[0]
while hp > score[1]:
kaisu += 1
hp -= score[1]
print(kaisu) | h, a = map(int, input().split())
print(__import__('math').ceil(h / a)) | 1 | 76,958,998,412,952 | null | 225 | 225 |
X = input().split()
print(X[2], X[0], X[1])
| X , Y = map(int,input().split())
a = 0
ans = "No"
for a in range(0,X+1):
if (a * 2)+((X-a) * 4)==Y:
ans = "Yes"
print(ans) | 0 | null | 25,902,584,762,880 | 178 | 127 |
def main(s):
a = 0 #r-w
b = 0 #w-r
for i in s:
if i == "R":
a += 1
ans = max(a,b) #無しもしない場合操作最大値
for i in s:
if i == "R":
a -= 1
else:
b += 1
now = max(a,b)
ans = min(ans, now)
print(ans)
if __name__ == '__main__':
n = int(input())
s = input()
main(s) | # -*- coding: utf-8 -*-
import sys
def main():
N = int( sys.stdin.readline() )
c_list = list(sys.stdin.readline().rstrip())
cnt = 0
L = 0
R = len(c_list) - 1
while L < R:
if (c_list[L] == "W") and (c_list[R] == "R"):
c_list[L], c_list[R] = c_list[R], c_list[L]
cnt += 1
L += 1
R -= 1
elif c_list[L] == "R":
L += 1
elif c_list[R] == "W":
R -= 1
print(cnt)
if __name__ == "__main__":
main()
| 1 | 6,343,975,363,922 | null | 98 | 98 |
#!/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()
| co ="coffee"
S = input()
if S[2]!=S[3]:
print("No")
elif S[4]!=S[5]:
print("No")
else:
print("Yes") | 1 | 42,323,990,379,360 | null | 184 | 184 |
def main():
N, T = (int(i) for i in input().split())
AB = [[int(i) for i in input().split()] for j in range(N)]
AB.sort()
A = [a[0] for a in AB]
B = [b[1] for b in AB]
ans = 0
dp1 = [[0]*(T+1) for _ in range(N+1)]
for i in range(N):
for j in range(T):
t = j - A[i]
if 0 <= t:
dp1[i+1][j] = max(dp1[i][j], dp1[i][t] + B[i])
else:
dp1[i+1][j] = dp1[i][j]
ans = max(ans, dp1[i][T-1] + B[i])
print(ans)
if __name__ == '__main__':
main()
| import numpy as np
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = int(1e9+7)
p = []
m = []
for a in A:
if a >= 0:
p.append(a)
else:
m.append(a)
p.sort(reverse=True)
m.sort(reverse=False)
ans = 1
if sum(np.sign(A)) == -N and K%2 == 1:
A = sorted(A, reverse=True)
for i in range(K):
ans = (ans*A[i])%mod
print(ans)
return
if N == K:
for i in range(K):
ans = (ans*A[i])%mod
print(ans)
return
m_pair = []
p_pair = []
if K%2 == 1:
ans *= p.pop(0)%mod
for i in range(0, len(m), 2):
if i+1 < len(m):
m_pair.append(m[i]*m[i+1])
# else:
# m_pair.append(m[i])
for i in range(0, len(p), 2):
if i+1 < len(p):
p_pair.append(p[i]*p[i+1])
else:
p_pair.append(p[i])
pairs = m_pair[:]
pairs.extend(p_pair)
pairs.sort(reverse=True)
for i in range(K//2):
ans = (ans*pairs[i])%mod
print(ans)
main()
| 0 | null | 80,690,199,471,842 | 282 | 112 |
n = input()
daylist = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
print(daylist[n]) | import numpy as np
def main():
n = int(input())
x = np.arange(n + 1)
x[x % 3 == 0] = 0
x[x % 5 == 0] = 0
print(x.sum())
if __name__ == '__main__':
main() | 0 | null | 84,159,760,972,800 | 270 | 173 |
# coding: utf-8
# Your code here!
import sys
n=int(input())
s=list(input())
if n%2==1:
print("No")
sys.exit()
else:
for i in range(n//2):
if s[i]==s[n//2+i]:
continue
print("No")
sys.exit()
print("Yes") | from collections import defaultdict
n, k = map(int, input().split())
m = defaultdict(int)
for _ in range(k):
input()
for x in input().split():
m[int(x)] += 1
result = 0
for i in range(1, n+1):
if m[i] == 0:
result += 1
print(result) | 0 | null | 86,026,174,209,630 | 279 | 154 |
T = str(input())
print(T.replace('?', 'D')) | 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,582,980,347,238 | null | 140 | 140 |
n,k = map(int,input().split())
w = []
for i in range(0,n):
w.append(int(input()))
def check(p):
i = 0
for j in range(0,k):
sm = 0
while sm + w[i] <= p:
sm = sm + w[i]
i = i + 1
if i == n:
return n
return i
def solve():
r = 1000000000
l = 0
while r-l > 1:
mid = int((r+l)/2)
v = check(mid)
if(v >= n):
r = mid
else:
l = mid
return r
print(solve())
| n, k = map(int,input().split())
w = [0]*n
for i in range(n):
w[i] = int(input())
minP = max(max(w), sum(w)//k)
maxP = sum(w)
left = minP
right = maxP
while left < right:
mid = (left + right) // 2
load = 0
cnt_track = 1
flag = 1
for i in range(n):
load += w[i]
if load > mid:
load = w[i]
cnt_track += 1
if cnt_track > k:
flag = 0
break
if flag:
right = mid
else:
left = mid + 1
print(left)
| 1 | 85,243,325,692 | null | 24 | 24 |
n = int(input())
tmp = input().split(' ')
tmp_map = map(int,tmp)
prices = list(tmp_map)
money = 1000
for i in range(n-1):
if prices[i] < prices[i+1]:
stocks = int(money/prices[i])
money += stocks*(prices[i+1]-prices[i])
print(money) | a=[input() for i in range(2)]
a1=int(a[0])
a2=[int(i) for i in a[1].split()]
money=1000
kabu=0
for i in range(a1-1):
if a2[i]<a2[i+1]:
kabu=int(money/a2[i])
money+=kabu*(a2[i+1]-a2[i])
print(money) | 1 | 7,328,839,786,308 | null | 103 | 103 |
N,K = map(int,input().split())
n_lis = [0]*N
for i in range(K):
d = int(input())
*A, = map(int,input().split())
for j in range(d):
a = A[j]
n_lis[a-1] = 1
print(n_lis.count(0)) | from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
def dict(a):
d={}
for x in a:
if d.get(x,-1)!=-1:
d[x]+=1
else:
d[x]=1
return d
def find_gt(a, x):
'Find leftmost value greater than x'
i = bi.bisect_right(a, x)
if i != len(a):
return i
else:
return -1
def main():
try:
n=I()
if n<=599:print(8)
elif n<=799:print(7)
elif n<=999:print(6)
elif n<=1199:print(5)
elif n<=1399:print(4)
elif n<=1599:print(3)
elif n<=1799:print(2)
elif n<=1999:print(1)
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
#for _ in range(I()):main()
for _ in range(1):main()
| 0 | null | 15,681,192,853,060 | 154 | 100 |
import math
N, D= list(map(int,input().split()))
cnt = 0
for i in range(N):
x, y = list(map(int, input().split()))
#print(math.sqrt((x^2)+(y^2)))
if math.sqrt((x*x)+(y*y)) <= D:
cnt+=1
print(cnt) | import sys
input = sys.stdin.readline
import numpy as np
N, M = map(int, input().split())
L = list(map(int, input().split()))
A = np.zeros(1<<18)
for i in L:
A[i] += 1
C = (np.fft.irfft(np.fft.rfft(A) * np.fft.rfft(A)) + .5).astype(np.int64)
G = C.cumsum()
count = np.searchsorted(G, N*N-M)
rest = N*N-M - G[count-1]
temp = (C[:count]*np.arange(count, dtype=np.int64)).sum() + count*rest
ans = sum(L)*2*N - temp
print(ans) | 0 | null | 56,684,917,334,692 | 96 | 252 |
import sys
import numpy as np
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def solve():
N = int(input())
edge = [[] for _ in range(N)]
ab = [tuple() for _ in range(N - 1)]
for i in range(N - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
edge[a].append(b)
edge[b].append(a)
ab[i] = (a, b)
# print(ab)
# print(edge)
max_v = 0
max_v_dim = 0
for i, e in enumerate(edge):
if max_v_dim < len(e):
max_v_dim = len(e)
max_v = i
# print(max_v)
# print(max_v_dim)
# bfs
q = deque()
q.append(max_v)
ec = np.full(N, -1, dtype='i8')
ec[max_v] = max_v_dim + 10
vc = dict()
# vc = np.full((N, N), -1, dtype='i8')
while q:
nv = q.popleft()
nc = ec[nv]
tc = 1
for v in edge[nv]:
v1, v2 = min(nv, v), max(nv, v)
if not ((v1, v2) in vc):
if nc == tc:
tc += 1
ec[v] = tc
vc[(v1, v2)] = tc
tc += 1
q.append(v)
print(max_v_dim)
for v1, v2 in ab:
print(vc[(v1, v2)])
if __name__ == '__main__':
solve()
| import math
h1, m1, h2, m2, k = map(int, input().split(" "))
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2
print(t2 - t1 - k) | 0 | null | 76,942,484,288,060 | 272 | 139 |
def main():
N, M = map(int, input().split())
if N & 1:
gen = ((i+1, N-i) for i in range(M))
else:
gen = ((i+1, N-i) if 2*i < N/2-1 else (i+1, N-i-1) for i in range(M))
[print(*s) for s in gen]
if __name__ == "__main__":
main()
| D, T, S = map(int, input().split())
print("Yes" if D <= (T*S) else 'No') | 0 | null | 16,108,896,954,388 | 162 | 81 |
n=int(input())
count=0
countmax=0
for i in range(n):
a,b = map(int,input().split())
if a==b:
count+=1
else:
countmax=max(countmax,count)
count=0
countmax=max(countmax,count)
if countmax>2:
print("Yes")
else:
print("No")
| x = 0
y = 0
z = 0
for i in range(9):
x += 1
y = 0
for j in range(9):
y += 1
z = x*y
print(x, end = 'x')
print(y, end = '=')
print(z) | 0 | null | 1,234,341,182,620 | 72 | 1 |
from sys import stdin
a, b = [int(x) for x in stdin.readline().rstrip().split()]
print(a*b, 2*(a+b))
| def rectangle(a, b):
S = a * b
L = a*2 + b*2
print(S, L)
a, b =[int(x) for x in input().split()]
rectangle(a, b) | 1 | 308,542,796,702 | null | 36 | 36 |
import math
a,b,h,m=map(int, input().split())
a_x=math.cos(abs(math.radians(6*m)-math.radians(30*h+0.5*m)))
print((a**2+b**2-2*a*b*a_x)**0.5)
| import sys
n = int(input())
for i in range(n):
ns = [x * x for x in map(int, input().split())]
if ns[0] + ns[1] == ns[2] or ns[0] + ns[2] == ns[1] or ns[1] + ns[2] == ns[0]:
print("YES")
else:
print("NO") | 0 | null | 10,019,184,684,398 | 144 | 4 |
K = int(input())
A, B = map(int,input().split())
C = A % K
if B - A >= K - 1:
print('OK')
elif C == 0:
print('OK')
elif C + B - A >= K:
print('OK')
else:
print('NG') | N, K = [int(v) for v in input().split()]
P = [int(v) for v in input().split()]
print(sum(sorted(P)[:K])) | 0 | null | 19,158,057,828,526 | 158 | 120 |
import copy
a = [int(c) for c in input().split()]
K = a[0]
N = a[1]
A = [int(c) for c in input().split()]
B = list(map(lambda x: x+K,copy.deepcopy(A)))
A = A+B
l = 0
tmp = 0
cnt = 0
for i in range(N):
tmp = A[i+1]-A[i]
if tmp > l :
cnt = i
l = tmp
print(K-l)
| def resolve():
a = int(input())
print(a+a*a+a*a*a)
if '__main__' == __name__:
resolve() | 0 | null | 26,952,731,501,142 | 186 | 115 |
a,b,c,d,e=map(int,input().split())
if a == 0:
print('1')
elif b== 0:
print('2')
elif c == 0:
print('3')
elif d==0:
print('4')
elif e == 0:
print('5') | s = input()
print("YNeos"[s[2:5:2] != s[3:6:2]::2]) | 0 | null | 27,667,143,555,742 | 126 | 184 |
H,W,K = list(map(int, input().split()))
table = [input() for _ in range(H)]
ans = 0
for mask_h in range(2 ** H):
for mask_w in range(2 ** W):
black = 0
for i in range(H):
for j in range(W):
if ((mask_h >> i) & 1 == 0) and ((mask_w >> j) & 1 == 0) and table[i][j] == '#': # 塗り潰し行、列ではなくて、色が黒'#'の場合
black += 1
if black == K:
ans += 1
print(str(ans)) | MOD = 10**9 + 7
def modpow(a: int, p: int, mod: int) -> int:
# return a**p (mod MOD) O(log p)
res = 1
while p > 0:
if p & 1 > 0:
res = res * a % mod
a = a**2 % mod
p >>= 1
return res
def comb(N, x):
numerator = 1
for i in range(N-x+1, N+1):
numerator = numerator * i % MOD
denominator = 1
for j in range(1, x+1):
denominator = denominator * j % MOD
d = modpow(denominator, MOD-2, MOD)
return numerator * d
n,a,b=map(int,input().split())
ans = (modpow(2,n,MOD)-1 - comb(n,a) - comb(n,b)) % MOD
print(ans) | 0 | null | 37,326,388,958,296 | 110 | 214 |
a, b = map(int, input().split())
answer = (a * b)
print(answer)
| x,y = list(map(int,input().split()))
print(x*y) | 1 | 15,711,401,126,236 | null | 133 | 133 |
import sys
input = sys.stdin.readline
def main():
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
d = v - w
if abs(a-b) <= t * d:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| A = list(map(int,input().split()))
B = list(map(int,input().split()))
T = int(input())
distance = abs(A[0] - B[0])
A[1] = A[1] * T
B[1] = B[1] * T
if distance <= (A[1] - B[1]):
print('YES')
else:
print('NO') | 1 | 15,167,707,700,742 | null | 131 | 131 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect_right
n = int(input())
s = list(input())
q = int(input())
al = 'abcdefghijklmnopqrstuvwxyz'
dicq = {i:[] for i in al}
for i, si in enumerate(s):
dicq[si].append(i)
def q1(iq, cq):
#print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq)) #更新前から削除
s[iq] = cq
dicq[cq].insert(bisect_left(dicq[cq], iq), iq) #更新後に追加
def q2(l, r):
ret = 0
for ai in al:
if len(dicq[ai])==0: continue
li = bisect_left(dicq[ai], l)
ri = bisect_right(dicq[ai], r)
if li != ri:
ret += 1
elif li == len(dicq[ai]): continue
elif dicq[ai][li] == l:
ret += 1
# print(l,r,ai,dicq[ai],li,ri,ret)
print(ret)
for i in range(q):
fg, x, y = input().split()
if fg == '1':
q1(int(x)-1, y)
else:
q2(int(x)-1, int(y)-1)
| # coding:utf-8
i = raw_input()
print i.swapcase()
| 0 | null | 32,183,186,456,678 | 210 | 61 |
n=int(input())
arr=list(map(int,input().split()))
ans=sum(arr)
if n==0:
if arr[0]==1:
print(1)
else:
print(-1)
exit()
for i in range(n):
if i<=30 and arr[i]>=2**i:
print(-1)
exit()
if n<=30 and arr[n]>2**n:
print(-1)
exit()
maxs=[0]*(n+1)
maxs[0]=1
for i in range(1,n):
maxs[i]=2*maxs[i-1]-arr[i]
tmp=arr[n]
for i in range(n-1,-1,-1):
maxs[i]=min(maxs[i],tmp)
tmp+=arr[i]
mins=[0]*(n+1)
for i in range(n-1,-1,-1):
mins[i]=(mins[i+1]+arr[i+1]+1)//2
for i in range(n):
if maxs[i]<mins[i]:
print(-1)
exit()
ans+=sum(maxs)
print(ans) | import sys
import numpy as np
from numba import njit
@njit('(i8[:],)', cache=True)
def solve(inp):
def bitree_sum(bit, t, i):
s = 0
while i > 0:
s += bit[t, i]
i ^= i & -i
return s
def bitree_add(bit, n, t, i, x):
while i <= n:
bit[t, i] += x
i += i & -i
def bitree_lower_bound(bit, n, d, t, x):
sum_ = 0
pos = 0
for i in range(d, -1, -1):
k = pos + (1 << i)
if k <= n and sum_ + bit[t, k] < x:
sum_ += bit[t, k]
pos += 1 << i
return pos + 1
def initial_score(d, ccc, sss):
bit_n = d + 3
bit = np.zeros((26, bit_n), dtype=np.int64)
INF = 10 ** 18
for t in range(26):
bitree_add(bit, bit_n, t, bit_n - 1, INF)
ttt = np.zeros(d, dtype=np.int64)
last = np.full(26, -1, dtype=np.int64)
score = 0
for i in range(d):
best_t = 0
best_diff = -INF
costs = ccc * (i - last)
costs_sum = costs.sum()
for t in range(26):
tmp_diff = sss[i, t] - costs_sum + costs[t]
if best_diff < tmp_diff:
best_t = t
best_diff = tmp_diff
ttt[i] = best_t
last[best_t] = i
score += best_diff
bitree_add(bit, bit_n, best_t, i + 2, 1)
return bit, score, ttt
def calculate_score(d, ccc, sss, ttt):
last = np.full(26, -1, dtype=np.int64)
score = 0
for i in range(d):
t = ttt[i]
last[t] = i
score += sss[i, t] - (ccc * (i - last)).sum()
return score
def pinpoint_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible):
cd = np.random.randint(0, d)
ct = np.random.randint(0, 26)
while ttt[cd] == ct:
ct = np.random.randint(0, 26)
diff = 0
t = ttt[cd]
k = bitree_sum(bit, t, cd + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2
b = ccc[t]
diff -= b * (cd - c) * (e - cd)
diff -= sss[cd, t]
k = bitree_sum(bit, ct, cd + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, ct, k) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, ct, k + 1) - 2
b = ccc[ct]
diff += b * (cd - c) * (e - cd)
diff += sss[cd, ct]
if diff > permissible:
bitree_add(bit, bit_n, t, cd + 2, -1)
bitree_add(bit, bit_n, ct, cd + 2, 1)
ttt[cd] = ct
else:
diff = 0
return diff
def swap_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible):
cd1 = np.random.randint(0, d - 1)
cd2 = cd1 + 1
ct1 = ttt[cd1]
ct2 = ttt[cd2]
if ct1 == ct2:
return 0
diff = 0
k = bitree_sum(bit, ct1, cd1 + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, ct1, k - 1) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, ct1, k + 1) - 2
diff += ccc[ct1] * (e + c - cd1 - cd2)
k = bitree_sum(bit, ct2, cd2 + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, ct2, k - 1) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, ct2, k + 1) - 2
diff -= ccc[ct2] * (e + c - cd1 - cd2)
diff -= sss[cd1, ct1] + sss[cd2, ct2]
diff += sss[cd1, ct2] + sss[cd2, ct1]
if diff > permissible:
bitree_add(bit, bit_n, ct1, cd1 + 2, -1)
bitree_add(bit, bit_n, ct1, cd2 + 2, 1)
bitree_add(bit, bit_n, ct2, cd1 + 2, 1)
bitree_add(bit, bit_n, ct2, cd2 + 2, -1)
ttt[cd1] = ct2
ttt[cd2] = ct1
else:
diff = 0
return diff
d = inp[0]
ccc = inp[1:27]
sss = np.zeros((d, 26), dtype=np.int64)
for r in range(d):
sss[r] = inp[27 + r * 26:27 + (r + 1) * 26]
bit, score, ttt = initial_score(d, ccc, sss)
bit_n = d + 3
bit_d = int(np.log2(bit_n))
loop = 4 * 10 ** 6
permissible_min = -3000.0
method_border = 0.5
best_score = score
best_ttt = ttt.copy()
for lp in range(loop):
permissible = (1 - lp / loop) * permissible_min
if np.random.random() < method_border:
diff = pinpoint_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible)
else:
diff = swap_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible)
score += diff
# print(lp, score, calculate_score(d, ccc, sss, ttt))
if score > best_score:
best_score = score
best_ttt = ttt.copy()
return best_ttt + 1
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))
| 0 | null | 14,324,998,117,668 | 141 | 113 |
while True:
h, w = map(int, raw_input().split())
if h == 0 and w == 0:
break
print(("#" * w + "\n") + ("#" + "." * (w-2) + "#" + "\n") * (h-2) + ("#" * w + "\n")) | def mergeSort(num_list, left, right):
if left + 1 < right:
mid = (left + right) / 2
mergeSort(num_list, left, mid)
mergeSort(num_list, mid, right)
merge(num_list, left, mid, right)
def merge(num_list, left, mid, right):
global count
L = list(num_list[left:mid])
L.append(float("inf"))
R = list(num_list[mid:right])
R.append(float("inf"))
i, j = 0, 0
for k in range(left, right):
if L[i] <= R[j]:
num_list[k] = L[i]
i += 1
count += 1
else:
num_list[k] = R[j]
j += 1
count += 1
count = 0
n = int(raw_input())
a = raw_input()
l = []
l = a.split(" ")
for i in range(len(l)):
l[i] = int(l[i])
mergeSort(l, 0, n)
print " ".join(map(str, l))
print count | 0 | null | 472,571,095,998 | 50 | 26 |
while True:
n, x = map(int, input().split())
if n == 0 and x == 0:
break
c = 0
for i in range(1, int(x/3)+2):
for j in range(i+1, int(x/2)+2):
k = x - i - j
if k <= j:
break
elif k <= n:
c += 1
print(c) | import itertools
while True:
n, x = map(int, input().split())
if n == x == 0:
break
i = 0
l = range(1, n+1)
for elem in itertools.combinations(l, 3):
if sum(elem) == x:
i += 1
print(str(i)) | 1 | 1,292,413,028,440 | null | 58 | 58 |
s = input()
t = input()
ans = 0
for i in range(len(s)-len(t)+1):
tm = 0
for j in range(len(t)):
if s[i+j] == t[j]:
tm += 1
ans = max(tm,ans)
print(len(t)-ans) | import itertools
n, x, y = map(int, input().split())
k = [0] * n
for v in itertools.combinations(list(range(1,n+1)), 2):
k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1
for item in k[1:]:
print(item) | 0 | null | 24,010,113,925,666 | 82 | 187 |
s=input()
l=len(s)
x=0
for i in range(l):
x=x+int(s[i])
if x%9==0:
print("Yes")
else:
print("No") |
import numpy as np
def main():
k,x = map(int, input().split())
if k*500 >= x:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 51,008,006,023,520 | 87 | 244 |
n, k = [int(x) for x in input().split()]
a_list = [int(x) - 1 for x in input().split()]
ci = 0
while k:
if k & 1:
ci = a_list[ci]
k >>= 1
a_list = [a_list[a_list[i]] for i in range(n)]
print(ci + 1) | n, k = map(int, input().split())
a = list(map(int, input().split()))
d = [[-1] * n for _ in range(70)]
for i in range(n):
d[0][i] = a[i] - 1
for i in range(1, 70):
for j in range(n):
d[i][j] = d[i - 1][d[i - 1][j]]
dst = 0
while k:
i = 70
while pow(2, i) & k <= 0:
i -= 1
dst = d[i][dst]
k -= pow(2, i)
print(dst + 1)
| 1 | 22,710,094,668,260 | null | 150 | 150 |
from collections import Counter
S = input()
N = len(S)
mod = [0] * (N+1)
now = 0
for i in range(N):
now += int(S[N-1-i]) * pow(10,i,2019) % 2019
now %= 2019
mod[N-i-1] = now
ans = 0
for l in Counter(mod).values():
ans += l * (l-1) // 2
print(ans) | s = input()
t = s[::-1]
n = len(s)
resid = [0] * 2019
resid[0] = 1
csum = 0
powoften = 1
for i in range(n):
csum = (csum + int(t[i]) * powoften) % 2019
powoften = (10 * powoften) % 2019
resid[csum] += 1
ans = 0
for i in range(2019):
ans += resid[i] * (resid[i] - 1) // 2
print(ans) | 1 | 30,817,158,809,120 | null | 166 | 166 |
s=input()
sr=s[::-1]
cntl=0
cntr=0
ll=[0]
rl=[0]
for i in range(len(s)):
if s[i]=="<":
cntl+=1
else:
cntl=0
if sr[i]==">":
cntr+=1
else:
cntr=0
ll.append(cntl)
rl.append(cntr)
rrl=rl[::-1]
ans=[]
for i in range(len(s)+1):
ans.append(max(rrl[i],ll[i]))
print(sum(ans)) | S = input()
N = len(S)+1
x = [0 for _ in range(N)]
l = 0
while(l<N-1):
r = l+1
while(r<N-1 and S[r]==S[l]):
r += 1
if S[l]=='<':
x[l] = 0
for i in range(l+1, r+1):
x[i] = max(x[i], x[i-1]+1)
else:
x[r] = 0
for i in range(r-1, l-1, -1):
x[i] = max(x[i], x[i+1]+1)
l = r
print(sum(x)) | 1 | 156,910,083,992,812 | null | 285 | 285 |
s = [i for i in input()]
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
| s=str(input())
j="No"
if s[2]==s[3] and s[4]==s[5]:
j="Yes"
print(j)
| 1 | 42,111,243,044,490 | null | 184 | 184 |
import sys
import math
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
N = ni()
AB_array = [na() for _ in range(N)]
# print(AB_array)
plus_dic = {}
minus_dic = {}
ans = 1
fish_count = 0
mod = 10 ** 9 + 7
zero_count = 0
for ab in AB_array:
a, b = ab
if a == 0 and b == 0:
zero_count += 1
continue
fish_count += 1
if a == 0:
vec = (0, 1)
if vec in plus_dic:
plus_dic[vec] += 1
else:
plus_dic[vec] = 1
continue
elif b == 0:
vec = (1, 0)
if vec in minus_dic:
minus_dic[vec] += 1
else:
minus_dic[vec] = 1
continue
c = math.gcd(a, b)
a = a // c
b = b // c
if a < 0:
a *= -1
b *= -1
if b > 0:
vec = (a, b)
if vec in plus_dic:
plus_dic[vec] += 1
else:
plus_dic[vec] = 1
else:
vec = (a, b)
if vec in minus_dic:
minus_dic[vec] += 1
else:
minus_dic[vec] = 1
# print(plus_dic, minus_dic, fish_count)
for k, vp in plus_dic.items():
x, y = k
if (y, -x) in minus_dic:
vm = minus_dic[(y, -x)]
ans = ans * (pow(2, vp, mod) + pow(2, vm, mod) - 1) % mod
fish_count -= (vp + vm)
ans = ans * pow(2, fish_count, mod) % mod
print((ans - 1 + zero_count) % mod)
| from math import gcd
MOD = 10**9+7
n = int(input())
d = {}
zero = 0
for i in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero += 1
continue
flip = 0
while not (a >= 0 and b > 0):
a, b = -b, a
flip ^= 1
g = gcd(a, b)
a //= g
b //= g
if not (a, b) in d:
d[(a, b)] = [0, 0]
d[(a, b)][flip] += 1
ans = 1
for (v1, v2) in d.values():
ans *= pow(2, v1, MOD) + pow(2, v2, MOD) - 1 # -1 is because need to remove the case that choose nothing
ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)
| 1 | 21,033,093,823,026 | null | 146 | 146 |
num = int(input())
answer = num + num * num + num * num * num
print(answer) | n=int(input())
res=0
for i in range(1,n+1):
if int(i*1.08)==n:
res=i
if res != 0:
print(res)
else:
print(":(") | 0 | null | 68,273,427,921,310 | 115 | 265 |
import itertools
N = int(input())
L = list(map(int,(input().split())))
L.sort()
Combi = itertools.combinations(L, 3)
count = 0
for i, j, k in Combi:
if((i+j)> k and i!=j!=k and i<j <k ):
count+=1
print(count) | from itertools import combinations
n = int(input())
L = list(map(int,input().split()))
ans = 0
for a,b,c in combinations(L,3):
ans += (2*max(a,b,c) < a+b+c)*(a != b and b != c and c != a)
print(ans) | 1 | 5,076,013,566,298 | null | 91 | 91 |
import math
a,b,c=map(int,input().split())
C=(c/180)*math.pi
S=(a*b*math.sin(C))/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C))**0.5
h=b*math.sin(C)
print("%.5f\n%.5f\n%.5f\n"%(S,L,h)) | import math
a,b,c=map(float,input().split())
h=b*math.sin(c/180.0*math.pi)
ad=a-b*math.cos(c/180.0*math.pi)
d=(h*h+ad*ad)**0.5
l = a + b + d
s = a * h / 2.0
print('{0:.6f}'.format(s))
print('{0:.6f}'.format(l))
print('{0:.6f}'.format(h)) | 1 | 171,713,702,442 | null | 30 | 30 |
n = int(input())
a = list(map(int, input().split()))
a.sort()
def main(a):
if 0 in a:
ans = 0
else:
ans = 1
for item in a:
ans *= item
if ans > 1000000000000000000:
ans = -1
break
return ans
ans = main(a)
print(ans)
| from sys import exit
n = int(input())
num_list = [int(i) for i in input().split()]
if 0 in num_list:
print(0)
exit()
ans = 1
for i in range(n):
ans *= num_list[i]
if ans > 10**18:
print(-1)
exit()
print(ans) | 1 | 16,124,037,959,890 | null | 134 | 134 |
x, n = map(int, input().split())
if n == 0:
print(x)
else:
a = [int(x) for x in input().split()]
ans1 = x
while ans1 in a :
ans1 -= 1
ans2 = x
while ans2 in a :
ans2 += 1
if abs(x - ans1) <= abs(x - ans2):
print(ans1)
else:
print(ans2)
| # Forbidden List
X, N = [int(i) for i in input().split()]
pi = [int(i) for i in input().split()]
pl = []
pu = []
for i in pi:
if i <= X:
pl.append(i)
if X <= X:
pu.append(i)
pl.sort(reverse=True)
pu.sort()
nl = X
for i in pl:
if i == nl:
nl -= 1
nu = X
for i in pu:
if i == nu:
nu += 1
if X - nl <= nu - X:
print(nl)
else:
print(nu)
| 1 | 14,085,120,692,992 | null | 128 | 128 |
A, B, C = map(int, input().split())
l = [A, B, C]
if len(set(l)) == 2:
print("Yes")
else:
print("No")
| n = input()
(p,q) = n.split()
print(q+p) | 0 | null | 85,545,485,293,808 | 216 | 248 |
S = input()
h = S // 3600
m = S % 3600 //60
s = S % 3600 % 60
print str(h) + ':' + str(m) + ':' + str(s) | n=input()
print':'.join(map(str,[n/3600,n%3600/60,n%60])) | 1 | 322,623,180,600 | null | 37 | 37 |
A,B = map(int, input().split())
for X in range(1,1001):
if (X*108//100-X)==A and (X*110//100-X)==B:
print(X)
exit()
print(-1) | import math
A, B = map(int, input().split())
answer = -1
for x in range(10000):
if math.floor(x * 0.08) == A and math.floor(x * 0.10) == B:
answer = x
break
print(answer) | 1 | 56,815,051,115,950 | null | 203 | 203 |
H1,M1,H2,M2,K = map(int,input().split())
A1 = H1*60+M1
A2 = H2*60+M2
print(max(0,A2-A1-K)) | h, m, h2, m2, k = map(int, input().split())
ans = (h2 * 60 + m2) - (h * 60 + m) - k
print(ans) | 1 | 18,077,682,767,400 | null | 139 | 139 |
N = list(map(int,input().split()))
print(N[0]*N[1]) | n,p=map(int,input().split())
s=input()
ans=0
if p==2 or p==5:
for i in range(n):
if int(s[i])%p==0:
ans+=i+1
else:
M=[0]*p
M[0]=1
tmp=0
for i in range(n):
tmp+=(int(s[-i-1])*pow(10,i,p))
tmp%=p
ans+=M[tmp]
M[tmp]+=1
print(ans) | 0 | null | 37,205,394,223,138 | 133 | 205 |
a,b=map(int,input().split())
def gcd(a,b):
while b:a,b=b,a%b
return a
def lcm(a,b):return a*b//gcd(a,b)
print(lcm(a,b)) | import numpy as np
a, b = map(int, input().split())
ans = np.lcm(a, b)
print(ans) | 1 | 113,246,930,611,200 | null | 256 | 256 |
k,x = [int(i) for i in input().split()]
ans=''
if k*500 >= x: ans = 'Yes'
else: ans='No'
print(ans)
| K,N = (int(x) for x in input().split())
if 500 *K >= N:
print('Yes')
else:
print('No') | 1 | 98,293,411,115,962 | null | 244 | 244 |
n=int(input())
A=tuple(map(int, input().split()))
cnt=0
def merge_sort(A,cnt):
m=len(A)
if m == 1:
return A,cnt
else:
mid=(m+1)//2
A1=tuple(A[:mid])
A2=tuple(A[mid:])
A1,cnt=merge_sort(A1,cnt)
A2,cnt=merge_sort(A2,cnt)
n1=len(A1)
n2=len(A2)
i1=0
i2=0
ans=[0]*(n1+n2)
j=0
while j < n1+n2:
if i1 == n1:
ans[j]=A2[i2]
i2+=1
cnt+=1
elif i2 == n2:
ans[j]=A1[i1]
i1+=1
cnt+=1
elif A1[i1] < A2[i2]:
ans[j]=A1[i1]
i1+=1
cnt+=1
else:
ans[j]=A2[i2]
i2+=1
cnt+=1
j += 1
return ans,cnt
sorted_A,cnt=merge_sort(A,0)
print(*sorted_A)
print(cnt)
| s = input()
p = input()
p_len = len(p)
if p in s:
print("Yes")
else:
for i in range(p_len):
if (p[:i] == s[-i:]) and (p[i:] == s[:p_len - i]):
print("Yes")
break
else:
print("No") | 0 | null | 911,190,960,510 | 26 | 64 |
def solve(L):
print((L / 3) ** 3)
if __name__ == '__main__':
L = int(input())
solve(L)
| #!/usr/bin/env python3
n = int(input())
n /= 3
print(n**3) | 1 | 47,220,680,085,920 | null | 191 | 191 |
#!/usr/bin/env python3
import sys
def solve(N: int, M: int, S: str):
# dp = [float('inf')]*(N+1)
# dp[N] = 0
# count = 1
# for i in range(N,-1,-1):
# if S[i] == "1":
# continue
# for j in range()
S = S[::-1]
cur_index = 0
answer = []
while True:
for i in range(M,0,-1):
if cur_index+i >= N:
answer.append(N-cur_index)
answer.reverse()
print(*answer)
return
if S[cur_index+i] == "1":
continue
else:
cur_index += i
answer.append(i)
break
else:
print(-1)
return
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
S = next(tokens)
solve(N, M, S)
if __name__ == '__main__':
main()
| n,a,b,=map(int,input().split())
c = n//(a+b)
da = n-c*(a+b)
if da>a:
da=a
print(c*a+da) | 0 | null | 97,636,952,464,772 | 274 | 202 |
import math
a, b, n = list(map(int, input().split()))
x = min(n, b - 1)
ans = math.floor((a * x) / b) - a * math.floor(x / b)
print(ans)
| a,b=map(int,input().split(' '))
count=0
if (a<=9 and a>=1) and (b<=9 and b>=1) :
print(a*b)
else:
print("-1")
| 0 | null | 92,785,356,625,412 | 161 | 286 |
s = input()
l = 0
r = len(s)-1
c = 0
while l <= r:
if s[l] != s[r]:
c += 1
l += 1
r -=1
print(c) | cnt = 1
def dep(G,s_cnt,f_cnt,np):
global cnt
s_cnt[np] = cnt
cnt += 1
for i in range(n):
if G[np][i] == 1 and s_cnt[i] == 0:
dep(G,s_cnt,f_cnt,i)
f_cnt[np] = cnt
cnt += 1
n = int(input())
G = [[0 for i in range(n)] for j in range(n)]
s_cnt = [0 for i in range(n)]
f_cnt = [0 for i in range(n)]
for i in range(n):
S = list(map(int, input().split()))
tmp_n = S[1]
for j in range(tmp_n):
G[i][S[j+2]-1] = 1
for i in range(n):
if s_cnt[i]==0:
dep(G,s_cnt,f_cnt,i)
for i in range(n):
print(i+1,s_cnt[i],f_cnt[i])
| 0 | null | 59,842,143,123,476 | 261 | 8 |
def solve(n):
su = 0
for i in range(1, n+1):
m = n//i
su += m*(2*i + (m-1)*i)//2
return su
n = int(input())
print(solve(n)) | import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
# 高速素因数分解(√n)
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
lcd = dict()
for i in num:
j = dict(factorization(i))
for x,y in j.items():
if not x in lcd.keys():
lcd[x] = y
else:
lcd[x] = max(lcd[x],y)
lc = 1
for i,j in lcd.items():
lc *= pow(i,j,mod)
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
ans =0
for i in range(n):
ans += lc*modinv(num[i],mod)
ans %= mod
print(ans) | 0 | null | 49,573,347,950,642 | 118 | 235 |
a = int(input())
b = input()
print(b.count('ABC')) | N = int(input())
ans = 0
for i in range(1, N + 1):
# 初項
a0 = i
# 公差
d = i
# 項数
n = N // i
temp = int(0.5 * n * (2 * a0 + (n - 1) * d))
ans += temp
print(ans)
| 0 | null | 55,125,986,222,432 | 245 | 118 |
X,K,D = map(int, input().split())
X = abs(X)
if X//D > K:
print(X-(D*K))
exit()
if (K-X//D)%2:
print(D-X%D)
else:
print(X%D) | N,K = map(int,input().split())
l = []
mod = 998244353
for i in range(K):
L,R = map(int,input().split())
l.append([L,R])
l.sort()
a = [0 for i in range(N+1)]
a[1] = 1
b = [0 for i in range(N+1)]
b[1] = 1
for i in range(2,N+1):
for j in range(K):
if l[j][0] < i:
a[i] += (b[i-l[j][0]]-b[max(0,i-l[j][1]-1)])%mod
else:
break
b[i] = (b[i-1]+a[i])%mod
mod = 998244353
print(a[N]%mod) | 0 | null | 3,908,713,967,720 | 92 | 74 |
from itertools import combinations_with_replacement as C
N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
a[i], b[i], c[i], d[i] = map(int, input().split())
A_ = list(range(1, M + 1))
A_ = list(C(A_, N))
ans = 0
ans_ = 0
for A in A_:
ans_ = 0
for i in range(Q):
if A[b[i] - 1] - A[a[i] - 1] == c[i]:
ans_ += d[i]
if ans < ans_:
ans = ans_
print(ans) | import sys
from sys import stdin
input = stdin.readline
n = int(input())
A =[int(x) for x in input().split()]
q = int(input())
M =[int(x) for x in input().split()]
dp = [[-1 for i in range(2001)] for j in range(21)]
def solve(i,m):
if dp[i][m] != -1:
return dp[i][m]
if m == 0:
dp[i][m] = True
elif i >= n:
dp[i][m] = False
elif solve(i+1,m):
dp[i][m] = True
elif solve (i+1, m-A[i]):
dp[i][m] = True
else:
dp[i][m] = False
return dp[i][m]
for m in M:
if solve(0,m):
print("yes")
else:
print("no")
| 0 | null | 13,755,984,862,790 | 160 | 25 |
S = input()
T = 'R' if S[1] == 'B' else 'B'
print(S[0]+T+S[2]) | S = input()
print("ABC" if S[1] == "R" else "ARC" )
| 1 | 24,177,250,034,198 | null | 153 | 153 |
X, Y, Z = map(int, input().split())
print(Z)
print(X)
print(Y) | X, Y, Z = list(map(str, input().split()))
print(Z + " " + X + " " + Y)
| 1 | 38,043,152,276,256 | null | 178 | 178 |
n, m, l = map(int, input().split())
A, B = [], []
C = [[0 for _ in range(l)] for _ in range(n)]
for _ in range(n):
A.append([int(x) for x in input().split()])
for _ in range(m):
B.append([int(x) for x in input().split()])
for i in range(n):
for j in range(l):
C[i][j] = 0
for x in range(m):
C[i][j] += A[i][x] * B[x][j]
for i in C:
print(*i) | from collections import deque
s = list(input())
queue = deque(s)
q = int(input())
rev_count = 0
for i in range(q):
query = list(input().split(" "))
if len(query) == 1:
rev_count += 1
else:
if query[1] == "1":
if rev_count % 2==0:
queue.appendleft(query[2])
else:
queue.append(query[2])
else:
if rev_count % 2==0:
queue.append(query[2])
else:
queue.appendleft(query[2])
queue = "".join(list(queue))
if rev_count % 2 == 0:
print(queue)
else:
print(queue[::-1])
| 0 | null | 29,372,342,586,352 | 60 | 204 |
s = input()
s = s.replace('hi', "")
if len(s) > 0:
print('No')
else:
print('Yes') | s = input()
hitachi = ""
for i in range(5):
hitachi += "hi"
if s==hitachi:
print("Yes")
exit(0)
print("No")
| 1 | 52,991,235,264,328 | null | 199 | 199 |
import sys
input=lambda :sys.stdin.readline().rstrip()
mod = 10**9+7
n, k = map(int, input().split())
d = [0] * (k+1)
for i in range(1, k+1):
d[i] = pow(k//i, n, mod)
for i in range(k, 0, -1):
for j in range(2*i, k+1, i):
d[i] -= d[j]
d[i] %= mod
ans=0
for i in range(1, k+1):
ans += d[i]*i
ans %= mod
print(ans) | n=int(input())
if n:
n-=1
else:
n+=1
print(n) | 0 | null | 19,847,506,674,788 | 176 | 76 |
L,R,d = map(int,input().split())
A = 0
for _ in range(L,R+1):
if _ %d == 0:
A += 1
print(A) | a = list(map(int, input().rstrip().split()))
resto=a[0]%a[-1]
if resto >0:
o = a[0]+a[-1]- resto
else:
o= a[0]
print((a[1]-o)//a[-1]+1)
| 1 | 7,502,113,572,800 | null | 104 | 104 |
n = int(input())
a = n // 100
b = n % 100
check = a > 20 or b / 5 <= a
print("1" if check else "0") | def resolve():
X = int(input())
dp = [0 for _ in range(X + 110)]
dp[0] = 1
for i in range(X + 1):
if dp[i] == 0:
continue
dp[i + 100] = 1
dp[i + 101] = 1
dp[i + 102] = 1
dp[i + 103] = 1
dp[i + 104] = 1
dp[i + 105] = 1
print(dp[X])
resolve()
| 1 | 127,090,394,457,290 | null | 266 | 266 |
N = int(input())
print('ACL' * N) | #-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
def main():
string=""
n = int(input())
for i in range(n):
string+="ACL"
print(string)
if __name__=="__main__":
main() | 1 | 2,210,429,027,716 | null | 69 | 69 |
n,m,q = map(int,input().split())
A = [0]*q
B = [0]*q
C = [0]*q
D = [0]*q
for i in range(q):
a,b,c,d = map(int,input().split())
A[i] = a
B[i] = b
C[i] = c
D[i] = d
walist = []
for i in range(2**(n+m-1)):
if bin(i).count("1") == n:
wa = 0
seq = []
value = 1
for j in range(n+m-1):
if (i>>j)&1 == 1:
seq += [value]
else:
value += 1
for k in range(q):
if seq[B[k]-1] - seq[A[k]-1] == C[k]:
wa += D[k]
walist += [wa]
print(max(walist))
| from itertools import combinations_with_replacement as R
N,M,Q = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(Q)]
print(max([sum((d if S[b-1] - S[a-1] == c else 0) for a,b,c,d in L) for S in R(range(1, M+1), N)])) | 1 | 27,586,543,763,100 | null | 160 | 160 |
def get_num(n, x):
ans = 0
for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
if n3 + min(n2 - 1, x - n3 - n2):
ans += 1
return ans
data = []
while True:
[n, x] = [int(m) for m in raw_input().split()]
if [n, x] == [0, 0]:
break
# if x < 3:
# print(0)
# else:
print(get_num(n, x)) | # -*- coding: utf-8
a = int(input())
b = list(map(int,input().split()))
s = 0
for i in range(a):
s +=b[i]
tr = 0
for i in range(a):
tr += b[i]**2
a2 = s**2-tr
a = a2//2
a %= 10**9+7
print(a) | 0 | null | 2,576,449,100,888 | 58 | 83 |
N = int(input())
ans=[0]*N
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
F=x**2 + y**2 + z**2 + x*y + y*z + z*x
if(N>=F):
ans[F-1] += 1
for i in ans:
print(i) | n = int(input())
A = [0]*12000
for i in range(1,101):
for j in range(1, 101):
for k in range(1, 101):
val = i**2 + j**2 + k**2 + i*j + i*k + j*k
if val < 12000:
A[i**2 + j**2 + k**2 + i*j + i*k + j*k] += 1
for i in A[1:n+1]:
print(i) | 1 | 7,957,044,098,740 | null | 106 | 106 |
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
lastd = [0]*26
point = 0
for j,k in enumerate(t):
kk = k-1
point += s[j][kk]
lastd[kk] = j+1
for l in range(26):
point -= c[l]*(j+1-lastd[l])
print(point) | import sys
input = sys.stdin.readline
M, MOD = 3005, 998244353
dp = [[0 for i in range(M)] for j in range(M)]
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp[0][0] = 1
for i in range(n):
for j in range(s + 1):
dp[i + 1][j] += dp[i][j] * 2
dp[i + 1][j] %= MOD
if s >= j + a[i]:
dp[i + 1][j + a[i]] += dp[i][j]
dp[i + 1][j + a[i]] %= MOD
print(dp[n][s]) | 0 | null | 13,751,718,682,880 | 114 | 138 |
n,x,y=map(int,input().split())
l=[]
for i in range(n-1):
for j in range(i+1,n):
d1=j-i
d2=abs((x-1)-i)+abs(j-(y-1))+1
d=min(d1,d2)
l.append(d)
import collections
c=collections.Counter(l)
for kk in range(1,n):
print(c[kk]) | n, m = map(int, input().split())
alst = list(map(int, input().split()))
alst.sort(reverse = True)
stand = sum(alst) / m / 4
if alst[m - 1] >= stand:
print("Yes")
else:
print("No") | 0 | null | 41,199,849,764,800 | 187 | 179 |
'''
Introduction to Heuristics Contest
A - AtCoder Contest Scheduling
'''
def main():
# 本番テストケースは365
D = int(input())
# コンテストタイプごとの満足度の下がりやすさ
C = list(map(int, input().split()))
# 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
S = []
for _ in range(D):
sday = list(map(int, input().split()))
S.append(sday)
''' とりあえず順番にやってくだけ
for i in range(D):
tmp = i % 26 + 1
print(tmp)
'''
''' 満足度Siの最高を選ぶ、満足度低下するCは未考慮
for i in range(D):
high = S[i].index(max(S[i])) + 1
print(high)
'''
#main()
def intro_heuristics_b():
# 本番テストケースは365
D = int(input())
# コンテストタイプごとの満足度の下がりやすさ
C = list(map(int, input().split()))
# 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
S = []
for _ in range(D):
sday = list(map(int, input().split()))
S.append(sday)
# 回答(出力)
T = [int(input()) for _ in range(D)]
# さいごに開催したコンテストの日付
last = [-1] * 26
# 満足度と不満度を計算して出力
val = 0
for d in range(D):
idx = T[d] - 1
satis = S[d][idx]
last[idx] = d
complain = 0
for j in range(26):
complain += C[j] * (d - last[j])
val += satis - complain
print(val)
intro_heuristics_b()
#def intro_heuristics_c():
| from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline
def main():
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
PP = [0]*N
for i, p in enumerate(P):
PP[i] = p*(p+1)/(2*p)
S = [0]*(N+1)
for i in range(1, N+1):
S[i] = PP[i-1] + S[i-1]
max_ = 0
for i in range(0, N-K+1):
max_ = max(max_, S[i+K] - S[i])
print(max_)
if(__name__ == '__main__'):
main()
| 0 | null | 42,275,221,219,352 | 114 | 223 |
import math
S = list(input())
K = int(input())
s = S * 2
c1 = 0
c2 = 0
for i in range(len(s)-1):
if s[i+1] == s[i]:
if i < len(S)-1:
c1 += 1
c2 += 1
s[i+1] = 0
c = S[0]
for s in S:
if s != c:
print(c1+(c2-c1)*(K-1))
exit()
print(math.floor(len(S)*K/2))
| a, b, k = map(int, input().split())
takahasi = max(0, a - k)
aoki = max(0, b - max(0, k - a))
print(takahasi, aoki) | 0 | null | 139,841,702,345,592 | 296 | 249 |
n,m=map(int,input().split())
a=[0]*n
ans=0
for i in range(m):
p,s=input().split()
p=int(p)-1
if a[p]!=1:
if s=='WA':a[p]-=1
else:
ans-=a[p]
a[p]=1
for i in range(n):
a[i]=max(a[i],0)
print(sum(a),ans) | n,m = map(int,input().split())
p=[0]*m
s=[0]*m
for i in range(m):
p[i],s[i]=map(str,input().split())
cor=[0]*n
fal=[0]*n
for i in range(m):
x=int(p[i])
if cor[x-1]==0:
if s[i]=='AC':
cor[x-1]=1
else:
fal[x-1]+=1
ans_cor=0
ans_fal=0
for i in range(n):
if cor[i]==1:
ans_cor+=1
ans_fal+=fal[i]
print(ans_cor,ans_fal) | 1 | 93,814,485,033,270 | null | 240 | 240 |
#coding:utf-8
from copy import deepcopy
n = int(input())
A = list(input().split())
B = deepcopy(A)
def BubbleSort(A,N):
for i in range(N):
for j in range(N-1,i,-1):
if A[j][1] < A[j-1][1]:
A[j], A[j-1] = A[j-1], A[j]
def SelectionSort(A,N):
for i in range(N):
minj = i
for j in range(i,N):
if A[j][1] < A[minj][1]:
minj = j
A[i], A[minj] = A[minj], A[i]
BubbleSort(A,n)
SelectionSort(B,n)
A = " ".join([data for data in A])
B = " ".join([data for data in B])
print(A)
print("Stable")
print(B)
if A == B:
print("Stable")
else:
print("Not stable")
| n = int(input())
a = list(map(int,input().split()))
from collections import Counter
b = Counter(a)
for i in b.values():
if i>1:
print('NO')
break
else:
print('YES') | 0 | null | 36,948,634,736,310 | 16 | 222 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mia, pla = [], []
for ai in a:
if ai < 0:
mia.append(ai)
elif ai >= 0:
pla.append(ai)
mia.sort(reverse=True)
pla.sort()
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt *= mia.pop()
elif len(pla) > 0:
cnt *= pla.pop()
k -= 1
elif len(pla) <= 1:
cnt *= mia.pop() * mia.pop()
k -= 2
elif len(pla) >= 2 and len(mia) >= 2:
if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt *= pla.pop()
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt *= mia.pop() * mia.pop()
k -= 2
cnt %= mod
print(cnt)
| import sys
input = sys.stdin.readline
n,k = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9 + 7
# from random import randint
# n = 10
# k = 4
# A = []
# for i in range(10):
# A.append(randint(-20,20))
# anss=0
# for i in range(n):
# for j in range(i+1,n):
# for ii in range(j+1,n):
# for jj in range(ii+1,n):
# anss = max(anss, A[i]*A[j]*A[ii]*A[jj])
# print(anss)
# print(A)
B = [[], []]
for i in range(n):
if A[i] >= 0:
B[0].append(A[i])
else:
B[1].append(A[i])
B[0].sort(reverse=True)
B[1].sort()
if k % 2 == 1 and len(B[0]) == 0:
ans = 1
ind = len(B[1])-1
for i in range(k):
ans = (ans * B[1][ind]) % mod
ind -= 1
print(ans)
elif k == n and len(B[1]) % 2 == 1:
ans = 1
for i in range(n):
ans = (ans * A[i]) % mod
print(ans)
else:
k0 = min(len(B[0]), k)
k1 = k-k0
if k1%2==1:
k0 -= 1
k1 += 1
# print(B,k0,k1)
while k1+1 < len(B[1]) and k0-2 >= 0 and B[1][k1]*B[1][k1+1] > B[0][k0-1]*B[0][k0-2]:
k1 += 2
k0 -= 2
# print(k0,k1)
# print(k1+1 < len(B[1]),B[1][k1]*B[1][k1+1] , B[0][k0-1]*B[0][k0-2])
ans = 1
for i in range(k0):
ans = (ans * B[0][i]) % mod
for i in range(k1):
ans = (ans * B[1][i]) % mod
print(ans)
| 1 | 9,480,817,861,218 | null | 112 | 112 |
n = input()
dp = [0, 10000]
for d in map(int, reversed(n)):
dp = [min(d + dp[0], d + 1 + dp[1]), min(10 - d + dp[0], 9 - d + dp[1])]
print(min(dp[0], 1 + dp[1]))
| s=input()[::-1]+'0'
d=[0,1]
for c in s:
x=int(c)
d=[x+min(d[0],1+d[1]),min(1+d[0],d[1])+9-x]
print(min(d))
| 1 | 71,173,922,212,580 | null | 219 | 219 |
N = int(input())
s = input()
res = 0
search = [("00"+str(s))[-3:] for s in range(0,1000)]
for v in search:
tmp = s
if v[0] in tmp:
tmp = tmp[tmp.index(v[0])+1:]
else:
continue
if v[1] in tmp:
tmp = tmp[tmp.index(v[1])+1:]
else:
continue
if v[2] in tmp:
res += 1
print(res)
| N, S = open(0).read().split()
S = list(map(int, list(S)))
N = int(N)
cnt = 0
for i in range(0, 10):
for j in range(0, 10):
for k in range(0, 10):
try:
n = S.index(i)
m = S[n+1:].index(j)
o = S[n+m+2:].index(k)
cnt += 1
except ValueError:
pass
print(cnt) | 1 | 129,329,376,859,732 | null | 267 | 267 |
X, Y = list(map(int, input().split()))
print(X*Y) | nums = input().split()
print(int(nums[0]) * int(nums[1]))
| 1 | 15,713,734,245,440 | null | 133 | 133 |
# -*- coding: utf-8 -*-
def selection_sort(A, N):
change = 0
for i in xrange(N):
minj = i
for j in xrange(i, N, 1):
if A[j] < A[minj]:
minj = j
if minj != i:
temp = A[minj]
A[minj] = A[i]
A[i] = temp
change += 1
return (A, change)
if __name__ == "__main__":
N = input()
A = map(int, raw_input().split())
result, change = selection_sort(A, N)
print ' '.join(map(str, result))
print change | num_list=[]
while True:
num = input()
if num == 0:
break
num_list.append(num)
for num in num_list:
print sum(map(int,list(str(num)))) | 0 | null | 812,297,362,370 | 15 | 62 |
x, k, d = map(int, input().split())
def sgn(x):
if x > 0:
return 1
if x < 0:
return -1
return 0
if x > 0:
x1 = x - k * d
else:
x1 = x + k * d
if sgn(x) == sgn(x1):
print(abs(x1))
exit()
xright = x % d
xleft = x % d - d
#0目前
xr = (abs(x - xright) // d) % 2
if k % 2 == xr:
print(abs(xright))
elif k % 2 != xr:
print(abs(xleft)) | X, K, D = map(int, input().split())
t = X // D
if abs(t) >= K:
if X > 0:
print(abs(X-(D*K)))
elif X < 0:
print(abs(X+(D*K)))
exit(0)
nokori = K - t
if X-(D*t) <= 0:
if nokori % 2 == 0:
print(abs(X-(D*t)))
else:
print(abs(X-(D*(t-1))))
else:
if nokori % 2 == 0:
print(abs(X-(D*t)))
else:
print(abs(X-(D*(t+1))))
| 1 | 5,224,455,933,752 | null | 92 | 92 |
import math
H, W = map(int, input().split(' '))
if H == 1 or W == 1:
print(1)
exit()
res = math.ceil((H*W)/2)
print(res)
| import math
h , w = map(int , input().strip().split())
if h != 1 and w != 1:
print(math.ceil(h * w / 2))
else:
print(1)
| 1 | 50,863,297,517,010 | null | 196 | 196 |
N, K = map(int ,input().split())
counter = 0
while N:
N //= K
counter += 1
print(counter) | N, K = map(int, input().split())
p = list(map(int, input().split()))
# サイコロ(1...p)の期待値は(1+p)/2
cum_sum = [0]
for i in range(0, N):
cum_sum.append(cum_sum[i] + (1 + p[i]) / 2)
# print(cum_sum)
# 調べる区間は[1,...,K],...,[N-K+1,...N]
ans = 0
for i in range(1, N - K + 2):
temp = cum_sum[i + K - 1] - cum_sum[i - 1]
# print(temp)
ans = max(ans, temp)
print(ans)
| 0 | null | 69,503,819,408,350 | 212 | 223 |
n = int(input())
a = n // 2
b = n % 2
print(a+b)
| import sys
N = int(input()) + 1
ans = N // 2
print(ans) | 1 | 59,188,031,507,400 | null | 206 | 206 |
n = int(input())
s = n**3
print(s)
| import sys
for x in sys.stdin:
if "?" in x:
break
print(eval(x.replace("/", "//"))) | 0 | null | 483,867,048,532 | 35 | 47 |
N = int(input())
K = int(input())
dp = [[[0]*2 for _ in range(4)] for _ in range(105)]
# dp[i][j][k]:上からi桁まで決めて0でない数字をj個用いた数字で
# k = 0の時Nと一致,k=1の時N未満が確定
# 求める答えはdp[len(str(N))][K][0] + dp[len(str(N))][K][1]
# k=0からk=1の遷移が不可逆
dp[0][0][0] = 1
length = len(str(N))
for i in range(length):
for j in range(4):
for k in range(2):
next_digit = int(str(N)[i])
for d in range(10):
ni = i+1
nj = j
nk = k
if d != 0:
nj += 1
if nj > K:
continue
if k == 0:
if next_digit < d:
continue
if next_digit > d:
nk = 1
dp[ni][nj][nk] += dp[i][j][k]
ans = dp[length][K][0] + dp[length][K][1]
print(ans)
| def nCkpow(n,k):
if n<k:
return 0
y=1
for i in range(k):
y*=n-i
y//=i+1
y*=9
return y
def f(s,m,k):
#print(m,k)
if len(s)-m<k:
return 0
if k==0:
return 1
if s[m]=='0':
return f(s,m+1,k)
l=len(s)-m
y=nCkpow(l-1,k)
y+=(int(s[m])-1)*nCkpow(l-1,k-1)
return y+f(s,m+1,k-1)
N=input()
K=int(input())
print(f(N,0,K)) | 1 | 75,561,701,730,180 | null | 224 | 224 |
r, b = input().split()
a, b = map(int, input().split())
u = input()
if r == u:
print(a-1, b)
else:
print(a, b-1) | import sys
nums = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if nums[0] < nums[1]:
print( "a < b" )
elif nums[0] > nums[1]:
print( "a > b" )
else:
print( "a == b" ) | 0 | null | 36,049,854,308,160 | 220 | 38 |
n=int(input())
if n==2:
count=1
else:
count=2
for i in range(2,int(n**0.5)+1):
if n%i==0:
k=n//i
while k>0:
if k%i==0:
k=k//i
else:
if k%i==1:
count+=1
break
elif (n-1)%i==0:
count+=1
if i!=(n-1)//i:
count+=1
print(count)
| import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
N = int(input())
#nの約数列挙
def divisor(n):
ass = []
for i in range(1,int(n**0.5)+1):
if n%i == 0:
ass.append(i)
if i**2 == n:
continue
ass.append(n//i)
return ass #sortされていない
ans = len(divisor(N-1))-1
b = divisor(N)
for bi in b:
if bi == 1:
continue
a = N
while a >= bi:
if a%bi == 0:
a = a//bi
else:
a = a%bi
if a == 1:
ans += 1
print(ans)
| 1 | 41,311,031,851,750 | null | 183 | 183 |
H, W = map(int, input().split())
if H == 1 or W == 1:
r = 1
else:
r = (H*W +2-1)//2
print(r)
| import math
def resolve():
import sys
input = sys.stdin.readline
row1 = [int(x) for x in input().rstrip().split(" ")]
h = row1[0]
w = row1[1]
if h == 1 or w == 1:
print(1)
return
ans = (h-(h%2))*(w-(w%2))/2
ans += (h%2)*(w-(w%2))/2
ans += (w%2)*(h-(h%2))/2
ans += (w%2)*(h%2)
print(int(ans))
if __name__ == "__main__":
resolve()
| 1 | 50,990,802,729,152 | null | 196 | 196 |
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(min(50, K)):
B = [0]*N
for i in range(N):
B[max(0, i-A[i])] += 1
r = i+A[i]+1
if r < N:
B[r] -= 1
A = list(accumulate(B))
print(*A)
| x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=1)[:x]
q=sorted(list(map(int,input().split())),reverse=1)[:y]
r=sorted(list(map(int,input().split())),reverse=1)
pq=sorted(p+q,reverse=1)
ans=sum(pq)
n=len(r)
count=-1
for i in range(n):
if r[i]>pq[count]:
ans+=(r[i]-pq[count])
count-=1
print(ans) | 0 | null | 30,056,941,255,902 | 132 | 188 |
import math
N = int(input())
A = list(int(input()) for _ in range(N))
def insertionSort(A,n,g,cnt):
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A,n):
cnt = 0
G = []
bet = 0
while True:
bet = 3*bet + 1
if bet <= n:
G.insert(0,bet)
else:
break
m = len(G)
for i in range(m):
cnt = insertionSort(A,n,G[i],cnt)
print(m)
outputNumList(G)
print(cnt)
def outputNumList(A):
tmp = map(str,A)
text = " ".join(tmp)
print(text)
shellSort(A,N)
for k in range(N):
print(A[k])
| #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でやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n = I()
S = input()
ans = 0
for i in range(1000):
nya = str(i).zfill(3)
x = S.find(nya[0])
y = S.find(nya[1], x+1)
z = S.find(nya[2], y+1)
if x != -1 and y != -1 and z != -1:
ans += 1
print(ans)
| 0 | null | 64,250,338,936,068 | 17 | 267 |
import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
N = ii()
A = li()
acc = list(accumulate(A))
#sa = acc[-1] -acc[0]
for i in range(N):
if acc[i] - (acc[-1] - acc[i]) >= 0:
break
if i == N-1:
print(abs(A[i] - acc[i-1]))
elif i == 0:
print(abs(acc[i] - (acc[-1] - acc[i])))
else:
ans = min(abs(acc[i] - (acc[-1] - acc[i])), abs(acc[i-1] - (acc[-1] - acc[i-1])))
print(ans) | import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
class UnionFind:
def __init__(self, n: int):
self._n = n
self._parents = [i for i in range(n)]
self._rank = [1 for _ in range(n)]
def unite(self, x: int, y: int) -> None:
px = self.find(x)
py = self.find(y)
# 一致していないときはリンクをつける
if px != py:
self._link(px, py)
def _link(self, x: int, y: int):
if self._rank[x] < self._rank[y]:
self._parents[x] = y
elif self._rank[x] > self._rank[y]:
self._parents[y] = x
else:
self._parents[x] = y
self._rank[y] += 1
def same(self, x: int, y: int) -> bool:
px = self.find(x)
py = self.find(y)
return px == py
def find(self, x: int) -> int:
if self._parents[x] == x:
return x
self._parents[x] = self.find(self._parents[x])
return self._parents[x]
N, M = map(int, input().split())
uf = UnionFind(N + 1)
for i in range(M):
A, B = map(int, input().split())
uf.unite(A, B)
s = set()
for i in range(1, N + 1):
s.add(uf.find(i))
print(len(s) - 1)
| 0 | null | 71,928,494,089,320 | 276 | 70 |
def insertion_sort(A,n,g):
cnt = 0
for i in range(g,n):
v = A[i]
j = i - g
while (j>=0)&(A[j]>v):
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return A, cnt
def shell_sort(A,n):
G = []
g = 1
while True:
G.append(g)
g = 3*g+1
if g>n:
break
m = len(G)
G = G[::-1]
cnt = 0
for i in range(m):
A,cnt_tmp = insertion_sort(A,n,G[i])
cnt += cnt_tmp
return G,A,cnt
n = int(input())
A = [int(input()) for i in range(n)]
G,A,cnt = shell_sort(A,n)
print(len(G))
print(*G)
print(cnt)
for i in range(n):
print(A[i])
| import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
S = SS()
len_S = len(S)
ans = 0
for i in range(len_S // 2):
if S[i] != S[len_S-1-i]:
ans += 1
print(ans)
if __name__ == '__main__':
resolve()
| 0 | null | 59,882,898,738,190 | 17 | 261 |
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal
from functools import reduce
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
H, W, k = input_list()
maze = [list(input()) for _ in range(H)]
ans = 0
for row_bit in itertools.product(range(2), repeat=H):
for col_bit in itertools.product(range(2), repeat=W):
cnt = 0
for row in range(H):
for col in range(W):
if maze[row][col] == "#" and (row_bit[row] and col_bit[col]):
cnt += 1
if cnt == k:
ans += 1
print(ans)
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
def bfs(H, W, black_cells, dist):
d = 0
while black_cells:
h, w = black_cells.popleft()
d = dist[h][w]
for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
new_h = h + dy
new_w = w + dx
if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
continue
if dist[new_h][new_w] == -1:
dist[new_h][new_w] = d + 1
black_cells.append((new_h, new_w))
return d
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| k=int(input())
s,m,c,a=input(),10**9+7,1,1
for i in range(k):c*=25*(k+len(s)-i)*pow(i+1,m-2,m)%m;c%=m;a+=c
print(a%m) | 0 | null | 10,859,897,329,218 | 110 | 124 |