{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Monad.Fix (fix)
import Data.Maybe
import Data.Array.Unboxed (Array, Ix, array, (!), range)
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt :: Num a => BS.ByteString -> a
readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntTuple :: Num a => BS.ByteString -> (a, a)
readIntTuple = tuplify2 . map readInt . BS.words
readIntList :: Num a => BS.ByteString -> [a]
readIntList = map readInt . BS.words

getInt :: Num a => IO a
getInt = readInt <$> BS.getLine
getIntList :: Num a => IO [a]
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

-----------------------------------------------------------------------------

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

main = do
    n <- getInt :: IO Int
    hs <- getIntList :: IO [Integer]
    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))
