{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Applicative
import Control.Monad.Fix
import Control.Monad.ST
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector Int -> Int
solve !n !an = minimum $ map cost $ median bn
 where
  bn = VU.imap (\(!i) (!a) -> a - i - 1) an

  cost k = VU.foldl' (\(!acc) (!b) -> acc + abs (b - k)) 0 bn

  median vs =
    let vs' = sort $ VU.toList vs
    in  if even n
          then [vs' !! (n `div` 2 - 1), vs' !! (n `div` 2)]
          else [vs' !! (n `div` 2)]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  an <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n an
