Inversion counting