main = do
  getLine
  hs <- map read . words <$> getLine :: IO [Int]
  print $ dp hs [] []

dp :: [Int] -> [Int] -> [Int] -> Int
dp []  _ zs = head zs 
dp (x:xs) [] _ = dp xs [x] [0]
dp (x:xs) [y] _ = dp xs [x,y] [abs (y-x),0]
dp (x:xs) (y1:y2:ys) (z1:z2:zs) = 
  let 
    m = min (z1 + abs (y1-x)) (z2 + abs (y2-x))
  in
    dp xs (x:y1:y2:ys) (m:z1:z2:zs)