Getting Running Time Error. Help!

I am getting run time error for Contest Page | CodeChef.
How can I optimize this…

here is my solution(working fine for test cases)

https://www.codechef.com/viewsolution/50527205