Why do I get a sigsegv in this program?

The first five test cases are running fine but I am getting a SIGSEGV in others. Please help.

Link for problem : CodeChef: Practical coding for everyone
Here’s my code for the same:(gcc 6.3 c compiler)

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