#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 123;
ll n, ans;
ll t[N << 2][2], a[N];
inline void modify(int v, int tl, int tr, int pos, int val, int k) {
  t[v][k] += val;
  if (tl == tr) {
    return;
  }
  int mid = (tl + tr) >> 1;
  if (mid >= pos)
    modify(v << 1, tl, mid, pos, val, k);
  else
    modify(v << 1 | 1, mid + 1, tr, pos, val, k);
}
ll get(int v, int tl, int tr, int l, int r, int k) {
  if (l > tr || tl > r) return 0;
  if (tl >= l && r >= tr) return t[v][k];
  int mid = (tl + tr) >> 1;
  return get(v << 1, tl, mid, l, min(mid, r), k) +
         get(v << 1 | 1, mid + 1, tr, max(mid + 1, l), r, k);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  set<int> s;
  map<int, int> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  while (!s.empty()) {
    m[*s.rbegin()] = s.size();
    s.erase(*s.rbegin());
  }
  for (int i = 1; i <= n; i++) a[i] = m[a[i]];
  for (int i = 1; i <= n; i++) {
    modify(1, 1, n, a[i], 1, 0);
    modify(1, 1, n, a[i], get(1, 1, n, a[i] + 1, n, 0), 1);
    ans += get(1, 1, n, a[i] + 1, n, 1);
  }
  cout << ans;
  return false;
}
