#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   long long sum;   int k, p, n, a[N + 1], i, b[N + 1], left_tree[N + 1], right_tree[N + 1];   vector<long long> leftv, rightv;   void update(int index, int value, int tree[]) {     while (index < N + 1) {       tree[index] += value;       index += (index & -index);     }   }   int read(int index, int tree[]) {     int sum = 0;     while (index > 0) {       sum += tree[index];       index -= (index & -index);     }     return sum;   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (i = 0; i < n; i++) {       a[i] = upper_bound(b, b + n, a[i]) - b;     }     for (i = 0; i < n; i++) {       update(a[i], 1, left_tree);       leftv.push_back(read(N, left_tree) - read(a[i], left_tree));     }     for (i = n - 1; i >= 0; i--) {       rightv.push_back(read(a[i], right_tree));       update(a[i], 1, right_tree);     }     reverse(rightv.begin(), rightv.end());     for (i = 0; i < n; i++) {       sum += rightv[i] * leftv[i];     }     cout << sum;   }   