Algorithms course labs, CT, ITMO, 2017-2018.
I solved these problems in my first graduation year. Each lab were a competition, and quick implementation of the solution determined your position in the result table. So there is a lot of "define", debug output and awful code style.
I just leave it here for history.
Please, do not copy the code if you don't understand it. But feel free to compare your own solution output results or peep a solution idea.