{-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}
import Control.Arrow
import Control.Monad.Fix
import Control.Monad
import Data.Char (ord, isDigit)
import Data.Bits
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import System.IO (stdin)

foreign import ccall "getchar_unlocked" cGetChar :: IO Char

-- Assume that input has non-digit symbol at the end.
readIONat :: (Bits a, Integral a) => IO a
readIONat = do
  let reader ch = fromIntegral $ ord ch - ord '0'

  !digit0 <- fix
    ( \(!f) (!_) -> do
      !ch <- cGetChar
      if isDigit ch then return ch else f ch
    )
    ' '
  flip fix (return $ reader digit0) $ \(!f) (!acc) -> do
    !s <- cGetChar
    if not (isDigit s)
      then acc
      else do
        !a <- acc
        let a' = shiftL a 1 + shiftL a 3 + reader s
        f (return a')

solve :: Int -> [Int16] -> Int32
solve n hs = fst $ fst dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp = foldl'
    ( \((!dp1, !dp2), (!x, !y)) (!i, !v) -> if i == 0
      then ((0, dp1), (v, x))
      else if i == 1
        then ((dp1 + abs (fromIntegral $ v - x), dp1), (v, x))
        else
          ( ( min (dp1 + abs (fromIntegral $ v - x))
                  (dp2 + abs (fromIntegral $ v - y))
            , dp1
            )
          , (v, x)
          )
    )
    ((-1, -1), (-1, -1))
    (zip ([0 ..] :: [Int]) hs)

main = do
  n  <- readIONat
  hs <- replicateM n readIONat
  print $ solve n hs
