#include<bits/stdc++.h> usingnamespacestd; int rev_count = 0; vector<int> merge_count(vector<int>&A, vector<int>&B) { vector<int> R; while (!A.empty() && !B.empty()) { int a = A.front(); int b = B.front(); if (b < a) { R.push_back(b); rev_count += A.size(); B.erase(B.begin()); } else { R.push_back(a); A.erase(A.begin()); } } R.insert(R.end(), A.begin(), A.end()); R.insert(R.end(), B.begin(), B.end()); return R; } vector<int> sort_count(vector<int>&L) { int ls = L.size(); if ( ls!= 1) { int x = ls / 2; vector<int> A, B; int i; for (i = 0; i < x; ++i) A.push_back(L.at(i)); for(;i<ls;++i) B.push_back(L.at(i)); A = sort_count(A); B = sort_count(B); L = merge_count(A, B); } return L; } intmain() { vector<int> L; int n; int t; cin >> n; for (int i = 0; i < n; ++i) { cin >> t; L.push_back(t); } sort_count(L); cout << rev_count << "\n"; for (int i = 0; i < n; i++) cout << L.at(i) << " "; system("pause"); return0; }