sort candidates by maxFreq first, then by frequency