#include<iostream>
#include <climits>
#include<vector>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	bool flag = true;
	int res = 0;
	while (flag) {
		flag = false;
		for (int i = N - 1;i > 0;i--) {
			if(A[i-1]>A[i]){
				int tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				flag = true;
				res++;
			}
		}
	}
	REP(i, N) {
		if (i < N - 1)cout << A[i] << " ";
		else cout << A[i] << "\n";
	}
	cout << res << "\n";

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (auto &x: a) cin >> x;
    for (auto &x: b) cin >> x;
    for (auto &x: c) cin >> x;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<long long> l(n);
    int j = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && c[j] <= b[i]) j++;
        l[i] = n - j;
    }
    for (int i = n - 1; i > 0; i--) l[i-1] += l[i];
    long long ans = 0;
    j = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && b[j] <= a[i]) j++;
        if (j == n) break;
        ans += l[j];
    }
    cout << ans << endl;
    return 0;
}