var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var input_array =input.trim().split("\n");
var numbers = input_array[1].split(' ').map((n) => Number(n));

var exchange_count = 0;

for (var i = 0; i < numbers.length; i++) {
  for (var j = numbers.length - 1; j > i; j--) {
    if (numbers[j] < numbers[j-1]) {
        var tmp = numbers[j];
        numbers[j] = numbers[j-1];
        numbers[j-1] = tmp;
        exchange_count++;
    }
  }
}

console.log(numbers.join(' '));
console.log(exchange_count);
