CHEFHACK: getting RTE

please help me i am getting rte again and again(have tried lots of stuffs) on the problem: http://www.codechef.com/problems/CHEFHACK/

link to my solution is: http://www.codechef.com/viewsolution/7303053