#include <stdio.h>

void bubbleSort(int ,int [100]);

int main(void){
    
    int n;
    int a[100];
    
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    
    bubbleSort(n, a);
    
    return 0;
}

void bubbleSort(int N,int A[100]){
    
    int flag = 1;
    int exchangeNumber;
    int sum = 0;
    
    while(flag == 1){
        flag = 0;
        for(int j = N-1;j>0;j--){
            if(A[j] < A[j-1]){
                exchangeNumber = A[j];
                A[j] = A[j-1];
                A[j-1] = exchangeNumber;
                flag = 1;
                sum++;
            }
        }
    }
    
    for (int j=0;j<N;j++) printf("%d ",A[j]);
    printf("\n%d\n",sum);
}