Counting inversions