count inversions