Martin and the nuclear reactor-HackerBlock DCB

https://hack.codingblocks.com/app/dcb/1457
//what is the problem with the code as it’s giving TLE .
help me to solve,please give if anybody have any more optimized solution.