#include <stdio.h>

// bubble sort


int main() {

    int n, tmp;
    int a[100];
    int count = 0;
    int flag = 1;

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


    while (flag) {
        flag = 0;
        for (int j=n-1; j>=1; j--){
            if (a[j] < a[j-1]) {
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }
    if (n == 1) {
        printf("%d", a[n-1]);
    } else {
        for(int i=0; i<n-1; i++) {
            printf("%d ", a[i]);
        }
        printf("%d\n", a[n-1]);
    }

    printf("\n%d", count);

    return 0;
}