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

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

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

print(dp[n-1])
# Frog2
N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = float("inf")
dp = [inf for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i + j >= N:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i+j]))
print(dp[-1])
import numpy as np
n,k=map(int,input().split())
h=np.array(list(map(int,input().split())))
dp=np.zeros(n,dtype="int32")
for i in range(1,n):
    start=0 if k>i else i-k
    dp[i]=np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(dp[-1])
n, k = map(int,input().split())
h = list(int(i) for i in input().split())

dp = [0] * n

for i in range(0, n - 1):
  if(i > 0):
    dp[i + 1] = min(dp[i - x] + abs(h[i + 1] - h[i - x]) for x in range(k) if (i - x) >= 0)
  else:
    dp[i + 1] = (abs(h[i + 1] - h[i]))

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

if __name__ == "__main__":
    main()
#python3

INF = int(1e9)

def main():

    n, k = map(int, input().split()) 
    h = [int(i) for i in input().split()] + [0]* 110


    dp = [INF] * 110000
    dp[0] = 0
    for i in range(n):
        for j in range(1, k+1):
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

    print(dp[n-1])

main()
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]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(10**5+10)
dp[0] = 0

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

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])
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0] + [float("inf")] * (N-1)

for i in range(1, N):
    for back in range(1, K+1):
        try:
            cost[i] = min(cost[i], cost[i-back] + abs(h[i] - h[i-back]))
        except IndexError:
            break

print(cost[-1])
#2回目


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

dp=[-1]*n

for i in range(min(k,n)):
    dp[i]=abs(h[i]-h[0])
#print(dp)

for i in range(k,n):
    #print(i)
    mindp=10**9
    for j in range(i-k,i):
        #print(j)
        mindp=min(mindp , abs(h[i]-h[j])+dp[j])
        
    dp[i]=mindp
 #   print(dp[i])
#print(dp)
print(dp[-1])
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            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 = list(map(int, input().split()))

cost = [0] * N
for i in range(1, N):
  #print('i=', i)
  st = max(i - K, 0)
  ci = 10**18

  for j in range(st, i):
    if cost[j] < ci:
      cj = cost[j] + abs(H[i] - H[j])
      #print('cj=', cj)
      ci = min(cj, ci)

  #print('ci=', ci)
  cost[i] = ci

#print(cost)
ans = cost[N-1]
print(ans)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]* N
dp[0] = 0
for j in range(1, N):
    for i in range(max(0, j-K), j):
        dp[j] = min(dp[i]+abs(h[j]-h[i]), dp[j])
print(dp[-1])
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
 
dp = [float('inf') for _ in range(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(nums[i]-nums[j]))
print(dp[-1])
n,K=map(int,input().split())
h=list(map(int,input().split()))
h.insert(0,0)
dp=[float('inf') for i in range(n+1)]
dp[1]=0
for i in range(1,n):
    for k in range(1,min(K+1,n-i+1)):
        dp[i+k]=min(dp[i+k],dp[i]+abs(h[i+k]-h[i]))
print(dp[n])
import sys
input=sys.stdin.readline
def main():
    n,k=map(int,input().split())
    H=list(map(int,input().split()))
    dp=[10**9]*(n)
    dp[0]=0
    for i in range(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[-1])        

main()
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-1):
    for j in range(min(i+1,K)):
        DP[i+1] = min(DP[i+1],DP[i-j]+abs(h[i+1]-h[i-j]))

print(DP[N-1])
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[float('inf') for i in range(n+1)]
dp[0]=0
for i in range(len(dp)):
    for j in range(i+1,i+k+1):
        if(j<len(l)):
      	    dp[j]=min(dp[j],dp[i]+abs(l[j]-l[i]))
print(dp[n-1])
n,k = [int(x) for x in input().strip().split()]
H = [int(x) for x in input().strip().split()]

inf = int(10e9 + 7)
dp = [inf] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1,min(n,i+k+1)):
        dp[j] = min (dp[j], dp[i] + abs(H[i] - H[j]))
print (dp[-1])
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    dp = [INF] * n
    dp[0] = 0
    H = list(map(int, input().split()))
    for i in range(n):
        for pi in range(i - k, i):
            if pi < 0:
                continue
            dp[i] = min(dp[i], dp[pi] + abs(H[i] - H[pi]))
    print(dp[n - 1])
