#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, temp = 0, coun = 0;
  scanf("%d", &n);
  int arra[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arra[i]);
  }
  for (int i = 1; i < n - 1; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (arra[j] < arra[j - 1]) {
        temp = arra[j];
        arra[j] = arra[j - 1];
        arra[j - 1] = temp;
        coun++;
      }
    }
  }
  for (int i = 0; i < n - 1; i++) {
    printf("%d ", arra[i]);
  }
  printf("%d\n", arra[n - 1]);
  printf("%d\n", coun);
}
