N,k = [int(x) for x in input().split()]

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

DP = [1000000000]*N

DP[0] = 0

def handan(i,x):

    if DP[i] > x:

        DP[i] = x

for i in range(1,N):

    for j in range(min(i,k)):

        x = DP[i-j-1] + abs(h[i]-h[i-j-1])

        handan(i,x)

print((DP[N-1]))
N,K = [int(x) for x in input().split()]

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

DP=[100000000000]*(N+1)

DP[0] = 0

DP[1] = 0

DP[2] = DP[1] + abs(h[0]-h[1])

for i in range(1,N):

    for j in range(i+1,min(i+K+1,N+1)):

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

print((DP[N]))
N, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
DP = [1000000000] * N
DP[0] = 0


def handan(i, x):
    if DP[i] > x:
        DP[i] = x


for i in range(1, N):
    for j in range(min(i, k)):
        x = DP[i - j - 1] + abs(h[i] - h[i - j - 1])
        handan(i, x)
print((DP[N - 1]))

N, K = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
DP = [100000000000] * (N + 1)
DP[0] = 0
DP[1] = 0
DP[2] = DP[1] + abs(h[0] - h[1])
for i in range(1, N):
    for j in range(i + 1, min(i + K + 1, N + 1)):
        DP[j] = min(DP[j], DP[i] + abs(h[j - 1] - h[i - 1]))
print((DP[N]))

-N, k = [int(x) for x in input().split()] +N, K = [int(x) for x in input().split()] -DP = [1000000000] * N +DP = [100000000000] * (N + 1) - - -def handan(i, x): -    if DP[i] > x: -        DP[i] = x - - +DP[1] = 0 +DP[2] = DP[1] + abs(h[0] - h[1]) -    for j in range(min(i, k)): -        x = DP[i - j - 1] + abs(h[i] - h[i - j - 1]) -        handan(i, x) -print((DP[N - 1])) +    for j in range(i + 1, min(i + K + 1, N + 1)): +        DP[j] = min(DP[j], DP[i] + abs(h[j - 1] - h[i - 1])) +print((DP[N]))