function main(input){
    let int = parseInt;
    
    let lines = input.split("\n");
    let length = int(lines[0]);
    let nums = lines[1].split(" ");
    nums= nums.map(item=>int(item));
    let sortedIndex=0;
    let swapCount=0;
    let numsPut = "";
    let swapped = false;
    if(length===1){
        console.log(nums[0]);
        console.log(0);
        return;
    }
    
    do{
        swapped = false;
        
        for(let i=length-1;i>sortedIndex;i--){
            if(nums[i]<nums[i-1]){
                let temp = nums[i];
                nums[i] = nums[i-1];
                nums[i-1] = temp;
                swapped = true;
                swapCount++;
            }
        }
        sortedIndex++;
    }while(swapped);
    for(let i=0;i<length;i++){
        numsPut +=String(nums[i])+" ";
    }
    console.log(numsPut.trim());
    console.log(String(swapCount));



}




main(require("fs").readFileSync("/dev/stdin","utf-8"));
