Ad hoc and practice with C++ STL multiset (overkilled)
Math with tricks