fun ac106(args: Array<String>) {
    val numList = args[1].split(" ").mapIndexed { index, s -> s.toLong() - index }.sorted()
    val med = numList[numList.size / 2]
    println(numList.map { Math.abs(it - med) }.sum())
}

fun main(args: Array<String>) {
    ac106(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}