#include<stdio.h>

int bubbleSort(int,int[100]);

int main(){
  int N,i,count;
  scanf("%d", &N);

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

  count = bubbleSort(N,A);

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

}

int bubbleSort(int N, int A[N]){
  int flag = 1;
  int j,t,count=0;
  while (flag==1){
      flag = 0;
      for(j=N-1; j>=0; j--){
	if (A[j] < A[j-1]){
	  t=A[j]; A[j]=A[j-1]; A[j-1]=t;
	  count++;
	  flag = 1;
	}
      }
  }
  return count;
}


