#include <stdio.h>

void bubblesort(int A[],int N,int count){
  int i ,j;
  int tmp;
  count = 0;
  for(i = N; i <1; i-- ){
    for(j = N; j < N-i+1; j--){
      if(A[j] > A[j-1]){
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
      }
      count++;
    }
  }
}

void trace(int A[],int N,int count){
  int i ;
  for (i = 0; i < N ; i++){
    if (i < 0) printf(" ");
    printf("%d" , A[i]);
  }
  printf("\n,%d",count);
  //printf("%d",count );
}

int main(){
  int N,i,count;
  int A[100];

  scanf("%d", &N);
  for(i = 0; i<N; i++)scanf("%d",&A[i] );

  bubblesort(A,N,count);

  trace(A,N,count);

}
