Harryxun/stf_run huggingface dataset:
# coding: utf-8
# Your code here!

n,k=map(int,input().split())

p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))

lps=[]
vtd=[False]*n
for i in range(n):
    if vtd[i]:continue
    now=p[i]
    vtd[now]=True
    vc=set()
    vc.add(now)
    while now!=i:
        now=p[now]
        vtd[now]=True
        vc.add(now)
    point=0
    for v in vc:
        point+=c[v]
    lps.append((list(vc),point))
# print(lps)
anslist=[]
for lp in lps:
    loop=lp[0]
    ls=len(loop)
    point=lp[1]
    if point<=0:
        ans=max(c)
        for first in loop:
            tmp=0
            now=first
            for j in range(min(k,ls)):
                now=p[now]
                tmp+=c[now]
                ans=max(ans,tmp)
        anslist.append(ans)

    if point>0:
        s=vc[100000]
        ans=max(c)
        for first in loop:
            tmp=0
            now=first
            for j in range(k%ls+1):
                now=p[now]
                tmp+=c[now]
                ans=max(ans,tmp)
        anslist.append(ans+point*(k//ls-1))
print(max(anslist))



### FIXED CODE ###

N,K=map(int,input().split())
P=[int(a)-1 for a in input().split()]
C=[int(a) for a in input().split()]
ans=-float("inf")
for si in range(N):
  x=si
  S=[]
  tot=0
  while True:
    x=P[x]
    S.append(C[x])
    tot+=C[x]
    if x==si:
      break
  L=len(S)
  t=0
  for i in range(L):
    t+=S[i]
    if i+1>K:
      break
    now=t
    if tot>0:
      e=(K-i-1)//L
      now+=tot*e
    ans=max(ans,now)
    
print(ans)
n = input()
answer = 0
for i in range(1, n):
	answer += i

print(answer)

### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    answer = (N-1)*N//2
    print(answer)
    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
    solve(N)

if __name__ == '__main__':
    main()
h,w=map(int,input().split())
s=[list(input()) for i in range(w)]
inf = h*w
d=[[inf]*h for i in range(w)]
if s[0][0]=="#":
    d[0][0]=1
else:
    d[0][0]=0
# def tate(x,y):
#     if x==0:
#         return d[x][y]
#     if s[x-1][y]=="#":
#         return tate(x-1,y)
#     return d[x-1][y]
# def yoko(x,y):
#     if y==0:
#         return d[x][y]
#     if s[x][y-1]=="#":
#         return yoko(x,y-1)
#     return d[x][y-1]
for j in range(1,w):
    if s[0][j]=="#" and s[0][j-1]==".":
        d[0][j]=d[0][j-1]+1
    else:
        d[0][j]=d[0][j-1]
for i in range(1,h):
    if s[i][0]=="#" and s[i-1][0]==".":
        d[i][0]=d[i-1][j]+1
    else:
        d[i][0]=d[i-1][0]
for i in range(1,h):
    for j in range(1,w):
        if s[i][j]=="#" and s[i][j-1]==".":
            p=d[i][j-1]+1
        else:
            p=d[i][j-1]
        if s[i][j]=="#" and s[i-1][j]==".":
            q=d[i-1][j]+1
        else:
            q=d[i-1][j]
        d[i][j]=min(p,q)
# for i in d:
#     print(i)
print(d[-1][-1])

### FIXED CODE ###

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
inf = h*w
d=[[inf]*w for i in range(h)]
if s[0][0]=="#":
    d[0][0]=1
else:
    d[0][0]=0
for j in range(1,w):
    if s[0][j]=="#" and s[0][j-1]==".":
        d[0][j]=d[0][j-1]+1
    else:
        d[0][j]=d[0][j-1]

for i in range(1,h):
    if s[i][0]=="#" and s[i-1][0]==".":
        d[i][0]=d[i-1][0]+1
    else:
        d[i][0]=d[i-1][0]

for i in range(1,h):
    for j in range(1,w):
        if s[i][j]=="#" and s[i][j-1]==".":
            p=d[i][j-1]+1
        else:
            p=d[i][j-1]
        if s[i][j]=="#" and s[i-1][j]==".":
            q=d[i-1][j]+1
        else:
            q=d[i-1][j]
        d[i][j]=min(p,q)
# for i in d:
#     print(i)
print(d[-1][-1])
def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return

  th = math.pi*60.0/180.0

  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_x + 1.0*b_x)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_x + 2.0*b_x)/3.0
  u_x = (t_x - s_x)*cos(th) + (t_y - s_y)*sin(th) + s_x
  u_y = (t_x - s_x)*sin(th) + (t_y - s_y)*cos(th) + s_y

  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %8.f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %8.f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %8.f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)



