#include<stdio.h>
int main(){
int v,i,n,j,a[100];
int c = 0;
scanf("%d",&n);
for(i = 0;i < n;i++){
scanf("%d",&a[i]);}

for(j = 0;j < n;j++){
 for(i = n-1;i > j; i--){
  if(a[i]<a[i-1]){
  v = a[i];
  a[i] = a[i - 1];
  a[i - 1] = v;
  c++;
  }
 }
}
  for(i = 0;i < n;i++){
  if(i == n-1)
  printf("%d\n",a[i]);
  else 
  printf("%d",a[i]);
}
  printf("%d\n",c);

 return 0;
}