Merge sort augmented to count the number of inversions