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

"""
20191116
"""

N = int(input())
h = list(map(int, input().split()))
cost = [0, abs(h[1]-h[0])] + [None for _ in range(N-2)]


def dp(i):
    cost[i] = min((cost[i-1] if cost[i-1] is not None else dp(i-1)) + abs(h[i]-h[i-1]),
                  (cost[i-2] if cost[i-2] is not None else dp(i-2)) + abs(h[i]-h[i-2]))
    return cost[i]


if __name__ == "__main__":
    ans = dp(N-1)
    print(ans)


Fixed submission:
# coding: utf-8

"""
20191116
"""

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

cost = [0, abs(h[1]-h[0])] + [None for _ in range(N-2)]

for i in range(2, N):
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]), cost[i-2] + abs(h[i]-h[i-2]))

print(cost[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

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

inf = pow(10, 10)

# current_shortests = [0] + [inf] * (n-1)

in_processing = [0]  # node-number
in_processing_len = [0]
shortest_fixed = []  # node-number
shortest_fixed_len = []


def argmin(l):
    output = 0
    for i in range(len(l)):
        if l[i] < l[output]:
            output = i

    return output


def search(l, v):
    for i in range(len(l)):
        if l[i] == v:
            return i


def fun():
    k = argmin(in_processing_len)
    node = in_processing[k]
    while node != n-1:

        # print("---------")
        # print(in_processing)
        # print(in_processing_len)
        # print(shortest_fixed)
        # print(shortest_fixed_len)
        # print(k)
        # print(node)
        # print("---------")

        # if node == n-1:
        #     return in_processing_len[k]

        shortest_fixed.append(node)
        shortest_fixed_len.append(in_processing_len[k])
        del in_processing[k]
        del in_processing_len[k]

        if node+1 < n and node+1 not in shortest_fixed:
            if node+1 not in in_processing:
                in_processing.append(node+1)
                in_processing_len.append(
                    shortest_fixed_len[-1] + abs(h[node+1] - h[node]))
            else:
                idx = search(in_processing, node+1)
                if in_processing_len[idx] > shortest_fixed_len[-1] + abs(h[node+1] - h[node]):
                    in_processing_len[idx] = shortest_fixed_len[-1] + abs(h[node+1] - h[node])
        if node+2 < n and node+2 not in shortest_fixed:
            if node+2 not in in_processing:
                in_processing.append(node+2)
                in_processing_len.append(
                    shortest_fixed_len[-1] + abs(h[node+2] - h[node]))
            else:
                idx = search(in_processing, node+2)
                if in_processing_len[idx] > shortest_fixed_len[-1] + abs(h[node+2] - h[node]):
                    in_processing_len[idx] = shortest_fixed_len[-1] + abs(h[node+2] - h[node])

        k = argmin(in_processing_len)
        node = in_processing[k]

    return in_processing_len[k]


print(fun())


Fixed submission:
# coding: utf-8

"""
20191116
"""

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

cost = [0, abs(h[1]-h[0])] + [None for _ in range(N-2)]

for i in range(2, N):
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]), cost[i-2] + abs(h[i]-h[i-2]))

print(cost[N-1])

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

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

inf = pow(10, 10)

# current_shortests = [0] + [inf] * (n-1)

in_processing = [0]  # node-number
in_processing_len = [0]
shortest_fixed = []  # node-number
shortest_fixed_len = []


def argmin(l):
    output = 0
    for i in range(len(l)):
        if l[i] < l[output]:
            output = i

    return output


def search(l, v):
    for i in range(len(l)):
        if l[i] == v:
            return i


def fun():
    k = argmin(in_processing_len)
    node = in_processing[k]

    # print("---------")
    # print(in_processing)
    # print(in_processing_len)
    # print(shortest_fixed)
    # print(shortest_fixed_len)
    # print(k)
    # print(node)
    # print("---------")

    if node == n-1:
        return in_processing_len[k]

    shortest_fixed.append(node)
    shortest_fixed_len.append(in_processing_len[k])
    del in_processing[k]
    del in_processing_len[k]

    if node+1 < n and node+1 not in shortest_fixed:
        if node+1 not in in_processing:
            in_processing.append(node+1)
            in_processing_len.append(
                shortest_fixed_len[-1] + abs(h[node+1] - h[node]))
        else:
            idx = search(in_processing, node+1)
            if in_processing_len[idx] > shortest_fixed_len[-1] + abs(h[node+1] - h[node]):
                in_processing_len[idx] = shortest_fixed_len[-1] + abs(h[node+1] - h[node])
    if node+2 < n and node+2 not in shortest_fixed:
        if node+2 not in in_processing:
            in_processing.append(node+2)
            in_processing_len.append(
                shortest_fixed_len[-1] + abs(h[node+2] - h[node]))
        else:
            idx = search(in_processing, node+2)
            if in_processing_len[idx] > shortest_fixed_len[-1] + abs(h[node+2] - h[node]):
                in_processing_len[idx] = shortest_fixed_len[-1] + abs(h[node+2] - h[node])

    output = fun()

    return output


ans = fun()

print(ans)


Fixed submission:
# coding: utf-8

"""
20191116
"""

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

cost = [0, abs(h[1]-h[0])] + [None for _ in range(N-2)]

for i in range(2, N):
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]), cost[i-2] + abs(h[i]-h[i-2]))

print(cost[N-1])