#include<stdio.h>
#include<stdlib.h>

int bubblesort(int a[],int n){
  int i,j,tmp,count;
  for(i=0; i<n-1; i++){
    for(j=n-1; j>i; j--){
      if(a[j]<a[j-1]){
      tmp = a[j];
      a[j] = a[j-1];
      a[j-1] = tmp;
      count++;
      }
    }
  }
  return count;
}



int main(){
  int num,i,result;
  int *A;
  scanf("%d",&num);

  A = calloc(num,sizeof(int));

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

  result = bubblesort(A,num);

  for(i=0; i<num; i++){
    printf("%d ",A[i]);
  }
  puts("");
  printf("%d\n",result);

  return 0;
}
