#include<stdio.h>
#define N 100

int main(void){
  int i,j,len,A[N],key,count=0;
  scanf("%d",&len);
  //printf("out put\n");
  for(i=0; i<len; i++)
    scanf("%d",&A[i]);
  for(i=0; i < len-1; i++){
    for(j=len-1; j>i; j--){
      if(A[j-1] > A[j]){
	key=A[j];
	A[j]=A[j-1];
	A[j-1]=key;
	count++;
      }
    }
  }
  for(i=0 ;i <len; i++)
    printf("%d ",A[i]);
  printf("\n%d\n",count);
  return 0;
}