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


def recursive(i):
    if i == 0:
        return 0
    res = math.inf
    res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    return res


print(recursive(N - 1))


Fixed submission:
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])

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


def recursive(i):
    if i == 0:
        return 0
    res = math.inf
    res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    return res


print(recursive(N - 1))


Fixed submission:
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])

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

dp = list([math.inf for i in range(N + 10)])  # dpテーブル


def recursive(i):
    res = math.inf
    if dp[i] < math.inf:
        return dp[i]

    if i == 0:
        return 0
    res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return res


print(recursive(N - 1))


Fixed submission:
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
import math
"""再帰的な解(メモ化つき)"""
N = int(input())
h = list(map(int, input().split()))

dp = list([math.inf for i in range(N)])  # dpテーブル


def recursive(i):
    res = math.inf
    if dp[i] < math.inf:
        return dp[i]
    if i == 0:
        return 0
    if i > 0:
        res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return res


print(recursive(N - 1))


Fixed submission:
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])

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


"""再帰的な解(メモ化つき)"""
N = int(input())
h = list(map(int, input().split()))

dp = list([math.inf for i in range(N)])  # dpテーブル


def recursive(i):
    if dp[i] < math.inf:
        return dp[i]
    if i == 0:
        return 0

    if i > 0:
        res = math.inf
        res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return res


print(recursive(N - 1))


Fixed submission:
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])

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

dp = list([math.inf for i in range(N)])  # dpテーブル


def recursive(i):
    if dp[i] < math.inf:
        return dp[i]
    if i == 0:
        return 0
    res = math.inf
    res = min(res, recursive(i - 1) + abs(h[i] - h[i - 1]))
    if i > 1:
        res = min(res, recursive(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return res


print(recursive(N - 1))


Fixed submission:
import math

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

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])