resolve()
import math

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

dp = [INF]*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[-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(max(i - k, 0), 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 = [0]
for i in range(1,N):
    a = DP[i-1] + abs(H[i]-H[i-1])
    for j in range(2,min(K,i)+1):
        b = DP[i-j] + abs(H[i]-H[i-j])
        a = min(a,b)
    DP.append(a)
print(DP[N-1])
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[0]=0
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])
def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = 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 i-j >= 0:
            dp[i] = chmin(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()))

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

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

print(dp[N-1])
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

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

    print(dp[n-1])

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

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

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

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

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

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

print(minTotalCostList[N-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):
    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])
def totalcost_dp(cost,N,k):
    dp = [float('inf')]*(N+1)
    dp[1] = 0
    
    
    for i in range(1,N+1):
        
        for j in range(i+1,k+i+1):
            if j < N+1:
                dp[j] = min(dp[j],dp[i]+abs(cost[i]-cost[j]))
                
    return dp[N]


n ,k= map(int,input().split())
cost = list(map(int,input().split()))
cost = [0]+cost
print(totalcost_dp(cost,n,k))
# EDPC B Frog 2
N, K = map(int, input().split())
H = list(map(int,input().split()))

cost = [float("inf")]*N
cost[0] = 0
cost[1] = abs(H[1]-H[0])

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

print(cost[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] + np.abs(H[i + 1: i + K + 1] - H[i]))


# print (cost)
print (cost[N - 1])
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    h_list = list(map(int, input().split()))

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

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

    print(dp[-1])


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


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


def main():
    size, jumps = map(int, input().split())
    array = list(map(int, input().split()))
    dp = [999999999] * size
    dp[0]= 0
    dp[1] = abs(array[0]- array[1])
    for i in range(2,size):
        dp[i] = min(abs(array[i] - array[j]) + dp[j] for j in range(max(0, i - jumps), i))
    print(dp[size-1])

if __name__ == "__main__":
    main()
n, k = map(int, input().split())
H = list(map(int, input().split()))
dp = [float("inf") for _ in range(n)]  # 最小化問題なのでinfで初期化
dp[0] = 0  # 初期条件

for i in range(n - 1):  # 配るDP
    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])
N,K=map(int,input().split())
import numpy as np
H=np.array([10**9]*(K-1)+list(map(int,input().split())))
dp=np.zeros(N+K-1)
for i in range(N-1):
    dp[i+K]=np.min(dp[i:i+K]+np.abs(H[i:i+K]-H[i+K]))
print(int(dp[-1]))
def main():
    (N, K) = map(int, input().split())
    H = [int(x) for x in input().split()]
    dp = [0] * N
    for i in range(1, N):
        ret = 10 ** 18
        for j in range(K):
            if i - 1 - j < 0:
                break
            ret = min(ret, dp[i-1-j] + abs(H[i] - H[i-1-j]))
        dp[i] = ret
    print(dp[-1])


if __name__ == '__main__':
    main()
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=[999999999999999]*n
d[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:
            break 
        d[i]=min(d[i],d[i-j]+abs(a[i]-a[i-j]))
print(d[n-1])
import numpy as np
n, k = map(int, input().split())
arr = np.array([0] + list(map(int, input().split())) + [0] * 100)

INF = 1 << 60
dp = np.full(arr.shape[0] + 100, INF)

dp[1] = 0

for i in range(1, n + 1):
    dp[i: i + k + 1] = np.minimum(dp[i: i + k + 1], dp[i] + np.abs(arr[i: i + k + 1] - arr[i]))

print(dp[n])
inf=(10**7)+1
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n,k=get_ints()
h=get_array()
li=[inf]*n
li[0]=0

for i in range(1,n):
    l=max(0,i-k)
    for j in range(l,i):




            li[i]=min(li[i],li[j]+abs(h[i]-h[j]))
##print(li)
print(li[n-1])
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**5]*n
for i in range(n):
  if i==0:
    dp[i]=0
  elif i==1:
    dp[i]=abs(h[1]-h[0])
  else:
    for j in range(1,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())
h = list(map(int, input().split()))

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

for i in range(K):
  h.append(float('inf'))

dp = [0]
for i in range(N+K):
  dp.append(float('inf'))

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

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

MAX = 10**5

dp = [MAX] * (n)
dp[0] = 0

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


