#include<bits/stdc++.h>usingnamespace std;constint N =1e5+10, M =1e6+10;int a[N], cnt[N];longlong t[M];int n;intlowbit(int x){return x &-x;}voidupdate(int x,int d){for(; x < M; x +=lowbit(x)) t[x]+= d;}intquery(int x){int retval =0;for(; x >=1; x -=lowbit(x)) retval += t[x];return retval;}intmain(){
cin >> n;for(int i =1; i <= n; i++) cin >> a[i], a[i]++;for(int i =1; i <= n; i++){update(a[i],1);
cnt[i]+= i -query(a[i]);}memset(t,0,sizeof t);for(int i = n; i >=1; i--){update(a[i],1);
cnt[i]+=query(a[i]-1);}longlong res =0;for(int i =1; i <= n; i++) res +=(1+ cnt[i])*(longlong)cnt[i]/2;
cout << res;return0;}