Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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


combi = []
perm = []

# 1からn桁の[1, 2]の数字の組み合わせのうち合計値がnになるものをcombiに代入
for i in range(int(n / 2), n + 1):
    tmp_combi = list(itertools.combinations_with_replacement([1, 2], i))
    for c in (tmp_combi):
        if sum(c) == n:
            combi.append(c)

# combiの順列を作成しpermに入れる
# setを使いユニークにしている
# 1, 1, 2 -> 1 1 2, 1 2 1, 2 1 1
for c in combi:
    for p in list(set(list(itertools.permutations(c)))):
        perm.append(p)

# 順列1つずつに対しコストを計算して最小値をmin_costに代入
min_cost = 10 ** 10
for p in perm:
    cost = 0
    p = list(p)
    pos = p.pop(0)
    if pos != 1:
        continue
    for j in p:
        cost += abs(h[pos - 1] - h[pos + j - 1])
        pos += j
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Fixed submission:
N = int(input())
blank = 2
h = list(map(int,input().split())) + [0] * blank
INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])

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

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


combi = []
perm = []

# 1からn桁の[1, 2]の数字の組み合わせのうち合計値がnになるものをcombiに代入
for i in range(n / 2, n + 1):
    tmp_combi = list(itertools.combinations_with_replacement([1, 2], i))
    for c in (tmp_combi):
        if sum(c) == n:
            combi.append(c)

# combiの順列を作成しpermに入れる
# setを使いユニークにしている
# 1, 1, 2 -> 1 1 2, 1 2 1, 2 1 1
for c in combi:
    for p in list(set(list(itertools.permutations(c)))):
        perm.append(p)

# 順列1つずつに対しコストを計算して最小値をmin_costに代入
min_cost = 10 ** 10
for p in perm:
    cost = 0
    p = list(p)
    pos = p.pop(0)
    if pos != 1:
        continue
    for j in p:
        cost += abs(h[pos - 1] - h[pos + j - 1])
        pos += j
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Fixed submission:
N = int(input())
blank = 2
h = list(map(int,input().split())) + [0] * blank
INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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


combi = []
perm = []
for i in range(1, n + 1):
    tmp_combi = list(itertools.combinations_with_replacement([1, 2], i))
    for c in (tmp_combi):
        if sum(c) == n:
            combi.append(c)


for c in combi:
    for p in list(set(list(itertools.permutations(c)))):
        perm.append(p)


min_cost = 10 ** 10
for p in perm:
    cost = 0
    p = list(p)
    pos = p.pop(0)
    if pos != 1:
        continue
    for j in p:
        cost += abs(h[pos - 1] - h[pos + j - 1])
        pos += j
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Fixed submission:
N = int(input())
blank = 2
h = list(map(int,input().split())) + [0] * blank
INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])