n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0

print '%.8f %8.f' % (a_x, a_y)
koch(n-1, a_x, a_y, b_x, b_y)
print '%.8f %8.f' % (b_x, b_y)

### FIXED CODE ###

def koch(n, a_x, a_y, b_x, b_y):
  if n == 0:
    return
 
  th = math.pi*60.0/180.0
 
  s_x = (2.0*a_x + 1.0*b_x)/3.0
  s_y = (2.0*a_y + 1.0*b_y)/3.0
  t_x = (1.0*a_x + 2.0*b_x)/3.0
  t_y = (1.0*a_y + 2.0*b_y)/3.0
  u_x = (t_x - s_x)*math.cos(th) - (t_y - s_y)*math.sin(th) + s_x
  u_y = (t_x - s_x)*math.sin(th) + (t_y - s_y)*math.cos(th) + s_y
 
  koch(n-1, a_x, a_y, s_x, s_y)
  print '%.8f %.8f' % (s_x, s_y)
  koch(n-1, s_x, s_y, u_x, u_y)
  print '%.8f %.8f' % (u_x, u_y)
  koch(n-1, u_x, u_y, t_x, t_y)
  print '%.8f %.8f' % (t_x, t_y)
  koch(n-1, t_x, t_y, b_x, b_y)
 
 

import math
n = input()
a_x = 0.0
a_y = 0.0
b_x = 100.0
b_y = 0.0
 
print '%.8f %.8f' % (a_x, a_y)
koch(n, a_x, a_y, b_x, b_y)
print '%.8f %.8f' % (b_x, b_y)
import math
x1,y1,x2,y2 = map(int,raw_input().split(' '))
x = abs(x1 - x2);
y = abs(y1 - y2);
a = y/math.sin(math.radians(45))
print a

### FIXED CODE ###

import math
x1,y1,x2,y2 = map(float,raw_input().split(' '))
x = abs(x1-x2);
y = abs(y1-y2);
a = math.sqrt(x**2 + y**2) 
print a
n=int(input())
a=list(map(int,input().split()))

a=sorted(a)
cnt=0
for i in range(n):
    if i == 0:
        if a[i] == a[i+1]:
            cnt+=1
        continue
    for j in range(i):
        if i == j:
            continue
        else:
            if (a[i]%a[j])==0:
                cnt+=1
                break
ans=n-cnt
print(ans)
           

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))

l=[0]*(10**6+1)
ans=0
#print(l)
for i in a:
    if l[i]==0:
        for j in range(i,10**6+1,i):
            l[j]+=1
    else:
        l[i]+=1
for i in a:
    if l[i]==1:
        ans+=1
print(ans)
import math
a,b=input().split()
b=int(float(b)*100)
s=(int(a)*b)
print(str(s[:-2]) if s>99 else 0)

### FIXED CODE ###

import math
a,b=input().split()
c=int(a)
d1=100*c*int(b[0])
d2=10*c*int(b[2])
d3=1*c*int(b[3])
ds=d1+d2+d3
if ds<100:
  print(0)
else:
  print(str(ds)[:-2])
from collections import deque
import numpy as np
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]
table = [[float('inf')]*(W) for _ in range(H)]
visited = [[False]*(W) for _ in range(H)]
start = []
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            table[i][j] = 0
            start.append((i,j))
