Auto-translated
Grigoriy, it's not a very good idea to post a hundred lines of code and ask people to find the error in it. For starters, just add print statements in each function and inside each if statement.
New here? I'm Roha — want a quick tour?