import sys

sys.setrecursionlimit(10**7)



N = int(eval(input()))

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



dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト

dp[N-1] = 0



def rec_memo(i):

    if dp[i] >= 0:

        return dp[i]

    

    if i == N-2:

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

        return dp[i]

    else:

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

        return dp[i]



print((rec_memo(0)))
import sys

sys.setrecursionlimit(10**7)



N = int(eval(input()))

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



dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト

dp[N-1] = 0



for i in reversed(list(range(N - 1))):

    if i == N - 2:

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

    else:

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



print((dp[0]))
import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [-1] * N  # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N - 1] = 0


def rec_memo(i):
    if dp[i] >= 0:
        return dp[i]
    if i == N - 2:
        dp[i] = rec_memo(i + 1) + abs(h[i + 1] - h[i])
        return dp[i]
    else:
        dp[i] = min(
            rec_memo(i + 1) + abs(h[i + 1] - h[i]),
            rec_memo(i + 2) + abs(h[i + 2] - h[i]),
        )
        return dp[i]


print((rec_memo(0)))

import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
h = list(map(int, input().split()))
dp = [-1] * N  # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N - 1] = 0
for i in reversed(list(range(N - 1))):
    if i == N - 2:
        dp[i] = dp[i + 1] + abs(h[i + 1] - h[i])
    else:
        dp[i] = min(dp[i + 2] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i]))
print((dp[0]))

- - -def rec_memo(i): -    if dp[i] >= 0: -        return dp[i] +for i in reversed(list(range(N - 1))): -        dp[i] = rec_memo(i + 1) + abs(h[i + 1] - h[i]) -        return dp[i] +        dp[i] = dp[i + 1] + abs(h[i + 1] - h[i]) -        dp[i] = min( -            rec_memo(i + 1) + abs(h[i + 1] - h[i]), -            rec_memo(i + 2) + abs(h[i + 2] - h[i]), -        ) -        return dp[i] - - -print((rec_memo(0))) +        dp[i] = min(dp[i + 2] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i])) +print((dp[0]))