Use the same algorithm for counting the number of words to sort as we