#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[1001001];
int l[1001001], r[1001001];
struct BIT {
  int max_val;
  int a[1001001];
  const static int mo = 1000000007;
  BIT(int maxv) { max_val = maxv; }
  inline int lowbit(int x) { return x & (-x); }
  inline int madd(int a, int b) {
    return (a += b) >= mo ? a - mo : (a < 0 ? a + mo : a);
  }
  void clear() { memset(a, 0, sizeof(a)); }
  void clear(int max_id) {
    for (int i = 0; i <= max_id; i++) a[i] = 0;
  }
  void add(int pos, int val) {
    for (pos = max(1, pos); pos <= max_val; pos += lowbit(pos))
      a[pos] = madd(a[pos], val);
  }
  int query(int pos) {
    int res = 0;
    for (; pos; pos -= lowbit(pos)) res = madd(res, a[pos]);
    return res;
  }
  int query(int l, int r) { return query(r) - (l ? query(l - 1) : 0); }
};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[i] = make_pair(x, i);
  }
  sort(a + 1, a + n + 1);
  BIT b_ma = BIT(n), b_mi = BIT(n);
  b_mi.clear(n);
  for (int i = 1; i <= n; i++) {
    int v = a[i].first, pos = a[i].second;
    r[i] = b_mi.query(pos + 1, n);
    b_mi.add(pos, 1);
  }
  b_ma.clear(n);
  for (int i = n; i > 0; i--) {
    int v = a[i].first, pos = a[i].second;
    l[i] = b_ma.query(1, pos - 1);
    b_ma.add(pos, 1);
  }
  long long int ans = 0LL;
  for (int i = 1; i <= n; i++) ans += 1LL * l[i] * r[i];
  printf("%I64d\n", ans);
  return 0;
}
