#include<stdio.h>
#define swap(a,b){a+=b;b=a-b;a-=b;}

int main(){
	int n,i,j,A[100],count=0;
	scanf("%d",&n);
	for (i = 0; i < n; i++)
		scanf("%d",&A[i]);

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

	for (i = 0; i < n; i++){
		printf("%d", A[i]);
		if (i < n - 1){ printf(" "); }
	}
	printf("\n%d\n",count);
	return 0;
}