Problem:
Selection Sort

Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

SelectionSort(A)
1 for i = 0 to A.length-1
2 mini = i
3 for j = i to A.length-1
4 if A[j] < A[mini]
5 mini = j
6 swap A[i] and A[mini]

Note that, indices for array elements are based on 0-origin.

Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.

Input

The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by space characters.

Output

The output consists of 2 lines.

In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.

In the second line, please print the number of swap operations.

Constraints

1 ≤ N ≤ 100

Sample Input 1

6
5 6 4 2 1 3

Sample Output 1

1 2 3 4 5 6
4

Sample Input 2

6
5 2 4 6 1 3

Sample Output 2

1 2 3 4 5 6
3

Solution in JAVA (judge verdict: Time Limit Exceeded)

import java.util.Scanner;

class Main {
	//scanner生成
	static Scanner scan = new Scanner(System.in);
	//要素数指定
	static int N = scan.nextInt();
	//配列にメモリ割当
	static int[] A = new int[N];
	static int change = 0;
	
	public static void main(String[] args) {
		System.out.print("aaa");
		Main main = new Main();
		//ループのカウント
		int count = 0;
		//配列に値を代入
		while(count < Main.N){
			Main.A[count] = scan.nextInt();
			count++;
		}
		//
		for (int i = 0;i < Main.N-1;i++){
			int mini = 0;
			mini=i;
			for(int j = i;j < Main.N-1;j++){
				if(Main.A[j] < Main.A[mini]){
					mini = j;
					main.swap(i,mini);
					Main.change++;
				}
			}	
		}
		main.call();
		System.out.println();
		System.out.print(Main.change);
	}
	
	public void swap(int i,int j){
		//添字iと添字jの配列の値を入れ替える
		int m = 0;
		m = Main.A[i];
		Main.A[i] = Main.A[j];
		Main.A[j] = m;
		
	}
	
	public int call(){
		int i = 0;
		while(true){
			System.out.print(Main.A[i]);
			if(i < Main.N - 1){
			System.out.print(" ");
			}
		}
	}
	
	
}