#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 7;
int a[N], tmp[N], c[N], n, pre[N], suf[N];
int ans = 0;
int lowbit(int x)
{
return x & -x;
}
void update(int i, int v)
{
for (; i <= n; i += lowbit(i))
{
c[i] += v;
}
}
int sum(int i)
{
int ans = 0;
for (; i > 0; i -= lowbit(i))
{
ans += c[i];
}
return ans;
}
int sum(int l, int r)
{
return sum(r) - sum(l - 1);
}
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
// 离散化
for (int i = 1; i <= n; i++)
{
tmp[i] = a[i];
}
sort(tmp + 1, tmp + n + 1);
int len = unique(tmp + 1, tmp + n + 1) - tmp - 1;
for (int i = 1; i <= n; i++)
{
a[i] = lower_bound(tmp + 1, tmp + len + 1, a[i]) - tmp;
}
// 顺着看,前面多少数比自己大
for (int i = 1; i <= n; i++)
{
update(a[i], 1);
pre[i] = sum(a[i] + 1, n);
}
memset(c, 0, sizeof c);
// 逆着看,前面多少数比自己小
for (int i = n; i >= 1; i--)
{
update(a[i], 1);
suf[i] = sum(1, a[i] - 1);
}
for (int i = 1; i <= n; i++)
{
ans += pre[i] * suf[i];
}
cout << ans;
return 0;
}