peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(input())
his = list(map(int, input().split()))
dp = []
for j in range(n):
  dp.append(0)
for i in range(0, n):
  if i >= 2:
    dpm1 = abs(his[i] - his[i-1])
    dpm2 = abs(his[i] - his[i-2])
    if dpm1 <= dpm2:
      dp[i] = dp[i-1] + dpm1
    else:
      dp[i] = dp[i-2] + dpm2
  elif i == 0:
    pass
  else:
    dp[i] = abs(his[i] - his[i-1])
print(dp[n-1])
N = int(input())
h = [0] + list(map(int, input().split())) #0-index

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

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

prev2 = 0
prev1 = abs(arr[0]-arr[1])

if n == 2:
  print(prev1)
  
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + prev1
    step_2 = abs(arr[i-1]-arr[i-2]) + prev2
    x = min(step_1, step_2)
    prev2 = prev1
    prev1 = x
   
print(prev1)
n=int(input())
cost=list(map(int,input().split()))
for i in range(2,n):
    cost[i]+=min(
        abs(cost[i]-cost[i-1]),
        abs(cost[i]-cost[i-2])
    )
print(cost[-1])
n=int(input())
l=list(map(int,input().split()))
dp=[0 for i in range(n)]

dp[1]=l[1]-l[0]
for i in range(2,n):
    dp[i]=min(dp[i-1]+l[i]-l[i-1],dp[i-2]+l[i]-l[i-2])

print(dp[n-1])
import numpy as np
N=int(input())
h=list(map(int,input().split()))

#N=4
#h=[10,30,40,20]

dp=np.zeros(N)
print(dp)
dp[1]=abs(h[1]-h[0])
print(dp)

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

#total

print(dp[-1])
n = int(input())
h = list(map(int,input().split()))
dp = [0, abs(h[0]-h[1])]
for i in range(n-2):
    dp.append(min(dp[-2] + abs(h[i]-h[i+2]), dp[-1] + abs(h[i]-h[i+1])))
print(dp[-1])
N = int(input())
a = [int(x) for x in input().split()]
def dp(N,a):
    F = [0]*(len(a))
    F[0]=0
    F[1]=abs(a[1]-a[0])
    if N == 1: return F[0]
    elif N == 2: return F[1]
    for n in range(2,N):
        F[n] = min(F[n-1] + abs(a[n]-a[n-1]),F[n-2]+abs(a[n]-a[n-2]))
    print(F)
    return F[-1] 
print(dp(N,a))
n = int(input())
h = list(map(int,input().split()))

dp = [10**5]*n

def chmin(a,b,i):
    if a > b:
        dp[i] = b

dp[0] = 0
for i in range(1,n):
    chmin(dp[i],dp[i-1] + abs(h[i] - h[i-1]),i)
    chmin(dp[i],dp[i-1] + abs(h[i] - h[i-2]),i)

print(dp[n-1])
n=int(input())
l=list(map(int,input().split()))
def frog(l,n):
  dp=[0]*n
  dp[0]=0
  dp[1]=abs(l[1]-l[0])
  for i in range(2,n):
    dp[i]=min(dp[i-1]+ abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
  return dp[n-1]
N = int(input())
A = list(map(int,input().split()))
dp = [0] * N
dp[1] = abs(A[1] - A[0])

for i in range(2,N):
    dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))

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

dp = 0
dp2 = 0
dp1 = abs(h[0] - h[1])
for i in range(2, n):
    dp = min(
        dp2 + abs(h[i] - h[i - 2]),
        dp1 + abs(h[i] - h[i - 1]))
    dp2, dp1 = dp1, dp
print(dp)
n = int(input())

l = [0] + [int(i) for i in input().split()]

ans = [0]*(n+2)

for i in range(2,n+1):
    ans[i]=min(ans[i-1]+abs(l[i-1]-l[i]),ans[i-2]+abs(l[i-2]-l[i]))


print(ans[-2])
N = int(input())
h = list(map(int, input().split()))

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

dp = []

for i, h in enumerate(H) :
  if (i==0) :
    dp.append(0)
    continue
  
  if (i==1) :
    dp.append(abs(H[0]-H[1]))
    continue
  
  one = abs(dp[i-2] + (H[i]-H[i-1]))
  two = abs(H[i]-H[i-2])
  
  if (one < two):
    dp.append(dp[i-1] + one)
  else :
    dp.append(dp[i-2] + two)

print(dp)
N = int(input())
h = list(map(int,input().split()))
cost = [100000]*N

