#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[100];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int s;
  int cnt = 0;
  int min;
  for (int i = 0; i < n; i++) {
    min = i;
    for (int j = i; j < n; j++) {
      if (arr[j] < arr[min]) {
        s = arr[j];
        arr[j] = arr[min];
        arr[min] = s;
        cnt++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << arr[i];
    if (i != (n - 1)) {
      cout << " ";
    } else {
      cout << "\n";
    }
  }
  cout << cnt / 3 << endl;
  return 0;
}
