import sys

sys.setrecursionlimit(500000)



def get_cost(arr, n, dp):

  if dp[n] != float('inf'):

    return dp[n]

  if n == 1:

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

    return dp[1]

  elif n == 0:

    dp[0] = 0

    return dp[0]

  else:

    dp[n] = min(

      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1, dp),

      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2, dp)

    )

    return dp[n]





N = int(eval(input()))

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

dp_arr = [float('inf')]*N

print((get_cost(arr, N-1, dp_arr)))

import sys

sys.setrecursionlimit(500000)



def get_cost(arr, n, dp):

  if dp[n] != -1:

    return dp[n]

  if n == 1:

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

    return dp[1]

  elif n == 0:

    dp[0] = 0

    return dp[0]

  else:

    dp[n] = min(

      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1, dp),

      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2, dp)

    )

    return dp[n]





N = int(eval(input()))

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

dp_arr = [-1]*N

print((get_cost(arr, N-1, dp_arr)))

import sys

sys.setrecursionlimit(500000)


def get_cost(arr, n, dp):
    if dp[n] != float("inf"):
        return dp[n]
    if n == 1:
        dp[1] = abs(arr[1] - arr[0])
        return dp[1]
    elif n == 0:
        dp[0] = 0
        return dp[0]
    else:
        dp[n] = min(
            abs(arr[n] - arr[n - 1]) + get_cost(arr, n - 1, dp),
            abs(arr[n] - arr[n - 2]) + get_cost(arr, n - 2, dp),
        )
        return dp[n]


N = int(eval(input()))
arr = [int(num) for num in input().split()]
dp_arr = [float("inf")] * N
print((get_cost(arr, N - 1, dp_arr)))

import sys

sys.setrecursionlimit(500000)


def get_cost(arr, n, dp):
    if dp[n] != -1:
        return dp[n]
    if n == 1:
        dp[1] = abs(arr[1] - arr[0])
        return dp[1]
    elif n == 0:
        dp[0] = 0
        return dp[0]
    else:
        dp[n] = min(
            abs(arr[n] - arr[n - 1]) + get_cost(arr, n - 1, dp),
            abs(arr[n] - arr[n - 2]) + get_cost(arr, n - 2, dp),
        )
        return dp[n]


N = int(eval(input()))
arr = [int(num) for num in input().split()]
dp_arr = [-1] * N
print((get_cost(arr, N - 1, dp_arr)))

-    if dp[n] != float("inf"): +    if dp[n] != -1: -dp_arr = [float("inf")] * N +dp_arr = [-1] * N