#include <stdio.h>
  
void bubbleSort( int A[], int N )
{
   int i, j, v;
   int wa = 0;

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

void syuturyoku( int A[], int N )
{
   int i;
   for ( i = 0; i < N; i++ ) {
      if ( i > 0 ) {
         printf(" ");
      }
      printf("%d", A[i]);
   }
   printf("\n");
}

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;
}