peterverebics/CodeNet_Python_118 huggingface dataset:
N, K = map(int, input().split())
H = list(map(int, input().split()))

H = [0] + H
dp = [0] * (N+1)

for i in range(2, N+1):
    dp[i] = dp[i-1] + abs(H[i]-H[i-1])
    for k in range(2, K+1):
        if i-k >= 1:
            dp[i] = min(dp[i], dp[i-k]+abs(H[i]-H[i-k]))

res = dp[N]
print(res)
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0

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

dp = [float("inf") for _ in range(N)]

def cost(n, m):
  return abs(h[n] - h[m])

dp[0] = 0

for i in range(N):
  for j in range(1, K + 1):
    if (i + j) <= N -1:
      dp[i + j] = min(dp[i + j], dp[i] + cost(i, i + j))

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

dp = [[] for _ in range(n)]
dp[0] = 0

for i in range(1,n):
    tmp = float('inf')
    for j in range(1,k+1):
        if i-j < 0:
            continue
        tmp = min(dp[i-j] + abs(hl[i]-hl[i-j]),tmp)
    dp[i] = tmp
print(dp[-1])
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))

dp = [sys.maxsize]*n
dp[0]=0

#print(dp)
for i in range(n):
  for j in range(i+1,i+k+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))
  #print(dp)
      
print(dp[n-1])
import numpy as np

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

DP = np.zeros(N, dtype=int)
H = np.array(H)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(H[i] - H[start:i]))

print(DP[-1])
import sys
read = lambda: sys.stdin.readline().rstrip()
 
def main():
    INF = 10 ** 20
 
    n,k = map(int,input().split())
    h = tuple(map(int,read().split()))
    dp = [INF]*(n+1)
    dp[0] = 0
 
    for i in range(1, n):
        for j in range(1, k + 1):
            if i-j >= 0: dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
 
    print(dp[n-1])
if __name__ == "__main__":
    main()
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  kk=i-k
  if kk<0:kk=0
  dp[i]=min(d+abs(hh-h[i])for d,hh in zip(dp[kk:i],h[kk:i]))
print(dp[n-1])
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,k = na()
h = na()

A = [0]+[float("inf")]*(n-1)

for i in range(1,n):
  for j in range(max(0, i-k), i):
    A[i] = min(A[i],A[j]+abs(h[i]-h[j]))

print(A[-1])
n, k = map(int, input().split())
h = list(map(int, input().split()))

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


def input():
    return sys.stdin.readline().strip()


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

INF = 10 ** 9
dp = [INF] * n
dp[0] = 0
for i in range(n - 1):
    for j in range(1, k + 1):
        if j >= n - i:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(H[i + j] - H[i]))
print(dp[-1])
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
for i in range(N):
    for k in range(1,K+1):
        if i+k >= N:
            continue
        dp[i+k] = min(dp[i+k],dp[i]+abs(h[i]-h[i+k]))
print(dp[N-1])
f_inf = float('inf')
N, K = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
h.append(f_inf)
h.append(f_inf)
dp = [f_inf for _ in range(N + 100)]
dp[0] = 0
for i in range(N - 1):
  for j in range(1, K + 1):
    if i + j > N - 1:
      break
    dp[i+j] = min(dp[i] + abs(h[i+j] - h[i]), dp[i+j])
print(dp[N-1])
import numpy as np

l,l2 = map(int,input().split())
x = np.array(list(map(int,input().split())))

dp = np.zeros(l,dtype=int)
dp[1] = abs(x[0]-x[1])

for i in range(2,l):
    y = max(i - l2,0)
    dp[i] = np.min(dp[y:i] + abs(x[y:i] - x[i]))
    
print(dp[-1])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, K = MAP()
h = LIST()

INF = 10**23

dp = [INF] * N
dp[0] = 0

for i in range(1, N):
    for j in range(1, K+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[-1])
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 16:49:00 2020

