function main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var values = input[1].split(" ").map(function(v) { return parseInt(v); });
  var count = bubbleSort(values, N);
  console.log(count);
  console.log(values.join(" "));
  return;
}

function bubbleSort(a, N) {
  var count = 0;
  var flag = true;
  while (flag) {
    flag = false;
    for (var j = N-1; j >= 1; j--) {
      if (a[j] < a[j-1]) {
        var v = a[j];
        a[j] = a[j-1];
        a[j-1] = v;
        flag = true;
        count++;
      }
    }
  }
  return count;
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));