import numpy as np



def resolve():

    n = int(eval(input()))

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

    k = 2



    dp = np.zeros(n, dtype=int)



    for i in range(1, n):

        start = max(0, i - k)

        dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))



    print((dp[n - 1]))



resolve()
def resolve():

    n = int(eval(input()))

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



    # i 番目の足場にたどり着くまでの最小コスト

    dp = [float('inf')] * n

    dp[0] = 0



    for i in range(1, n):

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

        if i > 1:

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



    print((dp[n - 1]))

    

resolve()
import numpy as np


def resolve():
    n = int(eval(input()))
    h = np.array(list(map(int, input().split())))
    k = 2
    dp = np.zeros(n, dtype=int)
    for i in range(1, n):
        start = max(0, i - k)
        dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
    print((dp[n - 1]))


resolve()

def resolve():
    n = int(eval(input()))
    h = list(map(int, input().split()))
    # i 番目の足場にたどり着くまでの最小コスト
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
    print((dp[n - 1]))


resolve()

-import numpy as np - - -    h = np.array(list(map(int, input().split()))) -    k = 2 -    dp = np.zeros(n, dtype=int) +    h = list(map(int, input().split())) +    # i 番目の足場にたどり着くまでの最小コスト +    dp = [float("inf")] * n +    dp[0] = 0 -        start = max(0, i - k) -        dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i])) +        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1])) +        if i > 1: +            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))