count inversions using merge sort