#include <stdio.h>

int main(){
	int i,n,temp;
	int count = 0;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	i=0;
	while(i!=n){
		if(a[i]>a[i+1]){
			temp = a[i];
			a[i] = a[i+1];
			a[i+1] = temp;
			count++;i=0;
		}else i++;
	}
	for(i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	printf("\n%d",count);
}