#include <iostream>
#include <vector>
using namespace std;
// Hàm đếm số nghịch thế theo giải pháp O(n^2)
int countInversionsNaive(const vector<int>& arr) {
int n = arr.size();
int count = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] > arr[j]) {
count++;
}
}
}
return count;
}
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cout << "Number of inversions (O(n^2)): " << countInversionsNaive(arr) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gSMOgbSDEkeG6v20gc+G7kSBuZ2jhu4tjaCB0aOG6vyB0aGVvIGdp4bqjaSBwaMOhcCBPKG5eMikKaW50IGNvdW50SW52ZXJzaW9uc05haXZlKGNvbnN0IHZlY3RvcjxpbnQ+JiBhcnIpIHsKICAgIGludCBuID0gYXJyLnNpemUoKTsKICAgIGludCBjb3VudCA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG4gLSAxOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCBuOyBqKyspIHsKICAgICAgICAgICAgaWYgKGFycltpXSA+IGFycltqXSkgewogICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBjb3VudDsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgdmVjdG9yPGludD4gYXJyKG4pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBjaW4gPj4gYXJyW2ldOwogICAgfQogICAgY291dCA8PCAiTnVtYmVyIG9mIGludmVyc2lvbnMgKE8obl4yKSk6ICIgPDwgY291bnRJbnZlcnNpb25zTmFpdmUoYXJyKSA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0=