#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e6 + 20;
map<int, int> m;
vector<int> v[4 * maxx + 10];
int n, a[maxx], b[maxx], tb[maxx], tk[maxx], x;
long long ans[4 * maxx + 10];
void build(int id = 1, int l = 0, int r = n) {
  if (l + 1 == r) {
    v[id].push_back(b[l]);
    ans[id] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid, r);
  ans[id] = (long long)(ans[id * 2] + ans[id * 2 + 1]);
  int p1 = 0, p2 = 0, l1 = v[id * 2].size(), l2 = v[id * 2 + 1].size();
  while (p1 < l1 || p2 < l2) {
    if (p1 < l1 && (p2 == l2 || v[id * 2][p1] < v[id * 2 + 1][p2])) {
      x = v[id * 2][p1];
      v[id].push_back(x);
      ans[id] += (long long)((long long)tb[x] * (long long)p2);
      tk[x] += p2;
      p1++;
    } else {
      x = v[id * 2 + 1][p2];
      v[id].push_back(x);
      ans[id] += (long long)((long long)tk[x] * (long long)(l1 - p1));
      tb[x] += (l1 - p1);
      p2++;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) m[a[i]] = i;
  for (int i = 0; i < n; i++) b[i] = m[b[i]];
  build();
  cout << ans[1] << endl;
  return 0;
}
