counting inversions