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