FIRESC Submission RE

I am unable to figure out why my solution - http://www.codechef.com/viewsolution/2415245 - for FIRESC is giving RE. Hope someone will help point out the error!