count inversions in array