import qualified Control.Monad as M
-- import qualified Data.Map.Strict as Map
import Data.Array.Unboxed (Array(..), array, (!))

type Hash  = Int
type Size  = Int
type Index = Int
type Value = Integer
type Data  = Array Index Value

main = do
    n <- readLn
    hs <- map read . words <$> getLine
    print $ solveMemo n (genArray n hs) 0

fix :: (a -> a) -> a
fix f = f (fix f)

memorize :: (Index -> a) -> (Index -> a)
memorize f = (map f [1 ..] !!)

hash2index :: Hash -> Index
hash2index = id

solveMemo :: Size -> Data -> Index -> Value
solveMemo n d = fix (memorize . solve n d)

solve :: Size -> Data -> (Index -> Value) -> Index -> Value
solve n d f i
  | i == n    = 0
  | i == n-1  = abs $ d!i - d!n
  | otherwise = min a b where
      a = solve n d f (i+1) + abs (d!i - d!(i+1))
      b = solve n d f (i+2) + abs (d!i - d!(i+2))

genArray :: Size -> [Integer] -> Array Hash Integer
genArray n xs = array (1, n) [x | x <- zip ixs xs] where
  ixs = map hash2index [1..n]
