#include <stdio.h>

int main()
{
  int x[100], n, i,j , swap;
  int count=0;


  scanf("%d", &n);



  for (i = 0; i < n; i++)
    scanf("%d", &x[i]);

  for (i = 0 ; i < ( n - 1 ); i++)
  {
    for (j = 0 ; j< n - i - 1; j++)
    {
      if (x[j] > x[j+1]) 
      {
        swap       = x[j];
        x[j]   = x[j+1];
        x[j+1] = swap;
        count++;
      }
    }
  }



  for ( i = 0 ; i < n ; i++ )
     printf("%d ", x[i]);
     printf("\n");
     printf("%d",count);

  return 0;
}