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

dp :: [Int] -> Int -> [Int] -> Int
dp xs 1 _ = dp xs 2 [(xs !! 0)]
dp xs 2 zs = dp xs 3 ((xs !! 1):zs) 
dp xs i (z1:z2:zs) 
  | length xs == i = z1
  | otherwise =
    let 
      m = min (z1 + abs ((xs !! (i-1))-(head xs))) (z2 + abs ((xs !! (i-2))-(head xs)))
    in
      dp xs (i+1) (m:z1:z2:zs)