Buggy python submission (verdict: Runtime Error):
import sys
# import pdb
input = sys.stdin.readline

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

dp_list = [-1 for _ in range(N)]
dp_list[0] = 0
dp_list[1] = abs(hs[1] - hs[0])

sys.setrecursionlimit(10000)
def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  result = min(dp_memo(p-1) + abs(hs[p] - hs[p-1]), dp_memo(p-2) + abs(hs[p] - hs[p-2]))
  dp_list[p] = result
  return result


def dp_recur():
  cost1 = 0
  cost2 = abs(hs[1] - hs[0])

  if N == 2:
    print(cost2)
    exit()
  # pdb.set_trace()
  for i in range(2, N):
    cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
    cost1 = cost2
    cost2 = cost3
  return cost3

# print(dp_recur())
print(dp_memo(N-1))


Fixed submission:
import sys
# import pdb
input = sys.stdin.readline

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

cost1 = 0
cost2 = abs(hs[1] - hs[0])

if N == 2:
  print(cost2)
  exit()
# pdb.set_trace()
for i in range(2, N):
  cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
  cost1 = cost2
  cost2 = cost3

print(cost3)

Buggy python submission (verdict: Runtime Error):
import sys
# import pdb
input = sys.stdin.readline

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

dp_list = [-1 for _ in range(N)]
dp_list[0] = 0
dp_list[1] = abs(hs[1] - hs[0])

def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  result = min(dp_memo(p-1) + abs(hs[p] - hs[p-1]), dp_memo(p-2) + abs(hs[p] - hs[p-2]))
  dp_list[p] = result
  return result


def dp_recur():
  cost1 = 0
  cost2 = abs(hs[1] - hs[0])

  if N == 2:
    print(cost2)
    exit()
  # pdb.set_trace()
  for i in range(2, N):
    cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
    cost1 = cost2
    cost2 = cost3
  return cost3

# print(dp_recur())
print(dp_memo(N-1))


Fixed submission:
import sys
# import pdb
input = sys.stdin.readline

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

cost1 = 0
cost2 = abs(hs[1] - hs[0])

if N == 2:
  print(cost2)
  exit()
# pdb.set_trace()
for i in range(2, N):
  cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
  cost1 = cost2
  cost2 = cost3

print(cost3)

Buggy python submission (verdict: Runtime Error):
import sys
# import pdb
input = sys.stdin.readline

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

dp_list = [-1 for _ in range(N)]

def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  if p == 0:
    return 0

  if p == 1:
    return abs(hs[1] - hs[0])

  result = min(dp_memo(p-1) + abs(hs[p] - hs[p-1]), dp_memo(p-2) + abs(hs[p] - hs[p-2]))
  dp_list[p] = result
  return result


def dp_recur():
  cost1 = 0
  cost2 = abs(hs[1] - hs[0])

  if N == 2:
    print(cost2)
    exit()
  # pdb.set_trace()
  for i in range(2, N):
    cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
    cost1 = cost2
    cost2 = cost3
  return cost3

# print(dp_recur())
print(dp_memo(N-1))


Fixed submission:
import sys
# import pdb
input = sys.stdin.readline

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

cost1 = 0
cost2 = abs(hs[1] - hs[0])

if N == 2:
  print(cost2)
  exit()
# pdb.set_trace()
for i in range(2, N):
  cost3 = min(cost2 + abs(hs[i] - hs[i-1]), cost1 + abs(hs[i] - hs[i-2]))
  cost1 = cost2
  cost2 = cost3

print(cost3)