Run time error with http://www.codechef.com/problems/ENCD04

This question was from a codecehef contest Encoder 2010.I saw there also that people complained about runtime error and in the practice problem also people have complained about runtime error.
So far nobody has been able to successfully able to solve this problem.
I know the logic and implementation behind this but I too got runtime error…
http://www.codechef.com/viewsolution/1287967
I request admin and other members to check if there’s a problem or my solution is lacking somewhere…