object Main extends App {
  def abs(n: Int): Int = if (n >= 0) n else -n

  def round(n: Double): Int = if (n - n.toInt.toDouble >= 0.5) n.toInt + 1 else n.toInt

  def floor(n: Double): Int = if (n < 0 && n - n.toInt != 0) n.toInt - 1 else n.toInt

  def min(n1: Int, n2: Int): Int = if (n1 > n2) n2 else n1

  def computeMean(i: Int, sum: Int, A: List[Int]): Int =
    if (A.isEmpty) floor(sum.toDouble / N)  // round(sum.toDouble / N)
    else computeMean(i + 1, sum + A.head - i, A.tail)

  def computeSadness(b: Int, i: Int, sum: Int, A: List[Int]): Int =
    if (A.isEmpty) sum
    else computeSadness(b, i + 1, sum + abs(A.head - i - b), A.tail)

  val N = io.StdIn.readInt()
  val A = io.StdIn.readLine().split(" ").map(_.toInt).toList
  val b = computeMean(1, 0, A)
  println(min(computeSadness(b, 1, 0, A), computeSadness(b + 1, 1, 0, A)))
}
