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 as (0,n-1)

tsearch as (l,r)
    | l == r = calc $ as V.! l
    | l+1 == r = min (calc $ as V.! l) (calc $ as V.! r)
    | l+2 == r = minimum [calc $ as V.! l, calc $ as V.! (l+1), calc $ as V.! r]
    | c1 < c2  = tsearch as (l,b2)
    | c1 == c2 = tsearch as (b1,b2)
    | c1 > c2  = tsearch as (b1,r)
    where
        c1 = calc $ as V.! b1
        c2 = calc $ as V.! b2
        b1 = l+(r-l)`div`3
        b2 = l+((r-l)`div`3)*2
        calc b = V.sum $ V.map (\a->abs $ a-b) as