#include <stdio.h>

int main()
{
        int v,n,i,j,A[1000];
        int count,c;
           c=0;
          j = n-1;
         scanf("%d",&n);
         for(i=0;i<n;i++){
         scanf("%d",&A[i]);
         }
          
          while(c<n){
          	
          ???while(j>=c){
          	if(A[j]???A[j+1]){
          v=A[j];
          ???A[j]=A[j+1];
          A[j+1]=v;
          ???count++;}
          
          j--;
          ???}
          ???c++;
          }
          for(i=0;i<n-1;i++){
          printf("%d+ +",A[i]);}
          ???printf("%d\n",A[n]);
          printf("%d",count);
          
        return 0;
}



 