#include <bits/stdc++.h>
int main(void) {
  int l, score = 0, i, j, k, f = 0, buf = 0;
  scanf("%d", &l);
  int ary[l];
  for (i = 0; i < l; i++) scanf("%d", &ary[i]);
  for (j = 0; j < l; j++) {
    f = 0;
    for (k = 0; k < j; k++) {
      if (ary[j] < ary[k]) {
        buf = ary[j], ary[j] = ary[k], ary[k] = buf, f = 1;
      }
    }
    if (f == 1) score++;
  }
  for (i = 0; i < l; i++) {
    (i < l - 1) ? printf("%d ", ary[i]) : printf("%d", ary[i]);
  }
  printf("\n%d\n", score);
  return 0;
}
