size = gets.to_i
array = gets.split(" ").map(&:to_i)

def selection_sort(size, array)
  count = 0
  (size-1).times do |i|
    min = i
    (i+1..size-1).each do |j|
      next if array[j].nil?
      if array[j] < array[min]
        min = j
      end
    end
    if array[i] != array[min]
      copy_i = array[i]
      array[i] = array[min]
      array[min] = copy_i
      count += 1
    end
  end
  puts array.join(" "), count
end

selection_sort(size, array)
