added CountInversions code