import Data.Array
import Control.Monad

main = do
    n <- read <$> getLine
    costs <- map read.words <$> getLine
    putStrLn.show.answer n $ listArray (1,n) costs

answer :: Int -> Array Int Int -> Int
answer n table = dp n table ! 1

dp n costs = array (1,n) $ (n,0) : (n-1, n#(n-1)) : [(k,min(ans!(k+1)+k#(k+1)) (ans!(k+2)+k#(k+2))) | k <- [1..n-2]] where
    a#b = abs $ (costs ! a) - (costs ! b)