counting inversion implementation