import std.stdio;
import std.string;
import std.algorithm;
import std.conv;

void main(){

    int N;
    int[] arr = new int[100];
    string[] s;
    int count = 0;
    readf("%d\n",&N);
    s = split(readln());
    for(int i=0;i<N;i++){
	arr[i] = to!int(s[i]);
    }

    for(int i=0;i<N;i++){
	for(int j=N-1;j>0;j--){
	    if(arr[j] < arr[j-1]) {
		count++;
		swap(arr[j],arr[j-1]);
	    }
	}
    }

    write(arr[0]);
    for(int i=1;i<N;i++){
	writef(" %d",arr[i]);
    } 
    writeln();
    writeln(count);
}