#include<stdio.h>

void space(int A[], int N){
  int i;
  for( i = 0; i < N; i++){
	if( i > 0 ){
  	printf(" ");
	}
	printf("%d", A[i]);
  }
  printf("\n");
}
int main(void){
  int N, a, 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;
  	}
	}
  }
  space(A, N);
  printf("%d\n",count);
}