import Data.List

main :: IO ()
main = do
    n <- read <$> getLine
    as <- map read . words <$> getLine
    print $ go as n
    return ()

go as n = sum [abs(x - median) | x <- xs]
    where
        xs = zipWith (-) as [1..]
        median = sort xs !! (n `div` 2)