// bubblesort.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdio.h"


int main()
{
    int N, a, A[1000],j,x, count;
    scanf("%d", &N);
    for (a = 0; a<N; a++)
        scanf("%d\n", &A[a]);

    int flag = 1;
    while (1) {
        flag = 0;
        for (j = N - 1; j < 0; j--) {
            if (A[j] < A[j - 1]) {
                x = A[j];
                A[j] = A[j - 1];
                A[j - 1] = x;
                flag = 1;
                count++;
            }
            
        }
    }

    for (j = 0; j < N - 1; j++)
        printf("%d ", A[j]);

    printf("%d\n", A[N - 1]);
    printf("%d\n", count);
    return 0;
}