{-# OPTIONS_GHC -O2 #-}
import Data.Array.Unboxed (Array, Ix, array, (!), range)
import Control.Monad.Fix (fix)

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

main = do
    n <- readLn :: IO Int
    -- let n = 20000
    hs <- map read . words <$> getLine :: IO [Integer]
    -- let hs = [1..(fromIntegral n)]
    print $ slvMemo (genArray n hs) (n-1)

genArray :: Index -> [Value] -> Data
genArray n xs = array (0, n-1) [x | x <- zip [0..n] xs]

memo :: (Index -> a) -> (Index -> a)
memo f = (map f [0..] !!)

slvMemo :: Data -> Index -> Value
slvMemo d = fix (memo . slv d)

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