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