output not correct

Can anybody please explain me where I went wrong .My output is showing 0 on online compiler, but is working well on codeblocks.
link to the question is:https://www.codechef.com/problems/SPREAD
ans is below: https://www.codechef.com/viewsolution/15527368

The reason is quite simple. You are using fflush(stdin) which is meant to be called on an output stream. If you use fflush(stdin) then behaviour of program is undefined according to standard. See this link to understand more.

Instead of this you can alternatively use getchar() for flushing out ā€˜\nā€™ character. See this modified program.

But this is just a trailer, you need to work hard to figure out which test case it is failing out there after submitting to online judge of codechef.