var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var n = lines[0];

var A = lines[1].split(' ').map(function(i) {
	return i - 0;
});

var cnt = 0;
for (var i = 0; i < n; i++) {
	for (var j = n - 1; j > i; j--) {
		if (A[j] < A[j - 1]) {
			var tmp = A[j];
			A[j] = A[j - 1];
			A[j - 1] = tmp;

			cnt++;
		}
	}
}  

console.log(A.join(' '));
console.log(cnt);