#include <stdio.h>

#define N 100

void display(int data[], int n);
void bubbleSort(int data[], int n);
void insertionSort(int data[], int n);

int main(){
	
	//??????
	int data[N];
	
	//??其?????即?????属
	int i, n;
	
	//????卒???属?????\???
	scanf("%d", &n);
	
	
	//??????????????\???
	for(i=0; i<n; i++){
		
		scanf("%d", &data[i]);
		
	}
	
	bubbleSort(data, n);
	
	return 0;
	
}



//?????????????卒???????????????????
void display(int data[], int n){
	
	int i;
	
	for(i=0; i<n; i++){
		if(i>0){
			printf(" ");
		}
		printf("%d", data[i]);
	}
	
	printf("\n");
	
	return;
}



//??????????????????
void bubbleSort(int data[], int n){
	
	int i, j, temp;
	int count = 0;
	
	for(i=0; i<n; i++){
		
		for(j=n-1; j>i; j--){
			
			if(data[j] < data[j-1]){
				
				temp = data[j];
				data[j] = data[j-1];
				data[j-1] = temp;
				
				//?????属????即????
				count++;
				
			}
			
		}
		
		//???????????其????????????
		//display(data, n);
		
	}
	
	
	//??????
	display(data, n);
	
	//???????????属?????????
	printf("%d\n", count);
	
	return;
}



//?????\?????????
void insertionSort(int data[], int n){
	
	int i, j, temp;
	
	for(i=1; i<n; i++){
		
		j = i;
		temp = data[j];
		
		while(j>0 && temp < data[j-1]){
			
			data[j] = data[j-1];
			j--;
			
		}
		data[j] = temp;
		
		//???????????其????????????
		//display(data, n);
	}
	
}