Compare pairs
Difficulty: Hard

Count the number of Comparison in an array. A comparsion in an array is a pair of *indices(x,y)* such that **a[x] > a[y]  and  x < y**.

In this problem you are given 2 arrays C and D and you have to return number of such 
pairs such that **c[x] > d[y]  and  x < y**.

Input Format:
First line contains n denoting the total number of elements.The next line contains n 
space separated integers of array C.This line is again followed by n space separated 
integers of array D.

Output Format:
Print the total number of pairs according to comparison.

**Constraints:**  
1<=n<=200000  
1<=C[i]<=10<sup>6</sup>  
1<=D[i]<=10<sup>6</sup>

Sample Input:
3  
3 4 5  
1 2 3

Sample Output:
2

Python 3 starter code:


Reference solution (C++):

<p>#include&lt;bits/stdc++.h></p>
using namespace std;        
long long tree[200005];    
int A[200005];  
int B[200005];  
long long query(int idx)  
{  
    long long res = 0;  
    while ( idx > 0 ) {  
        res += tree[idx];  
        idx -= (idx & (-idx));  
    }  
    return res;  
}  
void update(int idx)  
{  
    while ( idx <= 100001 ) {  
        tree[idx] += 1;  
        idx += (idx &(-idx));  
    }  
    return;  
}  

int main()  
{  
    int t=1,n;  
    while ( t--  ){  
        cin >> n;  
        for ( int i = 0; i < n; i++ ) cin >> A[i];  
        for ( int i = 0; i < n; i++ ) cin >> B[i];  
        memset(tree, 0, sizeof(tree));  
        long long ans = 0;  
        for ( int i = n-1; i >= 0; i-- ) {  
            ans += query(A[i]-1);  
            update(B[i]);  
        }  
        cout << ans << endl;  
    }  
       
   return 0;  
 }