
fun trace(a: IntArray?) = a?.let { println(a.joinToString(separator = " ")) }

fun insertionSort(a: IntArray?) {
    a?.let {
        for (i in 1 until a.size) {
            val v = a[i]
            var j = i - 1
            while (j >= 0 && a[j] > v) {
                a[j + 1] = a[j]
                j--
            }
            a[j + 1] = v
            trace(a)
        }
    }
}

fun main(args: Array<String>) {
    readLine()
    val a = readLine()
            ?.split(regex = "\\s+".toRegex())
            ?.map { it.toInt() }
            ?.toIntArray()
    trace(a)
    insertionSort(a)
}
