import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let Just (n,_) = BS.readInt li
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n as
  print ans

compute :: Int -> [Int] -> Int
compute n as = sum $ zipWith f as [b..]
  where
    total = sum as - n * pred n `div` 2
    (p,q) = divMod total n
    b = (if q*2 >= n then succ else id) (if total < 0 then pred p else p)
    f a b = abs (a - b)

{-
0 < Ai なので、
b = average $ zipWith (-) as [0..]
とすればよいだけでは。averageが四捨五入するように気を付ける。
b < 0のときのそれが要注意だった。
-}