#include<stdio.h>
int main(){
int a[100],i,j,n,temp,count=0;
//cin>>n;
scanf("%d\t",&n);
for(i=0;i<n;i++){
//cin>>a[i]>>" ";
scanf(" %d",&a[i]);
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i]>a[j]){
temp=a[i]; //swapping
a[i]=a[j];
a[j]=temp;
count++;
}
}
}
for(i=0;i<n;i++)
{
    //cout<<a[i]<<" ";
printf("%d ",a[i]);
}
//cout<<endl;
printf("\n");
//cout<<count;
printf("%d",count);
return 0;
}