def main():

    import sys

    input = sys.stdin.readline



    N = int(eval(input()))

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



    inf = float("inf")

    dp = [inf]*N



    dp[0] = 0

    step1, step2 = inf, inf



    for i in range(1, N):

        step1 = abs(H[i-1]-H[i]) + dp[i-1]

        if i >= 2:

            step2 = abs(H[i-2]-H[i]) + dp[i-2]

        step = min(step1, step2)



        dp[i] = min(dp[i], step)

    print((dp[-1]))





if __name__ == "__main__":

    main()

def main():

    import sys

    input = sys.stdin.readline



    N = int(eval(input()))

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



    inf = float("inf")

    dp = [inf]*N



    dp[0] = 0



    for i in range(N-1):

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

        if i != N-2:

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

    print((dp[-1]))





if __name__ == "__main__":

    main()

def main():
    import sys

    input = sys.stdin.readline
    N = int(eval(input()))
    H = list(map(int, input().split()))
    inf = float("inf")
    dp = [inf] * N
    dp[0] = 0
    step1, step2 = inf, inf
    for i in range(1, N):
        step1 = abs(H[i - 1] - H[i]) + dp[i - 1]
        if i >= 2:
            step2 = abs(H[i - 2] - H[i]) + dp[i - 2]
        step = min(step1, step2)
        dp[i] = min(dp[i], step)
    print((dp[-1]))


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline
    N = int(eval(input()))
    H = list(map(int, input().split()))
    inf = float("inf")
    dp = [inf] * N
    dp[0] = 0
    for i in range(N - 1):
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
        if i != N - 2:
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))
    print((dp[-1]))


if __name__ == "__main__":
    main()

-    step1, step2 = inf, inf -    for i in range(1, N): -        step1 = abs(H[i - 1] - H[i]) + dp[i - 1] -        if i >= 2: -            step2 = abs(H[i - 2] - H[i]) + dp[i - 2] -        step = min(step1, step2) -        dp[i] = min(dp[i], step) +    for i in range(N - 1): +        dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i])) +        if i != N - 2: +            dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))