cost[0] = 0
for i in range(N-1): 
  num = cost[i] + abs(h[i+1]-h[i])
  if cost[i+1] > num:
    cost[i+1] = num
  if i > 0:
    num2 = cost[i-1] + abs(h[i]-h[i-2])
    if cost[i+1] > num2:
      cost[i+1] =  num2
      
print(cost[N-1])
N=int(input())
line=input().split(" ")
dp=[]
for i in range(N):
    line[i]=int(line[i])
    dp.append(10000000000)
dp[0]=0
dp[1]=abs(line[1]-line[0])
for j in range(2,N):
    dp[j]=min(dp[j], dp[j-1]+abs(line[j]-line[j-1]))
    dp[j]=min(dp[j], dp[j-2]+abs(line[j]-line[j-2]))
print(dp)
def Frog1():
    N = int(input())
    Hs = list(map(int,input().split()))
    dp = [0 for i in range(N)]
    dp[0] = 0
    dp[1] = abs(Hs[1]-Hs[0])
    for i in range(2,N):
        dp[i] = min(abs(Hs[i-1]-Hs[i])+dp[i-1],abs(Hs[i-2]-Hs[i])+dp[i-2])
Frog1()
def frog(arr):
    
    n=len(arr)
    if n<=1:
        return 0
    dp=[0]*(n+1)
    dp[2]=abs(arr[0]-arr[1])
    if n==2:
        return dp[2]
    for i in range(3,n+1):
        
        dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i-2]),dp[i-2]+abs(arr[i-1]-arr[i-3]))
    return dp[n]
n=int(input())
arr=[int(i) for i in input().split()]
frog(arr)
n=int(input())
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[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
  print(dp)
print(dp[-2])
n=int(input())
h=[0]+list(map(int,input().split()))
dp=[0]*(n+1)

dp[2]=h[2]-h[1]
for i in range(3,n+1):
  jump1=dp[i-2]+abs(h[i-2]-h[i])
  jump2=dp[i-1]+abs(h[i-1]-h[i])
  dp[i]=min(jump1,jump2)

print(dp[n])
from functools import lru_cache
N = int(input())
heights = [int(h) for h in input().split()]
@lru_cache(None)
def dfs(i):
    if i == len(heights) - 1:
        return 0
    if i >= len(heights):
        return float("inf")

    return min(abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"),

               abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf"))
N = int(input())
hs = list(map(int, input().split()))

i = 0
total_cost = 0
while i < N-1:
    cost1 = abs(hs[i+1] - hs[i])
    cost2 = abs(hs[i+2] - hs[i]) if i+2 < N else None
    if cost2 is not None and cost2 <= cost1:
        i += 2
        total_cost += cost2
    else:
        i += 1
        total_cost += cost1

print(total_cost)
N = int(input())
h = [0] + list(map(int, input().split())) # 便宜上、先頭に[0]

dp = [None for _ in range(N+1)] # dp[i]：足場iに移動する最小コスト
dp[0] = 0 # 便宜上
dp[1] = 0 # 初期位置のため、0

for i in range(2, N+1):
    one = dp[i-1] + abs(h[i]-h[i-1]) # 1段前からの移動
    two = dp[i-2] + abs(h[i]-h[i-2]) # 2段前からの移動
    dp[i] = min(one, two)

print(dp[N])
inp = int(input())
if inp>=400 and inp<=599:
  ans = 8
elif inp>=600 and inp<=799:
  ans = 7
elif inp>=800 and inp<=999:
  ans = 6
elif inp>=1000 and inp<=1199:
  ans = 5
elif inp>=1200 and inp<=1399:
  ans = 4
elif inp>=1400 and inp<=1599:
  ans = 3
elif inp>=1600 and inp<=1799:
  ans = 2
elif inp>=1800 and inp<=1999:
  ans = 1
try:
    print(ans)
except:
    pass
n = int(input())
h = list(map(int,input().split()))

dp = [10**5]*n

def chmin(a,b,i):
    if a > b:
        dp[i] = b

dp[0] = 0
for i in range(1,n):
    chmin(dp[i],dp[i-1] + abs(h[i] - h[i-1]),i)
    if i >=2:
        chmin(dp[i],dp[i-2] + abs(h[i] - h[i-2]),i)

print(dp[n-1])
import math

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

res = [0]*n

for i in range(n):
  if i == 1:
    res[1] = abs(h[0] - h[1])
  temp1 = abs(h[i] - h[i-2])
  temp2 = abs(h[i] - h[i-1])
  
  res[i] = min(res[i-2] + temp1, res[i-1] + temp2)
  
print(res[n-1])
from sys import stdin


def solve():
    n = int(input())
    A = [int(i) for i in stdin.readline().split()]
    if n == 2: return abs(A[0] - A[1])
    curr = 0
    p2, p1 = A[0], abs(A[0] - A[1])
    for i in range(2, len(A)):
        # print(p2, p1)
        curr += min(abs(A[i] - A[i-1]), abs(A[i] - A[i-2]))
        p2 = p1
        p1 = curr
    return curr

print(solve())
number = int(input())
scaffolds = list(map(int, input().split()))
scaffolds.insert(0, 0)
costs = [ [0, 0] for i in range(number + 1)]

for i in range(len(costs)):
    hight = scaffolds[i]

    if 0 <= i - 1:
        min_v = min(costs[i - 1])
        hight_1 = scaffolds[i - 1]
        costs[i][0] = min_v + abs(hight_1 - hight)

    if 0 <= i - 2:
        min_v = min(costs[i - 2])
        hight_2 = scaffolds[i - 2]
        costs[i][1] = min_v + abs(hight_2 - hight)

print(min(costs[number]))
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*n

for i in range(1, n):
    c = 99999999999
    for j in range(max(0, i-k), i):
        c = min(c, dp[j]+abs(h[i]-h[j]))
        
    dp[i] = c
        
print(dp[-1])
n, k = [int(i) for i in input().split(" ")]
h = [int(i) for i in input().split(" ")]

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

for i in range(len(h)):
  for j in range(1, k+1, 1):
    if (i+j) < len(h):
      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()))

