#include<stdio.h>
//A is array and N is count
int bubble_sort(int array[],int size){
  int count=0,tmp,i,j;
  for(i=0;i<size;i++){
    for(j=i+1;j<size;j++){
      if(array[j]<array[i]){
        tmp=array[i];
        array[i]=array[j];
        array[j]=tmp;
        count++;
      }
    }
  }
  return count;
}

int main(void){
  int i,size,array[100000],count;
  scanf("%d",&size);
  for(i=0;i<size;i++){
    scanf("%d",&array[i]);
  }
  count = bubble_sort(array,size);
  for(i=0;i<size;i++){
    if(i>0) printf(" ");
    printf("%d",array[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}