import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Storable as V

main=do
    n<-readLn::IO Int
    as<-V.fromList.sort.map (\(i,a)->a-i).zip [1..].unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine::IO(V.Vector Int)
    print $ tsearch (f as) (0,n-1)

-- 三分探索 (最小値)
-- b<-[l..r]において最小のf bを求める
tsearch f (l,r)
    | (r-l)<3  = minimum $ map f [l..r]
    | c1 < c2  = tsearch f (l,b2)
    | c1 == c2 = tsearch f (b1,b2)
    | c1 > c2  = tsearch f (b1,r)
    where
        c1 = f b1
        c2 = f b2
        b1 = l+(r-l)`div`3
        b2 = l+((r-l)`div`3)*2

f as b = V.sum $ V.map (\a->abs $ a-e) as
        where e = as V.! b