Count inversions using merge_sort