Write first part of countInversions