ans = [0] * n

for i in range(1, n):
    l = min(i, k)
    hs = h[i]
    ans[i] = min([abs(hs - h[i - j])+ans[i-j] for j in range(1, l+1)])
    # j : 戻り幅
#print(ans)
print(ans[-1])
import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

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

print(c[n-1])
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0] * N
dp[0] = 0
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(i,K))])
 
print(dp[-1])
import sys
import numpy as np

N, K = list(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[start:i]-h[i]))
print(dp[N-1])
# sys.stdin.readline()
import sys
input = sys.stdin.readline

N,K=map(int, input().split())
h=list(map(int, input().split()))
import numpy as np 
      
f_inf = float('inf')
dp = [f_inf]*N
dp[0]=0
# hの配列を作る。
h = np.array(h)
 
#配るDP
for i in range(1,N):
    # start は負になることはない。
    start = max(0, i-K)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
    
print(dp[-1])
n, k = (int(x) for x in input().split())
h = [0] + [int(x) for x in input().split()]
dp = [float('inf')] * (n + 1)
dp[1] = 0
for i in range(2, n + 1):
    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])
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [10 ** 10] * 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])
import numpy as np
steps, limit = map(int, input().split())
heights = [int(height) for height in input().split()]
heights = np.array(heights, np.int)
costs = np.array([0] * steps, np.int)
def search(step, num):
    costs[step] = min(costs[step-num:step] + abs(heights[step-num:step] - heights[step]))
for i in range(1,steps):
    if i < limit:
        search(i, i)
    else:
        search(i, limit)
print(costs[steps-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):
  j = max(0, i-K)
  dp[i] = np.min(dp[j:i]+np.abs(h[i]-h[j:i]))
                 
print(dp[N-1])
n,k = map(int,input().split())
h = list(map(int,input().split()))

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

dp[0] = 0

def chmin(a,b,index):
    if a > b:
        dp[index] = b

for i in range(n-1):
    for j in range(1,k+1):
        chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]),i+j)
        if i+j >= n-1:
            break
print(dp[n-1])
n, k = map(int, input().split())
lst = list(map(int, input().split()))
cst = [float('inf')] * n
cst[0] = 0
for _ in range(0, n):
    m = min(n-(_+1),k)
    for i in range(0, m+1):   
      cst[_+i] = min(cst[_] + abs(lst[_+i] - lst[_]),cst[_+i])
print(cst[n-1])
from math import inf

n, k = map(int, input().split())
a = [int(i) for i in input().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:
            dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j])
        else:
            break

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

for j in range(N):
  for k in range(min(N, K+1)):
    if dp[j] > dp[j-k] + abs(h[j] - h[j-k]):
      dp[j] = dp[j-k] + abs(h[j] - h[j-k])
print(dp[N-1])
from sys import stdout, stdin, maxsize

