#include<iostream> #include<cstdio> #include<algorithm> #define maxn 30010 #define ll long long #define lowbit(i) ((i) & (-i)) usingnamespacestd;
int n, a[maxn];
int b[maxn], cnt; voidinit_hash(){ for (int i = 1; i <= n; ++i) b[i] = a[i]; sort(b + 1, b + n + 1); cnt = unique(b + 1, b + n + 1) - b - 1; for (int i = 1; i <= n; ++i) a[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b; }
structBit { int n, Bit[maxn];
inlinevoidadd(int i, int v){ while (i <= n) Bit[i] += v, i += lowbit(i); }
inlineintget_sum(int i){ int s = 0; while (i) s += Bit[i], i -= lowbit(i); return s; } } B1, B2;
intmain(){ cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; init_hash(); B1.n = B2.n = cnt; ll ans = 0; for (int i = 1; i <= n; ++i) { B2.add(a[i], B1.get_sum(a[i] - 1)); B1.add(a[i], 1); ans += B2.get_sum(a[i] - 1); } cout << ans << endl; return0; }