Count the number of invs, based on merge sort algorithm.