n, k = map(int, stdin.readline().split())
ls = list(map(int, stdin.readline().split()))
dp = [maxsize] * (n + 1)
dp[1] = 0
if n == 1:
	print(0)
else:
	dp[2] = abs(ls[1] - ls[0])
	for i in range(3, n + 1):
		j = 1
		while j <= k and i - j >= 0:
			dp[i] = min(dp[i - j] + abs(ls[i - 1] - ls[i - 1 - j]), dp[i])
			j += 1
	print(dp[n])
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [H[0]] * K + H

# dp[i] := 足場iに来るのにかかる最小のコスト
INF = 10**18
dp = [INF] * (K + N)
dp[0] = 0
for i in range(K, N + K):
    h = H[i]
    # TLEするので内包表記にする
    costs = [x + abs(y - h) for x, y in zip(dp[i - K:i], H[i - K:i])]
    dp[i] = min(costs)
ans = dp[-1]
print(ans)
N, K = map(int, input().split())
h = list(map(int, input().split()))

#dp[i]:i番目に到達するまでにはらうコストの最小値
INF = float('inf')
dp = [INF for i in range(N)]
dp[0] = 0

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


print(dp[N-1])
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    inf=10**10
    n,k=map(int,readline().split())
    h=np.array(list(map(int,readline().split())),dtype=np.int64)

    dp=np.full(n,inf,dtype=np.int64)
    dp[0]=0
    for i in range(n-1):
        end=min(n,i+k+1)
        sa=np.abs(h[i]-h[i+1:end])
        dp[i+1:end]=np.minimum(dp[i+1:end],dp[i]+sa)

    print(dp[n-1])

if __name__=="__main__":
    main()
import numpy as np

N,K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.full(N,10**10)
dp[0] = 0
for i in range(1,N):
    start = max(0,i-K)
    dp[i] = np.min(dp[start:i]+np.abs(h[i]-h[start:i]))
print(int(dp[-1]))
N,K=map(int,input().split())
h_list=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=float("inf")
    for j in range(1,min(i,K)+1):
        dp[i]=min(dp[i],dp[i-j]+abs(h_list[i-j]-h_list[i]))
print(dp[-1])
def main():
    platform_count, jumping_power = [int(x) for x in input().split()]
    platforms = [int(x) for x in input().split()]
    dp = [0]
    for i in range(1, platform_count):
        indexes = (i - x for x in range(1, jumping_power + 1) if i - x >= 0)
        dp.append(
            min(abs(platforms[i] - platforms[before]) + dp[before]
                for before in indexes))
    print(dp[platform_count - 1])


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

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

for i in range(n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
        continue

    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])
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
l=list(mi())
dp=[0]*a
dp[0]=0
for i in range(1,a):
    dp[i]=min(abs(l[i]-l[i-j-1])+dp[i-j-1] for j in range(min(i,b)))
print(dp[-1])
N, K = map(int, input().split())
h = list(map(int,input().split()))

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

for i in range(K, N):
  c = [float("INF")] * (K+1)
  for j in range(1, K+1):
    c[j] = dp[i-j] + abs(h[i] - h[i-j])
  dp[i] = min(c)
  
print(dp[N-1])
def cal_cost(co, h, i, j):
    return co + abs(h[i]-h[j])

n, k = map(int, input().split())
h = [int(i) for i in input().split(" ")]
lis = [0 for i in range(n)]
for i in range(1, n):
    a = min([cal_cost(lis[i-j], h, i-j, i) for j in range(1, k+1) if j<=i])
    lis[i] = a
print(lis[-1])
n,k = map(int,input().split())
h = list(map(int,input().split()))

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

for i in range(n-1):
    for j in range(i+1,min(i+k,n-1)+1):
        dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]))
        # print(dp)
print(dp[n-1])
n,k=[int(x) for x in input().split()]
infy=float('inf')
arr=[int(x) for x in input().split()]

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


print(val[n-1])
n, k, *h = map(int, open(0).read().split())
h += [0] * 200
dp = [0] + [float("inf")] * 100200
for i in range(1, n):
  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, k + 1))
print(dp[n - 1])
n, k = map(int, input().split())
h = list(map(int, input().split()))

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

f_inf = float('inf')

for _ in range(k+2):
    h.append(f_inf)

dp = [f_inf]*(n+k)

dp[0] = 0

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

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

dp = [0] + [1000000000000]*(N-1)

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])
def hoge():
  dp = [0] * (n + 5)
  for i in range(1, n):
    p = [dp[j] + abs(h_list[i] - h_list[j]) for j in range(max(0, i - k), i)]
    dp[i] = min(p)
  return dp[n - 1]

