#include <stdio.h>
 
void syuturyoku( int A[], int N )
{
   int i;
   for ( i = 0; i < N; i++ ) {
      if ( i > 0 ) {
         printf(" ");
      }
      printf("%d", A[i]);
   }
   printf("\n");
}
 
void bubbleSort( int A[], int N )
{
   int i, j, v;
   int wa = 0;

   for ( i = 0; i < N; i++ ) {
      j = N - 1 - i;
      if ( j >= 0 && A[ j ] < A[ j - 1 ] ) {
         v = A[ j ];
         A[ j ] = A[ j - 1 ];
         A[ j - 1 ] = v;

      }
      wa = wa + 1;
   }
}


int main()
{
   int N, i, j, wa;
   int A[100];
 
   scanf("%d", &N);
   for ( i = 0; i < N; i++ ) {
      scanf("%d", &A[i]);
   }

   bubbleSort( A, N );
   syuturyoku( A, N );
   printf("%d\n", wa);
 
   return 0;
}