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

dp = [float('inf')] * N
def f(i):
  if dp[i] < float('inf'):
    return dp[i]
  if i==0:
    return 0
  if i==1:
    return abs(hlist[1]-hlist[0])
  
  res = float('inf')
  res = min(res, f(i-1) + abs(hlist[i]-hlist[i-1]))
  res = min(res, f(i-2) + abs(hlist[i]-hlist[i-2]))
  dp[i] = res
  
  return dp[i]
print(f(N-1))


Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))

dp = [-1 for _ in range(N)]
dp[0] = 0
for n in range(N-2):
  cost = dp[n] + abs(hlist[n]-hlist[n+1])
  dp[n+1] = min(dp[n+1], cost) if dp[n+1] != -1 else cost
  cost = dp[n] + abs(hlist[n]-hlist[n+2])
  dp[n+2] = min(dp[n+2], cost) if dp[n+2] != -1 else cost
cost = dp[-2] + abs(hlist[-2]-hlist[-1])
dp[-1] = min(dp[-1], cost) if dp[-1] != -1 else cost
print(dp[-1])

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

dp = [float('inf')] * N
def f(i, n):
  if dp[i] < float('inf'):
    return dp[i]
  if i==0:
    return n
  if i==1:
    return n + abs(hlist[1]-hlist[0])
  dp[i-1] = min(dp[i-1], f(i-1, n+abs(hlist[i]-hlist[i-1])))
  dp[i-2] = min(dp[i-2], f(i-2, n+abs(hlist[i]-hlist[i-2])))
  return min(dp[i-1], dp[i-2])
print(f(N-1, 0))


Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))

dp = [-1 for _ in range(N)]
dp[0] = 0
for n in range(N-2):
  cost = dp[n] + abs(hlist[n]-hlist[n+1])
  dp[n+1] = min(dp[n+1], cost) if dp[n+1] != -1 else cost
  cost = dp[n] + abs(hlist[n]-hlist[n+2])
  dp[n+2] = min(dp[n+2], cost) if dp[n+2] != -1 else cost
cost = dp[-2] + abs(hlist[-2]-hlist[-1])
dp[-1] = min(dp[-1], cost) if dp[-1] != -1 else cost
print(dp[-1])

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

def f(i, n):
  if i==0:
    return n
  if i==1:
    return n + abs(hlist[1]-hlist[0])
  return min(f(i-1, n+abs(hlist[i]-hlist[i-1])), f(i-2, n+abs(hlist[i]-hlist[i-2])))
print(f(N-1, 0))

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))

dp = [-1 for _ in range(N)]
dp[0] = 0
for n in range(N-2):
  cost = dp[n] + abs(hlist[n]-hlist[n+1])
  dp[n+1] = min(dp[n+1], cost) if dp[n+1] != -1 else cost
  cost = dp[n] + abs(hlist[n]-hlist[n+2])
  dp[n+2] = min(dp[n+2], cost) if dp[n+2] != -1 else cost
cost = dp[-2] + abs(hlist[-2]-hlist[-1])
dp[-1] = min(dp[-1], cost) if dp[-1] != -1 else cost
print(dp[-1])

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

dp = [0 for _ in range(N)]
def f(i, n):
  if i==0:
    return n
  if i==1:
    return n + abs(hlist[1]-hlist[0])
  return min(f(i-1, n+abs(hlist[i]-hlist[i-1])), f(i-2, n+abs(hlist[i]-hlist[i-2])))
print(f(N-1, 0))

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))

dp = [-1 for _ in range(N)]
dp[0] = 0
for n in range(N-2):
  cost = dp[n] + abs(hlist[n]-hlist[n+1])
  dp[n+1] = min(dp[n+1], cost) if dp[n+1] != -1 else cost
  cost = dp[n] + abs(hlist[n]-hlist[n+2])
  dp[n+2] = min(dp[n+2], cost) if dp[n+2] != -1 else cost
cost = dp[-2] + abs(hlist[-2]-hlist[-1])
dp[-1] = min(dp[-1], cost) if dp[-1] != -1 else cost
print(dp[-1])