import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=sys.stdin.readline

def resolve():

    n=int(eval(input()))

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

    dp=[0]*n

    dp[1]=abs(H[1]-H[0])

    for i in range(2,n):

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

    print((dp[n-1]))

resolve()
import sys

INF = 1 << 60

MOD = 10**9 + 7 # 998244353

sys.setrecursionlimit(2147483647)

input = lambda:sys.stdin.readline().rstrip()

def resolve():

    n, k = int(eval(input())), 2

    dp = [INF] * n

    dp[0] = 0

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

    for i in range(n):

        for pi in range(i - k, i):

            if pi < 0:

                continue

            dp[i] = min(dp[i], dp[pi] + abs(H[i] - H[pi]))

    print((dp[n - 1]))

resolve()
import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = sys.stdin.readline


def resolve():
    n = int(eval(input()))
    H = list(map(int, input().split()))
    dp = [0] * n
    dp[1] = abs(H[1] - H[0])
    for i in range(2, n):
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))
    print((dp[n - 1]))


resolve()

import sys

INF = 1 << 60
MOD = 10**9 + 7  # 998244353
sys.setrecursionlimit(2147483647)
input = lambda: sys.stdin.readline().rstrip()


def resolve():
    n, k = int(eval(input())), 2
    dp = [INF] * n
    dp[0] = 0
    H = list(map(int, input().split()))
    for i in range(n):
        for pi in range(i - k, i):
            if pi < 0:
                continue
            dp[i] = min(dp[i], dp[pi] + abs(H[i] - H[pi]))
    print((dp[n - 1]))


resolve()

+INF = 1 << 60 +MOD = 10**9 + 7  # 998244353 -INF = float("inf") -MOD = 10**9 + 7 -input = sys.stdin.readline +input = lambda: sys.stdin.readline().rstrip() -    n = int(eval(input())) +    n, k = int(eval(input())), 2 +    dp = [INF] * n +    dp[0] = 0 -    dp = [0] * n -    dp[1] = abs(H[1] - H[0]) -    for i in range(2, n): -        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2])) +    for i in range(n): +        for pi in range(i - k, i): +            if pi < 0: +                continue +            dp[i] = min(dp[i], dp[pi] + abs(H[i] - H[pi]))