#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int i = 0, d = 0, count = 0, n, x;
	int k[10];
	char j[10][2];
	scanf("%d", &n);
	while (getchar() != '\n') {}

	fgets(j,(n* 2),stdin);
	
	for (i = 0; i < (n * 2); i++) {
		k[d] = atoi(j[i]);
		d++;
	}
		

	for (x = 0; x < n; x++) {//バブルソート
		for (i = (n - 1); i > 0;i-- ){
			if (k[i] < k[i - 1]) {
				d = k[i];
				k[i] = k[i - 1];
				k[i - 1] = d;
				count++;
			}
		}
	}

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

	return 0;
}
