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

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

h+=[0]*k

inf=float('inf')

dp=[inf]*(n+k)

dp[0]=0

for i in range(n):

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

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

print((dp[n-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(1,n):

    for j in range(max(0,i-k),i):

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



print((dp[n-1]))

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

-h += [0] * k -inf = float("inf") -dp = [inf] * (n + k) +dp = [float("inf")] * n -for i in range(n): -    for j in range(1, k + 1): -        dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j]) +for i in range(1, n): +    for j in range(max(0, i - k), i): +        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))