Buggy python submission (verdict: Runtime Error):
import sys

def solve(n,k,ar):

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

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

    print(dp[n-1])



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

    solve(n,k,ar)

Fixed submission:
import sys

def solve(n,k,ar):

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

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

    print(dp[n-1])



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

    solve(n,k,ar)

Buggy python submission (verdict: Runtime Error):
def solve(n,k,ar):

    dp = [0]*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(ar[i] - ar[j]))

    print(dp[n-1])



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

    solve(n,k,ar)

Fixed submission:
import sys

def solve(n,k,ar):

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

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

    print(dp[n-1])



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

    solve(n,k,ar)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(n,k,ar):

    dp = [int(1e9)]*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(ar[i]-ar[j]))
    print(dp[n-1])

def solve1(n,k,ar):
    dp = [int(1e9)] * (n)
    dp[0] = 0
    for i in range(1,n):
        for k in range(1,k+1):
            if i-k >= 0:
                dp[i] = min(dp[i], dp[i-k] + abs(ar[i]-ar[i-k]))

    print(dp[n-1])


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

    solve(n,k,ar)

Fixed submission:
import sys

def solve(n,k,ar):

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

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

    print(dp[n-1])



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

    solve(n,k,ar)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(n,k,ar):

    dp = [int(1e16)]*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(ar[i]-ar[j]))
    print(dp[n-1])

def solve1(n,k,ar):
    dp = [int(1e9)] * (n)
    dp[0] = 0
    for i in range(1,n):
        for k in range(1,k+1):
            if i-k >= 0:
                dp[i] = min(dp[i], dp[i-k] + abs(ar[i]-ar[i-k]))

    print(dp[n-1])


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

    solve(n,k,ar)

Fixed submission:
import sys

def solve(n,k,ar):

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

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

    print(dp[n-1])



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

    solve(n,k,ar)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(n,k,ar):
    MAXX = 10**9
    dp = [MAXX] * (n+1)
    dp[0] = 0
    dp[1] = 0

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





if __name__ == '__main__':
    n,k = map(int, input().split())
    ar = list(map(int, input().split()))
    ar.insert(0,0)

    solve(n,k,ar)

Fixed submission:
import sys

def solve(n,k,ar):

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

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

    print(dp[n-1])



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

    solve(n,k,ar)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k=list(map(int,input().split()))
a=np.array(map(int,input().split()))
if k>n:
   k=n-1
dp=np.array([int(0) for _ in range(n)])
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=np.min(np.add(dp[ind:i],np.abs(a[i]-a[ind:i])))
print(dp[-1])

Fixed submission:
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if k>n:
    k=n-1
dp=[int(0) for _ in range(n)]
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=min([dp[v]+abs(a[i]-a[v]) for v in range(ind,i)])
  #dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
#print(dp[n-1])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k=list(map(int,input().split()))
a=np.array(map(int,input().split()))
if k>n:
   k=n-1
dp=np.array([int(0) for _ in range(n)])
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=np.min(np.add(dp[ind:i],np.abs(a[i]-a[ind:i])))
print(dp[-1])

Fixed submission:
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if k>n:
    k=n-1
dp=[int(0) for _ in range(n)]
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=min([dp[v]+abs(a[i]-a[v]) for v in range(ind,i)])
  #dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
#print(dp[n-1])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
    n,k=list(map(int,input().split()))
    a=list(map(int,input().split()))
    if k>n:
        k=n-1
    dp=np.array([int(0) for _ in range(n)])
    dp[1]=abs(a[0]-a[1])
     
    for i in range(2,n):
      ind = max(0,i-k)
      dp[i]=np.minimum(np.sum(dp[ind:i],abs(a[i]-a[ind:i])))
      #dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
    #print(dp[n-1])
    print(dp[-1])

Fixed submission:
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if k>n:
    k=n-1
dp=[int(0) for _ in range(n)]
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=min([dp[v]+abs(a[i]-a[v]) for v in range(ind,i)])
  #dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
#print(dp[n-1])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if k>n:
    k=n-1
dp=np.array([int(0) for _ in range(n)])
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=np.minimum(np.sum(dp[ind:i]+abs(a[i]-a[ind:i]))s)
  #dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
#print(dp[n-1])
print(dp[-1])

Fixed submission:
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if k>n:
    k=n-1
dp=[int(0) for _ in range(n)]
dp[1]=abs(a[0]-a[1])
 
for i in range(2,n):
  ind = max(0,i-k)
  dp[i]=min([dp[v]+abs(a[i]-a[v]) for v in range(ind,i)])
  #dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
#print(dp[n-1])
print(dp[-1])