core ideas:
Sometimes you need auxiliary structures to maintain aggregates efficiently
lets us track the distribution of frequencies, enabling mode finding
The "decrease maxFreq" step is safe because you're removing elements one at a time, so frequency can only drop by This pattern (tracking counts of counts) appears in many MO problems. Remember it.