Sorting, Counting, and Comparing