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