Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    INF = 10**9
    dp = [INF] * N
    dp[0] = 0
    for i in range(N):
        for k in range(1, K+1):
            if i + k < N:
                dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
            else:
                break
    print(dp[N-1])

if __name__ == '__main__':
    main()

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	INF = 10**9
	dp = [INF] * N
	dp[0] = 0
	for i in range(N):
    	for k in range(1, K+1):
        	if i + k < N:
            	dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
        	else:
            	break
	print(dp[N-1])

if __name__ == '__main__':
	main()


Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))
	INF = 10**9
	dp = [INF] * N
	dp[0] = 0
	for i in range(N):
    	for k in range(1, K+1):
        	if i + k < N:
            	dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
        	else:
            	break
	print(dp[N-1])

if __name__ == '__main__':
  main()


Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
def main():
  N, K = map(int, input().split())
	h = list(map(int, input().split()))
	INF = 10**9
	dp = [INF] * N
	dp[0] = 0
	for i in range(N):
    	for k in range(1, K+1):
        	if i + k < N:
            	dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
        	else:
            	break
	print(dp[N-1])

if __name__ == '__main__':
  main()

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

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

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

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

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
        else:
            break
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(K):
        if i + k +1 < N:
            #print(i, i +k+1, h[i], h[i+k+1])
            dp[i+k+1] = min(dp[i+k+1], dp[i]+abs(h[i] - h[i+k+1]))
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i + k < N:
            dp[i+k] = min(dp[i+k], dp[i]+abs(h[i] - h[i+k]))
print(dp[N-1])