#include<stdio.h>
int main()
{
  int i,tmp,N,count=0,judge=1;
  int data[10];

  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%d",&data[i]);
  }

  while(1){
    judge = 0;
    for(i=N-1; i>0; i--){
      if(data[i] < data[i-1]){
        tmp = data[i];
        data[i] = data[i-1];
        data[i-1] = tmp;
        count++;
        judge = 1;
      }
    }
    if(judge==0) break;
  }

  for( i=0 ; i<N ; i++){
    printf("%d ",data[i]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}