def solve():
  global n, k, h_list
  n, k = map(int, input().split())
  h_list = list(map(int, input().split()))
  ans = hoge()
  print(ans)
  return 0

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

results = list()

results.append(0)

for i in range(1, n):
    score = float('INF')
    for j in range(1, min(k+1, i + 1)):
        score = min(score, results[i-j] + abs(hs[i-j] - hs[i]))
    results.append(score)

print(results[n-1])
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*(n+1)
dp[1] = 0

for i in range(1,n+1):
  for j in range(max(1,i-k),i):
    dp[i] = min(dp[i],dp[j]+abs(h[i-1]-h[j-1]))
print(dp[-1])
from numba import jit
import math

N, K = map(int,input().split())
h = list(map(int,input().split()))
@jit
def nya(N, K, h):
  dp=[0]*N
  for i in range(1,N):
    value=math.inf
    for j in range(1,K+1):
      if i-j<0:
        break
      value=min(value,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i]=value
  return(dp[N-1])
 
print(nya(N,K,h))
N, K = map(int,input().split())
H = list(map(int,input().split()))

#DP[i] i番目までの足場を見たときの足場iにたどり着く最小値

DP = [10**12 for _ in range(N + 1)] 
DP[0] = 0
for i in range(N):
    for k in range(1,K + 1):
        if 0 <= i - k and i - k < N:
            cost_min = 10**12
            cost_min = min(cost_min, DP[i - k] +  abs(H[i] - H[i - k]))
            DP[i] = min(DP[i],cost_min)
print(DP[N - 1])
n, k = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [0]
for i in range(1, n):
    mi = min([abs(h_list[i] - h_list[j]) + dp[j] for j in range(max(0, i - k), i)])
    dp.append(mi)
print(dp[-1])
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-1):
  for j in range(1, 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])
import math
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp_list = [math.inf] * N
dp_list[0] = 0

for i, h in enumerate(H[:-1]):
  for j in range(1, min(K + 1, N - i)):
    cost_step = abs(H[i] - H[i + j])
    cost_total = dp_list[i] + cost_step
    if dp_list[i + j] > cost_total:
      dp_list[i + j] = cost_total
      
print(dp_list[-1])
import sys
input = sys.stdin.readline
N,K=map(int,input().split())
import numpy as np
hights=np.array(list(map(int,input().split())))
steps=np.array([10**10]*N)
steps[0]=0
for i in range(N-1):
    gaps=hights[i+1:i+K+1]-hights[i]
    gaps=np.abs(gaps)
    gaps+=steps[i]
    steps[i+1:i+K+1]=np.minimum(steps[i+1:i+K+1],gaps)
print(steps[-1])
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

def chmin(a, b):
    if a > b:
        return b
    else:
        return a
f_inf = pow(10,9)+99

dp = [f_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] = chmin(dp[i], dp[i-j]+ abs(h[i] - h[i - j]))
print(dp[n-1])
n, k = map(int, input().split())
scaffolds = list(map(int, input().split()))
dp = [10 ** 5 * 10 ** 4] * 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], abs(scaffolds[i] - scaffolds[i + j]) + dp[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

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

print(dp[-1])
N,K=map(int,input().split())
H=list(map(int,input().split()))
DP=[0]*(N+1)
for i in range(2,N+1):
  L=[DP[i-j-1]+abs(H[i-1]-H[i-j-2])for j in range(min(K,i-1))]
  DP[i]=min(L)
print(DP[-1])
import numpy as np


def solve():
    N, K = map(int, input().split())
    h = np.array(list(map(int, input().split())))
    dp = np.full(N, 10**9, dtype=np.int)
    dp[0] = 0

    for i in range(1, N):
        dp[i:i + K] = np.fmin(
            dp[i:i + K],
            dp[i - 1] + np.abs(h[i:i + K] - h[i - 1])
        )
    return dp[-1]


if __name__ == "__main__":
    print(solve())
n,k,*h=map(int,open(0).read().split())

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

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

        if not 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()))
dp=[0]*(n)
if k+1<=n:
  max=k+1
else:
  max=n
  
for i in range(1,max):
  dp[i]=abs(h[0]-h[i])
 
for i in range(k,n):
  li=[abs(h[i]-h[ik])+dp[ik] for ik in range(i-1,i-k-1,-1) ]
  dp[i]=min(li)
  
print(dp[-1])
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
dp = [float("inf") for _ in range(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[-1])