#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define endl '\n'
#define all(v) v.begin(), v.end()
const long long sz = 3e5 + 5;
const long long sz1 = 1e7 + 1;
const long long inf = 1e18;
const long long mod = 998244353;
// mt19937 rng(time(NULL));
int a[sz];
int l[sz], r[sz];
inline void solve() {
    int n;
    cin >> n;
    ordered_set s, t;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        l[i] = s.order_of_key(a[i]);
        s.insert(a[i]);
    }
    for (int i = n; i >= 1; i--) {
        r[i] = t.order_of_key(a[i]);
        t.insert(a[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans += l[i] * r[i];
    cout << ans << endl;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |