#include <stdio.h>
int main(){
  int n,j,i,count,alg,k;
  scanf("%d",&n);
  int res[n];
  scanf("%d",res[n]);
  i=0;
  while(i!=n){
    for(j=n-1;j<=i+1;j++){
      if(res[j]<res[j-1]){
	res[j] = alg;
	alg = res[j-1];
	res[j-1] = res[j];
	count++;
      }
      i++;
    }
  }
  for(k=0;k<n;k++){
    printf("%d\n%d",res[k],count);
  }
    return 0;
  }