import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val n = in.readInt
  val a = in.readLine.split(" ").map(_.toInt)

  val map = mu.HashMap.empty[Int, Int]
  val maxCnt = (0 until n)./:(0) { (acc, i) =>
    val c = a(i) - (i+1)
    val v = map.getOrElse(c, 0) + 1
    map(c) = v
    if(acc < v) v else acc
  }

  val b = map.filter(_._2 == maxCnt).minBy(_._1.abs)._1.toLong

  val ans = a./:(0L, 1L){ case ((acc, idx), ai) =>
    (acc + (ai - (b + idx)).abs, idx + 1L)
  }._1

  println(ans)
}