#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
long long fn[2][N + 5], temp[N + 5], v[N + 5];
int n;
long long query(long long tree[], int k) {
  long long s = 0;
  while (k > 0) {
    s += tree[k];
    k -= k & -k;
  }
  return s;
}
void update(long long tree[], int k, int val) {
  while (k <= n) {
    tree[k] += val;
    k += k & -k;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> temp[i];
    v[i] = temp[i];
  }
  sort(temp + 1, temp + n + 1);
  for (int i = 1; i <= n; i++) {
    int poz = lower_bound(temp + 1, temp + n + 1, v[i]) - temp;
    v[i] = poz;
  }
  for (int i = 1; i <= n; i++) {
    s += query(fn[1], n) - query(fn[1], v[i]);
    update(fn[0], v[i], 1);
    update(fn[1], v[i], query(fn[0], n) - query(fn[0], v[i]));
  }
  cout << s;
}
