APRIL17 RNDGRID doubt

Hey guys!

I have been trying to solve this question(Bear and Random Grid [RNDGRID]) from APRIL17 LONG challenge for quite some time now. But I have constantly failed in clearing the last subtask. So, I was hoping if anyone of you guys could point out the mistake in this code.

[Question][1]

[My Solution][2]

Logic: thanks to this guy right [here][3].

Thank You :slight_smile:
[1]: https://www.codechef.com/problems/RNDGRID
[2]: https://www.codechef.com/viewsolution/14344915
[3]: https://discuss.codechef.com/questions/95670/rndgrid-editorial/95886