fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(" ").map { it.toInt() } as MutableList<Int>
    val (sortedArray, exchanges) = selectionSort(n, array)
    println(sortedArray.joinToString(" "))
    println(exchanges)
}

fun selectionSort(n: Int, array: MutableList<Int>): Pair<List<Int>, Int> {
    var exchanges = 0
    for (i in 0 until n) {
        var minj = i
        for (j in i until n) {
            if (array[j] < array[minj]) {
                minj = j
            }
        }
        if (i < minj) {
            val a = array[i]
            array[i] = array[minj]
            array[minj] = a
            exchanges++
        }
    }

    return array to exchanges
}
