#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 10;
int a[N];
long long tree[3][N];
long long dp[3][N];
set<int> st;
map<int, int> mp;
void build(int i, int i1, int l, int r) {
  int mid = (l + r) / 2;
  if (l == r)
    tree[i1][i] = dp[i1 - 1][l];
  else {
    build(i * 2, i1, l, mid);
    build(i * 2 + 1, i1, mid + 1, r);
    tree[i1][i] = tree[i1][i * 2] + tree[i1][i * 2 + 1];
  }
}
void update(int i, int i1, int l, int r, int idx) {
  if (l == r)
    tree[i1][i] = dp[i1 - 1][l];
  else {
    int mid = (l + r) / 2;
    if (idx >= l && idx <= mid)
      update(i * 2, i1, l, mid, idx);
    else
      update(i * 2 + 1, i1, mid + 1, r, idx);
    tree[i1][i] = tree[i1][i * 2] + tree[i1][i * 2 + 1];
  }
}
long long query(int i, int i1, int l, int r, int l1, int r1) {
  if (l > r1 || r < l1) return 0;
  if (l >= l1 && r <= r1) return tree[i1][i];
  int mid = (l + r) / 2;
  long long p1 = query(i * 2, i1, l, mid, l1, r1);
  long long p2 = query(i * 2 + 1, i1, mid + 1, r, l1, r1);
  return p1 + p2;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    st.insert(a[i]);
  }
  int cnt = 1;
  for (auto x : st) mp[x] = cnt++;
  for (int i = 0; i < n; i++) a[i] = mp[a[i]];
  for (int i = 1; i <= 2; i++) build(1, i, 1, n);
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 1; j <= 2; j++) {
      dp[j][a[i]] += query(1, j, 1, n, 1, a[i] - 1);
      update(1, j, 1, n, a[i]);
    }
    dp[0][a[i]] = 1;
    update(1, 1, 1, n, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += dp[2][a[i]];
  printf("%lld\n", ans);
}
