var input = require('fs').readFileSync('/dev/stdin', 'utf8');
input = input.split("\n");
var N = parseInt(input[0]);
var A = input[1].split(" ").map(function(e){ return parseInt(e,10)});

var count = 0;
for(var i = 0; i < N-1; i++){
  for(var j = N-1 ; j > i; j--){
    if(A[j-1] > A[j]){
      var tmp = A[j];
      A[j] = A[j-1];
      A[j-1] = tmp;
    count += 1;
    }
  }
};
console.log(A.join(" "));
console.log(count);