@author: matsui
"""



N,K=map(int,input().split())
h=[int(num) for num in input().split()]

dp=[0]*N
dp[1]=abs(h[0]-h[1])
   
def cost(h,N,K,dp):
    for i in range(2,N):
        dp[i]=min([abs(h[i]-h[j])+dp[j] for j in range(max(0, i-K), i)])
    return dp[-1]
    
print(cost(h,N,K,dp))
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i+k >= N:
            break
        dp[i+k] = min(dp[i+k], dp[i] + abs(H[i] - H[i+k]))

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

inf = 10**10
dp = [0] + [inf] * (n-1)

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

dp = [0] * n
for i in range(1, n):
  start = max(0, i - k)
  dp[i] = dp[start] + abs(h[start] - h[i])
  for j in range(start+1, i + 1):
    dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]))
  
print(dp[n-1])
MAX_N = 10**5+100
INF = float('inf')

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

# dp table
# dp[i] := 足場iに行くのにかかる最小のコスト
dp = [INF]*MAX_N
dp[0] = 0

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

dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
    for j in range(1, min(K + 1, N - i)):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
import numpy as np
n,k = list(map(int,input().split()))
h=np.array([int(i) for i in input().split()])
dp = np.array([0]*n)
for i in range(1,n):
    j=max(0,i-k)
    dp[i] = np.min(dp[j:i]+abs(h[i]-h[j:i]))
print(dp[-1])
# -*- coding: utf-8 -*-
import numpy as np
def fnSolv():
  iNum, iK = map(int, input().split())
  naHn  = np.array(list(map(int, input().split())))
  naDP  = np.zeros(iNum, dtype='int64')
  naLen = np.ones(iK) * 10**9
  for iI0 in range(1, iNum):
    iK0 = min([iK, iI0])
    naLen = naDP[iI0-iK0:iI0] + np.abs(- naHn[iI0-iK0:iI0] + naHn[iI0])
    naDP[iI0] = naLen.min()
  print(naDP[iNum-1])

if __name__ == '__main__':
  fnSolv()
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    l = list(map(int,input().split()))
    dp = [0]+ [100000000000]*(n-1)

    for i in range(1,n):
        
        for j in range(1,m+1):
            if i-j >= 0:
                dp[i] = min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))
        
    print(dp[n-1])

if __name__ == "__main__":
    main()
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[N - 1])
n, k = 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))
def main():
    import sys
    import numpy as np
    n, k = map(int, input().split())
    h = list(map(int, sys.stdin.readline().split()))
    h = np.array(h, dtype=np.int32)
    ans = np.full(n, 10**9, dtype=np.int32)
    ans[0] = 0
    for i in range(n):
        ans[i:i+k+1] = np.minimum(ans[i:i+k+1], ans[i]+np.abs(h[i:i+k+1]-h[i]))

    print(ans[n-1])

if __name__ == '__main__':
    main()
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    INF = 10**10
    DP = [INF]*N
    DP[0] = 0
    DP[1] = abs(h[1]-h[0])
    for i in range(2,N):
        DP[i] = min(DP[i-j] + abs(h[i-j]-h[i]) for j in range(1,min(K,i)+1))
    print(DP[-1])
    
if __name__ == "__main__":
    main()
n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 10 ** 10
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
#print(dp)
print(dp[n-1])
N,K = map(int,input().split())
H=list(map(int,input().split()))
INF=1000000000
dp=[INF]*(N+1)
dp[0]=0
for i in range(1,N):
  for j in range(1,K+1):
    if (i-j)>=0:
      dp[i]=min(dp[i],dp[i-j]+abs(H[i-j]-H[i]))
print(dp[N-1])
def main():
    N,K=map(int,input().split())
    h=list(map(int,input().split()))
    ans=[0]*N
    for i in range(1,N):
        ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
    print(ans[-1])
main()
N, K = map(int, input().split())
h = [i for i in map(int, input().split())]
memo = [0]*N
for i in range(N):
    mini = 10**10
    for j in range(i-min(i, K), i, 1):
        if memo[j] + abs(h[i]-h[j]) < mini:
            mini = memo[j] + abs(h[i]-h[j])
    if i != 0:
        memo[i] = mini
print(memo[N-1])
#Educational DP Contest
#B-Frog2

import sys
input = sys.stdin.readline

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

#dp table
dp = [float("inf")]*n
dp[0] = 0

#process1
for i in range(1,n):
    for j in range(max(0,i-k),i): #kの許容しうる範囲だけ回す
        b = abs(lst1[i]-lst1[j]) + dp[j] #(j迄の最小コスト)+(jからiまでのコスト)
        dp[i] = min(dp[i],b)

#output process
print(dp[-1])
def mincost(n, k, A):
    dp = [0] * n
    for i in range(1, n):
        dp[i] = float('inf')
        for j in range(i - 1, i - k - 1, -1):
            if j >= 0:
                dp[i] = min(dp[i], dp[j] + abs(A[j] - A[i]))
    return dp[n - 1]
 
 
if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    res = mincost(n, k, A)
    print(res)
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,min(N,K)):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

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

print(dp[n - 1])
N, K = [int(i) for i in input().split(' ')]
h = [int(hi) for hi in input().split(' ')]

dp = [float('inf')] * N
dp[0] = 0

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

print(dp[-1])
def chmin(a, b):
  if a > b:
    return b
  else:
    return a
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")]*N
dp[0] = 0
for i in range(N - 1): #ジャンプ地点
	for j in range(1, min(K + 1, N - i)): #ジャンプ距離
		dp[i+j] = chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
N, K = map(int, input().split())
*h, = map(int, input().split())

dp = [0] * N
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    c = 10**10
    for j in range(i - 1, max(i - K - 1, -1), -1):
        t = abs(h[j] - h[i]) + dp[j]
        if t < c:
            c = t
    dp[i] = c
print(dp[N - 1])
n, k = map(int, input().split())
*H, = map(int, input().split())
X = [0]
for i in range(1, n):
    x = 1 << 30
    for j in range(1, k+1):
        if i-j >= 0:
            x = min(x, X[i-j]+abs(H[i]-H[i-j]))
    X.append(x)
print(X[n-1])
import numpy as np

N, K = map(int, input().split())
H = np.array(list(map(int, input().split())) + [0] * (K + 2), dtype = np.int64) 

INF = 10 ** 9
cost = np.array([INF] * (N + K + 2), dtype = np.int64)
cost[0] = 0
for i in range(N):
    cost[i + 1: i + K + 1] = np.minimum(cost[i + 1: i + K + 1], cost[i] + abs(H[i + 1: i + K + 1] - H[i]))


# print (cost)
print (cost[N - 1])
n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=100000,100
#a=[i for i in range(100000)]

kl=[i for i in range(1,k+1)]

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

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

dp = [float('inf')]*n
dp[0] = 0
for i in range(1, min(k, len(lst))):
    dp[i] = abs(lst[i] - lst[0])
for i in range(k, n):
    for j in range(1, k+1):
        dp[i] = min(dp[i], dp[i-j]+abs(lst[i]-lst[i-j]))
print(dp[-1])
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, k = na()
h = na()

inf = 1 << 60
dp = [inf for i in range(n)]
dp[0] = 0

for i in range(n):
    p = min(i + k + 1, n)
    for j in range(i + 1, p):
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n - 1])
n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
for i in range(1, n):
    x=h[i]
    c[i] = min([c[j]+abs(x-h[j]) for j in range(max(0, i-k), i)])
print(c[n-1])
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K,*H = map(int,read().split())
dp = [0] *(N+K)
H = [H[0]]*K+H

for n in range(K,N+K):
  h = H[n]
  dp[n] = min(x+abs(y-h) for y,x in zip(H[n-K:n],dp[n-K:n]))
print(dp[-1])
n,k=list(map(int,input().split(" ")))
l=list(map(int,input().split(" ")))
f=[0]*n
f[1]=abs(l[1]-l[0])

for i in range(2,n):

	x1=f[i-1]+abs(l[i-1]-l[i])
	z=min(k,i)
	for j in range(z):
		# print(i,i-j-1)
		x1=min(x1,(f[i-j-1]+abs(l[i]-l[i-j-1])))

	# x2=f[i-2]+abs(l[i-2]-l[i])
	f[i]=x1
print(f[-1])
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [1000000000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
print(dp[n-1])
def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))
N,K = map(int,input().split())
h = [0] + list(map(int,input().split()))

dp = [0] * (N+1)

for i in range(2,N+1):
    scope = min(i-1,K)
    jump = [dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,scope+1)]
    dp[i] = min(jump)

print(dp[N])
# -*- coding: utf-8 -*-
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0, abs(h[0] - h[1])]
    for i in range(2, n):
        min_cost = float('inf')
        for j in range(max(i - k, 0), i):
            cost = dp[j] + abs(h[j] - h[i])
            if min_cost > cost:
                min_cost = cost
        dp.append(min_cost)


    print(dp[-1])


if __name__ == "__main__":
    main()
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    n, k = map(int, input().split())
    cst = list(map(int, input().split()))
    arr = [0] * n
    arr[1] = abs(cst[1] - cst[0])
    for i in range(2, n):
        arr[i] = min(abs(cst[j] - cst[i]) + arr[j] for j in range(max(i - k, 0), i))
    print(arr[n - 1])
if __name__ == '__main__':
    main()
n, k = map(int, input().split())
h = [int(_) for _ in input().split()]
dp = [1000000000] * n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
print(dp[n-1])
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        k = i
    else:
        k = K
    for j in range(i-k, i):
        dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]))

print(dp[-1])
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**15+1 for i in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j<N:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
        
print(dp[-1])
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [0]*(N)
dp[1] = abs(h[0] - h[1])
for i in range(0,N-2):
    dp[i+2] = min([dp[i+2-j]+abs(h[i+2-j]-h[i+2]) for j in range(1,min(K+1, i+3))])
print(dp[-1])
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [100000000000 for _ in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(min(i,k)+1):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
print(dp[-1])
import numpy as np

# 入力
N, K = map(int, input().split())
H = np.array([int(i) for i in input().split()])

# ndarray型のDPテーブルを生成
dp = np.zeros(N, dtype=int)
# 初期値をセット
dp[0] = 0

# 各足場へたどり着く最小コストを調べる
for i in range(1, N):
    s = max(0, i-K)
    dp[i] = min(dp[s:i] + np.abs(H[i] - H[s:i])) # iより前の足場のコストに足す

print(dp[N-1])
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    H = [int(x) for x in input().split()] + [0] * 200

    INF = 10 ** 10
    dp = [INF] * 10 ** 6
    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))
    print(dp[N - 1])


if __name__ == '__main__':
    main()
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*(N)
dp[1]=abs(h[0]-h[1])
for i in range(2,N):
    dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(0,i-K),i))
print(dp[N-1])
# B - Frog 2
def main():
    N, K, *H = map(int, open(0).read().split())
    H = [0] + H + [0] * K
    dp = [1 << 30] * (N + K + 1)
    dp[1] = 0
    for i, a in enumerate(H[1:N + 1], 1):
        for j, b in enumerate(H[i + 1:i + K + 1], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print(dp[N])


if __name__ == "__main__":
    main()
#input
N, K = map(int, input().split())
h = list(map(int, input().split()))

#output
dp = [0] * N
dp[1] = abs(h[1]-h[0])

for i in range(2, N):
    temp = abs(h[i]-h[i-1]) + dp[i-1]
    for j in range(2, K+1):
        if 0<= i-j <= N-1:
            temp = min(temp, dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = temp

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

dp = [float('inf')]*N

dp[0] = 0

for i in range(1,N):
    k = 1
    while(i-k >= 0):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
        if k == K:
            break
        if k < K:
            k += 1

print(dp[N-1])
import sys
def main():
    INF=sys.maxsize
    N,K=tuple(map(int,sys.stdin.readline().split()))
    h=tuple(map(int,sys.stdin.readline().split()))
    dp=[INF for _ in range(N)]
    dp[0]=0
    for i in range(1,N):
        for j in range(1,K+1):
            if i-j>=0:
                dij=dp[i-j]+abs(h[i]-h[i-j])
                if dij<dp[i]:dp[i] = dij
    print(dp[N-1])
if __name__=='__main__':main()
import sys
input = sys.stdin.readline
N, K = map(int, input().rstrip().split())
*h, = map(int, input().rstrip().split())
dp = [0] + [float('inf')]*(N-1)
for j in range(1,N):
    for i in range(max(0,j-K),j):
        dp[j] = min(dp[j],dp[i] + abs(h[j]-h[i]))
        # print("j -> {} || i -> {} || dp -> {} || h[j] -> {} || h[i] -> {}".format(j, i, dp, h[j], h[i]))
print(dp[-1])
import numpy as np

N, K = map(int, input().split())
places = np.array(list(map(int, input().split())))
dp_table = np.zeros(N+1, dtype=np.int)

for i in range(1, N):
    start = max(0, i-K)
    dp_table[i] = min(dp_table[start:i] + np.abs(places[i]-places[start:i]))

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

costs = [0] * N

for i in range(1,N):
  minimum = 99999999999
  for j in range(1, min(K, i)+1):
    minimum = min(minimum, costs[i-j] + abs(h[i] - h[i-j]))
  costs[i] = minimum

print(costs[N-1])
n,k = map(int,input().split())
l = list(map(int,input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(l[1]-l[0])+dp[0]
for i in range(2,n):
    r = i-k
    if r < 0:
        r = 0

    mi = 9999999999
    for j in range(r,i):
        t = dp[j]+abs(l[j]-l[i])
        if t < mi:
            mi = t

    dp[i] = mi

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

dp=[10**9]*(N)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j<=N-1:
            dp[i+j]=min(abs(H[i]-H[i+j])+dp[i],dp[i+j])

print(dp[N-1])
def sol(lis,K):
    import sys
    dp = [sys.maxsize]*len(lis)
    dp[0] = 0
    for i in range(len(lis)):
        for j in range(i+1,i+K+1):
            if j<len(lis):
                dp[j] = min(dp[j],dp[i]+abs(lis[j]-lis[i]))
    print(dp[-1])
n,k = list(map(int,input().split(' ')))
lis = list(map(int,input().split(' ')))
sol(lis,k)
N,K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * 10 ** 5

dp[0] = 0
for i in range(1, N):
  tmp = i
  if tmp > K:
    tmp = K
  for j in range(1,tmp + 1):
      dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]))

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

MAX = 10**9

dp = [MAX for i in range(n)]
dp[0] = 0

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

print(dp[-1])
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[0]*n
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
d=[10**9]*n
d[-1]=0
for i in range(n-2,-1,-1):
	mn=10**9
	for j in range(i+1,min(i+1+k,n),1):
		mn=min(mn,abs(l[i]-l[j])+d[j])
	d[i]=mn
#print(d)
print(d[0])
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*len(h)

for i in range(1,min(k,n)):
    temp=10**10
    for j in range(i):
        temp=min(temp,dp[j]+abs(h[i]-h[j]))
    dp[i]+=temp 
for p in range(min(k,n),n):
    temp=10**10
    for q in range(k):
        temp=min(temp,dp[p-k+q]+abs(h[p]-h[p-k+q]))
    dp[p]+=temp 
print(dp[-1])
import sys
import numpy as np

input=sys.stdin.readline

n,k=map(int,input().split())
h=[0]*n
h=list(map(int,input().split()))

dp=np.zeros(n,dtype=int)
h=np.array(h)

for i in range(1,n):
  start=max(0,i-k)
  dp[i]=min(dp[start:i] + np.abs(h[i]-h[start:i]))

print(dp[n-1])
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])
import math
from decimal import *

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [int(10e9)+7 for i in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if(i-j>=0):
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]) )
        else:
            break
print(dp[-1])
#DP-B

n,k=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(k):
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i-1]+abs(h[i+j]-h[i-1]))

print(dp[-1])