#include <bits/stdc++.h>
using namespace std;
struct BITree {
  vector<long long> values;
  int size;
  BITree(int n) {
    size = n;
    values.resize(size + 1);
  }
  long long getSum(int i) {
    i++;
    long long sum = 0;
    while (i <= size) {
      sum += values[i];
      i += i & -i;
    }
    return sum;
  }
  void update(int i, long long v) {
    i++;
    while (i > 0) {
      values[i] += v;
      i -= i & -i;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  vector<int> power(n);
  for (int i = 0; i < n; i++) power[a[i].second] = i;
  vector<int> doubles(n);
  BITree tree(n);
  for (int i = 0; i < n; i++) {
    tree.update(power[i] - 1, 1);
    doubles[power[i]] = tree.getSum(power[i]);
  }
  tree = BITree(n);
  vector<long long> triples(n);
  for (int i = 0; i < n; i++) {
    tree.update(power[i] - 1, doubles[power[i]]);
    triples[power[i]] = tree.getSum(power[i]);
  }
  long long ans = 0;
  for (long long t : triples) ans += t;
  cout << ans;
}
