peterverebics/CodeNet_Python_118 huggingface dataset:
arg = list(map(int, input().split())) # 1行, 配列
N = arg[0]
K = arg[1]
S = list(map(int, input().split())) # 1行, 配列

DP = [0] * N

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

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

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

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

for i in range(1,n):
    minm = float('inf')
    for j in range(1,min(k+1,i+1)):
    	minm = min(minm,dp[i-j]+abs(arr[i]-arr[i-j]))
    dp.append(minm)
print(dp[-1])
import numpy as np

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

dp = np.ones(N+1,dtype=float)*float('inf')
dp[0]=0
dp[1]=0
    

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

cost=[-1 for _ in range(N)]


for i in range(N):
    if i==0:
        cost[i]=0
    else:
        siten=max(i-K,0)
        min_cost=10**6
        for j in range(siten,i):
            m=cost[j]+abs(h[j]-h[i])
            if m<min_cost:
                min_cost=m
        cost[i]=min_cost

print(int(cost[N-1]))
n,k=map(int,input().split())
h=list(map(int,input().split()))
s=[0,abs(h[1]-h[0])]
total=10**5
for i in range(2,n):
    for j in range(1,k+1):
        if i-j<0:
            break
        total=min(total,abs(h[i]-h[i-j])+s[i-j])
    s.append(total)
    total=10**6
print(s[-1])
from sys import stdin,stdout
n,k=map(int,stdin.readline().split())
l=list(map(int,stdin.readline().split()))
l1=[]
for i in range(min(n,k)):
    l1.append(abs(l[i]-l[0]))
for i in range(min(n,k),n):
    cost=10**5
    if k>i:
        x=i
    else:
        x=k
    for j in range(1,x+1):
        cost=min(cost,abs(l[i]-l[i-j])+l1[-j])
    l1.append(cost)
stdout.write(str(l1[-1])+'\n')
n,k=map(int,input().split())
h=list(map(int,input().split()))

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

print(dp[n-1])
[n, k] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10 ** 5 for _ 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 + j] , dp[i] + abs(h[i] - h[i+j]))
print(dp[n-1])
N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
dp = [100 ** 10] * N
dp[0] = 0
dp[1] = abs(lst[0] - lst[1])
for i in range(2, N):
    j = K
    while j > 0:
        if i - j >= 0:
            tmp = dp[i - j] + abs(lst[i - j] - lst[i])
            dp[i] = min(dp[i], tmp)
        j -= 1
print(dp)
import math
from decimal import *

n, k = map(int, input().split())
nos = list(map(int, input().split()))
dp = [int(10e6) for i in range(n)]
dp[0] = 0
if(n>1):
    dp[1] = abs(nos[1]-nos[0])
for y in range(2, n):
    for x in range(1, k+1):
        if(y-x >= 0):
            dp[y] = min(dp[y], abs(nos[y-x]-nos[y])+dp[y-x])
print(dp[n-1])
N, K = map(int, input().split())
h = list(map(int, input().split()))

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

inf = 1000000

for i in range(1, N):
    mindp_i = inf

    for jump in range(1, min(i, K) + 1):
        dpcand = dp[i - jump] + abs(h[i] - h[i - jump])
        if dpcand < mindp_i:
            mindp_i = dpcand

    dp[i] = mindp_i

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

    return dp[-1]


if __name__ == '__main__':
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(compute(N, K, h))
n, k = map(int, input().split())
l = 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, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if dp[i] + temp < dp[i+j]:
                dp[i+j] = temp

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

c = []
c.append(0)

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

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

n,k = map(int, input().split(" "))
l = list(map(int, input().split(" ")))
dp = [float('inf')]*n
dp[0] = 0
for i in range(1, n):
    for j in range(max(0, i-k), i):
        dp[i] = np.minimum(dp[i], dp[j]+abs(l[j]-l[i]))
print(dp[-1])
N, K = map(int, input().split())
H = list(map(int, input().split()))

DP = [10**9]*N
DP[0] = 0
DP[1] = abs(H[1]-H[0])

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

print(DP[-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-1]-listH[i])+ cost[i-k-1],cost[i])
ans=cost[-1]      
print(ans)
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [1 << 62] * N
dp[0] = 0
for i in range(1, N):
    for j in range(i + 1, min(i + 1 + K, N)):
        cost = abs(H[i - 1] - H[j])
        dp[j] = min(dp[j], dp[i - 1] + cost)
