#include<stdio.h>


int main(void){
 int flag = 1;
int i,j,N,v,a[100]; 
int c =0;

    scanf("%d", &N);
     for ( i = 0; i < N; i++ ){ 
scanf("%d", &a[i]);
}
 
bubbleSort(a,N);
   
    for ( i = 0; i < N; i++ ) {
        printf(" %d\n", a[i]);
  if(i==N-1){
 printf("\n");
     } 
else { 
printf(" ");
}
     }



    

    printf("%d\n", c);
    return 0;
}
 
void bubbleSort(int a[],int N)
{
  int flag = 1;
int i,j,v; 
int c = 0;


    while ( flag ) {
        flag = 0;
        for ( j = N - 1; j >= 1; j-- ) {
            if ( a[j] < a[j - 1] ) {
                v = a[j];
                a[j] = a[j - 1];
                a[j - 1] = v;
                c++;
                flag = 1;
            }
        }
    }
}