The ultimate turnkey collection of algorithms from Competitive Programmer's Handbook by Antti Laaksonen, implemented in both Python (≥ 3.10) and C++ (≥ C++11).
Read the analysis of the algorithm in the book. Try it yourself. If you get stuck, have a look here.