
fun trace(a: IntArray) = println(a.joinToString(separator = " "))

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

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