#include <stdio.h>

int bubblesort(int [],int n);

int main(void) {
	int n,A[100];
	int i,j,c;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	c=bubblesort(A,n);
	for(i=0;i<n;i++) {
		printf("%d",A[i]);
		if(i!=n-1) printf(" ");
		else printf("\n");
	}
	printf("%d\n",c);
	return 0;
}

int bubblesort(int A[],int n){
	int i,j,a,count=0;
	for(i=0;i<n-1;i++){
		for(j=i;j<n;j++){
			if(A[i]>A[j]){
				a=A[i];
				A[i]=A[j];
				A[j]=a;
				count++;
			}
		}
	}
	
	return count;
}

