#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int array[N];
  for (int i = 0; i < N; i++) cin >> array[i];
  int counter = 0;
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (array[j] < array[minj]) {
        int temp = array[j];
        array[j] = array[minj];
        array[minj] = temp;
        counter += 1;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == N - 1)
      cout << array[i] << endl;
    else
      cout << array[i] << " ";
  }
  cout << counter / 3 << endl;
  return 0;
}
