peterverebics/CodeNet_Python_118 huggingface dataset:
nk = list(map(int,input().split()))
h = list(map(int,input().split()))
n,k = nk[0], nk[1] #5,3
DP = [0]
for i in range(1, n):#0~3 -> 1~4
  act = float("inf")
  for k_ in range(1, k+1):#0~2 -> 1~3
    if i-k_ < 0 : continue
    act = min(DP[-k_] + abs(h[i-k_]-h[i]), act)#
  DP+= [act]#[0,20,]
print(DP[-1])
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('Inf')] * (10 ** 5 + 1)
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 + j] - h[i]))
print(dp[n - 1])
from sys  import stdin,stdout

st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')

n,k=mp()
l=li()
dp=[INF for i in range(n)]
dp[0]=0

for i in range(n):

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

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

print(dp[-1])
n, k = 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 = 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(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]))
            
print(dp[-1])
n ,k= map(int,input().split())
h = list(map(int,input().split()))
#print(h)
inf = float("inf")
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)
print(dp[n-1])
n,k,*h=map(int,open(0).read().split())
a=[0]*n
for i in range(1,n):
    j=max(0,i-k)
    e=h[i]
    a[i]=min(A+abs(e-H) for A,H in zip(a[j:i],h[j:i]))
print(a[-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 < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

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

data = sys.stdin.readlines()

n, k = list(map(int, data[0].split()))
h = list(map(int, data[1].split()))

dp = [-1] * n
dp[0] = 0

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

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

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

for i in range(N-1):
  A=[]
  for j in range(K):
    if i-j>=0:
      A.append(dp[i-j]+abs(H[i-j]-H[i+1]))
  dp[i+1]=min(A)

print(dp[N-1])
N, K = map(int, input().rstrip().split(' '))
frog_lst = list(map(int, input().rstrip().split(' ')))
frog_jump_lst = []

def frog_jump(frog_jump_lst=[], index=0):
  if not frog_jump_lst:
    frog_jump_lst.append(0)
  else:
    now_pos = frog_lst[index]
    k = min(K, len(frog_jump_lst))
    pattern = [abs(now_pos - frog_lst[index-i]) + frog_jump_lst[-i] for i in range(1,k+1)]
    frog_jump_lst.append(min(pattern))

for j in range(N):
  frog_jump(frog_jump_lst, j)
print(frog_jump_lst[-1])
import sys
input = sys.stdin.readline

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

dp = [10**10] * 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+j] - h[i]))

print(dp[-1])
n, k = map(int,input().split())
h = list(map(int,input().split()))
INF = float('inf')
dp = [INF] * n 
dp[0] = 0 
dp[1] = abs(h[1] - h[0])




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

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

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

dp = [0] * n

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

print(dp[n-1])
N,K=map(int,input().split())
h=[int(i) for i in input().split()]
f_inf=float('inf')
dp=[f_inf]*(N+10)
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-j]+abs(h[i]-h[i-j]),dp[i])
print(dp[N-1])
N, K = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0, float("inf"))

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

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

print(dp[N])
import numpy as np

n, k = map(int, input().split())
h = np.array(input().split(), dtype=np.int64)

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

print(dp[-1])
[N,K]=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
DP=[1000000000 for i in range(N)]
DP[0]=0
for i in range(N):
	for j in range(max(i-K,0),i):
		DP[i]=min(DP[j]+abs(h[i]-h[j]),DP[i])


print(DP[N-1])
# coding: utf-8
import numpy as np

n, k = map(int, input().split())
h_list = np.array([int(x) for x in input().split()])

ans = np.zeros(n, dtype=int)

for i in range(1, n):
    start = max(i-k, 0)
    ans[i] = np.min(ans[start:i] + np.abs(h_list[start:i] - h_list[i]))
        
# print(ans)
print(ans[-1])
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0 for _ in range(n)]
for i in range(1, n):
    hi = h[i]
    x = 2 * 10 ** 9
    for j in range(1, min(k, i) + 1):
        x = min(x, dp[i - j] + abs(hi - h[i - j]))
    dp[i] = x
print(dp[-1])
#frog1からジャンプの回数が変数kになった
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(1,n):
    for j in range(1,k+1):
        if i-j<0:#out of indexを防ぐ
            continue
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))#dp[i]と大小を比較する
print(dp[n-1])
#!/usr/bin/env python3

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

    INF = 1 << 60
    dp = [INF] * 100010

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


if __name__ == "__main__":
    main()
[n,k] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

"""
初期条件
dp[0] = 0
dp[1] = h[1] - h[0]
"""

dp = [10 ** 9 + 7] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
if n > 2:
    for i in range(2,n):
        for j in range(1,min(i - 0,k)+1):
            dp[i] =min(dp[i - j] + abs(h[i]-h[i - j]),dp[i])
    print(dp[n-1])
else:
    print(dp[1])
import sys

