#include<iostream>
using namespace std;
int main(){
	int n, sort[100], hoge, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> sort[i];
	}
	for (int i = 0; i < n - 2;i++){
		for (int j = 0; j < n - 1 - i;j++){
			if (sort[j] > sort[j + 1]){
				hoge = sort[j];
				sort[j] = sort[j + 1];
				sort[j + 1] = hoge;
				cnt++;
			}
		}
	}
	for (int i = 0; i < n; i++){
		cout << sort[i] << " ";
	}
	cout << "\n";
	cout << cnt << "\n";
	return 0;
}