Buggy python submission (verdict: Runtime Error):
import math
import sys
sys.setrecursionlimit(10**6)

n, k = input().split()
n = int(n)
k = int(k)
mincost = [None]*n
h = list(map(int, input().split()))

def cost(n):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    x = [10**5]*k
    for i in range(k):
        if (n-i-2 < 0):
            break
        x[i] = cost(n-i-1) + abs(h[n-1]-h[n-i-2])
    mincost[n-1] = min(x)
  return mincost[n-1]

print(cost(n))


Fixed submission:
import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))


Fixed submission:
import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))


Fixed submission:
import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))


Fixed submission:
import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))

Buggy python submission (verdict: Runtime Error):
import math

def cost(n,h,mincost):
  if (n == 1):
    return 0
  elif (n == 2):
    return abs(h[1] - h[0])
  elif (mincost[n-1] is not None):
    return mincost[n]
  else:
  	mincost[n-1] = min(cost(n-1,h,mincost) + abs(h[n-1]-h[n-2]), cost(n-2,h,mincost) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

n = int(input())
h = [None]*n
mincost = [None]*n
i = 0

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

print(cost(n,h,mincost))


Fixed submission:
import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))

Buggy python submission (verdict: Runtime Error):
import math

def cost(n,h,mincost):
  if (n == 1):
    return 0
  elif (n == 2):
    return abs(h(1) - h(0))
  elif (mincost(n) is not None):
    return mincost[n]
  else:
  	mincost[n] = min(cost(n-1,h,mincost) + abs(h[n]-h[n-1]), cost(n-2,h,mincost) + abs(h[n]-h[n-2]))
  return mincost[n]

n = input()
h = [None]*n
mincost = [None]*n
i = 0

while(i<n):
  h[i] = input()
  i = i + 1 

return cost(n,h,mincost)

Fixed submission:
import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))

Buggy python submission (verdict: Runtime Error):
N = input()
height = list(map(int, input().split(" ")))
dp = [0]*N
 
for i in range(1,N):
  if i <= 2:
    dp[i] = abs(height[i]-height[0])
  if dp[i-1] < dp[i-2]:
    dp[i] = dp[i-1] + abs(height[i]-height[i-1])
  else:
    dp[i] = dp[i-2] + abs(height[i]-height[i-2])
 
print(dp[N-1])


Fixed submission:
N = int(input())
height = list(map(int, input().split(" ")))
dp = [0]*N
 
for i in range(1,N):
  if i <= 2:
    dp[i] = abs(height[i]-height[0])
  else:
    dp[i] = min(dp[i-1] + abs(height[i]-height[i-1]), dp[i-2] + abs(height[i]-height[i-2]))

print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N = input()
height = list(map(int, input().split(" ")))
dp = [0]*N
dp[1] = 

for i in range(1,N):
  if i <= 2:
    dp[i] = abs(height[i]-height[0])
  if dp[i-1] < dp[i-2]:
    dp[i] = dp[i-1] + abs(height[i]-height[i-1])
  else:
    dp[i] = dp[i-2] + abs(height[i]-height[i-2])

print(dp[N-1])

Fixed submission:
N = int(input())
height = list(map(int, input().split(" ")))
dp = [0]*N
 
for i in range(1,N):
  if i <= 2:
    dp[i] = abs(height[i]-height[0])
  else:
    dp[i] = min(dp[i-1] + abs(height[i]-height[i-1]), dp[i-2] + abs(height[i]-height[i-2]))

print(dp[N-1])