for (sy, sx) in start:
    visited[sy][sx] = True
    que = deque([(sx,sy)])
    while que:
        y,x = que.popleft()
        for dy, dx in ((1,0),(-1,0),(0,1),(0,-1)):
            ny,nx = y+dy, x+dx
            if 0<=ny<H and 0<=nx<W:
                if table[ny][nx] == float('inf'):
                    table[ny][nx] = table[y][x]+1
                    que.append((ny, nx))
print(np.array(table).max())


### FIXED CODE ###

from scipy.ndimage import distance_transform_cdt
H,W = map(int,input().split())
S = list(list(input()) for h in range(H))
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            S[h][w] = 0
        else:
            S[h][w] = 1
print(distance_transform_cdt(S, metric='taxicab').max())
from operator import mul
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")

MOD = 998244353
class Combination(object):
	def __init__(self, N, MOD):
		self.fac = [0] * (N + 1)
		self.inv = [0] * (N + 1)
		self.finv = [0] * (N + 1)
		self.fac[0], self.fac[1] = 1, 1
		self.inv[1] = 1
		self.finv[0], self.finv[1] = 1, 1
 
		# 前計算
		for i in range(2, N + 1):
			self.fac[i] = self.fac[i - 1] * i % MOD
			self.inv[i] = self.inv[MOD % i] * (MOD - (MOD // i)) % MOD
			self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD
 
	def com(self, N, k):
		return (self.fac[N] * self.finv[k] * self.finv[N - k]) % MOD


def main():
    N, M, K = map(int, input().split())

    if N == 1:
        print(1)

    Com = Combination(N-1, MOD)
    ans = 0
    for k in reversed(range(K+1)):
        ans += M * pow(M-1, N-k-1, MOD) * Com.com(N-1, k)
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from operator import mul
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")

MOD = 998244353
class Combination(object):
	def __init__(self, N, MOD):
		self.fac = [0] * (N + 1)
		self.inv = [0] * (N + 1)
		self.finv = [0] * (N + 1)
		self.fac[0], self.fac[1] = 1, 1
		self.inv[1] = 1
		self.finv[0], self.finv[1] = 1, 1
 
		# 前計算
		for i in range(2, N + 1):
			self.fac[i] = self.fac[i - 1] * i % MOD
			self.inv[i] = self.inv[MOD % i] * (MOD - (MOD // i)) % MOD
			self.finv[i] = self.finv[i - 1] * self.inv[i] % MOD
 
	def com(self, N, k):
		return (self.fac[N] * self.finv[k] * self.finv[N - k]) % MOD


def main():
    N, M, K = map(int, input().split())

    if N == 1:
        print(M)
        return

    Com = Combination(N-1, MOD)
    ans = 0
    for k in reversed(range(K+1)):
        ans += M * pow(M-1, N-k-1, MOD) * Com.com(N-1, k)
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()
N = int(input())
if k % 1000 == 0:
  print(0)
else:
  
	k = int(N/1000) + 1
    print(1000*k - N)

### FIXED CODE ###

N = int(input())
if N % 1000 == 0:
  print(0)
else:
  k = int(N/1000) + 1
  print(1000*k - N)
Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
print(A*B)
a = str(A*B)[:-2]
a = int(a)
print(a)


### FIXED CODE ###

Z = input().split()
A = int(Z[0])
B = Z[1].split('.')
B = int(B[0] + B[1])
#print(A*B)
if len(str(A*B)) <= 2:
  a = 0
else:
  a = str(A*B)[:-2]
  a = int(a)
print(a)
# coding: utf-8
import math

(n, m) = [int(i) for i in input().rstrip().split(" ")]

for i in range(n, math.sqrt(m) + 1):
    if m % i == 0:
        print(int(m / i))
        break


### FIXED CODE ###

# coding: utf-8
import math

(n, m) = [int(i) for i in input().rstrip().split(" ")]

ans = 0
divList = []
for i in range(1, int(math.sqrt(m)) + 1):
    if m % i == 0:
        j = m / i
        divList.append(i)
        divList.append(j)
divList = sorted(divList)
for i in divList:
    if i < n:
        continue
    ans = m / i
    break

print(int(ans))
S = input()
r_S = S[::-1]
devide = ["dream", "dreamer", "erase", "eraser"]
r_devide = [d[::-1] for d in devide]
string = r_S

while string != '':
  can = False
  for d in r_devide:
    if string[:len(d)] == d:
      can = True
      string = string[len(d):]
      print(string)
  if can == False:
    break

if can:
  print("Yes")
else:
  print("No")
     

### FIXED CODE ###

S = input()
r_S = S[::-1]
devide = ["dream", "dreamer", "erase", "eraser"]
r_devide = [d[::-1] for d in devide]
string = r_S

while string != '':
  can = False
  for d in r_devide:
    if string[:len(d)] == d:
      can = True
      string = string[len(d):]
  if can == False:
    break

if can:
  print("YES")
else:
  print("NO")
nm = [int(i) for i in input().split()]
  2
  3 result = (nm[0] * (nm[0] - 1)) // 2
  4 result += (nm[1] * (nm[1] - 1)) // 2
  5
  6 print(result)

### FIXED CODE ###

nm = [int(i) for i in input().split()]

result = (nm[0] * (nm[0] - 1)) // 2
result += (nm[1] * (nm[1] - 1)) // 2

print(result)
import numpy as np


N, M, C = map(int, input().split())
B = np.fromiter(map(int, input().split()), dtype=int)
As = list()
for i in range(N):
    a = np.fromiter(map(int, input().split()), dtype=int)
    As.append(a)
As = np.vstack(As)
print(np.sum(As @ B + C > 0))



### FIXED CODE ###

import numpy as np


N, M, C = map(int, input().split())
B = np.fromiter(map(int, input().split()), dtype=int)
As = list()
for i in range(N):
    a = np.fromiter(map(int, input().split()), dtype=int)
    As.append(a)
As = np.vstack(As)
print(int(np.sum(As.dot(B) + C > 0)))
from collections import deque

h,w = map(int,input().split())
ch, cw = map(int,input().split())
dh, dw = map(int,input().split())

G = []
for i in range(h):
    G.append(list(input()))

queue = deque([(ch-1, cw-1)])
S = [[float("inf")]*w for _ in range(h)]
S[ch-1][cw-1] = 0

while queue:
    y, x = queue.popleft()
    dx_dy = [[1,0],[0,1],[-1,0],[0,-1]]
    for k in range(4):
        i, j = dx_dy[i][0], dx_dy[i][1]
        if 0 <= x+i < w and 0 <= y+j < h:
            if S[y+j][x+i] > S[y][x] and G[y+j][x+i] == ".":
                S[y+j][x+i] = S[y][x]
                queue.appendleft((y+j, x+i))

    for i in range(-2, 3):
        for j in range(-2, 3):
            if i != 0 and j != 0:
                if 0 <= x+i < w and 0 <= y+j < h:
                    if S[y+j][x+i] > S[y][x] and G[y+j][x+i] == ".":
                        S[y+j][x+i] = S[y][x] + 1
                        queue.append((y+j, x+i))


if S[dh-1][dw-1] == float("inf"):
    print(-1)
else:
    print(S[dh-1][dw-1])

### FIXED CODE ###

from collections import deque


h, w = map(int,input().split())
ch, cw = map(lambda x: int(x) - 1, input().split())
dh, dw = map(lambda x: int(x) - 1, input().split())

G = []
for i in range(h):
    G.append(list(input()))

queue = deque([(ch, cw)])
S = [[float("inf")]*w for _ in range(h)]
S[ch][cw] = 0

while queue:
    y, x = queue.popleft()
    dx_dy = ((1,0),(0,1),(-1,0),(0,-1))
    ans = S[y][x]

    if (y, x) == (dh, dw):
            S[y][x] = ans
            break

    for j, i in dx_dy:
        if 0 <= x+i < w and 0 <= y+j < h and S[y+j][x+i] > ans and G[y+j][x+i] == ".":
            queue.appendleft((y+j, x+i))
            S[y+j][x+i] = ans
            

    ans += 1
    for i in range(-2, 3):
        for j in range(-2, 3):
            if 0 <= x+i < w and 0 <= y+j < h and S[y+j][x+i] > ans and G[y+j][x+i] == ".":
                S[y+j][x+i] = ans
                queue.append((y+j, x+i))


if S[dh][dw] == float("inf"):
    print(-1)
else:
    print(S[dh][dw])
N, X = map(int, input().split())
steps = list(input().split())
 
x = 0
count = 0
 
while x <= X and count <= N:
    x += int(steps[int(count)])
    count += 1
 
print(count)

### FIXED CODE ###

N, X = map(int, input().split())
steps = list(map(int,input().split()))
 
x = 0
count = 1

for i in steps:
    x += i
    if x <= X:
        count += 1
 
print(count)
import math

input_func = input
H, N = (int(i) for i in input_func().split())
A = []
B = []
for i in range(N):
    a, b = (int(j) for j in input_func().split())
    A.append(a)
    B.append(b)
A_max = max(A)
    
DP = [0]
for i in range(1, H+A_max):
    dp = math.inf
    for a, b in zip(A,B):
        if i-a>=0:
            dp = min(dp, DP[i-a] + b)
    DP.append(dp)
    #print(DP[i])
print(min(DP[H:H+A_max]))

### FIXED CODE ###

H, N = (int(i) for i in input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = (int(j) for j in input().split())
A_max = max(A)

DP = [0]*(H+A_max)
for i in range(1, H+A_max):
    dp = float('inf')
    for a, b in zip(A,B):
        if i-a>=0:
            dp = min(dp, DP[i-a] + b)
    DP[i] = dp
print(min(DP[H:]))
import sys
readline = sys.stdin.readline

N = int(readline())
X = readline().rstrip()

X0 = int(X, 2)
count1 = X.count("1")

X0mod0to1 = X0 % (count1 + 1) # 0->1に変化した際の、X0を割った余り
X0mod1to0 = X0 % (count1 - 1) # 1->0に変化した際の、X0を割った余り

def f(x): # 愚直にf(x)を求める式
  cnt = 0
  while x != 0:
    cnt += 1
    pc = bin(x).count("1")
    x %= pc
  return cnt

val = 1
ans = [-1] * N

for i in range(N - 1, -1, -1): # 下の桁から順に、f(Xi)の値を求める
  if X[i] == "0": # 0を1に変える場合
    pat = (X0mod0to1 + val % (count1 + 1)) % (count1 + 1)
    ans[i] = f(pat) + 1
  elif X[i] == "1": # 1を0に変える場合
    pat = (X0mod1to0 - val % (count1 - 1)) % (count1 - 1)
    ans[i] = f(pat) + 1
  val *= 2

print(*ans, sep = "\n")

### FIXED CODE ###

import sys
readline = sys.stdin.readline

N = int(readline())
X = readline().rstrip()

X0 = int(X, 2)
count1 = X.count("1")

X0mod0to1 = X0 % (count1 + 1) # 0->1に変化した際の、X0を割った余り
if count1 > 1:
  X0mod1to0 = X0 % (count1 - 1) # 1->0に変化した際の、X0を割った余り
else:
  X0mod1to0 = 0

from collections import defaultdict
dp = defaultdict(int)
dp[0] = 0
def f(x): # 愚直にf(x)を求める式
  if x in dp:
    return dp[x]
  pc = bin(x).count("1")
  val = f(x % pc) + 1
  dp[x] = val
  return val
  
val0to1 = 1
val1to0 = 1
ans = [-1] * N

for i in range(N - 1, -1, -1): # 下の桁から順に、f(Xi)の値を求める
  if X[i] == "0": # 0を1に変える場合
    pat = (X0mod0to1 + val0to1 % (count1 + 1)) % (count1 + 1)
    ans[i] = f(pat) + 1
  elif X[i] == "1": # 1を0に変える場合
    if count1 > 1:
      pat = (X0mod1to0 - val1to0 % (count1 - 1)) % (count1 - 1)
      ans[i] = f(pat) + 1
    else:
      ans[i] = 0
  val0to1 = val0to1 * 2 % (count1 + 1)
  if count1 != 1:
    val1to0 = val1to0 * 2 % (count1 - 1)

print(*ans, sep = "\n")
# A = int(input())
# B = int(input())
# C = int(input())
# D = int(input())
# E = int(input())
M = [int(input()) for _ in range(5)]
m = []
T = 0
for i in range(5):
    if M[i] % 10 == 0:
        T += M[i]
    else:
        T += M[i]
        T += 10 - M[i] % 10
        m.append(M[i] % 10)
print(T - (10 - min(m)))


### FIXED CODE ###

M = [int(input()) for _ in range(5)]
m = []
T = 0
for i in range(5):
    if M[i] % 10 == 0:
        T += M[i]
    else:
        T += M[i]
        T += 10 - M[i] % 10
        m.append(M[i] % 10)
print(T - (10 - (10 if not m else min(m))))
a,b=map(input().split());print(len([1 for i in range(a,b+1) if i//1000==i%100]))


### FIXED CODE ###

a,b=map(int,input().split());print(len([1 for i in range(a,b+1)if i//1000==i%10*10+i%100//10]))
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    a = np.fromstring(read(), np.int64, sep=' ')[1:]
    a = a[a % 2 == 0]
    if np.all((a % 3 == 0) or (a % 5 == 0)):
        print('APPROVED')
    else:
        print('DENIED')

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
  n = int(input())
  a = list(map(int, input().split()))

  r = 'APPROVED'

  for num in a:
    if num % 2 == 0:
      if num % 3 == 0 or num % 5 == 0:
        pass
      else:
        r = 'DENIED'
        break
  print(r)
  
main()
n, q=map(int, input().split())
s=input()


z=[0]*n
count=0
for i in range(n):
    z[i]=count
    if s[i]=="A":
        if s[i+1]=="C":
            count+=1
            z[i]+=1

for i in range(q):
    l, r =map(int,input().split())
    #r文字目までのACの数-(l-1)文字目まで
    if l==1:
        ans=z[r-1]
    elif r-l==1:
        if s[l-1]=="A" and s[l]=="C":
            ans=1
        else:
            ans=0
    else:
        ans=z[r-2]-z[l-2]
    print(ans)


### FIXED CODE ###

n, q=map(int, input().split())
s=input()


z=[0]*n
count=0
for i in range(n):
    z[i]=count
    if s[i]=="A" and i<=n-2:
        if s[i+1]=="C":
            count+=1
            z[i]+=1

for i in range(q):
    l, r =map(int,input().split())
    #r文字目までのACの数-(l-1)文字目まで
    if l==1:
        ans=z[r-2]
    elif r-l==1:
        if s[l-1]=="A" and s[l]=="C":
            ans=1
        else:
            ans=0
    else:
        ans=z[r-2]-z[l-2]
    print(ans)
import sys

def ans(index, array, k):
    r = right(index, array, k)
    l =  left(index, array, k)
    return min(r, l)


def right(index, array, k):
    start = max(0, k-(index-1)) + index
    count = sys.maxsize
    for i in range(start, min(len(array), k+index+1)):
        tmp = array[i]
        tmp += array[i] - array[k -(i - index + 1)]
        count = count if count < tmp else tmp

    if n > (index + k - 1):
        count = count if count < array[index + k - 1] else array[index + k - 1]
    
    return count

def left(index, array, k):
    n = len(array)
    start = min(0, n-index-k) + index
    count = sys.maxsize
    
    for i in range(max(0, start - k), start):
        tmp = -array[i]
        tmp += -array[i] + array[k -(start - index)]
        count = count if count < tmp else tmp

    if index >= k:
        count = count if count < -array[index-k] else -array[index-k]
    
    return count

n,k = map(int, input().split())

x = [int(i) for i in input().split()] 

for i in range(n):
    if x[i] >= 0:
        index = i
        break

print(ans(index, x, k))




### FIXED CODE ###

import sys

def ans(index, array, k):
    r = right(index, array, k)
    l =  left(index, array, k)
    return min(r, l)


def right(index, array, k):
    start = max(index, k-1)
    count = sys.maxsize
    for i in range(start, min(len(array), k+index)):
        tmp = array[i]
        j = index - (k - (i - index + 1))
        tmp += array[i] - array[j]
        count = count if count < tmp else tmp

    if len(array) > (index + k - 1):
        count = count if count < array[index + k - 1] else array[index + k - 1]
    
    return count

def left(index, array, k):
    n = len(array)
    start = min(index, n - k + 1)
    count = sys.maxsize
    
    for i in range(max(0, start - k), start):
        tmp = -array[i]
        j = k + i - 1
        tmp += -array[i] + array[j]
        count = count if count < tmp else tmp

    if index >= k:
        count = count if count < -array[index-k] else -array[index-k]
    
    return count

n,k = map(int, input().split())

x = [int(i) for i in input().split()] 

index = n
for i in range(n):
    if x[i] >= 0:
        index = i
        break

print(ans(index, x, k))
n,m,l = map(int,input().split())
a = [[0]*m for i in range(n)]
b = [[0]*l for i in range(m)]
c = []
for i in range(n):
    a[i] = list(map(int,input().split()))

for i in range(m):
    b[i] = list(map(int,input().split()))

for k,v in a:
    tmp = []
    for kk,vv in zip(*b):
        tmp.append(k * kk + v * vv)
    c.append(tmp)

for i in range(n):
    for j in range(l):
        print("%d" %c[i][j],end="")
        if(j < l-1): print(" ",end="")
        else: print()


### FIXED CODE ###

n,m,l = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(m)]

[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*b)]for x in a]]
n,m = map(int, input().split())
a_list = []
for i in range(m):
    a_list.append(int(input()))

# memo = [-1 for _ in range(n)]
step_now = 0
step_1   = 0
step_2   = 0
DIV_NUM = 1000000007
if 1 in a_list:
    a_list = alist.pop(0)
    step_now = 0
else:
    step_now = 1
for i in range(1, n):
    if i == 1:
        step_1 = step_now
        if i+1 in a_list:
            a_list = alist.pop(0)
            step_now = 0
        else:
#             memo[i] = (memo[0] + 1) % DIV_NUM
            step_now = step_1 + 1
    else:
        step_2 = step_1
        step_1 = step_now
        if i+1 in a_list:
            a_list = alist.pop(0)
            step_now = 0
        else:
#             memo[i] = (memo[i-1] + memo[i-2]) % DIV_NUM
            step_now = (step_1 + step_2) % DIV_NUM
    if step_now ==  step_1 == step_2 == 0:
        break

print(step_now)

### FIXED CODE ###

n,m = map(int, input().split())
a_list = []
for i in range(m):
    a_list.append(int(input()))

# memo = [-1 for _ in range(n)]
step_now = 0
step_1   = 0
step_2   = 0
DIV_NUM = 1000000007
if 1 in a_list:
    a_list.pop(0)
    step_now = 0
else:
    step_now = 1
for i in range(1, n):
    if i == 1:
        step_1 = step_now
        if i+1 in a_list:
            a_list.pop(0)
            step_now = 0
        else:
#             memo[i] = (memo[0] + 1) % DIV_NUM
            step_now = step_1 + 1
    else:
        step_2 = step_1
        step_1 = step_now
        if i+1 in a_list:
            a_list.pop(0)
            step_now = 0
        else:
#             memo[i] = (memo[i-1] + memo[i-2]) % DIV_NUM
            step_now = (step_1 + step_2) % DIV_NUM
    if step_now ==  step_1 == step_2 == 0:
        break

print(step_now)
l = input().split()
a=input()

b=a.split("-")


if len(b[0]) == l[0] and len(b[1])==l[1] and and len(b)<3:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

A, B = map(int, input().split())
S = input()

if S[A] == "-" and S.count("-") == 1:
  print("Yes")
else:
  print("No")