import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

main=do
    n<-readLn::IO Int
    as<-sort.map (\(i,a)->a-i).zip [1..].unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine::IO[Int]
    let m = sortBy cp $ M.toList $ foldl (\m k -> M.insertWith(+)k 1 m) M.empty as
    let n = fst$head m
    let mi = head as
    let ma = last as
    print $ minimum [sum $ map (\a->abs$a-n) as, sum $ map (\a->abs$a-mi) as, sum $ map (\a->abs$a-ma) as]

cp :: (Int,Int) -> (Int,Int) -> Ordering
cp (a,b) (c,d) = if b/=d then compare d b else compare (abs a) (abs c)
