fun main(args: Array<String>) {
    readLine()
    val xs = readLine()!!.split(' ').map { it.toLong() }

    var l = -1000000001L
    var r = 1000000001L

    while ((r - l) >= 3) {
        val m0 = (l * 2 + r) / 3
        val m1 = (l + r * 2) / 3

        if (f(xs, m0) < f(xs, m1)) {
            r = m1
        } else {
            l = m0
        }
    }

    println((0..3).map { f(xs, l + it) }.min())
}

private fun f(xs: List<Long>, b: Long): Long {
    return xs.mapIndexed { i, x -> Math.abs(x - (b + i + 1)) }.sum()
}