#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; //1-indexedに注意!!! template struct BIT{ private: int n; vector bit; public: BIT(int n):n(n){ bit.resize(n+1); } T sum(int i){ T res = 0; while(i > 0){ res += bit[i]; i -= i&-i; } return res; } void add(int i,T val){ while(i <= n){ bit[i] += val; i += i&-i; } } }; int main(){ int n; cin >> n; vector m(n); rep(i,n) cin >> m[i]; ll ans = 0; BIT bit(n); rep(i,n){ bit.add(m[i],1); ans += (i+1) - bit.sum(m[i]); } cout << ans << endl; return 0; }