from functools import lru_cache

import sys



sys.setrecursionlimit(10**6)



N = int(eval(input()))

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



@lru_cache(maxsize=None)

def recur(i):

    if i == N - 1:

        return 0

    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))



print((recur(0)))



# dp = [0]*(N + 1)

# for i in range(N):

from functools import lru_cache

import sys



sys.setrecursionlimit(10**6)



N = int(eval(input()))

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



# @lru_cache(maxsize=None)

# def recur(i):

#     if i == N - 1:

#         return 0

#     return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

#

# print(recur(0))



dp = [float("inf")]*(N + 2)

dp[0] = 0

for i in range(N - 1):

    dp[i + 1] = min(dp[i + 1], abs(h[i] - h[i + 1]) + dp[i])

    if i < N - 2:

        dp[i + 2] = min(dp[i + 2], abs(h[i] - h[i + 2]) + dp[i])



print((dp[N - 1]))

from functools import lru_cache
import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
h = list(map(int, input().split()))


@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(
        abs(h[i] - h[i + 1]) + recur(i + 1),
        abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)),
    )


print((recur(0)))
# dp = [0]*(N + 1)
# for i in range(N):

from functools import lru_cache
import sys

sys.setrecursionlimit(10**6)
N = int(eval(input()))
h = list(map(int, input().split()))
# @lru_cache(maxsize=None)
# def recur(i):
#     if i == N - 1:
#         return 0
#     return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))
#
# print(recur(0))
dp = [float("inf")] * (N + 2)
dp[0] = 0
for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], abs(h[i] - h[i + 1]) + dp[i])
    if i < N - 2:
        dp[i + 2] = min(dp[i + 2], abs(h[i] - h[i + 2]) + dp[i])
print((dp[N - 1]))

- - -@lru_cache(maxsize=None) -def recur(i): -    if i == N - 1: -        return 0 -    return min( -        abs(h[i] - h[i + 1]) + recur(i + 1), -        abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)), -    ) - - -print((recur(0))) -# dp = [0]*(N + 1) -# for i in range(N): +# @lru_cache(maxsize=None) +# def recur(i): +#     if i == N - 1: +#         return 0 +#     return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2))) +# +# print(recur(0)) +dp = [float("inf")] * (N + 2) +dp[0] = 0 +for i in range(N - 1): +    dp[i + 1] = min(dp[i + 1], abs(h[i] - h[i + 1]) + dp[i]) +    if i < N - 2: +        dp[i + 2] = min(dp[i + 2], abs(h[i] - h[i + 2]) + dp[i]) +print((dp[N - 1]))