#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 9;
int s[N], p[N], tem[N],cnt[N], n;
void work()
{
for (int i = 1; i <= n; i++)
p[i] = i;
// 这种和下面这种都行,非降序并且保留原来次序要用s[x]<s[y],不大了解c++的Lambda表达式
stable_sort(p + 1, p + 1 + n, [&](int x, int y)
{ return s[x] < s[y]; });
// stable_sort(p+1,p+1+n,[&](int x,int y)->bool{return s[x]<s[y];});
}
void merge_sort(int a[], int b[], int l, int r)
{
if (l >= r){
b[l]=a[l]; return ;
}
long long ans = 0;
int mid = (l + r) >> 1;
merge_sort(a, b, l, mid);
merge_sort(a, b, mid + 1, r);
int i = l, j = mid + 1, k = l;
while (i <= mid && j <= r)
{
if (b[i] <= b[j])
cnt[b[i]]+=j-mid-1 ,a[k++] = b[i++];
else
cnt[b[j]]+=mid-i+1, a[k++] = b[j++];
}
while (i <= mid)
cnt[b[i]]+=r-mid,a[k++] = b[i++];
while (j <= r)
a[k++] = b[j++];
for (int i = l; i <= r; i++)
b[i] = a[i];
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> s[i];
//使用work离散化以方便累计每个元素的逆序
work();
//使用归并排序计算每个元素的逆序
merge_sort(p,tem,1,n);
long long ans =0;
for(int i=1;i<=n;i++) ans+=(long long )(cnt[i])*(cnt[i]+1)/2;
cout<<ans<<endl;
}