#include <bits/stdc++.h>
using namespace std;
struct Node {
  int pos;
  int val;
} recode[1000010];
long long ad[1000010], lb[1000010], rs[1000010], ls[1000010], n, c[1000010];
long long ans;
int cmp(Node x, Node y) { return x.val < y.val; }
int lowbit(int x) { return x & (-x); }
void add(int po, int val) {
  while (po <= n + 1) {
    c[po] += val;
    po += lowbit(po);
  }
}
int getsum(int po) {
  long long sum = 0;
  while (po > 0) {
    sum += c[po];
    po -= lowbit(po);
  }
  return sum;
}
int main() {
  scanf("%d", &n);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &recode[i].val);
    recode[i].pos = i;
  }
  sort(recode + 1, recode + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    ad[recode[i].pos] = i;
  }
  for (int i = 1; i <= n; i++) {
    add(ad[i], 1);
    ls[ad[i]] = getsum(ad[i]) - 1;
    lb[ad[i]] = i - ls[ad[i]] - 1;
    rs[ad[i]] = ad[i] - ls[ad[i]] - 1;
    ans += lb[ad[i]] * rs[ad[i]];
  }
  printf("%I64d\n", ans);
}
