#include<stdio.h>
#define N 100
int main(){
    int i,j,n,a[N],temp,count=0;
scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++){
        for(j=n-1;j>i;j--)
            if(a[j-1]>a[j]){
                temp = a[j-1];
                a[j-1] = a[j];
                a[j] = temp;
                count++;
            }
    }
    for(i=0;i<n;i++){
        printf("%d ",a[i]);
    }
    printf("\n");
    printf("%d",count);
    return 0;
}

