Buggy python submission (verdict: Runtime Error):

def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

Fixed submission:
import sys
n = int(input())
h = list(map(int, input().split()))
dp = [-1] * n

sys.setrecursionlimit(n + 2)
def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

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

dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

Fixed submission:
import sys
n = int(input())
h = list(map(int, input().split()))
dp = [-1] * n

sys.setrecursionlimit(n + 2)
def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

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

# i:足場
dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

Fixed submission:
import sys
n = int(input())
h = list(map(int, input().split()))
dp = [-1] * n

sys.setrecursionlimit(n + 2)
def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

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

# i:足場
dp = [-1] * n

def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))

Fixed submission:
import sys
n = int(input())
h = list(map(int, input().split()))
dp = [-1] * n

sys.setrecursionlimit(n + 2)
def dfs(i):
    if dp[i] != -1:
        return dp[i]
    if i == n - 1:
        return 0
    cost = 0
    if i == n - 2:
        cost = dfs(i + 1) + abs(h[i] - h[i + 1])
    else:
        cost = min(dfs(i + 1) + abs(h[i] - h[i + 1]), dfs(i + 2) + abs(h[i] - h[i + 2]))
    dp[i] = cost
    return cost

print(dfs(0))