#include <bits/stdc++.h>
using namespace std;
const long long int N = 1000009;
const long long int mod = 1000000007;
long long int n;
vector<long long int> a;
map<long long int, long long int> mp;
set<long long int> s;
vector<long long int> ans;
long long int tree[4 * N + 2], lazy[4 * N + 2];
long long int max(long long int x, long long int y) { return (x + y); }
void update(long long int l, long long int r, long long int s, long long int e,
            long long int idx, long long int val) {
  if (lazy[idx] != 0) {
    tree[idx] += lazy[idx];
    if (l != r) {
      lazy[2 * idx + 1] += lazy[idx];
      lazy[2 * idx + 2] += lazy[idx];
    }
    lazy[idx] = 0;
  }
  if (l > e || r < s) {
    return;
  }
  long long int mid = (l + r) / 2;
  if (l >= s && r <= e && (l != r)) {
    tree[idx] += val;
    lazy[2 * idx + 1] += val;
    lazy[2 * idx + 2] += val;
    return;
  } else if (l >= s && r <= e) {
    tree[idx] += val;
    return;
  }
  update(l, mid, s, e, 2 * idx + 1, val);
  update(mid + 1, r, s, e, 2 * idx + 2, val);
  tree[idx] = max(tree[2 * idx + 1], tree[2 * idx + 2]);
}
long long int query(long long int l, long long int r, long long int s,
                    long long int e, long long int idx) {
  if (l > e || r < s) {
    return 0;
  }
  if (lazy[idx] != 0) {
    tree[idx] += lazy[idx];
    long long int val = lazy[idx];
    lazy[idx] = 0;
    if (l != r) {
      lazy[2 * idx + 1] += val;
      lazy[2 * idx + 2] += val;
    }
  }
  if (l >= s && r <= e) {
    return tree[idx];
  }
  long long int mid = (l + r) / 2;
  long long int a = query(l, mid, s, e, 2 * idx + 1);
  long long int b = query(mid + 1, r, s, e, 2 * idx + 2);
  return max(a, b);
}
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  pre();
  cin >> n;
  a.assign(n, 0);
  ans = a;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  long long int idx = 0;
  for (auto i : s) {
    mp[i] = idx;
    idx++;
  }
  for (long long int i = 0; i < n; i++) {
    a[i] = mp[a[i]];
  }
  for (long long int i = 0; i < n; i++) {
    update(0, n - 1, a[i], a[i], 0, 1);
    ans[i] = query(0, n - 1, a[i] + 1, n - 1, 0);
  }
  memset(tree, 0, sizeof(tree));
  memset(lazy, 0, sizeof(lazy));
  for (long long int i = (n - 1); i >= 0; i--) {
    update(0, n - 1, a[i], a[i], 0, 1);
    ans[i] *= query(0, n - 1, 0, a[i] - 1, 0);
  }
  cout << accumulate(ans.begin(), ans.end(), (long long int)0) << "\n";
  return 0;
}