N, K = map(int, sys.stdin.readline().split())
h = tuple(map(int, sys.stdin.readline().split()))
cost = [None]*N
cost[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i + j > N-1:
            break
        tmp = cost[i] + abs(h[i] - h[i+j])
        if cost[i+j] == None or cost[i+j] > tmp:
            cost[i+j] = tmp

print(cost[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(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i])
print(dp[-1])
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):    
    start=max(0,i-k)
    dp[i]=min(dp[j]+abs(l[i]-l[j]) for j in range(start,i))
print(dp[-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 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 itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i,j in itertools.product(range(1,N),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])
import sys

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

dp = [sys.maxsize] * N
dp[0] = 0
for i in range(1, N):
    limit = K if K <= i else i
    for j in range(1, limit + 1):
        a = abs(steps[i] - steps[i - j]) + dp[i - j]
        dp[i] = a if a < dp[i] else dp[i]

print(dp[N - 1])
# N = int(input())


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

print(dp[N])
import sys
sys.setrecursionlimit(2000000001)

def solve(n,k,ar,dp,x):
	ab = abs; mn = min
	if x>=n-2: return dp[x]
	if not dp[x] is -1: return dp[x]
	dp[x] = mn(map(lambda i:ab(ar[x]-ar[i])+solve(n,k,ar,dp,i), range(x+1,mn(n,x+k+1))))
	return dp[x]

def main():
	I = lambda:map(int,sys.stdin.readline().split())
	pr = lambda x:sys.stdout.write(f'{x}\n')
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	pr(solve(n,k,ar,dp,0))

main()
import sys
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[sys.maxsize]*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(l[i]-l[j]))


print(dp[-1])
import sys


INF = sys.maxsize

N, K = (int(x) for x in input().split())
heights = [int(x) for x in input().split()]

memo = [INF] * N

for i in range(N - 1, -1, -1):
  if i == N - 1:
    # ゴールからゴールの距離を0で初期化
    memo[i] = 0
    continue
  cost = INF
  for j in range(1, K + 1):
    # 範囲外
    if i + j >= N:
      continue
    cost = min(cost, memo[i + j] + abs(heights[i] - heights[i + j]))
  memo[i] = cost             

print(memo[0])
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**10
    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] = list(map(int,input().split()))
h = list(map(int,input().split()))


#配るdp
inf = float('inf')
dp = [inf]*N

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

print(dp[N-1])
def main():
    n,k = map(int,input().split())
    h = [int(i) for i in input().split()]
    INF =  float('inf')
    dp = [INF for i in range(n)]
    dp[0] = 0
    dp[1] = abs(h[0]-h[1])
    for i in range(2,n):
        dp[i] = min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,min(i,k)+1))
    print(dp[n-1])

main()
#-*-coding:utf-8-*-
import numpy as np

def main():
    n,k = map(int,(input().split()))
    ashiba=np.array((input().split()),int)
    dp=np.zeros(n,dtype=int)
    for i in range(1,n):
        start=max(0,i-k)
        dp[i]=min(dp[start:i]+abs(ashiba[i]-ashiba[start:i]))
    print(dp[n-1])

if __name__ == "__main__":
    main()
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

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

dp = [0] * n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(H[0] - H[i])
    else:
        cands = []
        for j in range(1, k+1):
            if i - j >= 0:
                cost = dp[i - j] + abs(H[i - j] - H[i])
                cands.append(cost)

        dp[i] = min(cands)

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

table = [0] * N
for i in range(1, N):
    table[i] = min(abs(H[i] - H[j]) + table[j] for j in range(max(0, i - K), i))

print(table[N-1])
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    h=list(map(int,input().split()))+[INF]*K
    dp=[INF]*(2*10**5)
    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+k]-h[i]))
    print(dp[N-1])

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

dp = [0]*(10**6)
dp[0] = 0
for i in range(1, n):
    dp[i] = 10**9
    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])
INFTY = 10**9

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

dp = [INFTY] * N
dp[0] = 0
for i in range(1,N):
    j = 1
    while j <= K and i-j >= 0:
        dp[i] = min(dp[i], dp[i-j]+abs(H[i-j]-H[i]))
        j += 1

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

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

inf = 100000000000000
dp = [inf for x in range(N)]

dp[0] = 0
for i in range(0, 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])
from sys import maxint

N, K = map(int,raw_input().split())
stones = map(int,raw_input().split())

costs = [maxint] * N 
costs[0] = 0
for n in range(N) :
  for k in range(1,min(K, N-n-1)+1) : 
    costs[n+k] = min(costs[n+k], costs[n] + abs(stones[n]-stones[n+k]))
  
print costs[-1]
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [0,abs(h[1]-h[0])]
for i in range(2,n):
    u = []
    for j in range(1,min(i,k)+1):
        u.append(dp[i-j]+abs(h[i]-h[i-j]))
    dp.append(min(u))

print(dp[n-1])
import numpy as np

N,k=map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N, dtype=int)

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

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

def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0] * (N + 1)

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

if __name__ == "__main__":
    main()
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [10**6] * 100005
dp[0] = 0
# dp[1] = abs(h[1]-h[0])
for i in range(1, N):
    dp[i] = min(dp[i-j] + abs(h[i-j] - h[i]) for j in range(1,min(K,i)+1))
    # print([dp[i-j] + abs(h[i-j] - h[i]) for j in range(1,min(K,i)+1)])
    # for j in range(1, min(K,i)+1):
    #     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
    ans[1]=abs(h[1]-h[0])
    for i in range(2,N):
        ans[i]= min(abs(h[i]-h[j])+ans[j] for j in range(max(0,i-K),i))
    print(ans[-1])
