#include <bits/stdc++.h>
using namespace std;
int arr[1000001], temp[1000001];
int BITree[1000002];
int getFrontSum(int index) {
  int sum = 0;
  while (index > 0) {
    sum += BITree[index];
    index -= (index & (-index));
  }
  return sum;
}
int getBackSum(int index, int n) {
  int sum = 0;
  while (index <= n) {
    sum += BITree[index];
    index += (index & (-index));
  }
  return sum;
}
void Update(int index, int vl, int n) {
  while (index <= n) {
    BITree[index] += vl;
    index += (index & (-index));
  }
}
int main() {
  int n;
  cin >> n;
  int i;
  memset(BITree, 0, sizeof(BITree));
  long long int smaller[n], greater[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    temp[i] = arr[i];
  }
  sort(temp, temp + n);
  for (i = 0; i < n; i++)
    arr[i] = (lower_bound(temp, temp + n, arr[i]) - temp + 1);
  long long int cnt = 0;
  for (i = n - 1; i >= 0; i--) {
    smaller[i] = (getFrontSum(arr[i] - 1));
    Update(arr[i], 1, n);
  }
  memset(BITree, 0, sizeof(BITree));
  for (i = 0; i < n; i++) {
    greater[i] = i - getFrontSum(arr[i]);
    Update(arr[i], 1, n);
  }
  for (i = 0; i < n; i++) cnt += (smaller[i] * greater[i]);
  cout << cnt << "\n";
  return 0;
}
