#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; class BinaryIndexTree { public: vector data; BinaryIndexTree(ll size) { data.resize(size, 0); } void add(ll i, ll x) { i++; ll n = data.size(); while (i <= n) { data[i - 1] += x; i += i & -i; } } ll sum(ll stop) { ll result = 0; ll i = stop; while (i > 0) { result += data[i - 1]; i -= i & -i; } return result; } ll range_sum(ll start, ll stop) { return sum(stop) - sum(start); } }; int main() { int N; cin >> N; vector P(N); for (auto &x: P) cin >> x; BinaryIndexTree bit(N + 1); ll result = 0; for (auto x: P) { result += bit.range_sum(x + 1, N + 1); bit.add(x, 1); } cout << result << endl; return 0; }