var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
var n = +input.shift();
var nums = input.shift().split(' ').map(Number);
var swapTimes = 0;

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

  console.log(numbers.join(' '));
  console.log(swapTimes);
}

bubbleSort(nums);