#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
    int i,j,k,l,a[100],tmp,count=0;
    char input[4001],*p;
     
    fgets(input,sizeof input,stdin);
    sscanf(input,"%d",&i);
     
    fgets(input,sizeof input,stdin);
    p=strtok(input," ");
    a[0]=atoi(p);
     
    for(j=1;j<n;j++){
        p=strtok(NULL," ");
        a[j]=atoi(p);
    }
     
    l=i-1;
    for(j=0;j<n-1;j++){
        for(k=0;k<l;k++){
            if(a[k]>a[k+1]){
                tmp=a[k];
                a[k]=a[k+1];
                a[k+1]=tmp;
                count++;
            }
        }
        l--;
    }
    for(j=0;j<n;j++){
        printf("%d",a[j]);
        if(j!=i-1){
            printf(" ");
        }
    }
    printf("\n%d\n",count);
     
     
     
     
    return 0;
}