Buggy python submission (verdict: Runtime Error):
import numba as nb
@nb.njit
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Fixed submission:
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin , stdout
def fun(a,k): ## k different steps can be taken
    if len(a)==1:
        return 0
    dp = [float('inf')]*len(a)
    dp[0]=0
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 1
        for j in range(1,k+1):
            if i-j<0:
                break
            dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]))
    return dp[-1]
  

n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k))

Fixed submission:
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Buggy python submission (verdict: Time Limit Exceeded):
def fun(a,k): ## k different steps can be taken
    if len(a)==1:
        return 0
    dp = [float('inf')]*len(a)
    dp[0]=0
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        for j in range(1,min(k+1,i+1)):
            dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]))
    return dp[-1]


from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k))

Fixed submission:
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Buggy python submission (verdict: Time Limit Exceeded):
def fun(a,k):
    if len(a)==1:
        return 0
    dp = [float('inf')]*len(a)
    dp[0]=0
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        for j in range(k,0,-1):
            dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]))
    return dp[-1]
  
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k))

Fixed submission:
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Buggy python submission (verdict: Time Limit Exceeded):
def fun(a,k):
    if len(a)==1:
        return 0
    dp = [float('inf')]*len(a)
    dp[0]=0
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        for j in range(k,0,-1):
            dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]))
    return dp[-1]
n,k = map(int , input().split())
a = list(map(int , input().split()))
print(fun(a,k))

Fixed submission:
def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    mi=float("inf")
    temp=1
    for j in range(i-1,-1,-1):
        if temp>k:
            break
        else:
            temp+=1
        if abs(a[i]-a[j])+dp[j]<mi:
            mi=abs(a[i]-a[j])+dp[j]
    dp[i]=mi
print(dp[n-1])

Fixed submission:
import numba as nb
@nb.njit
def solve(n,k,a):
    dp=[0]*n
    dp[1]=abs(a[1]-a[0])
    for i in range(2,n):
        mi=10**9
        temp=1
        for j in range(i-1,-1,-1):
            if temp>k:
                break
            else:
                temp+=1
            if abs(a[i]-a[j])+dp[j]<mi:
                mi=abs(a[i]-a[j])+dp[j]
        dp[i]=mi
    print(dp[n-1])
n,k=map(int,input().split())
a=list(map(int,input().split()))
solve(n,k,a)