# dpA

def main():

    n = int(eval(input()))

    A = tuple(map(int, input().rstrip().split()))

    dp = [0] + [float("inf")] * (n - 1)

    for i in range(1, n):

        for j in range(1, 3):

            if i - j >= 0:

                dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))

    print((dp[-1]))





if __name__ == "__main__":

    main()
# A - Frog 1

from collections import defaultdict





def main():

    N, *H = list(map(int, open(0).read().split()))

    H = [0] + H + [0, 0]

    dp = defaultdict(lambda: 1 << 30)

    dp[1] = 0

    for i, a in enumerate(H[1:N + 1], 1):

        for j, b in enumerate(H[i + 1:i + 3], i + 1):

            dp[j] = min(dp[j], dp[i] + abs(a - b))

    print((dp[N]))





if __name__ == "__main__":

    main()

# dpA
def main():
    n = int(eval(input()))
    A = tuple(map(int, input().rstrip().split()))
    dp = [0] + [float("inf")] * (n - 1)
    for i in range(1, n):
        for j in range(1, 3):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
    print((dp[-1]))


if __name__ == "__main__":
    main()

# A - Frog 1
from collections import defaultdict


def main():
    N, *H = list(map(int, open(0).read().split()))
    H = [0] + H + [0, 0]
    dp = defaultdict(lambda: 1 << 30)
    dp[1] = 0
    for i, a in enumerate(H[1 : N + 1], 1):
        for j, b in enumerate(H[i + 1 : i + 3], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print((dp[N]))


if __name__ == "__main__":
    main()

-# dpA +# A - Frog 1 +from collections import defaultdict + + -    n = int(eval(input())) -    A = tuple(map(int, input().rstrip().split())) -    dp = [0] + [float("inf")] * (n - 1) -    for i in range(1, n): -        for j in range(1, 3): -            if i - j >= 0: -                dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j])) -    print((dp[-1])) +    N, *H = list(map(int, open(0).read().split())) +    H = [0] + H + [0, 0] +    dp = defaultdict(lambda: 1 << 30) +    dp[1] = 0 +    for i, a in enumerate(H[1 : N + 1], 1): +        for j, b in enumerate(H[i + 1 : i + 3], i + 1): +            dp[j] = min(dp[j], dp[i] + abs(a - b)) +    print((dp[N]))