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

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

dp=[10**9]*n



dp[0]=0

for i in range(1,n):

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

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

    

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

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



dp = [10 ** 9] * N

dp[0] = 0



for i in range(1, N):

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

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

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

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
dp = [10**9] * N
dp[0] = 0
for i in range(1, N):
    for j in range(min(i, K) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print((dp[-1]))

-n, k = list(map(int, input().split())) -h = list(map(int, input().split())) -dp = [10**9] * n +N, K = list(map(int, input().split())) +H = list(map(int, input().split())) +dp = [10**9] * N -for i in range(1, n): -    for j in range(1, min(k + 1, i + 1)): -        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])) -print((dp[n - 1])) +for i in range(1, N): +    for j in range(min(i, K) + 1): +        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j])) +print((dp[-1]))