import sys

reader = (s.rstrip() for s in sys.stdin)

input = reader.__next__

sys.setrecursionlimit(1000000)





def solve(stns, idx, mem):



    if idx >= len(stns) -1:

        return 0



    if idx in mem: 

        return mem[idx]



    if idx == len(stns) - 2: 

        #cant take more than one step

        final_step = abs(stns[idx] - stns[idx+1])

        mem[idx] = final_step

        return final_step

    else: 

        # step: i + 11

        step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx+1])

        # step: i + 2

        step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx+2])



        min_cost = min(step1, step2)

        mem[idx] = min_cost 



        return min_cost







def take_input():

    n = eval(input())

    stns = [int(x) for x in input().split()]

    mem = {}

    res = solve(stns, 0, mem)

    print(res)



take_input()
import math





def solve(stns, n, idx, dp):

    for i in range(n):

        for j in range(1, 3):

            j = i + j # step i + 1, i + 2

            if j < n:

                # min(existing min, new path using i)

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

    return dp[n-1]



def take_input():

    n = int(eval(input()))

    stns = [int(x) for x in input().split()]

    dp = [math.inf for i in range(n)]

    dp[0] = 0

    res = solve(stns, n, 0, dp)

    print(res)



take_input()
import sys

reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)


def solve(stns, idx, mem):
    if idx >= len(stns) - 1:
        return 0
    if idx in mem:
        return mem[idx]
    if idx == len(stns) - 2:
        # cant take more than one step
        final_step = abs(stns[idx] - stns[idx + 1])
        mem[idx] = final_step
        return final_step
    else:
        # step: i + 11
        step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx + 1])
        # step: i + 2
        step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx + 2])
        min_cost = min(step1, step2)
        mem[idx] = min_cost
        return min_cost


def take_input():
    n = eval(input())
    stns = [int(x) for x in input().split()]
    mem = {}
    res = solve(stns, 0, mem)
    print(res)


take_input()

import math


def solve(stns, n, idx, dp):
    for i in range(n):
        for j in range(1, 3):
            j = i + j  # step i + 1, i + 2
            if j < n:
                # min(existing min, new path using i)
                dp[j] = min(dp[j], dp[i] + abs(stns[i] - stns[j]))
    return dp[n - 1]


def take_input():
    n = int(eval(input()))
    stns = [int(x) for x in input().split()]
    dp = [math.inf for i in range(n)]
    dp[0] = 0
    res = solve(stns, n, 0, dp)
    print(res)


take_input()

-import sys - -reader = (s.rstrip() for s in sys.stdin) -input = reader.__next__ -sys.setrecursionlimit(1000000) +import math -def solve(stns, idx, mem): -    if idx >= len(stns) - 1: -        return 0 -    if idx in mem: -        return mem[idx] -    if idx == len(stns) - 2: -        # cant take more than one step -        final_step = abs(stns[idx] - stns[idx + 1]) -        mem[idx] = final_step -        return final_step -    else: -        # step: i + 11 -        step1 = solve(stns, idx + 1, mem) + abs(stns[idx] - stns[idx + 1]) -        # step: i + 2 -        step2 = solve(stns, idx + 2, mem) + abs(stns[idx] - stns[idx + 2]) -        min_cost = min(step1, step2) -        mem[idx] = min_cost -        return min_cost +def solve(stns, n, idx, dp): +    for i in range(n): +        for j in range(1, 3): +            j = i + j  # step i + 1, i + 2 +            if j < n: +                # min(existing min, new path using i) +                dp[j] = min(dp[j], dp[i] + abs(stns[i] - stns[j])) +    return dp[n - 1] -    n = eval(input()) +    n = int(eval(input())) -    mem = {} -    res = solve(stns, 0, mem) +    dp = [math.inf for i in range(n)] +    dp[0] = 0 +    res = solve(stns, n, 0, dp)