
#include<stdio.h>

int main(){
int v,n,i,j,A[100];
int count=0;
 scanf("%d",&n);
 for(i=0;i<n;i++){
 scanf("%d",A[i]);}

while(j){
  j=0;
 for(i=1;i<n;i++){
  if(A[i]<A[i-1]){
    v=A[i];
    A[i]=A[i-1];
    A[i-1]=v;
    j++;
    count++;
   }
 }
}
 for(i=0;i<n;i++){
 printf("%d ",A[i]);}
if(i==n-1)printf("%d\n",A[i]);
printf("%d\n",count);

return 0;
}