#include<stdio.h>

int main()
{
    int n,swap,i,j,cont=0;
    int arr[101];
    scanf("%d",&n);
    for(i=0;i<n;i++)
                    scanf("%d",&arr[i]);
    
    for(i=0;i<n;i++)
    {
                    for(j=i+1;j<n;j++)
                    {
                                      if(arr[j] < arr[i])
                                      {
                                                cont = cont+1;
                                                swap = arr[j];
                                                arr[j] = arr[i];
                                                arr[i] = swap;
                                      }
                    }
    }
    for(i=0;i<n;i++)
    {
                    if(i<n-1)
                    printf("%d ",arr[i]);
                    else
                    printf("%d\n",arr[i]);
    }
    printf("%d",cont);
    return 0;
}
    
    
    