{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: Int -> [Int16] -> Int32
solve n hs = fst $ fst dp
 where
  h1 : h2 : h3 = hs

  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp           = foldl'
    (\((!dp1, !dp2), (!x, !y)) (!i, !v) ->
      ( ( min (dp1 + abs (fromIntegral $ v - x))
              (dp2 + abs (fromIntegral $ v - y))
        , dp1
        )
      , (v, x)
      )
    )
    ((fromIntegral $ abs $ h1 - h2, 0), (h2, h1))
    (zip ([2 ..] :: [Int]) h3)

main = do
  let sillyTail b | B.null b  = b
                  | otherwise = B.tail b
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt b
        | B.null b = Nothing
        | otherwise = fmap (first fromIntegral . second sillyTail) $ B.readInt b

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- unfoldr readInt <$> B.getLine
  print $ solve n hs
