Count inversions