import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    }
}

class BubbleSort{
    int[] bubNum;
    public BubbleSort(int[] bubNum){
        this.bubNum = bubNum;
    }
    
    int count = 0;
    public void changeOfBubNum(){
        int minNum = 0;
        for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        }
    }
    
    public void outPutOfBubNum(){
        for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        }
        System.out.print("\n");
    }
    
    public void outPutOfBubCount(){
         System.out.println(count);
    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz