#include <stdio.h>

int main(void){
        int i,n,temp;
        int count = 0;
        scanf("%d",&n);
        int a[n];
        for(i=0;i<n;i++){
                scanf("%d",&a[i]);
        }
        i=0;
        while(i!=n){
                if(a[i]>a[i+1]){
                        temp = a[i];
                        a[i] = a[i+1];
                        a[i+1] = temp;
                        count++;i=0;
                }else i++;
        }
        for(i=0;i<n-1;i++){
                printf("%d ",a[i]);
        }
        printf("%d",a[n-1]);
        printf("\n%d\n",count);

        return 0;
}