Count number of inversions in an integer array

Modification of Merge sort, O(n logn).