def slove():

    import sys

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    a = list(map(int, input().rstrip('\n').split()))

    ls = [0] * n

    for i in range(1, n):

        if i == 1:

            ls[i] = abs(a[i] - a[i-1])

        else:

            ls[i] = min(ls[i-1] + abs(a[i] - a[i-1]), ls[i-2] + abs(a[i] - a[i-2]))

    print((ls[-1]))





if __name__ == '__main__':

    slove()

import sys





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

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

    dp = [10 ** 10] * n

    dp[0] = 0

    for i in range(1, n):

        if i == 1:

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

        else:

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

    print((dp[-1]))





if __name__ == '__main__':

    solve()

def slove():
    import sys

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    a = list(map(int, input().rstrip("\n").split()))
    ls = [0] * n
    for i in range(1, n):
        if i == 1:
            ls[i] = abs(a[i] - a[i - 1])
        else:
            ls[i] = min(
                ls[i - 1] + abs(a[i] - a[i - 1]), ls[i - 2] + abs(a[i] - a[i - 2])
            )
    print((ls[-1]))


if __name__ == "__main__":
    slove()

import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    h = list(map(int, readline().split()))
    dp = [10**10] * n
    dp[0] = 0
    for i in range(1, n):
        if i == 1:
            dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i])
        else:
            dp[i] = min(
                dp[i - 1] + abs(h[i - 1] - h[i]),
                dp[i - 2] + abs(h[i - 2] - h[i]),
                dp[i],
            )
    print((dp[-1]))


if __name__ == "__main__":
    solve()

-def slove(): -    import sys +import sys -    input = sys.stdin.readline -    n = int(input().rstrip("\n")) -    a = list(map(int, input().rstrip("\n").split())) -    ls = [0] * n + +def solve(): +    readline = sys.stdin.buffer.readline +    mod = 10**9 + 7 +    n = int(readline()) +    h = list(map(int, readline().split())) +    dp = [10**10] * n +    dp[0] = 0 -            ls[i] = abs(a[i] - a[i - 1]) +            dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i]) -            ls[i] = min( -                ls[i - 1] + abs(a[i] - a[i - 1]), ls[i - 2] + abs(a[i] - a[i - 2]) +            dp[i] = min( +                dp[i - 1] + abs(h[i - 1] - h[i]), +                dp[i - 2] + abs(h[i - 2] - h[i]), +                dp[i], -    print((ls[-1])) +    print((dp[-1])) -    slove() +    solve()