print(dp[-1])
def main():
    n, k = map(int, input().split())
    stns = [int(i) for i in input().split()]
    INF = 10**9
    dp = (n + k) * [INF]
    dp[0] = 0
    k = k + 1
    for i in range(n):
        for j in range(1, k):
            j = j + i 
            if j < n: dp[j] = min(dp[j], dp[i] + abs(stns[i] - stns[j]))
            else: break
    print(dp[-1])

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


dp = [10000]*n
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if 0 <= i-j:

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

print(dp[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-1):
    for j in range(i + 1, min(N, i + K + 1)):
        DP[j] = min(DP[j], DP[i] + abs(High[i] - High[j]))
print(DP[N-1])
#!/usr/bin/env python3
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float('inf') for i in range(N+K+1)]

if K >= N:
    print(0)
    exit()
dp[0] = 0
for i in range(1, K+1):
    dp[i] = abs(H[i]-H[0])

if K==N:
    print(min(dp))
    exit()

for i in range(0, N):
    for j in range(i+1, i+K+1):
        if j < N:
            dp[j] = min(dp[i] + abs(H[i] - H[j]), dp[j])
print(dp[N-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):
  m = []
  for j in range(1, k+1):
    m.append(dp[i-j] + abs(h[i]-h[i-j]))
  dp[i] = min(m)
  
print(dp[-1])
#B-Frog2
N,K=map(int,input().split())
h=list(map(int,input().split()))

dp=[0 for i in range(N)]
dp[1]=abs(h[1]-h[0])


for i in range(2,N):
    min_num=10000
    for j in range(max(0,i-K),i):
        print(dp[i-j]+abs(h[i]-h[j]),j)
        if min_num>dp[j]+abs(h[i]-h[j]):
            min_num=dp[j]+abs(h[i]-h[j])
    dp[i]=min_num

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

INF = 10**5

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] = min(DP[i+j], DP[i] + abs(H[i] - H[i+j]))
            # print(DP)
    # print('--')

print(DP[N-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-1,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())
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):
    dp[i + 1: i + k + 1] = np.minimum(dp[i + 1: i + k + 1], dp[i] + np.abs(arr[i + 1: i + k + 1] - arr[i]))

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

print(minToatalCostList[N-1])
def main():
    n,k= map(int,input().split())
    h = [int(i) for i in input().split()]
    inf = 10**7
    dp = [inf]*100005
    dp[0] = 0
    for i in range(1,n):
        con = inf
        for j in range(1,min(k,i)+1):
            con = min(con,dp[i-j] + abs(h[i-j] - h[i]))
        dp[i] = con
    print(dp[n-1])
main()
n, k = list(map(int,input().split()))
l = list(map(int,input().split()))
dp = [10**8]*n
dp[0] = 0
dp[1] = abs(l[0] - l[1])
for i in range(2,n):
    for j in range(i-1,max(0,i-k)-1,-1):
        tem = dp[j] + abs(l[i] - l[j])
        if tem<dp[i]:
            dp[i] = tem
    
print(dp[n-1])
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

INF = 10**6

# DP = [INF] * N
DP = [INF] * ((10**5)+10)
DP[0] = 0

for i in range(1, N):
    for j in range(1, K+1):
        if 0 <= i - j < N:
            DP[i] = min(DP[i], DP[i-j] + abs(H[i-j] - H[i]))
print(DP[N-1])
# B Frog 2

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

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

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

print(dp[n-1])
N,K = [int(i) for i in input().rstrip().split()]
H = [int(i) for i in input().rstrip().split()]
H = [H[0]]*K + H
C = [0]*K
print(H)
print(C)
for i,h in enumerate(H):
    if i < K: continue
    c = [C[-1-j]+abs(H[i-j-1]-h) for j in range(K)]
    C += [min(c)]
print(C[-1])
N, K = map(int, input().split(' '))

heights = tuple(map(int, input().split(' ')))

dp = [10 ** 6] * N
dp[0] = 0

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

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

dp    = [100000000]*( len(h) )
dp[0] = 0
for ii in range( 1, len(dp) ):
    for kk in range( max(0, ii-K), ii ):
        dp[ii] = min( dp[ii], dp[kk] + abs( h[kk] - h[ii] ) )
    
print(dp[-1])
def b_frog_2(stones, k):
    dp = [10e5+1] * 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))

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

DP=[10000000000]*N

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

print(DP[N-1])
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
H = list(map(int,input().split()))
DP = [0]*N
for _ in range(1,N):
  Hi = H[_]
  c = 10**5
  for j in range(max(0,_-K),_):
    c = min(c, DP[j] + abs(Hi - H[j]))
  DP[_] = c
print(DP[-1])
# EDPC B Frog 2
N, K = map(int, input().split())
H = list(map(int,input().split()))

