import sys

import numpy as np

input = sys.stdin.readline



def main():

    N = int(eval(input()))

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

    h += [0, 0]

    dp = np.full(N+2, int(1e15))



    dp[0] = 0

    for i in range(N):

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

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

    # print(dp)

    print((int(dp[N-1])))



if __name__ == "__main__":

    main()
N = int(eval(input()))

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



# dp[i] := iからN-1までいく最小コスト

dp = [-1] * N



dp[N-1] = 0

dp[N-2] = abs(h[N-1] - h[N-2])



for i in range(N-3, -1, -1):

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



print((dp[0]))
import sys
import numpy as np

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    h = list(map(int, input().split()))
    h += [0, 0]
    dp = np.full(N + 2, int(1e15))
    dp[0] = 0
    for i in range(N):
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
    # print(dp)
    print((int(dp[N - 1])))


if __name__ == "__main__":
    main()

N = int(eval(input()))
h = list(map(int, input().split()))
# dp[i] := iからN-1までいく最小コスト
dp = [-1] * N
dp[N - 1] = 0
dp[N - 2] = abs(h[N - 1] - h[N - 2])
for i in range(N - 3, -1, -1):
    dp[i] = min(abs(h[i] - h[i + 1]) + dp[i + 1], abs(h[i] - h[i + 2]) + dp[i + 2])
print((dp[0]))

-import sys -import numpy as np - -input = sys.stdin.readline - - -def main(): -    N = int(eval(input())) -    h = list(map(int, input().split())) -    h += [0, 0] -    dp = np.full(N + 2, int(1e15)) -    dp[0] = 0 -    for i in range(N): -        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) -        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2])) -    # print(dp) -    print((int(dp[N - 1]))) - - -if __name__ == "__main__": -    main() +N = int(eval(input())) +h = list(map(int, input().split())) +# dp[i] := iからN-1までいく最小コスト +dp = [-1] * N +dp[N - 1] = 0 +dp[N - 2] = abs(h[N - 1] - h[N - 2]) +for i in range(N - 3, -1, -1): +    dp[i] = min(abs(h[i] - h[i + 1]) + dp[i + 1], abs(h[i] - h[i + 2]) + dp[i + 2]) +print((dp[0]))