There is a common opinion that we want multiset in Python e.g. ABC170 E. Almost anything can be done in combination with [heapq
Combination of heapq and dict (hash table) heapq+dict.
dichotomous search
It is said that "ordered sets are faster in square partitioning" (unconfirmed).
SkipList
This page is auto-translated from /nishio/Pythonでmultiset using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.