#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map
const ll N = 1e6 + 5;
ll ft[N];
void add(ll in , ll val){
for(;in <= N; in += in&-in)ft[in] += val;
}
ll query(ll in){
ll ans = 0;
for(;in > 0; in -= in&-in)ans += ft[in];
return ans;
}
void doit(){
ll n, i, s = 0, x, ans = 0;
cin >> n;
rep(i,0,n){
cin >> x;
ans += query(x - 1);
add(x,x);
}
cout << ans << nl;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input1.txt","r",stdin);
// freopen("output1.txt","w",stdout);
// #endif
// ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
for(ll i = 1; i <= t; i++){
doit();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbXR2KGtpdCkgY291dDw8I2tpdDw8IiAtICI8PGtpdDw8IlxuIjsKI2RlZmluZSBmZiBmaXJzdAojZGVmaW5lIHNzIHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIHJlcChpLGEsYikgZm9yKGk9YTtpPGI7aSsrKQojZGVmaW5lIHBpaSBwYWlyPGxsICwgbGw+CiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSx4LmVuZCgpCiNkZWZpbmUgbmwgIlxuIgojZGVmaW5lIHVtcCB1bm9yZGVyZWRfbWFwCgpjb25zdCBsbCBOID0gMWU2ICsgNTsKbGwgZnRbTl07Cgp2b2lkIGFkZChsbCBpbiAsIGxsIHZhbCl7CiAgICBmb3IoO2luIDw9IE47IGluICs9IGluJi1pbilmdFtpbl0gKz0gdmFsOwp9CgpsbCBxdWVyeShs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