O(n2)暴力可过
#include <bits/stdc++.h>
using namespace std;
char *p1, *p2, buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
int x = 0, f = 1; char c = nc();
while (c < 48 || c > 57) f = (c == '-') ? -1 : 1, c = nc();
while (c >= 48 && c <= 57) x = x*10 + c-48, c = nc();
return x*f;
}
#define int long long
int n, a[30005], res;
signed main()
{
// freopen("P1637.txt", "r", stdin);
n = rd();
for (int i = 1; i <= n; ++i) a[i] = rd();
for (int k = 1; k <= n; ++k) {
int l = 0, r = 0;
for (int i = 1; i <= k - 1; ++i) if (a[i] < a[k]) ++l;
for (int j = k + 1; j <= n; ++j) if (a[j] > a[k]) ++r;
res += l * r;
}
printf("%lld\n", res);
return 0;
}