import Data.List

main = do
    getLine
    scaffolds <- map read.words <$> getLine
    print.answer $ reverse scaffolds

answer (x:xs) = snd.foldl jump (x, 0) $ zip xs (tail xs) where
    jump (i0,cost) (i1,i2)
        | abs(i1-i0) < abs (i2-i0) = (i1, cost+abs (i1-i0))
        | otherwise = (i2, cost+abs (i2-i0))