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]: RNDGRID Problem - CodeChef
[2]: CodeChef: Practical coding for everyone
[3]: RNDGRID - Editorial - #6 by fruwajacybyk - editorial - CodeChef Discuss