#include<iostream> #include<cstdio> #include<algorithm> #include<cctype> #define maxn 500010 #define gc getchar #define lowbit(i) ((i) & (-i)) #define ll long long usingnamespacestd;
intread(){ int x = 0; char c = gc(); while (!isdigit(c)) c = gc(); while (isdigit(c)) x = x * 10 + c - '0', c = gc(); return x; }
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; }
int Bit[maxn]; inlinevoidadd(int i, int v){ while (i <= cnt) Bit[i] += v, i += lowbit(i); }
inlineintget_sum(int i){ int s = 0; while (i) s += Bit[i], i -= lowbit(i); return s; }
intmain(){ n = read(); for (int i = 1; i <= n; ++i) a[i] = read(); init_hash(); ll ans = 0; for (int i = n; i; --i) { add(a[i], 1); ans += get_sum(a[i] - 1); } cout << ans << endl; return0; }