import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- sort . zipWith (\a b -> b - a) [1..] <$> getIntList
    let a1 = as !! ((n-1) `div` 2)
        a2 = as !! (n `div` 2)
        b1 = (a1 + a2) `div` 2
        b2 = (a1 + a2 + 1) `div` 2
        sad1 = sum $ map (\a -> abs (a - b1)) as
        sad2 = sum $ map (\a -> abs (a - b2)) as
    print $ if n == 1 then 0 else min sad1 sad2