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

l = list(map(int, input().split()))

dp = [float("inf")]*n

dp[0] = 0

for i in range(n-1):

    for j in range(1,min(k+1,(n-i))):

        dp[i+j]=min(dp[i]+(abs(l[i]-l[i+j])),dp[i+j])

print((dp[-1]))
n, k = list(map(int, input().split()))

h = list(map(int, input().split()))

dp=[float("inf")]*n

dp[0]=0

for i in range(n-1):

    for j in range(1,min(k+1,abs(n-i))):

        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[j+i]))

print((dp[-1]))
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, min(k + 1, (n - i))):
        dp[i + j] = min(dp[i] + (abs(l[i] - l[i + j])), dp[i + j])
print((dp[-1]))

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, min(k + 1, abs(n - i))):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[j + i]))
print((dp[-1]))

-l = list(map(int, input().split())) +h = list(map(int, input().split())) -    for j in range(1, min(k + 1, (n - i))): -        dp[i + j] = min(dp[i] + (abs(l[i] - l[i + j])), dp[i + j]) +    for j in range(1, min(k + 1, abs(n - i))): +        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[j + i]))