#include<stdio.h>

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


 
  