Buggy python submission (verdict: Runtime Error):
Nlist = list(map(int, input().split()))
h = list(map(int, input().split()))
n = Nlist[0]
k = Nlist[1]
 
dp = []
for i in range(n):
	dp.append(int(0))
 
for s in range(1,n):
	if s - k < 0:
		l = 0
	else:
		l = s - k
	temp = dp[l] + abs(h[s] - h[l])
	for t in range(l, s):
		temp = min(temp, dp[t] + abs(h[t] - h[s]))
	dp[s] = temp

print(dp[n-1])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
sys.setrecursionlimit(200000)

n = int(input())
h = list(map(int, input().split()))

dp = []
for i in range(n):
    dp.append(-1)
 
def flog(m):
    if dp[m] != -1:
        return dp[m]
    if m == 0:
        dp[m] = 0
        return 0
    if m == 1:
        dp[m] = abs(h[0]-h[1])
        return dp[m]
    else:
        dp[m] = min(flog(m-1) + abs(h[m-1] - h[m]),flog(m-2) + abs(h[m-2] - h[m]))
        return dp[m]
  
print(flog(n-1))

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)

n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
    dp.append(-1)
 
 
def flog(m):
    if dp[m] != -1:
        return dp[m]
    if m == 0:
        dp[m] = 0
        return 0
    if m == 1:

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(flog(j-1) + abs(h[j-1] - h[j]),flog(j-2) + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(0)
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(flog(j-1) + abs(h[j-1] - h[j]),flog(j-2) + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

dp = []
for i in range(n):
    dp.append(-1)


def flog(m):
    if dp[m] >= 0:
        return dp[m]
    if m == 0:
        dp[m] = 0
        return 0
    if m == 1:
        dp[m] = abs(h[0]-h[1])
        return dp[m]
    else:
        dp[m] = min(flog(m-1) + abs(h[m-1] - h[m]),flog(m-2) + abs(h[m-2] - h[m]))
        return dp[m]
  
print(flog(n-1))

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))

dp = []
for i in range(n):
    dp.append(-1)


def flog(m):
    if dp[m] != -1:
        return dp[m]
    if m == 0:
        dp[m] = 0
        return 0
    if m == 1:
        dp[m] = abs(h[0]-h[1])
        return dp[m]
    else:
        dp[m] = min(flog(m-1) + abs(h[m-1] - h[m]),flog(m-2) + abs(h[m-2] - h[m]))
        return dp[m]
  
print(flog(n-1))
  

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
 
dp = []
for i in range(n):
	dp.append(int(0))
dp[0] = 0
dp[1] = abs(h[0]-h[1])
 
for j in range(2,n):
	dp[j] = min(dp[j-1] + abs(h[j-1] - h[j]),dp[j-2] + abs(h[j-2] - h[j]))
  
print(dp[n-1])