import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n 

-- |
-- >>> solve 5 [2, 2, 3, 5, 5]
-- 2
-- >>> solve 9 [1, 2, 3, 4, 5, 6, 7, 8, 9]
-- 0
-- >>> solve 6 [6, 5, 4, 3, 2, 1]
-- 18
-- >>> solve 7 [1, 1, 1, 1, 2, 3, 4]
-- 6
solve :: Int -> [Int] -> Int 
solve n as = minimum ys
    where
        xs = sort . map (\(a, i) -> a - i) $ zip as [1..]
        s = sum xs
        ys = build 0 n 0 s xs

        build a b c d (e : es) = (a - b) * e + d - c : build (a + 1) (b - 1) (c + e) (d - e) es
        build _ _ _ _ _ = []
        

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine