#include <bits/stdc++.h>
int main() {
  int n, a[100], j, c = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    int t = a[i];
    for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j], c++;
    a[j + 1] = t;
  }
  for (int i = 0; i < n - 1; i++) std::cout << a[i] << " ";
  std::cout << a[n - 1] << std::endl << c << std::endl;
  return 0;
}
