Please Help!

When I run this code it gives correct answer but while submitting the code it give run time error
how is this even possible if the coded executed correctly but giving run time error??
Question:

solution:
https://www.codechef.com/viewsolution/57478069
Please help me I am stuck in this question !!