import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    }
    
    public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    }
    
    public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void selectionSort(int[] A, int N) {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    }
    
    public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    }
    
    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    }
    
    public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    }
    
    public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void selectionSort(int[] A, int N) {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    }
    
    public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    }
    
    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    } main {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    } BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); r new BufferedReader(new InputStreamReader(System.in)) int N = readInt(r); N readInt(r) readInt r String[] numStrings = r.readLine().split(" "); numStrings r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " int[] A = new int[N]; A new int[N] N for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = Integer.parseInt(numStrings[i]);
        } {
            A[i] = Integer.parseInt(numStrings[i]);
        } A[i] = Integer.parseInt(numStrings[i]) A[i] A i Integer.parseInt(numStrings[i]) Integer.parseInt Integer numStrings[i] numStrings i selectionSort(A, N) selectionSort A N String[] args args public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    } insertionSort {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    } System.out.println(dump(A, N)) System.out.println System.out System System.out dump(A, N) dump A N for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        } int i = 1; int i = 1; i 1 i <= (N - 1) i (N - 1) N 1 i++ i++ i {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        } {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        } int v = A[i]; v A[i] A i int j = i - 1; j i - 1 i 1 while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            } j >= 0 && A[j] > v j >= 0 j 0 A[j] > v A[j] A j v {
                A[j + 1] = A[j];
                j--;
            } A[j + 1] = A[j] A[j + 1] A j + 1 j 1 A[j] A j j-- j A[j + 1] = v A[j + 1] A j + 1 j 1 v System.out.println(dump(A, N)) System.out.println System.out System System.out dump(A, N) dump A N int[] A A int N N public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    } bubbleSort {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    } int swapCount = 0; swapCount 0 boolean flag = true; flag true while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        } flag = false flag false for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            } int j = N - 1; int j = N - 1; j N - 1 N 1 j >= 1 j 1 j-- j-- j {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            } {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            } if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                } A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                } swapInt(A, j, j - 1) swapInt A j j - 1 j 1 swapCount++ swapCount flag = true flag true System.out.println(dump(A, N)) System.out.println System.out System System.out dump(A, N) dump A N System.out.println(swapCount) System.out.println System.out System System.out swapCount int[] A A int N N public static void selectionSort(int[] A, int N) {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    } selectionSort {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    } int swapCount = 0; swapCount 0 for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        } {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        } int minj = i; minj i for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            } int j = i; int j = i; j i j < N j N j++ j++ j {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            } {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            } if (A[j] < A[minj]) {
                    minj = j;
                } A[j] < A[minj] A[j] A j A[minj] A minj {
                    minj = j;
                } minj = j minj j if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            } A[i] != A[minj] A[i] A i A[minj] A minj {
                swapInt(A, i, minj);
                swapCount++;
            } swapInt(A, i, minj) swapInt A i minj swapCount++ swapCount System.out.println(dump(A, N)) System.out.println System.out System System.out dump(A, N) dump A N System.out.println(swapCount) System.out.println System.out System System.out swapCount int[] A A int N N public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    } swapInt {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    } int v = A[j]; v A[j] A j A[j] = A[k] A[j] A j A[k] A k A[k] = v A[k] A k v int[] A A int j j int k k public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    } dump {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    } StringBuilder builder = new StringBuilder(); builder new StringBuilder() for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        } {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        } if (i != 0) {
                builder.append(" ");
            } i != 0 i 0 {
                builder.append(" ");
            } builder.append(" ") builder.append builder " " builder.append(A[i]) builder.append builder A[i] A i return builder.toString(); builder.toString() builder.toString builder int[] A A int N N public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    } readInt {
        return Integer.parseInt(r.readLine());
    } return Integer.parseInt(r.readLine()); Integer.parseInt(r.readLine()) Integer.parseInt Integer r.readLine() r.readLine r BufferedReader r r public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    }
    
    public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    }
    
    public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void selectionSort(int[] A, int N) {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    }
    
    public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    }
    
    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    }
    
    public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    }
    
    public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void selectionSort(int[] A, int N) {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    }
    
    public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    }
    
    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int N = readInt(r);
        String[] numStrings = r.readLine().split(" ");
        int[] A = new int[N];
        for (int i = 0;i < N;i++) {
            A[i] = Integer.parseInt(numStrings[i]);
        }
//        insertionSort(A, N);
//        bubbleSort(A, N);
        selectionSort(A, N);
    }
    
    public static void insertionSort(int[] A, int N) {
        System.out.println(dump(A, N));
        for (int i = 1;i <= (N - 1);i++) {
            int v = A[i];
            int j = i - 1;
            while (j >= 0 && A[j] > v) {
                A[j + 1] = A[j];
                j--;
            }
            A[j + 1] = v;
            System.out.println(dump(A, N));
        }
    }
    
    public static void bubbleSort(int[] A, int N) {
        int swapCount = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int j = N - 1;j >= 1;j--) {
                if (A[j] < A[j - 1]) {
                    swapInt(A, j, j - 1);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void selectionSort(int[] A, int N) {
        int swapCount = 0;
        for (int i = 0;i < N;i++) {
            int minj = i;
            for (int j = i;j < N;j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (A[i] != A[minj]) {
                swapInt(A, i, minj);
                swapCount++;
            }
        }
        System.out.println(dump(A, N));
        System.out.println(swapCount);
    }
    
    public static void swapInt(int[] A, int j, int k) {
        int v = A[j];
        A[j] = A[k];
        A[k] = v;
    }
    
    public static String dump(int[] A, int N) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0;i < N;i++) {
            if (i != 0) {
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        return builder.toString();
    }
    
    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
}