Algo how to count number of inversions