#include<stdio.h>
int main(){
 int flag,i,j,count=0,n,key;
 scanf("%d",&n);
 int A[n];
 for(i=0;i<n;i++)
 scanf("%d",&A[i]);
     for(j=n-1;j>1;j--){
       if (A[j] < A[j-1]){
       count++;
       key = A[j];
         A[j] = A[j-1];
         A[j-1] = key;
       }
     }
   for(i=0;i<n;i++)
   printf("%d",A[i]);
   printf("\n%d\n",count);
   return 0;
}


