count inversions helper object