#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
constexpr int MAXN = 2e5 + 1;
vector<int> tree(2 * MAXN , 0);
void modify(int p , int val)
{
for(tree[p += MAXN] += val ; p > 1 ; p /= 2)
{
tree[p / 2] = tree[p] + tree[p ^ 1];
}
}
int sum(int l , int r) //[l , r)
{
int res = 0;
for(l += MAXN , r += MAXN ; l < r ; l /= 2 , r /= 2)
{
if(l % 2)
{
res += tree[l];
++l;
}
if(r % 2)
{
--r;
res += tree[r];
}
}
return res;
}
int main() {
int n;
cin >> n;
vector<int> p(n);
for(auto& el : p) cin >> el;
ll ans = 0;
for(int i = n - 1 ; i >= 0 ; --i)
{
ans += sum(0 , p[i]);
modify(p[i] , 1);
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmNvbnN0ZXhwciBpbnQgTUFYTiA9IDJlNSArIDE7Cgp2ZWN0b3I8aW50PiB0cmVlKDIgKiBNQVhOICwgMCk7Cgp2b2lkIG1vZGlmeShpbnQgcCAsIGludCB2YWwpCnsKCWZvcih0cmVlW3AgKz0gTUFYTl0gKz0gdmFsIDsgcCA+IDEgOyBwIC89IDIpCgl7CgkJdHJlZVtwIC8gMl0gPSB0cmVlW3BdICsgdHJlZVtwIF4gMV07Cgl9Cn0KCmludCBzdW0oaW50IGwgLCBpbnQgcikgLy9bbCAsIHIpCnsKCWludCByZXMgPSAwOwoJZm9yKGwgKz0gTUFYTiAsIHIgKz0gTUFYTiA7IGwgPCByIDsgbCAvPSAyICwgciAvPSAyKQoJewoJCWlmKGwgJSAyKQoJCXsKCQkJcmVzICs9IHRyZWVbbF07CgkJCSsrbDsKCQl9CgkJCgkJaWYociAlIDIpCgkJewoJCQktLXI7CgkJCXJlcyArPSB0cmVlW3JdOwoJCX0KCX0KCQoJcmV0dXJuIHJlczsKfQoKaW50IG1haW4oKSB7CglpbnQgbjsKCWNpbiA+PiBuOwoJCgl2ZWN0b3I8aW50PiBwKG4pOwoJZm9yKGF1dG8mIGVsIDogcCkgY2luID4+IGVsOwoJCglsbCBhbnMgPSAwOwoJCglmb3IoaW50IGkgPSBuIC0gMSA7IGkgPj0gMCA7IC0taSkKCXsKCQlhbnMgKz0gc3VtKDAgLCBwW2ldKTsKCQltb2RpZnkocFtpXSAsIDEpOwoJfQoJCgljb3V0IDw8IGFucyA8PCBlbmRsOwoKCXJldHVybiAwOwp9