{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed ((!))


query :: Int -> [Int] -> Int
query n ais = sum $ map (abs . subtract mid) diffs 
 where
   diffs = sort $ zipWith (-) ais [1..]
   mid = diffs !! ((n-1) `div` 2)

main :: IO ()
main = do
  n <- read <$> getLine
  ais <- unfoldr (B.readInt . B.dropWhile (==' ')) <$> B.getLine
  putStrLn $ show $ query n ais