Buggy python submission (verdict: Runtime Error):
# coding:utf-8
 
N = int(input())
H = [int(hi) for hi in input().split()]
 
# 地点iへの最小コストを計算する関数
def dp(i):
    if i == 0:
        return 0
    elif i == 1:
        return abs(H[0]-H[1])
    else:
        return min(dp(i-2)+abs(H[i-2]-H[i]), dp(i-1)+abs(H[i-1]-H[i]))
 
min_cost = dp(N-1)
print(min_cost)



Fixed submission:
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])

for i in range(2, N):
    dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])
    
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]

# 地点iへの最小コストを計算する関数
def dp(i):
    if i == 1:
        return 0
    elif i == 0:
        return 0
    elif i == 2:
        return abs(H[0]-H[1])
    else:
        dp_i_1 = dp(i-1)+abs(H[i-2]-H[i-1])
        dp_i_2 = dp(i-2)+abs(H[i-3]-H[i-1])
        return min(dp_i_1, dp_i_2)

cost = dp(N)
print(cost)

Fixed submission:
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])

for i in range(2, N):
    dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])
    
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]

# 地点iへの最小コストを計算する関数
def dp(i):
    if i == 1:
        return 0
    elif i == 2:
        return abs(H[0]-H[1])
    else:
        dp_i_1 = dp(i-1)+abs(H[i-2]-H[i-1])
        dp_i_2 = dp(i-2)+abs(H[i-3]-H[i-1])
        return min(dp_i_1, dp_i_2)

cost = dp(N)
print(cost)

Fixed submission:
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])

for i in range(2, N):
    dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])
    
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]

cost1, cost2 = 0, 0

def jump(_k: int, k: int, cost: int) -> int:
    global H, N
    cost += abs(H[_k] - H[k])
    if k == N-1:
        return cost
    if k+1 <= N-1:
        cost1 = jump(k, k+1, cost)
    if k+2 <= N-1:
        cost2 = jump(k, k+2, cost)
    else:
        cost2 = cost1
    if cost1 <= cost2:
        return cost1
    else:
        return cost2

if N == 2:
    cost1 = jump(0, 1, 0)
    print(cost1)
else:
    cost1 = jump(0, 1, 0)
    cost2 = jump(0, 2, 0)
    if cost1 > cost2:
        print(cost2)
    else:
        print(cost1)


Fixed submission:
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])

for i in range(2, N):
    dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])
    
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]

def jump(_k: int, k: int, cost: int) -> int:
    global H, N
    cost += abs(H[_k] - H[k])
    if k == N-1:
        return cost
    if k+1 <= N-1:
        cost1 = jump(k, k+1, cost)
    if k+2 <= N-1:
        cost2 = jump(k, k+2, cost)
    else:
        cost2 = cost1
    if cost1 <= cost2:
        return cost1
    else:
        return cost2

if N == 2:
    cost1 = jump(0, 1, 0)
    cost2 = cost1
else:
    cost1 = jump(0, 1, 0)
    cost2 = jump(0, 2, 0)

if cost1 > cost2:
    print(cost2)
else:
    print(cost1)

Fixed submission:
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])

for i in range(2, N):
    dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])
    
print(dp[N-1])