/*
1 bubbleSort(A, N) // N ??????????´?????????? 0-????????????????????? A
2   flag = 1 // ????????£??\????´?????????¨??????
3   while flag
4     flag = 0
5     for j ??? N-1 ?????? 1 ?????§
6       if A[j] < A[j-1]
7         A[j] ??¨ A[j-1] ?????????
8         flag = 1
*/
int sort(int *A, int N)
{
	int count = 0, flag = 1, i,tmp;
	while (flag)
	{
		flag = 0;
		for ( i = N-1; i >=1; i--)
		{
			if (A[i]<A[i-1])
			{
				tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				flag = 1;
				count++;
			}
		}
	}
	return count;
}
#include<stdio.h>

int main()
{
	int N, A[100];
	scanf("%d", &N);
	int i;
	for (i = 0; i < N; i++)
		scanf("%d", &A[i]);
	int t = sort(A, N);
	for (i = 0; i < N; i++)
		printf("%d ", A[i]);
	printf("\b\n%d\n", t);
	return 0;
}