#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int INF = 0x3f3f3f3f;
struct node {
  int l, r;
  long long sum;
} tree[maxn << 2];
int a[maxn], b[maxn];
long long p[maxn], q[maxn];
void push_up(int i) { tree[i].sum = tree[i << 1].sum + tree[i << 1 | 1].sum; }
void build(int i, int l, int r) {
  tree[i].l = l;
  tree[i].r = r;
  tree[i].sum = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
}
void updata(int i, int x, long long k) {
  if (tree[i].l == tree[i].r && tree[i].l == x) {
    tree[i].sum = k;
    return;
  }
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (x <= mid)
    updata(i << 1, x, k);
  else
    updata(i << 1 | 1, x, k);
  push_up(i);
}
long long query(int i, int x, int y) {
  if (tree[i].l >= x && tree[i].r <= y) return tree[i].sum;
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (y <= mid)
    return query(i << 1, x, y);
  else if (x > mid)
    return query(i << 1 | 1, x, y);
  else
    return query(i << 1, x, mid) + query(i << 1 | 1, mid + 1, y);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + 1 + n);
  int m = unique(b + 1, b + 1 + n) - (b + 1);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + 1 + m, a[i]) - b;
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    p[i] = query(1, a[i], n);
    updata(1, a[i], 1ll);
  }
  build(1, 1, n);
  for (int i = n; i >= 1; i--) {
    q[i] = query(1, 1, a[i]);
    updata(1, a[i], 1ll);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += p[i] * q[i];
  cout << ans << endl;
}
