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

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

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

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

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

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

slv :: Index -> Data -> (Index -> Value) -> Index -> Value
slv n d f i
  | i == n-1  = 0
  | i == n-2  = abs $ d!i - d!(n-1)
  | 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))
