import qualified Data.ByteString.Char8 as BC
import Data.List
import Data.Maybe

main = do
    _ <- getLine
    as <- fromJust . mapM (fmap fst . BC.readInt) . BC.words <$>  BC.getLine
    print $ solve as

solve :: [Int] -> Int
solve xs = let xs' = zipWith (-) xs [1..]
               in sum . map (abs . subtract (median xs')) $ xs'

median :: Ord a => [a] -> a
median xs = let xs' = sort xs
                n = length xs
                in xs' !! (n `div` 2)