var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");

var A=Arr[1].split(" ").map(Number);
var N=Arr[0];

let cnt = 0;

for(let i = 0;i<N;i++){
    let j = i;
    while(j !== 0){
        if(A[j-1]>A[j]){
            let tmp = A[j-1];
            A[j-1] = A[j];
            A[j] = tmp;
            
            cnt++;
        }
        j--;
    }
}

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