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