#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define ll long long
#define double double long
#define fori(i,j,k) for(ll i=j; i<=k;i++)
#define study ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define all(s) s.begin(),s.end()
#define ins insert
#define ss second
#define ff first
const ll sz=1e6+10;
ll INF=1e18;
ll mod=1e9+7;
vector<ll>lef,righ;
ll n;
void update(ll pos, ll sm, ll wh){
if(wh){
while(pos<=n){
righ[pos]+=sm;
pos+=(pos&(-pos));
}
}
else{
while(pos<=n){
lef[pos]+=sm;
pos+=(pos&(-pos));
}
}
}
ll sum(ll pos,ll wh){
ll ad=0;
if(wh)
while(pos>0){
ad+=righ[pos];
pos-=(pos&(-pos));
}
else
while(pos>0){
ad+=lef[pos];
pos-=(pos&(-pos));
}
return ad;
}
void work(){
ll ans=0;
cin>>n;
vector<ll>v(n+10,0);
set<ll>st; map<ll,ll>meh;
lef.assign(n+10,0);
righ.assign(n+10,0);
fori(i,1,n){
cin>>v[i];
st.ins(v[i]);
}
ll cr=1;
for(auto x: st){
meh[x]=cr++;
}
fori(i,1,n){
v[i]=meh[v[i]];
update(v[i],1,1);
}
fori(i,1,n){
update(v[i],-1,1);
ll cur=sum(v[i]-1,1);
cur*=sum(v[i]-1,0);
update(v[i],1,0);
ans+=cur;
}
cout<<ans<<endl;
}
int main()
{
//#ifndef LOCAL
// freopen("log.txt","r",stdin);
// freopen("log1.txt","w",stdout);
//#endif
study;
ll t=1;
//cin>>t;
fori(i,1,t){
work();
}
}