print(dp[-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(N-1):
        for j in range(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])
if __name__=='__main__':main()
N,K=map(int,input().split())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]

for i in range(2,N):
    cand=10**5
    for j in range(K):
        if j==i:
            break
        cand=min(cand,cost[i-j-1]+abs(h[i]-h[i-j-1]))
    cost.append(cand)

print(cost[-1])
N,K=map(int,input().split())
listH=list(map(int,input().split()))
cost=[10**5]*N
cost[0]=0
for i in range(1,N):
  for k in range(K):
    if i-k>=0:
      cost[i]=min(abs(listH[i-k]-listH[i])+ cost[i-k],cost[i])
ans=cost[-1]      
print(ans)
import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n,k=get_ints()
h=get_array()
li=[99999]*n
li[0]=0

li[1]=abs(h[1]-h[0])
for i in range(2,n):
    l=max(0,i-k)
    for j in range(l,i):




            li[i]=min(li[i],li[j]+abs(h[i]-h[j]))
##print(li)
print(li[n-1])
import numpy as np
N,K=map(int,input().split())
listH=list(map(int,input().split()))
cost=np.array([10**5]*N)
cost[0]=0
for i in range(1,N):
  for k in range(1,min(i+1,K+1)):
    cost[i]=min(abs(listH[i-k]-listH[i])+ cost[i-k],cost[i])
ans=cost[-1]      
print(ans)
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] = dp[i - j] + abs(h[i - j] - h[i])

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

# dp[i] = 足場i(0~n-1)に到着するコストの最小値
dp = [10*18]*(n)
dp[0] = 0

for i in range(n) :
    for j in range(1,k+1) :
        if i+j >= n :
            continue
        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())
arr = [int(i) for i in input().split()]
dp = [float("inf") for j in range(n)]
dp[0] = 0
for i in range(n):
    dp[i] = float("inf")
    for j in range(i+1,i+k+1):
        if j < n:
            val = (abs(arr[i]-arr[j]) + dp[i]) 
            dp[j] = min(dp[j],val)
print(dp[n-1])
n,k=map(int,input().split())
h=list(map(int,input().split()))
DP=[10**9+1]*n
DP[0]=0
DP[1]=abs(h[1]-h[0])
for i in range(1,n):
    for j in range(max(0,i-k),min(i+1,n-1)):
        DP[i]=min(DP[i],DP[i-j]+abs(h[i]-h[i-j]))
print(DP[-1])
def main():
    N,K = map(int, input().split())
    h = list(map(int, input().split()))
    cost = [10*8]*N
    cost[0] = 0

    for j in range(1,N):
        for i in range(1,min(j,K)+1):
            cp = cost[j-i] + abs(h[j]-h[j-i])
            if cost[j] > cp : cost[j] = cp
        
    print(cost[-1])

    return

if __name__ == "__main__":
    main()
#DP B
import sys
N, K = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))

dp = [-1 for _ in range(N)]
#print(dp)
#print(H)
dp[1] = abs(H[1]-H[0])
#print(dp)

for i in range(2, N):
    for k in range(1, K+1):
        if i-k>=0:
            tmp = abs(H[i]-H[i-k]) + dp[i-k]
            if dp[i] ==-1 or tmp < dp[i]:
                dp[i] = tmp
    #print(dp)
print(dp[-1])
N,K=map(int,input().strip().split())
h=list(map(int,input().strip().split()))

inf=100000000

dp=[inf for n in range(N)]
dp[0]=0
for n in range(1,N):
    chmin=inf
    for  k in range(1,K+1):
        if n-k>=0:
            chmin=min(chmin,dp[n-k]+abs(h[n]-h[n-k]))
    dp[n]=chmin
print(dp[N-1])
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
import numpy as np


def main():
    N, K = list(map(int, input().split()))
    H = list(map(int, input().split()))
    H = np.array(H)

    cost = np.array([100000] * N)
    cost[0] = 0
    for i in range(1, N):
        cost[i] = min(
            cost[max(i - K, 0)] + abs(H[i] - H[max(i - K, 0): i]))
        # print(i, cost[i])
    print(cost[N - 1])


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

dp = [10000000]*(N)
dp[0]=0
for i in range(0,N):
  for j in range(0,K+1):
    if i+j<N: 
    	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()))
K=min(N,K)

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

