#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int dem = 0;
  int a[100000];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int mini = i;
    for (int j = i; j < n; j++) {
      if (a[j] < a[mini]) {
        int temp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = temp;
        dem++;
      }
    }
  }
  cout << a[0];
  for (int i = 1; i < n; i++) cout << " " << a[i];
  cout << endl;
  cout << dem << endl;
  return 0;
}
