Python 3 - too slow on ACM14KP1 problem

Hello, I have been trying to compare my solution Solution: 47871970 | CodeChef to other python solutions posted for problem Contest Page | CodeChef but I can’t figure out what is so slow in my program. Any suggestion?
Thanks