let sort a n = 
  let rec selection_sort a c =
    let rec selection j acc =
      if j < n then selection (j+1) (if a.(j) < a.(acc) then j else acc)
      else acc
    in
    function
      i when i = n -> a,c
    | i ->
      selection_sort
        a
        (match selection (i+1) i with
         | j when i != j ->
           let ai = a.(i) in
           a.(i) <- a.(j);
           a.(j) <- ai;
           c+1
         | _ -> c)
        (i+1)
  in
  selection_sort a 0 0

let () =
  let n = read_int () in
  let a = read_line () |> Str.split (Str.regexp " ")
          |> List.map int_of_string |> Array.of_list in
  let sorted,c = sort a n in
  Array.iteri
    (fun i x -> Printf.printf (if i=n-1 then "%d\n" else "%d ") x) sorted;
  Printf.printf "%d\n" c