#include<stdio.h>
#define N 100
int bsort(int *a, int n){
  int count=0;
  int i, j, tmp;
  for(i=0;i<n;i++){
    for(j=0;j+i<n-1;j++){
      if(a[j]>a[j+1]){
        count++;
        tmp=a[j];
        a[j]=a[j+1];
	a[j+1]=tmp;
      }     
    }
  }
  return count;
}
int main(){
  int n;
  int a[N];
  int i;
  int count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  count=bsort(a, n);
  for(i=0;i<n;i++){
    printf("%d ", a[i]);
  }
  printf("\n");
  printf("%d\n", count);
  return 0;
}