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