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

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



ans = [float('inf')]*(10**6)



ans[0] = 0

def dp(n):

  for i in range(n):

    for j in range(k+1):

      if i+j < n:

        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))

  return ans[n-1]



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

lst = list(map(int, input().split())) + [0]*k

ans = [float('inf')]*(n+k)

ans[0] = 0



def dp():

  for i in range(n):

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

      ans[i+j] = min(ans[i+j], ans[i] + abs(lst[i+j]-lst[i]))



dp()



print((ans[n-1]))
n, k = list(map(int, input().split()))
step = list(map(int, input().split()))
ans = [float("inf")] * (10**6)
ans[0] = 0


def dp(n):
    for i in range(n):
        for j in range(k + 1):
            if i + j < n:
                ans[i + j] = min(ans[i + j], ans[i] + abs(step[i + j] - step[i]))
    return ans[n - 1]


print((dp(n)))

n, k = list(map(int, input().split()))
lst = list(map(int, input().split())) + [0] * k
ans = [float("inf")] * (n + k)
ans[0] = 0


def dp():
    for i in range(n):
        for j in range(1, k + 1):
            ans[i + j] = min(ans[i + j], ans[i] + abs(lst[i + j] - lst[i]))


dp()
print((ans[n - 1]))

-step = list(map(int, input().split())) -ans = [float("inf")] * (10**6) +lst = list(map(int, input().split())) + [0] * k +ans = [float("inf")] * (n + k) -def dp(n): +def dp(): -        for j in range(k + 1): -            if i + j < n: -                ans[i + j] = min(ans[i + j], ans[i] + abs(step[i + j] - step[i])) -    return ans[n - 1] +        for j in range(1, k + 1): +            ans[i + j] = min(ans[i + j], ans[i] + abs(lst[i + j] - lst[i])) -print((dp(n))) +dp() +print((ans[n - 1]))