Buggy python submission (verdict: Runtime Error):
import sys
read = lambda: sys.stdin.readline().rstrip()
 
def main():
    INF = 10 ** 20
 
    n,k = map(int,input().split())
    height = tuple(map(int,read().split()))
    dp = [INF]*(n+1)
    dp[0] = 0
 
    
    for step in range(1, k + 1):
    	for target in range(n, 0, -1):
            if target-step >= 0: dp[target] = min(dp[target], dp[target - step] + abs(height[target] - height[target - step]))
 
    print(dp[n-1])
 
if __name__ == "__main__":
    main()

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
def main():
    INF = 10 ** 20
 
    n,k = map(int,input().split())
    height = tuple(map(int,read().split()))
    dp = [INF]*(n+1)
    dp[0] = 0
 
    for target in range(1, n):
        for step in range(1, k + 1):
            if target-step >= 0: dp[target] = min(dp[target], dp[target - step] + abs(height[target] - height[target - step]))
 
    print(dp[n-1])

if __name__ == "__main__":
    main()

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys
read = lambda: sys.stdin.readline().rstrip()

def main():

	A0 = tuple(map(int, read().split()))

  	INF = 10 ** 20

    n,k = map(int,input().split())
    h = tuple(map(int,read().split()))
    dp = [INF]*(n+1)
    dp[0] = 0

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

 
if __name__ == "__main__":
    main()

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
INF = 10 ** 20
 
n,k = map(int,input().split())
height = list(map(int,input().split()))
dp = [INF]*(n+1)
dp[0] = 0
 
for step in range(1, k+1):
    for i in range(step,n):
        dp[i] = min(dp[i], dp[i-step]+abs(h[i]-h[i-step]))
 
print(dp[n-1])

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
"""

"""
INF = 10 ** 20

N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[i-K:i],h[i-K:i])])
 
print(dp[-1])

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
INF = 10**10
 
dp = [INF]*N
dp[0] = 0
 
for i,hi in enumerate(h):
    if i == 0:
        continue
    s = i-K if i-K >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk,hk in zip(dp[s:i],h[s:i])])
 
print(dp[-1])