count inversions using the merge sort