import Data.List

ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))

f a b = sum $ map abs $ zipWith (-) a [b+1..]

diff a b = f a (b+1) - f a b

calc a = let b = ibsearch ((>=0) . diff a) (maximum a, minimum a - length a - 1) in min (f a b) (f a (b+1))

main = getLine >> getLine >>= print . calc . map read . words
