#include <stdio.h>

int main() {
	int N;
	int temp;
	int flag;
	int count = 0;
	int A[1000] = {};

	scanf("%d", &N);

	for(int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	while(flag) {
		flag = 0;
		for(int i = 0; i < N-1; i++) {
			if(A[i] > A[i+1]) {
				temp = A[i+1];
				A[i+1] = A[i];
				A[i] = temp;
				flag = 1;
				count++;
			}
		}
	}
	for(int i = 0; i < N; i++) {
	       printf("%d", A[i]);
           if(i != N-1)
           	putchar(' ');
	}
	printf("\n%d\n", count);
}
