def func():

    N = int(eval(input()))

    H = [int(i) for i in input().split()]

    

    dp = [0]*N

    for i in range(1, N):

        L = []

        for j in range(max(0, i-2), i):

            L.append(dp[j] + abs(H[i] - H[j]))

        dp[i] = min(L)



    print((dp[-1]))

    

if __name__=="__main__":

    func()
N = int(eval(input()))

H = [int(i) for i in input().split()]

dp = [0] * N



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



for i in range(2, N):

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

print((dp[-1]))
def func():
    N = int(eval(input()))
    H = [int(i) for i in input().split()]
    dp = [0] * N
    for i in range(1, N):
        L = []
        for j in range(max(0, i - 2), i):
            L.append(dp[j] + abs(H[i] - H[j]))
        dp[i] = min(L)
    print((dp[-1]))


if __name__ == "__main__":
    func()

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

-def func(): -    N = int(eval(input())) -    H = [int(i) for i in input().split()] -    dp = [0] * N -    for i in range(1, N): -        L = [] -        for j in range(max(0, i - 2), i): -            L.append(dp[j] + abs(H[i] - H[j])) -        dp[i] = min(L) -    print((dp[-1])) - - -if __name__ == "__main__": -    func() +N = int(eval(input())) +H = [int(i) for i in input().split()] +dp = [0] * N +dp[1] = abs(H[1] - H[0]) +for i in range(2, N): +    dp[i] = min(dp[i - 2] + abs(H[i] - H[i - 2]), dp[i - 1] + abs(H[i] - H[i - 1])) +print((dp[-1]))