readI :: String -> Integer
readI = read

main = do
    getLine
    a <- map readI . words <$> getLine
    print $ solve a

solve x | sadness 0 x > sadness 1 x = feelSadUp 1 x
             | sadness 0 x == sadness 1 x = sadness 0 x 
             | otherwise =  feelSadDown 0 x
sadness b x = mourn b 0 x
mourn :: Integer -> Integer -> [Integer] -> Integer
mourn b i [] = 0
mourn b i (a:as) = abs ( a - ( b + i ) )  + mourn b ( i + 1 ) as
feelSadUp b x = if sadness b x <= sadness (b+1) x then sadness b x else feelSadUp (b+1) x
feelSadDown b x = if sadness b x >= sadness (b-1) x then sadness b x else feelSadDown (b-1) x
