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