Difficult problem, fine solution
https://gitlab.sirius-web.org/python-students-22/abaturov_volkov/-/tree/master/task_6