for i in range (1,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])
    print(dp)

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])
import sys

n,k = list(map(int, input().split(" ")))
l = list(map(int, input().split(" ")))
l = [999999]*k + l
print(l)
dp= [0]*(n+k)

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

print(dp[n + k - 1])
def b_frog_2(stones, k):
    dp = [0] * len(stones)
    dp[0] = 0
    for i in range(1, len(stones)):
        for j in range(max(0, i - k), i):
            dp[i] = min(dp[i], dp[j] + abs(stones[i] - stones[j]))
    return dp[-1]


def main2():
    N, K = list(map(int, input().split()))
    h = list(map(int, input().split()))
    print(b_frog_2(h, K))
N, K = map(int, input().split())

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

INF = 10**6
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:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(H[i-j] - H[i]))

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

for i in range(1,n):
    c = 100000
    for j in range(1,min(k+1,i+1)):
        c = min(abs(h[i] - h[i - j]) + dp[i - j], c)
    dp.append(c)
print(dp[-1])
##Educational-DP B
n,k = map(int,input().split())
h = tuple(map(int,input().split()))

dp = [10**4 + 1] * 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[j]-h[i]))
        
#print(dp)
print(dp[-1])
import sys
input = sys.stdin.readline

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

for i in range(1, n):
    for j in range(min(k, i)):
        memo = abs(h[i] - h[i - j - 1]) + dp[i - j - 1]
        if dp_memo > memo:
            dp_memo = memo
    dp[i] = dp_memo
    dp_memo = 10 ** 4

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

dp_list = [10**4+1]*len(H)
dp_list[0]=0

## DP
for h in range(1,len(H)): ## 各位置ごとに計算していく
  loop_cnt = min(K,h) ## 前の石にどれくらい戻れるか、の計算
  cost = dp_list[h]
  for m in range(1,loop_cnt+1):
    cost_tmp = abs(H[h]-H[h-m])+dp_list[h-m]
    cost = min(cost,cost_tmp)
  dp_list[h] = cost

ans = dp_list[-1]
print(ans)
MAX = 10 ** 6
def solve(arr, n, k):
    if n == 2:
        return arr[1] - arr[0]

    dp = [MAX] * 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[i] - arr[j]))

    return dp[-1]

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

print(solve(arr, n, k))
[n, k] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10 ** 6 for _ in range(n)]
dp[0] = 0
for i in range(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 = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
minToatalCostList = [100000 for i in range(N)]
minToatalCostList[0] = 0

for i in range(1,N) :
	for j in range(1,K+1) :
		if j > i or minToatalCostList[i] == 0 :
			break
		else :
			minToatalCostList[i] = min(minToatalCostList[i], (abs(h[i] - h[i-j]) + minToatalCostList[i-j] ))

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

DP = [1000000]*N
DP[0] = 0
for i in range(N):
    for j in range(K):
        if i + j + 1 >= N:
            break
        DP[i + j + 1] = min(DP[i + j + 1], DP[i] + abs(High[i] - High[i + j + 1]))
print(DP[N-1])
import numpy as np
import sys

n, k = map(int, input().split())
dp = np.full(n, 10005, dtype=int)
h = np.array([int(x) for x in input().split()])
dp[0] = 0
for i in range(n):
	j = 0
	while i - j >= 0 and j <= k:
		dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
		j += 1
print(dp[n - 1])
N,K = map(int,input().split())
h = list(map(int,input().split()))

cost = [0]
for i in range(2,N+1):
    print(i)
    cost.append( min([cost[j] + abs(h[i-1]-h[j]) for j in range(max(0,i-K-1), i-1)]) )
print(cost)
import numpy
N, K = map(int,input().split())
h = numpy.array(input().split(),numpy.int32)


dp = numpy.array([10**5]*N,numpy.int32)
dp[0] = 0

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

print(dp[-1])
N,K = list(map(int,input().split()))
h = list(map(int,input().split()))
DP = [float("inf")]*N

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

DP[1] = abs(h[1]-h[0])
for i in range(K,N):
    for k in range(1,K+1):
        DP[i] = min(DP[i],DP[i-k]+abs(h[i]-h[i-k]))
print(DP[N-1])
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N, K = geta(int)
    h = geta(int)

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

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

    print(dp[-1])

if __name__ == "__main__":
    main()