import Data.List
import qualified Data.ByteString.Char8 as B
main=do
  n<-readLn::IO Int
  as<-sort.zipWith (flip (-)) [1..].unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  print.minimum.map (f as) $ [as !! (n`div`2 - 1), as !! (n `div` 2), as !! (n `div` 2 + 1)]

f as m = sum.map abs.map ((-) m) $ as
