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

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



dp = [float('inf') for _ in range(n)]

dp[0] = 0

for i in range(n):

    for j in range(1,k+1):

        if i + j < n:

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

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

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

mincost_ls = [float('inf')] * n

mincost_ls[0] = 0

for i in range(n):

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

        if j < n:

            mincost_ls[j] = min(mincost_ls[j], mincost_ls[i] + abs(h_ls[j]-h_ls[i]))

print((mincost_ls[-1]))



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

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

-dp = [float("inf") for _ in range(n)] -dp[0] = 0 +mincost_ls = [float("inf")] * n +mincost_ls[0] = 0 -    for j in range(1, k + 1): -        if i + j < n: -            dp[i + j] = min(dp[i + j], dp[i] + abs(h_ls[i + j] - h_ls[i])) -print((dp[-1])) +    for j in range(i + 1, i + k + 1): +        if j < n: +            mincost_ls[j] = min(mincost_ls[j], mincost_ls[i] + abs(h_ls[j] - h_ls[i])) +print((mincost_ls[-1]))