#include using namespace std; // one-based numbering template struct Fenwick { vector bit; int N; Fenwick(int n) { N = n; bit.resize(n+1, 0); } void add(int a, T w) { for (int x = a; x <= N; x += x & -x) bit[x] += w; } T sum(int a) { T ret = 0; for (int x = a; x > 0; x -= x & -x) ret += bit[x]; return ret; } }; int main() { int n; cin >> n; Fenwick f(n); long long ans = 0; for (int i = 0; i < n; i++) { int k; cin >> k; ans += i - f.sum(k); f.add(k, 1); } cout << ans << endl; }