def main():

    n = int(eval(input()))

    arr = [int(e) for e in input().split()]

    t = [float('inf')] * (n + 1)

    t[0] = 0

    t[1] = 0 

    t[2] = abs(arr[1] - arr[0])

    for i in range(3, n + 1):

        l1 = t[i - 1] + abs(arr[i - 2] - arr[i - 1])

        l2 = t[i - 2] + abs(arr[i - 3] - arr[i - 1])

        t[i] = min(l1, l2)

    print((t[n]))

    return 0





if __name__ == '__main__':

    main()
import sys

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

input = reader.__next__

sys.setrecursionlimit(1000000)

# do magic here

n = int(eval(input()))

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



MAX = 10000000



dp = {}





def solve(x):

    if x==0:

        return 0

    if x < 0:

        return MAX

    if x in dp:

        return dp[x]

    a = abs(heights[x-1] - heights[x]) + solve(x-1)

    b = abs(heights[x-2] - heights[x]) + solve(x-2)

    dp[x] = min(a,b)

    return dp[x]



print((solve(n-1)))

def main():
    n = int(eval(input()))
    arr = [int(e) for e in input().split()]
    t = [float("inf")] * (n + 1)
    t[0] = 0
    t[1] = 0
    t[2] = abs(arr[1] - arr[0])
    for i in range(3, n + 1):
        l1 = t[i - 1] + abs(arr[i - 2] - arr[i - 1])
        l2 = t[i - 2] + abs(arr[i - 3] - arr[i - 1])
        t[i] = min(l1, l2)
    print((t[n]))
    return 0


if __name__ == "__main__":
    main()

import sys

reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
sys.setrecursionlimit(1000000)
# do magic here
n = int(eval(input()))
heights = [int(x) for x in input().split()]
MAX = 10000000
dp = {}


def solve(x):
    if x == 0:
        return 0
    if x < 0:
        return MAX
    if x in dp:
        return dp[x]
    a = abs(heights[x - 1] - heights[x]) + solve(x - 1)
    b = abs(heights[x - 2] - heights[x]) + solve(x - 2)
    dp[x] = min(a, b)
    return dp[x]


print((solve(n - 1)))

-def main(): -    n = int(eval(input())) -    arr = [int(e) for e in input().split()] -    t = [float("inf")] * (n + 1) -    t[0] = 0 -    t[1] = 0 -    t[2] = abs(arr[1] - arr[0]) -    for i in range(3, n + 1): -        l1 = t[i - 1] + abs(arr[i - 2] - arr[i - 1]) -        l2 = t[i - 2] + abs(arr[i - 3] - arr[i - 1]) -        t[i] = min(l1, l2) -    print((t[n])) -    return 0 +import sys + +reader = (s.rstrip() for s in sys.stdin) +input = reader.__next__ +sys.setrecursionlimit(1000000) +# do magic here +n = int(eval(input())) +heights = [int(x) for x in input().split()] +MAX = 10000000 +dp = {} -if __name__ == "__main__": -    main() +def solve(x): +    if x == 0: +        return 0 +    if x < 0: +        return MAX +    if x in dp: +        return dp[x] +    a = abs(heights[x - 1] - heights[x]) + solve(x - 1) +    b = abs(heights[x - 2] - heights[x]) + solve(x - 2) +    dp[x] = min(a, b) +    return dp[x] + + +print((solve(n - 1)))