module Main where

import Control.Applicative
import Control.Monad

fk :: (Num a) => a -> [a] -> a
fk b as = sum $ zipWith f as [1 .. length as]
  where
    f a i = abs $ a - (b + fromIntegral i)

main :: IO ()
main = do
    n <- readLn
    as <- fmap read . words <$> getLine
    let bs = zipWith (\a b -> a - b) as [1 .. n]
    let b = fromIntegral . round $ (sum bs) / n
    print $ round $ minimum [fk b as, fk (b - 1) as, fk (b + 1) as]