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

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

dp = [0]*n

dp[1] = abs(h[1]-h[0])

for i in range(2, n):

    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i, k)+1))

print((dp[-1]))

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

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

INF = float('inf')

dp = [INF]*n

dp[0] = 0



for i in range(n):

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

        if n <= i+j:

            continue

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

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

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

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