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