#include <bits/stdc++.h>
using namespace std;
long long BIT[2][1000005] = {0};
long long b[1000005];
void update(long long i, long long d, long long t = 1) {
  while (i < 1000005) {
    BIT[d][i] += t;
    i += (i & (-i));
  }
}
long long query(long long i, long long d) {
  long long ans = 0;
  while (i > 0) {
    ans += BIT[d][i];
    i -= (i & (-i));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x, y;
  cin >> n;
  vector<pair<long long, long long> > vt;
  long long ans = 0;
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    vt.push_back(make_pair(x, i));
    m[x] = i;
  }
  int z = 1;
  for (auto x : m) m[x.first] = z++;
  for (auto x : vt) b[x.second] = m[x.first];
  for (long long i = n - 1; i >= 0; i--) {
    long long t = query(b[i] - 1, 0);
    ans += query(b[i] - 1, 1);
    update(b[i], 0);
    update(b[i], 1, t);
  }
  cout << ans << "\n";
  return 0;
}
