Editorial
Let be the maximum frequency of any size. Each bundle needs two rice cakes of different sizes.
If some size appears more than times, each rice cake of that size must be paired with a rice cake of another size, so at most bundles are possible. If , the most frequent size can be paired with the remaining cakes and bundles can be formed.
Hence the answer is . Counting frequencies with a hash table takes expected time. Solution written by GPT5.6