#include <stdio.h>
int main(void){
	int a[101];
	int N,i,j,swap,awi = 0,flag = 1;
	
	scanf("%d", &N);
	
	for(i=0; i<N; i++){
		scanf("%d",&a[i]);
	}
	
	i = 0;
	
	while(flag){
		flag = 0;
		
		for(j=N-1; j >= i+1; j--){
			if( a[j] < a[j-1] ){
				swap = a[j];
				a[j] = a[j-1];
				a[j-1] = swap;
				awi++;
			}
			flag = 1;
			i++;
		}
	}
			
	for(i=0; i<N; i++){
		if(i){
			printf(" ");
		}
		printf("%d",a[i]);
	}
	printf("\n");
	printf("%d\n",awi);
	
	return 0;
}