#include <bits/stdc++.h>
int main(void) {
  int i, n, j, t, k, A[100];
  int count = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (A[i] > A[j]) {
        t = A[j];
        A[j] = A[i];
        A[i] = t;
        count++;
      }
    }
  }
  for (k = 0; k < n; k++) printf("%d ", A[k]);
  printf("\n");
  printf("%d\n\n", count / 3);
  return 0;
}
