#include <stdio.h>

int main()
{
        int v,n,i,j,A[1000];
        int count,c=1;
           c=0;
          j = n-1;
         scanf("%d",&n);
         for(i=0;i<n;i++){
         scanf("%d",&A[i]);
         }
          
          while(j){
          j=0
          ???for(i=1;i<n;i++)
          if(A[i]<A[i-1]){
          v=A[i];
          ???A[i]=A[i-1];
          A[i-1]=v;
          ???count++;
          j=1;
          }
          ???}
          }
          for(i=0;i<n;i++){
          printf("%d ",A[i]);
          if(i==n-1)???printf("%d\n",A[i]);}
          printf("%d\n",count);
          
        return 0;
}



 
    
   