#include<stdio.h>

int main(void){
  int N, a, b, i, j, k, count = 0;
  int A[100];
  scanf("%d", &N);
  for(a = 0; a < N; a++){
	scanf("%d", &A[a]);
  }
  
  for( i = N - 1; i >= 0; i-- ){
	  for(j = i - 1 ; j >= 0; j-- ){
      if(A[i] < A[j]){
        k = A[j];
        A[j] = A[i];
        A[i] = k;
        count += 1;
      	}
    	}
   }
   
  for( b = 0; b < N; b++){
	  if( b > 0 ){
  	  printf(" ");
	  }
	  printf("%d", A[b]);
    }
    printf("\n");
    printf("%d?\n",count);
}