f_inf = float("inf")
cost = [f_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+1,N-i)):
        cost[i] = min(cost[i],cost[i-k]+abs(H[i]-H[i-k]))

print(cost[N-1])
import sys
input = sys.stdin.readline
import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])

dp = np.full(N+K+1, 10**5)
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

        # print(dp)
print(dp[N-1])
import sys

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

print(dp[n-1])
N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]

for i in range(N+1):
    for k in range(1, K+1):
        if i - k >= 1:
            if dp[i] != 0:
                dp[i] = min(dp[i-k] + abs(h[i] - h[i-k]), dp[i])
            else:
                dp[i] = dp[i-k] + abs(h[i] - h[i-k])
print(dp[N])
from sys import stdin,stdout
n,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
dp=[9999]*n;dp[-1]=0
for i in range(n-1,-1,-1):
    for j in range(i+1,min(n,i+k+1)):
        dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j])
#print(dp,sep=' ')
stdout.write(str(dp[0])+'\n')
N, K = map( int, input().split() )
h = list( map( int, input().split() ))

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

print( l[ N - 1 ] )
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)
N, K = map(int, input().split())
H = list(map(int, input().split()))
INF = 10**6

ans = [INF] * N
ans[0] = 0
ans[1] = abs(H[1] - H[0])

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

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

print(DP[-1])
n,k = map(int,input().split())
l = list(map(int,input().split()))
dp = []
dp.append(0)
for i in range(1,k+1):
    if i==n:
        break
    dp.append(abs(l[i]-l[0]))
for i in range(k+1,n):
    dp.append(10001)
for i in range(k+1,n):
    for j in range(1,k+1):
        dp[i] = min(dp[i-j]+abs(l[i-j]-l[i]),dp[i])
print(dp[n-1])
n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 1001001001
dp = [inf] * (n+1)

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

for i in range(n):
    for j in range(k):
        if i + j >= n:
            break
        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 = list(map(int, input().split()))
dp = [10001]*n
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        if j > i:
            break
        dp[i] = min(dp[i], abs(arr[i]-arr[i-j]) + dp[i-j])
print(dp[-1])
import sys
import numpy as np
#inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    print(start)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
    print(dp)
print(dp[n-1])
n,k = map(int,input().split())
h = list(map(int,input().split())) + [0]*k
cost = [0] + [10000]*(n+k)
for i in range(n):
      for j in range(1,k+1):
            cost[i+j] = min(cost[i]+abs(h[i]-h[i+j]),cost[i+j])
print(cost[n-1])
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N + 1)
dp[1] = 0
dp[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    dp[i] = dp[i - 1] + abs(H[i] - H[i - 1])
    for j in range(max(1, i - K), K + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N])
n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=float('inf')

dp=[0]*(n+1)
dp[0]=INF
dp[1]=0
s=[]
for i in range(2,n+1):
  if i-3<0:
    dp[i]=dp[i-1]+abs(h[i-1]-h[i-2])
  else:
    for j in range(1,k):
      s.append(dp[i-j]+abs(h[i-1]-h[i-j-1]))
      s.sort()
      dp[i]=s[0]
  
print(dp[n])
N, K = map(int,input().split())
h = [int(i) for i in input().split()]

dp = [10**5]*N 
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])
import numpy as np  

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

dp = np.zeros(n+1)

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])
n,k = map(int,input().split())
h = list(map(int,input().split()))
h = [h[0]]*k + h
cost = [0] * (k+1) +[1010]*(n-1)
for i in range(n):
      i+=k
      for j in range(k):
            cost[i] = min(cost[i-j-1]+abs(h[i]-h[i-j-1]),cost[i])
print(cost[-1])
n,k = map(int,input().split())
h = list(map(int,input().split()))
start = h[0]
for i in range(n):
    h[i] -= start
dp = [10**4]*n
dp[0] = h[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[i]-h[j]))
print(dp[-1])
n, k = map(int, input().split())
h = list(map(int, input().split()))

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

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

print(minToatalCostList[N-1])
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[10**5+1]*n
cost[0]=0
for i in range(n):
  for j in range(min(k+1,n-i)):
    cost[i+j]=min(cost[i+j],cost[i]+abs(h[i]-h[i+j]))
print(cost[n-1])
N, K = map(int, input().split())
h = [0] + list(map(int, input().split()))
dp = [0]*(N+1) # 足場iにたどり着くまでの最小コスト
for i in range(2,N+1):
  for j in range(1,K+1):
    dp[i] = dp[i-1] + abs(h[i]-h[i-1])
    if i-j >= 0:
      dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])