main()
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    H = np.array(H)
    #dp[i]:iまでくるのに最小のコスト
    dp = np.zeros(N, dtype = int)
    for i in range(1, N):
        hi = H[i]
        dp[i] = min(dp[max(0,i-K):i] + np.abs(hi-H[max(0,i-K):i]))
    print(dp[-1])

if __name__=='__main__':
    main()
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, K = LI()
H = LI()

INF = 10 ** 10


def main():
    dp = [INF] * N
    dp[0] = 0
    for i in range(1, N):
        n = min(K + 1, i + 1)
        for j in range(1, n):
            dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
    ans = dp[-1]
    print(ans)


if __name__ == "__main__":
    main()
def main():
    n,k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n

    def cost(i,j):
        return abs(h[i]-h[j])

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

if __name__ == '__main__':
    main()
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

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

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

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

print(dp[N])
# print(dp)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np

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

dp = np.ones(N)*float("inf")
dp[0] = 0
dp[1] = abs(H[1] - H[0])

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

print(int(dp[N-1]))
N,K=map(int,input().split())
H=[int(i) for i in input().split()]
f_inf=float('inf')
dp=[f_inf]*(N+5)
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-j]+abs(H[i-j]-H[i]),dp[i])
print(dp[N-1])
n, k= map(int, input().split())
h = list(map(int, input().split()))
h = [0] + h

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

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

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

dp = [0]+[10**9 + 7] * (n-1)
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])
N,K = map(int,input().split())
import numpy as np
H = np.array(input().split(), dtype = int)

INF = 10 ** 9 + 1
dp = np.full(N,INF,dtype = int)
dp[0] = 0

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

print(dp[-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):
    dp[i] = min([dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)])
print(dp[-1])
import math


def get_min(num_step):
    res = float("inf")
    for i in range(1, min(num_step, K)+1):
        cost = costs[num_step-i] + abs(steps[num_step] - steps[num_step-i])
        if cost < res:
            res = cost
    return res


N, K = map(int, input().split(" "))
steps = list(map(int, input().split(" ")))
costs = [None] * N
costs[0] = 0

for i in range(1, N):
    costs[i] = get_min(i)

print(costs[N-1])
n, k = [int(x) for x in input().split()]
seq = [int(x) for x in input().split()]
dp = [0]*n
k = min(k, n)
for i in range(1, k):
    dp[i] = abs(seq[i] - seq[0])
# print(dp)
for i in range(k, n):
    a = dp[i-1] + abs(seq[i] - seq[i-1])
    for j in range(k-1):
        a = min(a, dp[i-2-j] + abs(seq[i] - seq[i-2-j]))
    dp[i] = a
# print(dp)
print(dp[-1])
import numpy as np

#  入力
n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

#  方針
#  i番目の足場にいるという状態に対して
#  その足場に最も少ないコストを記録する．

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

print(dp[-1])
N, K = map(int,input().split())
hN = list(map(int,input().split()))
dp = [1000000000]*N
dp[0] = 0
for n in range(N-1):
  for k in range(min(K,N-n-1)):
    dp[n+k+1] = min(dp[n+k+1], dp[n]+abs(hN[n]-hN[n+k+1]))
print(dp[-1])
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0 for i in range(n)]
for i in range(1, n):
    m = 10**10
    index = i-1
    num = k
    while index >= 0 and num:
        m = min(m, dp[index]+abs(h[index]-h[i]))
        index-=1
        num-=1
    dp[i] = m
print(dp[n-1])
N,K = map(int,input().split())
lh = list(map(int,input().split()))
dp = [float("inf")]*N
dp[0] = 0
for i in range(N):
    for k in range(i+1,min((i+K+1),N)):
        dp[k] = min(dp[k],(dp[i]+abs(lh[i]-lh[k])))
print(dp[-1])
import sys
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _dbg(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

N, K = inpl()
h = inpl()

INF = 10**10

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

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

print(dp[N-1])
INF = 2**31-1
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0

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

print(dp[n-1])
import sys
n, k = map(int, sys.stdin.readline().strip('\n').split())
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(1, n):
  for j in range(k+1):
    if i-j>=0: dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]))
print(dp[n-1])
import numpy as np
N, K = map(int, input().split())
h = list(map(int, input().split()))
h = np.array(h, dtype='int32')
x = [0] * N
x = np.array(x, dtype='int32')
x[0] = 0
x[1] = x[0] + abs(h[1] - h[0])
for i in range(2, N):
    if (i < K):
        x[i] = min(x[0:i] + abs(h[i] - h[0:i]))
    else:
        x[i] = min(x[i - K:i] + abs(h[i] - h[i - K:i]))
print(x[N - 1])
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**100]*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-j]+abs(h[i]-h[i-j]),dp[i])
        else:
            break
print(dp[-1])
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**10 for i in range(N)]
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i<N-j:
            dp[i+j]=min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])