#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FOD(i, a, b) for(int i = (a); i >= (b); i--)
#define file(name) if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define el cout << '\n'
#define maxn int(3e5 + 5)
using namespace std;
typedef long long ll;
int n, t[maxn];
int l[maxn], r[maxn];
ll res, a[maxn];
vector<ll> vals;
void update(int x, int v) {
for(; x <= n; x += x & -x) t[x] += v;
}
int get(int x) {
int res = 0;
for(; x; x -= x & -x) res += t[x];
return res;
}
void compress() {
FOR(i, 1, n) vals.push_back(a[i]);
sort(vals.begin(), vals.end());
vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
FOR(i, 1, n) a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin() + 1;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
FOR(i, 1, n) cin >> a[i];
compress();
FOR(i, 1, n) {
l[i] = get(a[i] - 1);
update(a[i], 1);
}
memset(t, 0, sizeof t);
FOD(i, n, 1) {
r[i] = get(a[i] - 1);
update(a[i], 1);
}
FOR(i, 1, n) res += 1LL * l[i] * r[i];
cout << res;
return 0;
}