#include <bits/stdc++.h>
int main() {
  int i, j, flag = 1, n, data[100], temp, cont = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &data[i]);
  while (flag) {
    flag = 0;
    for (i = n - 1; i >= 0; i--) {
      temp = data[i];
      if (data[i] < data[i - 1]) {
        data[i] = data[i - 1];
        data[i - 1] = temp;
        flag = 1;
        cont++;
      }
    }
  }
  for (i = 0; i < n; i++) printf(" %d", data[i]);
  printf("\n%d\n", cont);
  return 0;
}
