Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

b = np.zeros(K, int)
for j in range(K):
    b[j] = a[max(2-(j+1),0)] + abs(hs[2] - hs[max(2-(j+1),0)])
    
for i in range(2, N):
    b = np.hstack((b[1:], np.array([a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)])])))
    a[i] = np.min(b)
print(a[-1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

b = np.zeros(K, int)
for j in range(K):
    b[j] = a[max(2-(j+1),0)] + abs(hs[2] - hs[max(2-(j+1),0)])
    
for i in range(2, N):
    b = np.hstack((b[1:], np.array([a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)])])))
    a[i] = np.min(b)
print(a[-1])
a

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

b = np.zeros(K, int)
for j in range(K):
    b[j] = a[max(2-(j+1),0)] + abs(hs[2] - hs[max(2-(j+1),0)])
    
for i in range(2, N):
    b = np.hstack((b[1:], np.array([a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)])])))
    a[i] = np.min(b)
print(a[-1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

b = np.zeros(K, int)
for j in range(K):
    b[j] = a[max(i-(j+1),0)] + abs(hs[i] - hs[max(i-(j+1),0)])
    
for i in range(2, N):
    
    b = np.hstack((b[1:], np.array([a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)])])))
    a[i] = np.min(b)
print(a[-1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0
 
a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

for i in range(2, N):
    #a[i] = min(a[max(i-2,0)] + abs(hs[i] - hs[max(i-2,0)]),
    #           a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)]))
    
    #b = np.zeros(K, int)
    #for j in range(K):
    #    b[j] = a[max(i-(j+1),0)] + abs(hs[i] - hs[max(i-(j+1),0)])
    
    bmin = float('inf')
    for j in range(K):
        bmin = min(bmin, a[max(i-(j+1),0)] + abs(hs[i] - hs[max(i-(j+1),0)]))    
    
    a[i] = bmin
print(a[-1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0
 
a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

for i in range(2, N):
    #a[i] = min(a[max(i-2,0)] + abs(hs[i] - hs[max(i-2,0)]),
    #           a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)]))
    
    b = np.zeros(K, int)
    for j in range(K):
        b[j] = a[max(i-(j+1),0)] + abs(hs[i] - hs[max(i-(j+1),0)])
    a[i] = np.min(b)    
print(a[-1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0
 
a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

for i in range(2, N):
    #a[i] = min(a[max(i-2,0)] + abs(hs[i] - hs[max(i-2,0)]),
    #           a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)]))
    
    b = np.zeros(K, int)
    for j in range(K):
        b[j] = a[max(i-(j+1),0)] + abs(hs[i] - hs[max(i-(j+1),0)])
    a[i] = np.min(b)    
print(a[-1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])