
main = do
  n <- readLn :: IO Int
  as <- fmap (map read . words) getLine :: IO [Int]
  print . solve $ zipWith (\x y -> x - y) as [1..]

snk :: [Int] -> Int -> Int
snk as b = sum $ map (\a -> abs(a - b)) as

solve :: [Int] -> Int
solve bs = minimum $ map (snk bs) candidates
  where
    optb = div (sum bs) (length bs)
    candidates = [optb - 2, optb - 1, optb, optb + 1, optb + 2]
