#include <bits/stdc++.h>
using namespace std;
vector<long long> fb(1000010 + 1, 0), fe(1000010 + 1, 0);
void update(long long which, long long idx, long long val) {
  if (which == 1) {
    while (idx < 1000010) {
      fb[idx] += val;
      idx += idx & -idx;
    }
  } else {
    while (idx < 1000010) {
      fe[idx] += val;
      idx += idx & -idx;
    }
  }
}
long long query(long long which, long long idx) {
  if (which == 1) {
    long long ans = 0;
    while (idx > 0) {
      ans += fb[idx];
      idx -= idx & -idx;
    }
    return ans;
  } else {
    long long ans = 0;
    while (idx > 0) {
      ans += fe[idx];
      idx -= idx & -idx;
    }
    return ans;
  }
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  long long begtime = clock();
  ;
  map<long long, long long> comp;
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (long long i = 0; i < n; ++i) cin >> arr[i];
  vector<long long> arr2 = arr;
  sort(arr2.begin(), arr2.end());
  long long cur = 1;
  for (long long i = 0; i < n; i += 1) comp[arr2[i]] = cur, cur += 1;
  long long ans = 0;
  for (long long i = 0; i < n; i += 1) {
    update(2, comp[arr[i]], 1);
  }
  for (long long i = 0; i < n; i += 1) {
    long long le = query(2, comp[arr[i]] - 1);
    long long gr = query(1, 1000010) - query(1, comp[arr[i]]);
    ans += le * gr;
    update(1, comp[arr[i]], 1);
    update(2, comp[arr[i]], -1);
  }
  cout << ans << endl;
  long long endtime = clock();
  cerr << endl
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC
       << " ms";
  return 0;
}
