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