#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5+10;
ll a[N];
int fw[N];
void upd(int idx){
for(; idx < N; idx += idx&(-idx)) fw[idx]++;
}
int query(int idx){
int res = 0;
for(; idx > 0; idx -= idx&(-idx)) res += fw[idx];
return res;
}
int dpl[N], dpr[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<ll> v;
for(int i = 1; i <= n; ++i) cin >> a[i], v.push_back(a[i]);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i = 1; i <= n; ++i) a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
for(int i = 1; i <= n; ++i){
dpl[i] = query(a[i]-1);
upd(a[i]);
}
memset(fw, 0, sizeof fw);
for(int i = n; i >= 1; --i){
dpr[i] = query(a[i]-1);
upd(a[i]);
}
ll res = 0;
for(int i = 1; i <= n; ++i){
res += 1LL*dpl[i]*dpr[i];
}
cout << res << '\n';
}