added Inversion-counting algorithm