Count inversions in array