#include using namespace std; template struct BIT { int n; vector dat; BIT(int n=0){ initialize(n); } void initialize(int nin){ n = nin; dat.assign(n, 0); } T sum(int i){ T s = 0; while(i >= 0){ s += dat[i]; i = (i & (i+1)) - 1; } return s; } T sum_between(int i, int j){ return sum(j) - sum(i-1); } void plus(int i, T x){ while(i < n){ dat[i] += x; i |= i+1; } } // a[0]+...+a[ret] >= x int lower_bound(T x){ if(x < 0) return -1; int ret = -1; int k = 1; while(2*k <= n) k <<= 1; for( ;k>0; k>>=1){ if(ret+k < n && dat[ret+k] < x){ x -= dat[ret+k]; ret += k; } } return ret + 1; } }; int main(){ int N; cin >> N; vector A(N), B(N); for(int i=0; i> A[i], A[i]--; for(int i=0; i> B[i], B[i]--; vector R(N); for(int i=0; i bit(N); int64_t ans = 0; for(int a : A){ ans += bit.sum_between(a, N-1); bit.plus(a, 1); } cout << ans << endl; return 0; }