from sys import stdin
MAX=10001
N,K=map(int,stdin.readline().split())
h=[int(i) for i in stdin.readline().split()][:N]
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(h[j]-h[i]))
    #print(dp)
print(dp[-1])
N, K = map(int, input().split())
H = list(map(int, input().split()))
INF = 10**8

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])
import numpy as np

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

table = np.full(N + K, 10 ** 10)
table[0] = 0

for i in range(1, N):
    table[i:i + K] = np.minimum(table[i:i + K], np.abs(H[i:i + K] - H[i - 1]) + table[i - 1])

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

dp = [0]*n
dp[0] = 0
for i in range(1,min(n,k)):
    mn = 100000
    for j in range(i-1,-1,-1):
        p = abs(arr[i]-arr[j])
        mn = min(mn,p+dp[j])
    dp[i] = mn

for i in range(min(n,k),n):
    mn = 100000
    for j in range(i-k,i,1):
        p = abs(arr[i]-arr[j])
        mn = min(mn,p+dp[j])
    dp[i] = mn
print(dp[n-1])
n,k= map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**7
dp = [inf]*100005
dp[0] = 0
for i in range(1,n):
    con = inf
    for j in range(1,k):
        if j > len(h):
            break
        con = min(con,dp[i-j]+abs(h[i]-h[i-j]))
        if abs(h[i]-h[i-j]) == 0:
            break
    dp[i] = con
print(dp[n-1])
n,k=map(int,input().split())
dp=[0]*(n+1)
h=list(map(int,input().split()))
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    mincost=100000000
    for j in range(1,k+2):
        if i-j<0:
            break
        tmp=dp[i-j]+abs(h[i]-h[i-j])
        mincost=min(mincost,tmp)
    dp[i]=mincost
print(dp[n-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):
  minimum = 10**9
  for j in range(1,K+1):
    if i-j<1:
      break
    else:
      if dp[i-j]-abs(H[i]-H[i-j]) < minimum:
        minimum = dp[i-j]+abs(H[i]-H[i-j])
  dp[i] = minimum
print(dp[-1])
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
dp[1] = h[1] - h[0]
for i in range(2, N):
    for j in range(1, K+1):
        if j <= i:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
print(dp[-1])
import math

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

res = [10**5] * n
res[0] = 0

for i in range(1, n):
  temp = False
  for j in range(k, 0, -1):
    if i - j < 0:
      continue
    res[i] = min(res[i-j] + abs(h[i] - h[i-j]), res[i])

print(res[n-1])
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [100000]*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[n-1])
import numpy as np
inf=10000007

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

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



##print(dp)
##print(li)
print(dp[-1])
#Frog1
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.insert(0,0)
dp={1:0}
for val3 in range(2,n+1):
    dp[val3]=int(1e7)
for val in range(2,n+1):
    for val2 in range(1,min(val,k+1)):
        dp[val]=min(dp[val],dp[val-val2]+abs(h[val]-h[val-val2]))
print(dp[n])
n,k=[int(i) for i in input().split(' ')]
h=[int(i) for i in input().split(' ')]

dp=[10**10]*n
dp[0]=0

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

print(dp[n-1])
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(1,size):
  for j in range(i+1,1+i+jumps):
    if j < size:
      dp[j] = min(dp[j], dp[i]+abs(array[i] - array[j]))
print(dp[size-1])
import numpy as np

inf = 10000007

n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype=int)
dp[0] = 0
temp=inf
for i in range(1, n):
    l = max(0, i - k)
    temp=inf
    for j in range(l,i):
        temp=min(temp,dp[j]+abs(h[i]-h[j]))
    dp[i]=temp

##print(li)
print(dp[-1])
n, k = map( int, input().split() )
h = [ int( hi ) for hi in input().split() ]
#print( n, k )
#print( h )

cost = [ 0 ] * n
for ni in range( 1, n ):
    for ki in range( 1, k+1 ):
#        print( ni, ki )
        if ni-ki >= 0:
            costx = cost[ ni-ki ] + max( h[ ni ]-h[ ni-ki ], h[ ni-ki ]-h[ ni ] )
            cost[ ni ] = max( cost[ ni-ki ], costx )

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

dp_table = [99999999] * (N+1)

# 初期化
dp_table[0] = 0
dp_table[1] = abs(places[1] - places[0])

for i in range(2, N):
    for j in range(1, K+1):
        cost = dp_table[i-j] + abs(places[i] - places[i-j])
        dp_table[i] = dp_table[i] if cost > dp_table[i] else cost

print(dp_table[N-1])