code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,629B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
n=int(input())
s=input()
c=s[0]
for i in range(1,n):
if s[i]!=s[i-1]:
c=c+s[i]
print(len(c))
| n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
B = sorted(A+A[1:],reverse=True)
print(sum(B[:n-1]))
| 0 | null | 89,393,938,272,740 | 293 | 111 |
charge, n_coin = map(int,input().split())
coin_ls = list(map(int, input().split()))
coin_ls = [0] + coin_ls
dp = [[float('inf')] * (charge+1) for _ in range(n_coin+1)]
dp[0][0] = 0
for coin_i in range(1,n_coin+1):
for now_charge in range(0,charge+1):
if now_charge - coin_ls[coin_i] >= 0:
dp[coin_i][now_charge] = min(dp[coin_i][now_charge], dp[coin_i][now_charge-coin_ls[coin_i]]+1)
dp[coin_i][now_charge] = min(dp[coin_i-1][now_charge], dp[coin_i][now_charge])
print(dp[n_coin][charge])
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,T,*ab = map(int, read().split())
AB = []
for a, b in zip(*[iter(ab)]*2):
AB.append((a, b))
AB.sort()
dp = [[0] * (T+1) for _ in range(N+1)]
ans = 0
for i in range(N):
w_i, v_i = AB[i]
for j in range(T):
if j < w_i:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = max(dp[i][j - w_i] + v_i, dp[i][j])
ans = max(ans, dp[i][T-1] + v_i)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 75,564,538,020,246 | 28 | 282 |
def main():
n, a, b = map(int, input().split(" "))
one_round = a+b
x = n // one_round
n = n % one_round
ans = x * a
ans += min(n,a)
print(ans)
if __name__ == "__main__":
main() | # coding: utf-8
import sys
ans = []
while ( 1 ):
strings = input()
if (len(strings) == 1 and int(strings[0]) == 0):
break
ans = 0
for s in strings:
ans += int(s)
print(ans) | 0 | null | 28,442,915,549,888 | 202 | 62 |
def f(p, k, W):
i = 0
t = 0
s = 0
while i < len(W) and t < k:
if s + W[i] <= p:
s += W[i]
i += 1
else:
s = 0
t += 1
return i
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
l = 0
r = 100000 * 10000 // k
while r - l > 1:
mid = (l + r) // 2
v = f(mid, k, W)
if v >= n:
r = mid
else:
l = mid
print(r)
| #インプットdataの格納
n, k = map(int, input().split())
n_list = list()
for i in range(n):
n_list.append(int(input()))
#data処理
left = 0
right = 100000*10000
while (right - left) > 1:
mid = (left + right) // 2
i = 0
for j in range(k):
weight = 0
while i < n:
if (weight + n_list[i]) > mid:
break
else:
weight += n_list[i]
i += 1
if i >= n:
right = mid
else:
left = mid
#結果表示
print(right)
| 1 | 91,842,436,988 | null | 24 | 24 |
n,k=map(int, input().split())
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(min(50,k)):
new=[0]*n
for i in range(n):
j=a[i]
l=max(0,i-j)
r=min(n-1,i+j)
new[l]+=1
if r+1<n:
new[r+1]-=1
new=list(accumulate(new))
a=new
print(*a)
| import math
n,k=map(int,input().split())
a=[0]*n
ans=[0]*n
a=list(map(int,input().split()))
check=math.ceil(math.log2(n))+1
if (k>=42):
a=[n]*n
print(" ".join(map(str,a)))
else:
for _ in range(k):
ans=[0]*n
table=[0]*n
for i in range(n):
left=max(0,i-a[i])
right=min(n-1,i+a[i])
table[left]+=1
if (right+1<n):
table[right+1]-=1
#print(left,right)
#for j in range(left,right+1):
# ans[j]+=1
#print(table)
for i in range(1,n):
table[i]+=table[i-1]
a=table
print(" ".join(map(str,a))) | 1 | 15,459,185,719,448 | null | 132 | 132 |
import sys
import math
def resolve(in_):
a, b, n = map(int, next(in_).split())
x = min(b - 1, n)
return math.floor(a * x / b) - a * math.floor(x / b)
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| n,a,b = map(int,input().split())
if a == 0:
print(0)
elif a+b <= n and n%(a+b) < a:
print((n//(a+b))*a + n%(a+b))
elif a+b <= n and n%(a+b) >= a:
print((n//(a+b))*a + a)
elif n < a+b and n < a:
print(n)
elif n < a+b and a <= n:
print(a)
| 0 | null | 42,165,504,075,706 | 161 | 202 |
s = int(input())
dp = [0]*(2001)
dp[3] = 1
mod = 10**9+7
for i in range(4,s+1):
dp[i] = (dp[i-1] + dp[i-3]) % mod
print(dp[s]) | mod=1000000007
dp=[1]*2001
for i in range(3,2001):
for j in range(i+3,2001):
dp[j]=(dp[j]+dp[i])%mod
n=int(input())
if n<3:print(0)
else:print(dp[n]) | 1 | 3,280,637,096,594 | null | 79 | 79 |
n = int(input())
x = 1
print "",
while x <= n:
if x%3==0:
print str(x),
else:
t = x
while t:
if t%10==3:
print str(x),
t = 0
else:
t /= 10
x += 1
print | import itertools
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
N = [i for i in range(1,n+1)]
N_dict = {v:(i+1) for i,v in enumerate(itertools.permutations(N, n))}
#print(N_dict)
print(abs(N_dict[P] - N_dict[Q])) | 0 | null | 50,790,049,736,820 | 52 | 246 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
if max(a) < 0:
a.sort()
ans = 1
if k % 2 == 0:
for e in a[:k]:
ans *= e
ans %= mod
else:
for e in a[-k:]:
ans *= e
ans %= mod
print(ans)
elif k == n:
ans = 1
for e in a:
ans *= e
ans %= mod
print(ans)
else:
neg = []
pos = []
for e in a:
if e < 0:
neg.append(e)
else:
pos.append(e)
neg.sort()
pos.sort(reverse=True)
ans = 1
if k % 2:
ans *= pos.pop(0)
k -= 1
nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]
nums.sort(reverse=True)
for e in nums[:k//2]:
ans *= e
ans %= mod
print(ans)
| from sys import stdin
input = stdin.readline
from collections import Counter
def solve():
N = int(input())
a = list(map(int,input().split()))
assert N & 1 == 0
s = 0
res = []
for v in a:
s ^= v
for v in a:
res.append(s^v)
print(' '.join(map(str,res)))
if __name__ == '__main__':
solve()
| 0 | null | 10,977,378,933,712 | 112 | 123 |
K, N = map(int, input().split())
A = list(map(int, input().split()))
import numpy as np
a = np.array(A)
D = np.diff(a)
D = np.append(D, a[0] + K - a[-1])
ind = np.argmax(D)
if N == 2:
print(a[ind+1]-a[ind])
elif ind == len(a)-1:
ans = -a[0] + a[ind]
print(ans)
else:
ans = K - (a[ind+1]-a[ind])
print(ans)
| import sys
a=sys.stdin.buffer.read
K,N,*A=map(int,a().split())
A+=[A[0]+K]
print(K-max(y-x for x,y in zip(A,A[1:]))) | 1 | 43,246,516,256,712 | null | 186 | 186 |
n1 = input()
A = map(int, raw_input().split())
n2 = input()
q = map(int, raw_input().split())
list = set()
def solve(i,m):
if m == 0:
return True
if i >= n1 or m > sum(A):
return False
res = solve(i+1,m) or solve(i+1,m-A[i])
return res
for m in q:
if solve(0,m):
print "yes"
else:
print "no" | #Exhaustive Search (bit全探索ver)
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
count_list = []
for i in range(1<<n):
copy_A = A.copy()
count = 0
for j in range(n):
mask = 1 << j
if mask & i != 0:
count += A[j]
count_list.append(count)
for k in m:
if k in count_list:
print('yes')
else:
print('no')
| 1 | 99,028,405,440 | null | 25 | 25 |
from collections import deque
import numpy as np
H,W = map(int,input().split())
maze = [input() for _ in range(H)]
ans = 0
for x in range(H):
for y in range(W):
if maze[x][y]=='#':
continue
dist = [[0]*W for i in range(H)]
Q = deque([[x,y]])
while Q:
h,w = Q.popleft()
for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
h2,w2 = h+i,w+j
if 0<=h2<H and 0<=w2<W and dist[h2][w2]==0 and maze[h2][w2]!='#':
dist[h2][w2] = dist[h][w]+1
Q.append([h2,w2])
dist[x][y] = 0
ans = max(ans, np.max(dist))
print(ans) | # sr,sc,gr,gcの総当りでTLEした
# goalは各startに対して最も遠い地点とすればよい
def main():
from collections import deque
dd = 0, 1, 0, -1
H, W = map(int, input().split())
G = [input() for _ in range(H)]
def dist(sr, sc):
if G[sr][sc] == '#':
return -1
memo = [[-1] * W for _ in range(H)]
dq = deque()
dq.append((sr, sc, 0))
memo[sr][sc] = 0
while dq:
r, c, d = dq.popleft()
nd = d + 1
for i in range(4):
nr = r + dd[i]
nc = c + dd[i ^ 1]
if not (0 <= nr < H and 0 <= nc < W):
continue
if ~memo[nr][nc]:
continue
if G[nr][nc] == '#':
continue
dq.append((nr, nc, nd))
memo[nr][nc] = nd
return d
ans = 0
for sr in range(H):
for sc in range(W):
ans = max(ans, dist(sr, sc))
print(ans)
if __name__ == '__main__':
main()
| 1 | 95,037,155,447,832 | null | 241 | 241 |
def main():
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
count += (i != minj)
A[i], A[minj] = A[minj], A[i]
print(" ".join(map(str,A)))
print(count)
if __name__ == "__main__":
import os
import sys
if len(sys.argv) > 1:
if sys.argv[1] == "-d":
fd = os.open("input.txt", os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())
main()
else:
main() | def sel_sort(A, N):
''' 選択ソート '''
count = 0
for n in range(N):
minm = n
for m in range(n, N):
if A[m] < A[minm]:
minm = m
if minm != n:
A[n], A[minm] = A[minm], A[n]
count += 1
return (A, count)
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split(' ')))
ans = sel_sort(A, N)
print(' '.join([str(x) for x in ans[0]]))
print(ans[1])
| 1 | 19,821,107,170 | null | 15 | 15 |
n = int(input())
x = input()
popcnt = x.count("1")
def powmod(lst,mod):
if not mod: return
d = 1
for i in range(n)[::-1]:
d %= mod
lst[i] = d
d *= 2
def xmod(mod):
if not mod: return
res = 0
d = 1
for i in range(n)[::-1]:
d %= mod
if int(x[i]):
res += d
res %= mod
d *= 2
return res
def solve(x):
res = 1
while x != 0:
popcnt = 0
for i in range(20):
if x>>i & 1: popcnt += 1
x %= popcnt
res += 1
return res
powlst0 = [0]*n
powlst1 = [0]*n
powmod(powlst0,popcnt+1)
x0 = xmod(popcnt+1)
powmod(powlst1,popcnt-1)
x1 = xmod(popcnt-1)
for i in range(n):
if int(x[i]):
if popcnt == 1: print(0)
else: print(solve((x1-powlst1[i])%(popcnt-1)))
else: print(solve((x0+powlst0[i])%(popcnt+1))) | def pc(x):
return format(x, 'b').count('1')
N = int(input())
X = input()
Xo = int(X, 2)
count = 0
ans = 0
ori = pc(Xo)
X = list(X)
Xp = Xo%(ori + 1)
if ori == 1:
Xm = 0
else:
Xm = Xo % (ori - 1)
# for i in range(N-1, -1, -1):
for i in range(N):
if ori == 1 and X[i] == '1':
print(0)
continue
else:
if X[i] == '1':
# ans = Xm - pow(2, i, ori - 1)
ans = Xm - pow(2, N-1-i, ori - 1)
ans %= ori - 1
else:
# ans = Xp - pow(2, i, ori + 1)
ans = Xp + pow(2, N-1-i, ori + 1)
ans %= ori + 1
count = 1
while ans > 0:
# count += 1
# if ans == 1:
# break
ans %= pc(ans)
count += 1
print(count)
count = 1
| 1 | 8,144,480,923,242 | null | 107 | 107 |
while True:
H,W = map(int, input().split())
if H == 0 and W == 0:
break
a = "#" * W
for i in range(H):
print(a)
print() | while True:
H,W = map(int,input().split(" "))
if H == 0 and W == 0:
break
[print(*["#"*W]) for _ in range(H)]
print()
| 1 | 792,206,974,080 | null | 49 | 49 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = str(readline().rstrip().decode('utf-8'))
d = {"2": "hon", "4": "hon", "5": "hon", "7": "hon", "9": "hon", "0": "pon", "1": "pon", "6": "pon", "8": "pon", "3": "bon"}
print(d[n[-1]])
if __name__ == '__main__':
solve()
| def main():
H1,M1,H2,M2,K = map(int,input().split())
time1 = H1*60 + M1
time2 = H2*60 + M2
time = time2-time1
ans = time-K
return ans
print(main())
| 0 | null | 18,655,521,325,252 | 142 | 139 |
n = list(map(int, input()[::-1])) + [0]
s = 0
res = 0
for i, ni in enumerate(n[:-1]):
k = ni + s
if k < 5 or (k == 5 and int(n[i + 1]) < 5):
res += k
s = 0
else:
res += 10 - k
s = 1
res += s
print(res)
| N = input()
n = len(N)
a = int(N[0])
b = 11-int(N[0])
for i in range(n-1):
a1 = min(a+int(N[i+1]), b+int(N[i+1]))
b1 = min(a+11-int(N[i+1]), b+9-int(N[i+1]))
a = a1
b = b1
print(min(a,b)) | 1 | 71,229,196,101,954 | null | 219 | 219 |
import random
import numpy as np
D=int(input())
C=np.array(list(map(int,input().split())))
S=[]
for _ in range(D):
S.append(list(map(int,input().split())))
l=np.zeros(26,int)
def decrease(d):
return np.dot(C,(d-l))
def pick(i,l):
diff=[]
ll=l.copy()
for j in range(26):
ll[j]=i
diff.append(S[i][j]-decrease(i))
return np.argmax(diff)+1
for i in range(D):
p=pick(i,l)
print(p)
l[p-1]=i+1 | from copy import copy
import random
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
ps = [0]*26
for j in range(26):
pl = copy(last)
pl[j] = i+1
ps[j] += s[i][j]
for k in range(26):
ps[j] -= c[k]*(i+1-pl[k])
idx = ps.index(max(ps))
last[idx] = i+1
ans[i] = idx+1
score += max(ps)
for k in range(1,37001):
na = copy(ans)
x = random.randint(1,365)
y = random.randint(1,365)
z = random.randint(min(x,y),max(x,y))
if x == y:
continue
na[x-1],na[y-1] = na[y-1],na[x-1]
na[x-1],na[z-1] = na[z-1],na[z-1]
last = [0]*26
ns = 0
for i in range(D):
last[na[i]-1] = i+1
ns += s[i][na[i]-1]
for j in range(26):
ns -= c[j]*(i+1-last[j])
if k%100 == 1:
T = 300-(298*k/37000)
p = pow(math.e,-abs(ns-score)/T)
if ns > score or random.random() < p:
ans = na
score = ns
for a in ans:
print(a) | 1 | 9,607,476,649,882 | null | 113 | 113 |
N,D = map(int,input().split())
xy = []
for i in range(N):
x,y = map(int,input().split())
xy.append([x,y])
ans = 0
for i in range(N):
x = xy[i][0]
y = xy[i][1]
if(D*D >= (x*x + y*y)):
ans+=1
print(ans) | import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n,d = map(int,input().split())
for i in range(n):
x,y = map(int,input().split())
if x**2 + y ** 2 <= d**2:
count += 1
print(count) | 1 | 5,951,465,512,788 | null | 96 | 96 |
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def resolve():
h1,m1,h2,m2,k = mi()
res = convert(h2,m2) - convert(h1,m1) - k
print(res)
def convert(h,m):
return h*60 + m
if __name__ == "__main__":
resolve() | from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
h1,m1,h2,m2,k=nii()
minute=(h2-h1)*60
minute+=m2-m1
minute-=k
print(minute) | 1 | 18,077,395,306,500 | null | 139 | 139 |
def solve():
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
if a==p:
p += 1
else:
ans += 1
if p==1:
ans = -1
return ans
print(solve()) | x = int(input())
a = 0
b = 0
flg = True
while True:
a += 1
for i in range(a):
if a**5 - i**5 == x:
a = a
b = i
flg = False
break
elif a**5 + i**5 == x:
a = a
b = -i
flg = False
break
if flg == False:
break
a = str(a)
b = str(b)
print(a+' '+b) | 0 | null | 70,339,180,739,082 | 257 | 156 |
N = int(input())
S = [input() for i in range(N)]
ans = len(set(S))
print(ans) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: C_fix
# CreatedDate: 2020-06-27 13:59:01 +0900
# LastModified: 2020-06-27 14:04:38 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
n = int(input())
s = []
for i in range(n):
s.append(input())
s = list(set(s))
print(len(s))
if __name__ == "__main__":
main()
| 1 | 30,204,576,005,068 | null | 165 | 165 |
while True:
n = int(input())
s = []
if n == 0:
break
s = list(map(int, input().split()))
m = sum(s) / n
v = 0
for i in s:
v += (i - m) ** 2
ans = (v / n) ** (1/2)
print('{:10f}'.format(ans))
| import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
import string
def main():
H,W = i_map()
dy_dx=[[1,0],[0,1],[-1,0],[0,-1]]
rc=[input() for i in range(H)]
ans = 0
for sy in range(H):
for sx in range(W):
if rc[sy][sx] == "#":
continue
dist=[[-1 for _ in range(W)] for _ in range(H)]
dist[sy][sx] = 0
d=deque()
d.append([sx,sy])
while d:
nx, ny = d.popleft()
for dy,dx in dy_dx:
y,x = ny+dy,nx+dx
if 0<=y<H and 0<=x<W and rc[y][x] != "#" and dist[y][x] == -1:
dist[y][x] = dist[ny][nx] + 1
d.append([x,y])
ans = max(ans, max(list(itertools.chain.from_iterable(dist))))
print(ans)
if __name__=="__main__":
main()
| 0 | null | 47,628,225,536,258 | 31 | 241 |
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
n = int(input())
items = {input() for _ in range(n)}
print(len(items))
if __name__ == "__main__":
main() | S = input()
day = ["SAT","FRI","THU","WED","TUE","MON","SUN"]
print(day.index(S) + 1)
| 0 | null | 81,901,748,617,920 | 165 | 270 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def divisors(n):
lower = []
upper = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
lower.append(i)
if i != n // i:
upper.append(n // i)
lower.extend(reversed(upper))
return lower
def main():
N = int(readline())
D = divisors(N)
D1 = divisors(N - 1)
ans = len(D1) - 1
for d in D:
if d == 1:
continue
n = N
while n % d == 0:
n //= d
if n % d == 1:
ans += 1
print(ans)
return
if __name__ == '__main__':
main()
| X = int(input())
print('Yes') if X >= 30 else print('No') | 0 | null | 23,605,206,846,272 | 183 | 95 |
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
if N%2 == 0:
ans += 2*sum(A[1:(N-2)//2+1])
else:
ans += 2*sum(A[1:(N-2)//2+1])+A[(N-2)//2+1]
print(ans) | N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
ans = A[0] + sum(A[1:N//2])*2
if N % 2 == 1:
ans += A[N//2]
# print(A[1:N//2])
# スコアを獲得できるのはN-1回
print(ans)
| 1 | 9,230,719,622,488 | null | 111 | 111 |
import math
k = int(input())
su = 0
lis = []
for x in range(1, k+1):
for y in range(1, k+1):
a = math.gcd(x, y)
lis.append(a)
for z in range(1, k+1):
for p in lis:
ans = math.gcd(p, z)
su += ans
print(su) | N=int(input())
S=input()
kouho=[]
for n in range(1000):
st=str(n)
if len(st)<=2:
st='0'*(3-len(st))+st
kouho.append(st)
ans=0
for k in kouho:
number=0
for s in S:
if k[number]==s:
number+=1
if number==3:
break
if number == 3:
ans += 1
print(ans)
| 0 | null | 81,805,013,679,182 | 174 | 267 |
N, M = map(int, input().split())
countlis = [0] * (N+1)
penalty = 0
clear = 0
checkset = set()
for i in range(1,M+1):
p,s = input().split()
p = int(p)
if p in checkset:
continue
if s == "WA":
countlis[p] += 1
elif s == "AC":
penalty += countlis[p]
clear += 1
checkset.add(p)
print("{0} {1}".format(clear, penalty)) | a, b = [int(a) for a in input().split()]
print("unsafe" if a <= b else "safe") | 0 | null | 61,255,530,413,560 | 240 | 163 |
N,K=map(int,input().split())
A=[int(x)-1 for x in input().split()]
t,i,dist=0,0,{0:0}
while K>0:
K,i,t=K-1,i+1,A[t]
if t in dist:
K%=i-dist[t]
else:
dist[t]=i
print(t+1)
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
N,K=map(int, sys.stdin.readline().split())
A=[None]+map(int, sys.stdin.readline().split())
visit=[ 0 for _ in range(N+1) ]
L=[] #閉路になった町番号を順番に記録する
def func(fro):
global K
to=A[fro]
visit[fro]+=1
if visit[fro]==2:
L.append(fro)
if visit[to]<=1: #閉路ループは2回まで許可する
K-=1 #操作回数を減らす
if K==0: #Kが途中でゼロになれば、その時に移動しようとしていたtoが答え
print to
quit()
func(to)
func(1)
K-=1
l=len(L)
print L[K%l]
| 1 | 22,901,470,485,668 | null | 150 | 150 |
s = int(input())
MOD = 10**9 + 7
b3 = 1; b2 = 0; now = 0 # now == b1
for n in range(3, s+1):
b1 = now
now = (b1 + b3) % MOD
b3, b2 = b2, b1
print(now)
| def mod_comb_k(n, k, p):
"""二項係数 0(1)
Args:
n (int): 添字
k (int): 添字
p (int): 除数
Returns:
int: nCk mod p
"""
if n < k or n < 0 or k < 0:
return 0
else:
return fact[n] * fact_inv[k] * fact_inv[n-k] % p
def com_init(n, p):
"""二項係数の計算の前処理 O(N)
Args:
n (int): 上限値
p (int): 除数
"""
for i in range(n):
fact.append(fact[-1] * (i+1) % p)
fact_inv[-1] = pow(fact[-1], p-2, p)
for i in range(n-1, -1, -1):
fact_inv[i] = fact_inv[i+1] * (i+1) % p
s = int(input())
mod = 10 ** 9 + 7
fact = [1]
fact_inv = [0] * (s+1)
com_init(s, mod)
res = 0
for i in range(1, s//3+1):
res = (res + mod_comb_k(s-i*2-1, i-1, mod)) % mod
print(res) | 1 | 3,319,596,807,680 | null | 79 | 79 |
data =[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]
line =int(input())
print(data[line -1]) | import math
n=int(input());
arr=[]
j=2
while j*j<=n:
cnt=0
while n%j==0:
cnt=cnt+1
n=n/j
if cnt!=0:
arr.append(cnt)
j=j+1
if n>1:
arr.append(1)
ans=int(0)
for i in arr:
ans=ans+int((math.sqrt(1+8*i)-1)/2)
print(ans) | 0 | null | 33,289,662,789,346 | 195 | 136 |
n = int(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
num = n % 10
if num in hon:
print("hon")
elif num in pon:
print("pon")
elif num == 3:
print("bon") | n=input()
a=n[-1]
if a in "24579":
print('hon')
elif a in "0168":
print('pon')
else:
print('bon') | 1 | 19,241,743,389,330 | null | 142 | 142 |
s = input()
if s[-1] == s[-2]:
if s[-3] == s[-4]:
print("Yes")
exit()
print("No") | n,k = map(int,input().split())
person = [0]*n
for i in range(k):
d = int(input())
A = list(map(int,input().split()))
for j in range(len(A)):
person[A[j]-1] = 1
print(person.count(0))
| 0 | null | 33,343,217,606,170 | 184 | 154 |
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
n=int(input())
ans=0
for i in range(1,n+1):
ans+=i*(n//i)*(1+n//i)//2
print(ans) | from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
from operator import mul
from functools import reduce
n = int(input())
m = 0
for i in range(1,n+1):
a = n // i
m += a*(a+1)*i//2
print(m) | 1 | 11,095,175,635,090 | null | 118 | 118 |
X, Y, A, B, C = map(int, input().split())
L = []
P = list(map(int, input().split()))
P.sort(reverse=True)
L += P[:X]
Q = list(map(int, input().split()))
Q.sort(reverse=True)
L += Q[:Y]
L += list(map(int, input().split()))
L.sort(reverse=True)
print(sum(L[:X + Y]))
| ''' 1.降序排列,选出x个红苹果,y个绿苹果
2.使用c个无色苹果去更新这x+y个苹果中的小值,直到最小也比无色苹果的大为止'''
nums = [int(i) for i in input().split()]
x = nums[0]
y = nums[1]
a = nums[2]
b = nums[3]
c = nums[4]
redApples = [int(i) for i in input().split()]
greenApples = [int(i) for i in input().split()]
colorless = [int(i) for i in input().split()]
redApples.sort(reverse=True)
greenApples.sort(reverse=True)
colorless.sort(reverse=True)
redApples = redApples[:x]
greenApples = greenApples[:y]
res = redApples+greenApples
res.sort(reverse=True)
currIndex = len(res)-1
for i in range(len(colorless)):
if colorless[i] <= res[currIndex]:
break
res[currIndex] = colorless[i]
currIndex -= 1
if currIndex < 0:
break
print(sum(res))
| 1 | 44,753,793,682,160 | null | 188 | 188 |
a,b,c = map(int,raw_input().split())
if a>b:
tmp = a
a = b
b = tmp
if b>c:
tmp = b
b = c
c = tmp
if a>b:
tmp = a
a = b
b = tmp
print "%d %d %d" %(a,b,c) | N,K = map(int,input().split())
H = list(map(int,input().split()))
print(sum(K<=h for h in H)) | 0 | null | 89,244,758,219,628 | 40 | 298 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
A, B, C = map(int, input().split())
if A == B and B != C:
print("Yes")
elif B == C and B != A:
print("Yes")
elif C == A and C != B:
print("Yes")
else:
print("No") | while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break;
for i in range(0, a):
if i % 2 == 0:
print(("#." * int((b + 1) / 2))[:b])
else:
print((".#" * int((b + 1) / 2))[:b])
print("") | 0 | null | 34,610,462,331,148 | 216 | 51 |
x, y = map(int,input().split())
ans = 0
for i in range(x+1):
for j in range(x+1):
if 2*i + 4 * j == y and i + j == x:
ans += 1
if ans > 0:
print('Yes')
else:
print('No') | X,Y = map(int,input().split())
check = False
for i in range(0,X+1):
for j in range(0,X+1):
if i + j == X and 2*i + 4*j == Y:
check = True
if check:
print("Yes")
else:
print("No") | 1 | 13,804,836,389,120 | null | 127 | 127 |
def main():
s = int(input())
mod = 10**9 + 7
dp = [0] * (s+1)
dp[0] = 1
# for i in range(1, s+1):
# for j in range(0, (i-3)+1):
# dp[i] += dp[j]
# dp[i] %= mod
for i in range(1, s+1):
if i < 3:
dp[i] = 0
else:
dp[i] = dp[i-1] + dp[i-3]
dp[i] %= mod
print(dp[-1])
if __name__ == "__main__":
main()
| #事前に階乗を計算しておく maximにnの最大値をいれる
maxim = 10**6+1
MOD = 10**9+7
kaijou = [1]*(maxim)
for i in range(1,maxim):
kaijou[i]=(kaijou[i-1]*i)%MOD
#nCr
def nCr(n,r):
if n < r:
return 0
return ((kaijou[n]*pow(kaijou[r],MOD-2,MOD))%MOD*pow(kaijou[n-r],MOD-2,MOD))%MOD
#nHr
def nHr(n,r):
if r == 0:
if n == 0:
return 1
return 0
return ((kaijou[n+r-1]*pow(kaijou[n],MOD-2,MOD))%MOD*pow(kaijou[r-1],MOD-2,MOD))%MOD
N = int(input())
ans = 0
for i in range(1,(N//3)+1):
tmp = nHr(N-3*i,i)
ans = (ans+tmp)%MOD
print(ans) | 1 | 3,246,985,631,498 | null | 79 | 79 |
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
P = t1 * (b1 - a1)
Q = t2 * (b2 - a2)
if P + Q == 0:
print("infinity")
return
if P * (P + Q) > 0:
print(0)
return
P = abs(P)
Q = abs(Q)
T = P % (Q - P)
S = P // (Q - P)
if T == 0:
ans = 2 * S
else:
ans = 2 * S + 1
print(ans)
main()
| #! /usr/bin/python
if __name__ == "__main__":
n = int(raw_input())
array = map(int, raw_input().split())
for i in range(1, n):
print " ".join(map(str, array))
key = array[i]
j = i - 1
while j >= 0 and array[j] > key:
array[j+1] = array[j]
j -= 1
array[j+1] = key
print " ".join(map(str, array)) | 0 | null | 65,560,726,499,058 | 269 | 10 |
W = input()
T = ""
while True:
x = input()
if x == "END_OF_TEXT":
break
T += x + " "
num = 0
for t in T.split():
if t.lower() == W.lower():
num += 1
print(num) | A,B = map(int, input().split())
a = A - B * 2
if a <= 0:
print("0")
else:
print(a) | 0 | null | 83,875,030,249,240 | 65 | 291 |
import re
T = input()
print(re.sub(r'\?', 'D', T))
| t = str(input())
ans = t.replace("?","D")
print(ans) | 1 | 18,349,279,837,688 | null | 140 | 140 |
n, m = map(int, input().split())
c = 0
if n >= 2:
c += n*(n-1) /2
if m >= 2:
c += m*(m-1) /2
print(int(c)) | N, M = map(int, input().split())
totalN = 1/2*(N-1)*N
totalM = 1/2*(M-1)*M
import math
print(math.floor(totalN + totalM))
| 1 | 45,481,923,094,930 | null | 189 | 189 |
N, K = map(int, input().split())
result = 1
for i in range(K, N+1):
tmp_min = (i - 1) * i // 2
tmp_max = (N * (N + 1) - (N - i) * (N - i + 1)) // 2
result += tmp_max - tmp_min + 1
result %= 10 ** 9 + 7
print(result)
| n = int(input())
s, t = input().split(' ')
q = ''
for i in range(n):
q += s[i]
q += t[i]
print(q)
| 0 | null | 72,644,219,852,412 | 170 | 255 |
t = int(raw_input())
a = raw_input().split()
small = int(a[0])
large = int(a[0])
total = 0
for i in a:
v = int(i)
if v < small:
small = v
if v > large:
large = v
total = total + v
print small,large,total | s = str(input())
apple = ["SUN","MON","TUE","WED","THU","FRI","SAT","SUN"]
print(7-apple.index(s)) | 0 | null | 67,076,577,515,820 | 48 | 270 |
N=int(input())
def num_divisors_table(n):
table=[0]*(n+1)
for i in range(1,n+1):
for j in range(i,n+1,i):
table[j]+=1
return table
l=num_divisors_table(N)
ans=0
for i in range(1,N+1):
ans+=i*l[i]
print(ans) | n,k = map(int, input().split())
p = list(map(int,input().split()))
p_sort = sorted(p)
print(sum(p_sort[:k])) | 0 | null | 11,334,357,269,960 | 118 | 120 |
def resolve():
print("Yes" if input() == input()[:-1] else "No")
if '__main__' == __name__:
resolve() | if __name__ == '__main__':
s = input()
t = input()
if s == t[:-1]:
print("Yes")
else:
print("No")
| 1 | 21,391,979,168,890 | null | 147 | 147 |
import statistics
n = int(input())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i] = map(int,input().split())
cen_a=statistics.median(a)
cen_b=statistics.median(b)
if n%2==1:
print(cen_b-cen_a+1)
else:
print(int((cen_b-cen_a)*2+1))
| a,b,c=map(int,input().split(" "))
print((a//b+(a%b>0))*c) | 0 | null | 10,813,807,711,630 | 137 | 86 |
n=int(input())
cnt=0
Arm=[]
for i in range(n):
x,l=map(int,input().split())
Arm.append([x+l,x-l])
Arm.sort()
dis=-float('inf')
for i in range(n):
if dis<=Arm[i][1]:
cnt+=1
dis=Arm[i][0]
print(cnt)
| inputs = list(input())
stack = []
L = []
tmp_total = 0
counter = 0
upper = 0
for i,x in enumerate(inputs):
if(x == '\\'):
stack.append(i)
elif(x == '/') and stack:
tmp = stack.pop()
total_layer = i-tmp
if L:
while L and L[-1][0] > tmp:
cal = L.pop()
total_layer += cal[1]
L.append((i, total_layer))
print(sum([j[1] for j in L]))
if(len(L) != 0):
print(str(len(L))+ ' ' + ' '.join([str(i[1]) for i in L]))
else:
print(str(len(L)))
| 0 | null | 44,972,592,830,540 | 237 | 21 |
import heapq
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=[]
for i in range(x):
ans.append(p[i])
for j in range(y):
ans.append(q[j])
ans.sort()
heapq.heapify(ans)
for j in range(c):
min_a=heapq.heappop(ans)
if min_a<=r[j]:
heapq.heappush(ans,r[j])
else:
heapq.heappush(ans,min_a)
break
print(sum(ans))
| x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
colorless = list(map(int, input().split()))
red.sort(reverse = True)
green.sort(reverse = True)
colorless.sort(reverse = True)
ret = red[:x] + green[:y]
ret.sort()
for i in range(len(colorless)):
if ret[i] < colorless[i]:
ret[i] = colorless[i]
else:
break
print(sum(ret)) | 1 | 44,501,751,900,192 | null | 188 | 188 |
A1=input()
A2=input()
A3=input()
#N=int(N)
list1 = A1.split()
list1 = [int(i) for i in list1]
list2 = A2.split()
list2 = [int(i) for i in list2]
list3 = A3.split()
list3 = [int(i) for i in list3]
N = input()
N=int(N)
num=[]
for i in range(N):
num.append(int(input()))
T1 = all([(i in num ) for i in list1])
T2 = all([(i in num ) for i in list2])
T3 = all([(i in num ) for i in list3])
T4 = all([(list1[0] in num),(list2[0] in num),(list3[0] in num)])
T5 = all([(list1[1] in num),(list2[1] in num),(list3[1] in num)])
T6 = all([(list1[2] in num),(list2[2] in num),(list3[2] in num)])
T7 = all([(list1[0] in num),(list2[1] in num),(list3[2] in num)])
T8 = all([(list1[2] in num),(list2[1] in num),(list3[0] in num)])
if (any([T1,T2,T3,T4,T5,T6,T7,T8])) == True:
print("Yes")
else:
print("No") | n = int(input())
i = 1
while i <= n:
if i%3 == 0:
print(' ' + str(i), end="")
else:
num = i
while 0 < num:
if num % 10 == 3:
print(' ' + str(i), end="")
break
num //= 10
i += 1
print() | 0 | null | 30,524,535,298,896 | 207 | 52 |
N=int(input())
import copy
raw=[0]*10
a=[]
for i in range(10):
a.append(copy.deepcopy(raw))
ans=0
#print(a)
for i in range(1,N+1):
temp=str(i)
#print(temp)
a[int(temp[0])][int(temp[-1])]+=1
#print(a)
for i in range(10):
for j in range(10):
ans+=a[i][j]*a[j][i]
print(ans)
| import sys
N=int(input())
A=list(map(int,input().split()))
M=10**9+7
G={k:0 for k in range(-1,max(A)+1)}
G[-1]=3
X=1
for a in A:
X*=G[a-1]-G[a]
X%=M
G[a]+=1
print(X)
| 0 | null | 108,145,677,472,800 | 234 | 268 |
from functools import reduce
from math import gcd, sqrt,ceil
n = int(input())
a = list(map(int,input().split()))
m = 10**6
a_gcd = reduce(gcd,a)
if a_gcd != 1:
print("not coprime")
exit(0)
isset = a_gcd == 1
hurui = [i for i in range(m+1)]
for i in range(2,ceil(sqrt(m))+1):
for j in range(2,ceil(sqrt(i))+1):
if i==2:
continue
if i%j == 0:
break
else:
for k in range(i+i,m,i):
if hurui[k] != k:
continue
hurui[k] = i
continue
s = set()
p_f = True
for ai in a:
t = set()
while(ai > 1):
t.add(hurui[ai])
ai //= hurui[ai]
for ti in t:
if ti in s:
print("setwise coprime")
exit(0)
else:
s.add(ti)
print("pairwise coprime") | n=int(input())
s=[]
for i in range(n):
s.append(input())
s.sort()
t=1
m=0
a=s[0]
for i in range(n-1):
if s[i+1]==a:
t+=1
else:
a=s[i+1]
m=max(t,m)
t=1
m=max(t,m)
t=1
x=[]
a=s[0]
for i in range(n-1):
if s[i+1]==a:
t+=1
else:
a=s[i+1]
if t==m:
x.append(s[i])
t=1
if t==m:
x.append(s[len(s)-1])
for i in range(len(x)):
print(x[i]) | 0 | null | 36,890,562,048,540 | 85 | 218 |
H, A = map(int, input().split())
res = H // A
if H % A:
res += 1
print(res) | H, A = map(int, input().split())
count = 0
while True:
H -= A
count += 1
if H <= 0:
print(count)
exit() | 1 | 77,146,995,121,952 | null | 225 | 225 |
while True:
H, W = map(int, input().split())
if H == W == 0:
break
for i in range(H):
if i % 2 == 0:
if W % 2 != 0:
print("#." * (W // 2) + "#")
continue
print("#." * (W // 2))
else:
if W % 2 != 0:
print(".#" * (W // 2) + ".")
continue
print(".#" * (W // 2))
print() | while True:
h, w = map(int, input().split())
if h == w == 0: break
for c in ['\n' if y == w else '#' if (x+y) % 2 == 0 else '.' for x in range(0,h) for y in range(0, w + 1)]: print(c, end='')
print('') | 1 | 877,279,181,888 | null | 51 | 51 |
#!/usr/bin/python
ar = []
while True:
tmp = [int(i) for i in input().split()]
if tmp == [0,0]:
break
else:
ar.append(tmp)
for i in range(len(ar)):
for j in range(ar[i][0]):
for k in range(ar[i][1]):
if j == 0 or j == ar[i][0] - 1 or k == 0 or k == ar[i][1] - 1:
print('#' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n')
else:
print('.' , end='' if k !=ar[i][1]-1 else '\n' if j != ar[i][0]-1 else '\n\n') | while True:
h,w=map(int,input().split())
if h==0 and w==0:
break
for y in range(h):
for x in range(w):
if y==0 or y==h-1 or x==0 or x==w-1:
print("#",end='')
else:
print(".",end='')
print()
print() | 1 | 826,917,414,662 | null | 50 | 50 |
N=int(input())
A=list(map(int, input().split()))
for a in A:
if a%2==0:
if a%3==0 or a%5==0:
continue
else:
print("DENIED")
exit()
print("APPROVED") | n = int(input())
a = [int(x) for x in input().split()]
for i in a:
if i%2==0:
if i%3!=0 and i%5!=0:
print("DENIED")
exit()
print("APPROVED") | 1 | 69,148,592,587,220 | null | 217 | 217 |
S, T = [input() for _ in range(2)]
cnt = 0
for i, c in enumerate(S):
if c != T[i]:
cnt += 1
print(cnt) | a = list(input())
b = list(input())
num = len(a)
S = 0
for i in range(num):
if a[i] != b[i]:
S += 1
print(S) | 1 | 10,554,257,921,860 | null | 116 | 116 |
while(True):
x, y = map(int, input().split())
if(x == y == 0):
break
if(x <= y):
print("%d %d" % (x, y))
else:
print("%d %d" % (y, x)) | import sys
def number():
a = []
b = []
i = 0
while True:
x,y = map(int,input().split())
if x == 0 and y == 0:
break
a.append(x)
b.append(y)
i += 1
for j in range(len(a)):
if a[j] < b[j]:
print (a[j],b[j])
else:
print (b[j],a[j])
if __name__ == "__main__":
number() | 1 | 512,709,995,490 | null | 43 | 43 |
import sys
input = sys.stdin.readline
def log(*args):
print(*args, file=sys.stderr)
def main():
n = int(input().rstrip())
ans = [0 for _ in range(n)]
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
if tmp > n:
break
# if x == y == z:
# ans[tmp - 1] = 1
# elif x == y or y == z or z == x:
# ans[tmp - 1] = 3
# else:
# ans[tmp - 1] = 6
ans[tmp - 1] += 1
for v in ans:
print(v)
if __name__ == '__main__':
main()
| def cal(i,j,k):
a = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i
return a
N = int(input())
ans = [0] * (N + 1)
m = int(N ** 0.5)
for i in range(1,m):
for j in range(1,m):
for k in range(1,m):
if cal(i,j,k) <= N:
ans[cal(i,j,k)] += 1
for i in range(1,N+1):
print(ans[i]) | 1 | 7,887,126,665,572 | null | 106 | 106 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = [0]
for i in range(n):
s.append((s[-1] + a[i] - 1) % k)
# dic = {remainder:number}
dic = {0:1}
ans = 0
if n < k:
for i in range(1, n+1):
if s[i] in dic:
ans += dic[s[i]]
dic[s[i]] += 1
else:
dic[s[i]] = 1
else:
for i in range(1, k):
if s[i] in dic:
ans += dic[s[i]]
dic[s[i]] += 1
else:
dic[s[i]] = 1
for i in range(k, n+1):
dic[s[i-k]] -= 1
if s[i] in dic:
ans += dic[s[i]]
dic[s[i]] += 1
else:
dic[s[i]] = 1
print(ans) | s=input()
p=input()
s2=s*2
ren=s2.count(p)
if ren==0:
print('No')
else:
print('Yes')
| 0 | null | 69,990,285,490,970 | 273 | 64 |
def solve():
N, K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())
ans = -float("inf")
for pos in range(N):
used = [-1] * N
cost = [0] * (N+1)
for k in range(N+1):
if k:
cost[k] = cost[k-1] + C[pos]
if used[pos] >= 0:
loop_size = k-used[pos]
break
used[pos] = k
pos = P[pos] - 1
if cost[loop_size] <= 0:
ans = max(ans, max(cost[1:K+1]))
else:
a, b = divmod(K, loop_size)
v1 = cost[loop_size] * (a-1) + max(cost[:K+1])
v2 = cost[loop_size] * a + max(cost[:b+1])
ans = max(ans, max(v1, v2) if a else v2)
print(ans)
solve()
| import math
def solve():
N = int(input())
A = list(map(int, input().split()))
if(N == 0 and A[0] == 1):
print(1)
return
leaf_list = [0] * (N+1)
for d in range(N, -1 , -1):
if(d == N):
leaf_list[d] = (A[d],A[d])
else:
Min = math.ceil(leaf_list[d+1][0]/2) + A[d]
Max = leaf_list[d+1][1] + A[d]
leaf_list[d] = (Min,Max)
if(not(leaf_list[0][0] <= 1 and leaf_list[0][1] >= 1)):
print(-1)
return
node_list = [0] * (N+1)
node_list[0] = 1
for d in range(1, N+1):
node_list[d] = min((node_list[d-1] - A[d-1]) * 2, leaf_list[d][1])
print(sum(node_list))
solve() | 0 | null | 12,175,610,761,002 | 93 | 141 |
N = int(input())
X = input()
x = X[::-1]
one = X.count('1')
up = 0
down = 0
for i in range(N):
up += (int(x[i]) * pow(2,i,one+1) % (one+1))
up %= one+1
if one > 1:
down += (int(x[i]) * pow(2,i,one-1) % (one-1))
down %= one-1
# print(up,down)
def f(ud,one):
if one <= 0:
return 0
else:
if ud == 0:
return 1
cnt = 0
while ud != 0:
ud = ud % one
one = format(ud,'b').count('1')
cnt += 1
return cnt
for i in range(len(X)):
if X[i] == '1':
if one > 1:
print(f((down - pow(2,(len(X)-1) - i, one-1)) % (one-1),one-1))
#print(down - pow(2,(len(X)-1) - i, one-1) % (one-1))
else:
print(0)
else:
print(f((up + pow(2,(len(X)-1) - i, one+1)) % (one+1),one+1))
#print(up + pow(2,(len(X)-1) - i, one+1) % (one+1))
| N = int(input())
x = list(input())[::-1]
num = 0
nump = 0
numm = 0
pop_num = 0
for i in range(N):
if x[i] == "1":
pop_num += 1
for i in range(N):
if x[i] == "1":
num += pow(2,i,pop_num)
num %= pop_num
nump += pow(2,i,pop_num+1)
nump %= pop_num + 1
if pop_num-1 != 0:
numm += pow(2,i,pop_num - 1)
numm %= pop_num - 1
def popcnt(n):
c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
return c
x = x[::-1]
def calc(i,depth,n):
if depth == 0:
if x[i] == "1":
tmp = numm
if pop_num - 1 != 0:
tmp -= pow(2,N-i-1,pop_num-1)
tmp %= (pop_num - 1)
else:
return 0
return calc(i,depth+1,tmp)
else:
tmp = nump
tmp += pow(2,N-i-1,pop_num+1)
tmp %= (pop_num + 1)
return calc(i,depth+1,tmp)
else:
if n == 0: return depth
return calc(i,depth+1, n % popcnt(n))
for i in range(N):
print(calc(i,0,0))
| 1 | 8,151,420,939,288 | null | 107 | 107 |
K = int(input())
S =input()
def cmb(n,r,p):
if(r<0) or (n<r):
return 0
return fact[n]*factinv[r]*factinv[n-r]%p
p = 10 ** 9 + 7
N = 2 * 10**6+3
fact = [1] * ( N + 3)
factinv = [1] * (N + 3)
inv = [0]* (N + 3)
inv[1] = 1
for i in range(2,N+1):
fact[i] = fact[i-1] * i % p
inv[i] = p-inv[p % i] * (p//i) % p
factinv[i] = factinv[i-1] * inv[i] % p
def powmod(a,n,mod):
res = 1
while n > 0:
if n & 1:
res = res * a % mod
a = a * a % mod
n>>=1
return res
ss = len(S)
ans = 0
k = 1;
for i in range(K+1):
ans += cmb(ss+K-i-1,ss-1,p) * k * powmod(25,K-i,p)
ans %= p
k = k * 26 % p
print(ans) | k = int(input())
s = str(input())
mod = 1000000007
decided_keta = len(s)
all_keta = len(s) + k
kai_list = [1 for i in range(2000010)]
for i in range(2,len(kai_list)):
kai_list[i] = (kai_list[i-1]*i)%mod
answer = 0
for last_given_character_posi in range(decided_keta-1,all_keta):
given_posi_pattern = kai_list[last_given_character_posi]*pow(kai_list[decided_keta-1],mod-2,mod)%mod*pow(kai_list[last_given_character_posi-decided_keta+1],mod-2,mod)%mod
char_pattern = pow(25,last_given_character_posi-(decided_keta-1),mod)
rest_char_pattern = pow(26,all_keta-(last_given_character_posi+1),mod)
answer = (answer + given_posi_pattern*char_pattern%mod*rest_char_pattern%mod)%mod
print(answer) | 1 | 12,846,162,960,554 | null | 124 | 124 |
r = int(input())
print(r*2*314/100) | # -*- coding: utf-8 -*-
import math
a = int(input())
print(2*a*math.pi) | 1 | 31,539,665,741,298 | null | 167 | 167 |
def main():
n = int(input())
# a, b, c, d = map(int, input().split())
a = list(map(int, input().split()))
# s = input()
mx = 0
result = 0
for num in a:
mx = max(mx, num)
if mx > num:
result += mx - num
print(result)
if __name__ == '__main__':
main()
| import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ
class Heap:
def __init__(self, data, reverse=False):
self.reverse = -1 if reverse else 1
self.data = [self.reverse * d for d in data]
HQ.heapify(self.data)
def push(self, x): return HQ.heappush(self.data, self.reverse * x)
def pop(self): return self.reverse * HQ.heappop(self.data)
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())
n = I()
xs = Is()
ans = 0
now = xs[0]
for x in xs[1:]:
if x < now:
ans += (now - x)
now = max(x, now)
print(ans) | 1 | 4,486,407,839,010 | null | 88 | 88 |
from sys import stdin
n = int(stdin.readline().strip())
a_lst = [int(x) for x in stdin.readline().strip().split()]
pos = len(a_lst) // 2
min_diff = 10000000000000000000
while(True):
left = sum(a_lst[:pos])
right = sum(a_lst[pos:])
diff = right - left
if min_diff > abs(diff): min_diff = abs(diff)
else: break
if diff > 0: pos += 1
elif diff < 0: pos -= 1
print(min_diff) | s=input()
k=int(input())
cnt=1
temp=[]
for i in range(len(s)-1):
if s[i]==s[i+1]: cnt+=1
else:
temp.append([s[i],cnt])
cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
print(k*len(s)//2)
exit()
ans=0
if temp[0][0]!=temp[-1][0]:
for pair in temp:
if pair[1]!=1: ans+=pair[1]//2
print(ans*k)
else:
for pair in temp[1:-1]:
if pair[1]!=1: ans+=pair[1]//2
ans*=k
ans+=(k-1)*((temp[0][1]+temp[-1][1])//2)
ans+=temp[0][1]//2+temp[-1][1]//2
print(ans) | 0 | null | 158,561,867,883,740 | 276 | 296 |
import sys
input=sys.stdin.readline
def main():
r,c,k=map(int,input().split())
v=[0] * (c * r)
for _ in range(k):
ri,ci,a=map(int,input().split())
v[(ri-1)*c + (ci-1)]=a
dp= [0] * (c * r * 4)
#print(dp)
x = c * r
if v[0]>0: dp[x] = v[0]
for i in range(r):
for j in range(c):
idx = i*c+j
idx2 = (i-1)*c + j
idx3 = i*c + j-1
if i>0:
dp[x + idx] = max(dp[x + idx], dp[idx2]+v[idx])
dp[idx] = max(dp[idx],dp[idx2])
dp[x + idx]=max(dp[x + idx],dp[x + idx2]+v[idx])
dp[idx]=max(dp[idx],dp[x + idx2])
dp[x + idx]=max(dp[x + idx],dp[2*x + idx2]+v[idx])
dp[idx]=max(dp[idx],dp[2*x + idx2])
dp[x + idx]=max(dp[x + idx],dp[3*x + idx2]+v[idx])
dp[idx]=max(dp[idx],dp[3*x + idx2])
if j>0:
dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx])
dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx])
dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx])
dp[idx]=max(dp[idx],dp[idx3])
dp[x + idx]=max(dp[x + idx],dp[x + idx3])
dp[2*x + idx]=max(dp[2*x + idx],dp[2*x + idx3])
dp[3*x + idx]=max(dp[3*x + idx],dp[3*x + idx3])
#print(dp)
ans=0
for i in range(4): ans=max(dp[i*x + (r-1)*c + (c-1)],ans)
return print(ans)
if __name__=="__main__":
main()
| import sys
# import time
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
# dp = [[[0] * 3 for _ in range(c + 5)] for _ in range(r + 5)]
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]
for i in range(k):
r1, c1, v = map(int, input().split())
# dp[r1][c1][0] = v
pt[r1][c1] = v
# start = time.time()
a = 0
def solve():
memo = [[0] * 4 for _ in range(c + 1)]
prev = [[0] * 4 for _ in range(c + 1)]
for i in range(1, r + 1):
memo, prev = prev, memo
for j in range(1, c + 1):
V = pt[i][j]
memo[j][0] = max(prev[j][3], memo[j - 1][0])
memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])
# dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
# dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
# dp[i][j][0])
# dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
# dp[i][j][1])
# process_time = time.time() - start
# print(process_time)
# print(dp[r][c][2])
return memo[-1][3]
if __name__ == '__main__':
print(solve())
| 1 | 5,553,835,790,882 | null | 94 | 94 |
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, 10**5 + 1):
fact.append((fact[-1] * i) % Mod)
inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
factinv.append((factinv[-1] * inv[-1]) % Mod)
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
def sieve_of_eratosthenes(n):
if not isinstance(n,int):
raise TypeError("n is not int")
if n<2:
raise ValueError("n is not effective")
prime = [1]*(n+1)
for i in range(2,int(math.sqrt(n))+1):
if prime[i] == 1:
for j in range(2*i,n+1):
if j%i == 0:
prime[j] = 0
res = []
for i in range(2,n+1):
if prime[i] == 1:
res.append(i)
return res
class UnionFind:
def __init__(self,n):
self.parent = [i for i in range(n+1)]
self.rank = [0 for i in range(n+1)]
def findroot(self,x):
if x == self.parent[x]:
return x
else:
y = self.parent[x]
y = self.findroot(self.parent[x])
return y
def union(self,x,y):
px = self.findroot(x)
py = self.findroot(y)
if px < py:
self.parent[y] = px
else:
self.parent[px] = py
def same_group_or_no(self,x,y):
return self.findroot(x) == self.findroot(y)
def main(): #startline-------------------------------------------
n = int(input())
ls = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
val = list(str(i))
ls[int(val[-1])][int(val[0])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += ls[i][j] * ls[j][i]
print(ans)
if __name__ == "__main__":
main() #endline=============================================== | def myfindall(s,ps):
# start = 0
matchlist =[]
while True:
tmp = s.find(ps)
if tmp < 0 :
break
if len(matchlist)>0:
matchlist.append(tmp+matchlist[-1]+1)
else:
matchlist.append(tmp)
s = s[tmp+1:]
return matchlist
instr = raw_input()
findstr = raw_input()
matchlist = myfindall(instr,findstr[0])
matchflag = False
y=0
for x in matchlist:
if matchflag:
break
while True:
if y >= len(findstr):
print "Yes"
matchflag = True
break
if x >= len(instr):
x = 0
if instr[x]==findstr[y]:
x+=1
y+=1
else:
y=0
break
if not matchflag:
print "No" | 0 | null | 43,932,861,592,572 | 234 | 64 |
A = sum([list(map(int,input().split()))for _ in range(3)],[])
N = int(input())
b = [int(input()) for _ in range(N)]
f=0
for i in range(9):
if A[i]in b:f|=1<<i
ans=[v for v in [7,56,73,84,146,273,292,448]if f&v==v]
print('Yes' if ans else 'No')
| # -*- coding: utf-8 -*-
"""
Created on Sun Aug 9 20:50:35 2020
@author: akros
"""
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 9 16:51:42 2020
@author: akros
"""
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
a = []
for i in range(N):
a.append(int(input()))
if A1[0] == a[i]:
A1[0] = True
elif a[i] == A1[1]:
A1[1] = True
elif a[i] == A1[2]:
A1[2] = True
elif a[i] == A2[0]:
A2[0] = True
elif a[i] == A2[1]:
A2[1] = True
elif a[i] == A2[2]:
A2[2] = True
elif a[i] == A3[0]:
A3[0] = True
elif a[i] == A3[1]:
A3[1] = True
elif a[i] == A3[2]:
A3[2] = True
if A1[0] == True and A1[1] == True and A1[2] == True:
print("Yes")
elif A1[0] == True and A2[0] == True and A3[0] == True:
print("Yes")
elif A1[0] == True and A2[1] == True and A3[2] == True:
print("Yes")
elif A1[1] == True and A2[1] == True and A3[1] == True:
print("Yes")
elif A1[2] == True and A2[2] == True and A3[2] == True:
print("Yes")
elif A2[0] == True and A2[1] == True and A2[2] == True:
print("Yes")
elif A3[0] == True and A3[1] == True and A3[2] == True:
print("Yes")
elif A1[2] == True and A2[1] == True and A3[0] == True:
print("Yes")
else:
print("No")
| 1 | 59,564,722,334,140 | null | 207 | 207 |
# 16-Character-Sum_of_Numbers.py
# ??°?????????
# ?????????????????°???????????????????¨??????????????????°?????????????????????????????????
# Input
# ?????°??????????????????????????\?????¨??????????????????????????????????????????????????????????????´??° x ?????????????????§?????????????????????
# x ??? 1000 ?????\????????´??°??§??????
# x ??? 0 ?????¨?????\?????????????????¨??????????????????????????????????????????????????????????????£????????????????????????
# Output
# ????????????????????????????????????x ???????????????????????????????????????????????????
# Sample Input
# 123
# 55
# 1000
# 0
# Sample Output
# 6
# 10
# 1
data=[]
while 1:
temp = int( input() )
if temp==0:
break;
else:
data.append( temp )
for i in range( len(data) ):
num = list( map(int, list( str( data[i] ) ) ) )
print( sum(num) ) | import sys
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v==w or w>v:
print('NO')
sys.exit()
else:
tp=(b-a)/(v-w)
tm=(a-b)/(v-w)
if b>a:
if t>=tp:
print('YES')
else:
print('NO')
else:
if t>=tm:
print('YES')
else:
print('NO')
| 0 | null | 8,330,291,651,460 | 62 | 131 |
X = int(input())
for a in range(-1000, 1000):
for b in range(-1000, 1000):
if a ** 5 - b ** 5 == X:
print(a, b)
break
else:
continue
break
| import sys
X = int(input())
for a in range(-118,120) :
for b in range(-119,119) :
if a**5 - b**5 == X :
print(a,b)
sys.exit()
| 1 | 25,455,474,766,280 | null | 156 | 156 |
n=int(input())
S=input().split(' ')
q=int(input())
T=input().split(' ')
def equal_element(S,T):
m=0
for i in range(len(T)):
for j in range(len(S)):
if S[j]==T[i]:
m+=1
break
return(m)
print(equal_element(S,T))
| N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
sum = sum(A) ** 2
squ = 0
for i in range(N):
squ += A[i] ** 2
answer = int(((sum - squ) // 2 ) % mod)
print(answer) | 0 | null | 1,973,243,451,190 | 22 | 83 |
x = int(input())
a = 1
flag = True
while flag:
upper = a**5-x
b = a
while True:
if b**5 == upper:
flag = False
a -= 1
break
if b**5<upper:
break
b -= 1
a += 1
print(a,b) | X=int(input())
div=X//100
mod=X%100
print(1 if 5*div>=mod else 0) | 0 | null | 76,081,226,971,970 | 156 | 266 |
#atcoder template
def main():
import sys
imput = sys.stdin.readline
#文字列入力の時は上記はerrorとなる。
#ここにコード
#input
N = int(input())
A, B = [0] * N, [0] * N
for i in range(N):
A[i], B[i] = map(int, input().split())
#output
import statistics as st
import math
p = st.median(A)
q = st.median(B)
# %%
if N % 2 == 0:
print(int((q-p)/0.5)+1)
else:
print(int(q-p)+1)
#N = 1のときなどcorner caseを確認!
if __name__ == "__main__":
main() | n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
if n % 2 == 1:
print(b[n//2] - a[n//2] + 1)
else:
print(b[n//2] + b[n//2-1] - a[n//2] - a[n//2-1] + 1) | 1 | 17,176,113,826,424 | null | 137 | 137 |
a, b, c = map(int, raw_input().split())
num = [a, b, c]
num.sort()
print num[0], num[1], num[2] | while True:
a = list(map(lambda x : int(x), input().split(" ")))
if a[0] == 0 and a[1] == 0:
break
for i in range(a[0]):
for j in range(a[1]):
print("#", end="")
print()
print() | 0 | null | 581,550,540,990 | 40 | 49 |
X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)
| s=int(raw_input())
print str(s//3600)+':'+str(s//60%60)+':'+str(s%60) | 0 | null | 21,384,214,242,812 | 185 | 37 |
data = {
'S': [int(x) for x in range(1,14)],
'H': [int(x) for x in range(1,14)],
'C': [int(x) for x in range(1,14)],
'D': [int(x) for x in range(1,14)]
}
count = int(input())
for c in range(count):
(s, r) = input().split()
r = int(r)
del data[s][data[s].index(r)]
for i in ('S', 'H', 'C', 'D'):
for v in data[i]:
print(i, v) | # Function for calc
def match(n, a, b):
if (b - a)% 2 == 0:
print((b-a)/2)
else:
if (n - b) >= a:
print((a)+((b-(a+1))/2))
else:
x=(n-b+1)
print(x+((n-(a+x))/2))
# Run match
in_string = raw_input()
[N, A, B] = [int(v) for v in in_string.split()]
match(N, A, B)
| 0 | null | 55,384,996,627,040 | 54 | 253 |
n = int(input())
arr = []
for i in range(n):
x,y = list(map(int,input().split()))
arr.append((x,y))
arr = sorted(arr)
ans = 0
pre = 1e10
for i in range(n):
ans = max(ans, arr[i][0] + arr[i][1] - pre)
pre = min(pre, arr[i][0] + arr[i][1])
pre = 1e10
for i in range(n):
ans = max(ans, arr[i][0] - arr[i][1] - pre)
pre = min(pre, arr[i][0] - arr[i][1])
print(ans) | N = int(input())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
tmp = sum(v*(v-1)//2 for v in ctr.values())
for a in A:
print(tmp - ctr[a] + 1) | 0 | null | 25,750,138,167,722 | 80 | 192 |
nm = input().split(" ")
n = int(nm[0])
m = int(nm[1])
if n == m:
print("Yes")
else:
print("No") | n,m = list(map(int,input().split()))
if n ==m:
print("Yes")
if n!=m:
print("No") | 1 | 83,311,352,155,290 | null | 231 | 231 |
A = list(map(int, input().split()))
#print(A)
def hantei(list):
for a in range(len(list)):
if list[a] == 0:
return a+1
print(hantei(A)) | def resolve():
X = list(map(int, input().split()))
print(X.index(0)+1)
if '__main__' == __name__:
resolve() | 1 | 13,454,445,724,290 | null | 126 | 126 |
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
num = 0
for i in A:
num += i
if A[M-1] >= num/(4*M):
print('Yes')
else:
print('No') | import sys
while 1:
H, W = map(int, raw_input().split())
if H==0 and W==0:
break
for i in range(H):
for j in range(W):
if (i+j)%2==0:
sys.stdout.write('#')
else:
sys.stdout.write('.')
sys.stdout.write('\n')
print '' | 0 | null | 19,809,513,364,960 | 179 | 51 |
while 1:
string = raw_input()
if string == "-":
break
l = len(string)
for i in xrange(int(input())):
h = int(input())
lower = string[0:h]
upper = string[h:l]
string = upper + lower
print string | while True:
cards=input()
if cards=="-":break
for i in range(int(input())):
h=int(input())
cards=cards[h:]+cards[:h]
print(cards)
| 1 | 1,869,448,378,940 | null | 66 | 66 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
h = [int(input()) for i in range(10)]
h.sort()
h.reverse()
print(h[0])
print(h[1])
print(h[2]) | n = int(raw_input())
card = [i+" "+str(j) for i in "SHCD" for j in range(1,14)]
for i in range(n):
card.remove(raw_input())
pass
for i in card:
print i
| 0 | null | 530,464,767,048 | 2 | 54 |
import numpy as np
mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
for num, a in enumerate(A):
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP[a] += pow(2, num, mod)
DP %= mod
print(DP[s])
| n,m=map(int,input().split())
l=[[0,0] for i in range(n)]
for i in range(m):
p,s=input().split()
p=int(p)
if s=="AC":
if l[p-1][0]!=1:
l[p-1][0]=1
else:
if l[p-1][0]!=1:
l[p-1][1]+=1
ac=0
wa=0
for i in range(len(l)):
ac+=l[i][0]
if l[i][0]!=0:
wa+=l[i][1]
print(ac,wa) | 0 | null | 55,521,855,164,698 | 138 | 240 |
N, K, S = map(int,input().split())
if S != 10**9:
A = [S]*K + [S+1]*(N-K)
else:
A = [S]*K + [1]*(N-K)
print(*A)
| n, k, s = map(int, input().split())
ans = []
for i in range(k):
ans.append(s)
for i in range(n-k):
if s == 10**9:
ans.append(10**9-1)
else:
ans.append(s+1)
print(*ans, sep=' ')
| 1 | 91,312,565,390,210 | null | 238 | 238 |
N = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N, 2):
if a[i] % 2 == 1:
cnt += 1
print(cnt) | n = int(input())
z = input().split()
odd = 0
for i in range(n):
if i % 2 == 0:
if int(z[i]) % 2 == 1:
odd += 1
print(odd) | 1 | 7,804,305,160,870 | null | 105 | 105 |
def main():
x_tuple = tuple(map(int, input().split()))
print(x_tuple.index(0) + 1)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
def solve(x: "List[int]"):
return x.index(0) + 1
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
x = [int(next(tokens)) for _ in range(5)] # type: "List[int]"
print(solve(x))
if __name__ == '__main__':
main()
| 1 | 13,377,568,778,982 | null | 126 | 126 |
def bubble_sort(data):
for i in range(len(data) - 1):
for j in range(len(data) - 1, i, -1):
if int(data[j][1]) < int(data[j - 1][1]):
data[j], data[j - 1] = data[j - 1], data[j]
def selection_sort(data):
for i in range(len(data)):
min_j = i
for j in range(i, len(data)):
if int(data[j][1]) < int(data[min_j][1]):
min_j = j
if min_j != i:
data[i], data[min_j] = data[min_j], data[i]
input()
cards = [x for x in input().split()]
cards_b = cards.copy()
cards_s = cards.copy()
bubble_sort(cards_b)
selection_sort(cards_s)
for data in [cards_b, cards_s]:
print(' '.join(data))
if data == cards_b:
print("Stable")
else:
print("Not stable") | def bubblesort(N, A):
C, flag = [] + A, True
while flag:
flag = False
for j in range(N-1, 0, -1):
if int(C[j][1]) < int(C[j-1][1]):
C[j], C[j-1] = C[j- 1], C[j]
flag = True
return C
def selectionSort(N, A):
C = [] + A
for i in range(N):
minj = i
for j in range(i,N):
if int(C[j][1]) < int(C[minj][1]):
minj = j
C[i], C[minj] = C[minj], C[i]
return C
N, A= int(input()), input().split()
Ab = bubblesort(N, A)
print(*Ab)
print('Stable')
As = selectionSort(N, A)
print(*As)
if Ab != As:
print('Not stable')
else:
print('Stable') | 1 | 23,916,259,532 | null | 16 | 16 |
import sys
while 1:
H,W = map(int,sys.stdin.readline().split())
if H == W == 0:
break
print(('#'*W + '\n')*H) | import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
cnt = 0
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) ) | 0 | null | 401,754,403,322 | 49 | 17 |
N = input()
A=[]
for i in N:
A.append(i)
hon = ["2","4","5","7","9"]
pon = ["0","1","6","8"]
bon = ["3"]
if A[-1] in hon:
print("hon")
elif A[-1] in pon:
print("pon")
else:
print("bon") | def main() -> None:
n = input()
if n[-1] in ['2', '4', '5', '7', '9']:
print('hon')
elif n[-1] in ['0', '1', '6', '8']:
print('pon')
else:
print('bon')
return
if __name__ == '__main__':
main()
| 1 | 19,305,453,844,960 | null | 142 | 142 |
while True:
H,W = map(int,input().split())
if H == W == 0:
break
for i in range(H):
print(('#.'*W)[i%2:][:W])
print()
| while True:
[H,W]=[int(x) for x in input().split()]
if [H,W]==[0,0]:
break
unit="#."
for i in range(0,H):
print(unit*(W//2)+unit[0]*(W%2))
unit=unit[1]+unit[0]
print("") | 1 | 869,318,120,100 | null | 51 | 51 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
r = [0]*n
index = 0
for i in range(1,n+1) :
if b[a[index]-1] != 0 :
break
b[a[index]-1] = i
index = a[index] - 1
for i in range(1,n+1) :
if r[a[index]-1] != 0 :
break
r[a[index]-1] = i
index = a[index] - 1
maxb = max(b)
maxr = max(r)
if k <= maxb :
print(b.index(k)+1)
else :
k = k - maxb
if k%maxr == 0 :
print(r.index(maxr)+1)
else :
print(r.index(k%maxr)+1) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n, k = LI()
a = LI()
check_num = [-1] * n
idx = 0
cnt = 1
while 1:
idx = a[idx] - 1
if check_num[idx] != -1:
s = check_num[idx] - 1
cnt -= 1
break
check_num[idx] = cnt
cnt += 1
if cnt >= k:
for i in range(n):
if check_num[i] == k:
print(i+1)
quit()
else:
roop_num = cnt - s
x = (k - (s + 1)) % roop_num
for i in range(n):
if check_num[i] - s - 1 == x:
print(i+1)
quit() | 1 | 22,628,228,641,118 | null | 150 | 150 |
#!/usr/bin/env python3
n, r = map(int, input().split())
print(r + 100 * (10 - n) * (10 > n))
| import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
a, b = map(int, input().split())
c = a - b*2
if c < 0:
print(0)
return
print(c)
main()
| 0 | null | 114,414,817,347,868 | 211 | 291 |
def multi():
for i in range(1, 10):
for j in range(1, 10):
print(str(i) + "x" + str(j) + "=" + str(i * j))
if __name__ == '__main__':
multi()
| for i in range(1, 10):
for ii in range(1, 10):
print('{}x{}={}'.format(i, ii, i*ii)) | 1 | 448,448 | null | 1 | 1 |
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0 and n >= 4:
dp = [[0, 0] for i in range(n)]
dp[0][0] = a[0]
dp[1][1] = a[1]
dp[2][0] = a[0] + a[2]
for i in range(3, n):
dp[i][0] = dp[i - 2][0] + a[i]
dp[i][1] = max(dp[i - 3][0], dp[i - 2][1]) + a[i]
print(max(dp[n - 2][0], dp[n - 1][1]))
elif n % 2 != 0 and n >= 5:
dp = [[0, 0, 0] for i in range(n)]
dp[0][0] = a[0]
dp[1][1] = a[1]
dp[2][0] = a[0] + a[2]
dp[2][2] = a[2]
dp[3][1] = a[1] + a[3]
dp[3][2] = a[0] + a[3]
for i in range(3, n):
dp[i][0] = dp[i - 2][0] + a[i]
dp[i][1] = max(dp[i - 3][0], dp[i - 2][1]) + a[i]
dp[i][2] = max(dp[i - 4][0], dp[i - 3][1], dp[i - 2][2]) + a[i]
print(max(dp[n - 3][0], dp[n - 2][1], dp[n - 1][2]))
elif n == 2:
print(max(a[0], a[1]))
else:
print(max(a[0], a[1], a[2])) | s = input()
t = input()
c = 0
for i in range(len(s)):
if not s[i] == t[i]:
c += 1
print(c) | 0 | null | 23,876,941,123,670 | 177 | 116 |
s = input()
if s.isupper():
print("A")
else:
print("a")
| a = ord(input())
if ord("a") <= a <= ord("z"):
print("a")
else:
print("A")
| 1 | 11,212,188,100,152 | null | 119 | 119 |
t = int(input())
s = t**3
print(s) | cube = input()
print(cube**3) | 1 | 276,900,726,802 | null | 35 | 35 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
ans = float("inf")
for i in range(1, n+1):
if n%i==0:
ans = min(ans, i+n//i)
if i*i>n:
break
print(ans-2) | S = int(input())
A = [0,0,1]
if S == 1 or S == 2:
print(0)
elif S == 3:
print(1)
else:
for i in range(3,S):
A += [A[i-1] + A[i-3]]
print(A[i] % (10 ** 9 + 7)) | 0 | null | 82,409,089,682,696 | 288 | 79 |
n = int(input())
for i in range(9, 0, -1):
if n % i == 0 and n // i <= 9:
print('Yes')
exit()
print('No') | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: D
# CreatedDate: 2020-08-30 13:56:28 +0900
# LastModified: 2020-08-30 14:22:16 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter
def main():
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
takahashi = ''
for t in T:
if t == 's':
takahashi += 'r'
elif t == 'p':
takahashi += 's'
else:
takahashi += 'p'
for i in range(K, N):
if takahashi[i-K] == takahashi[i]:
takahashi = takahashi[:i] + '_' + takahashi[i+1:]
ans = takahashi.count('r')*R + takahashi.count('s')*S + takahashi.count('p')*P
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 133,953,745,803,762 | 287 | 251 |