Strange Grid

https://www.codechef.com/problems/SGRID

my solution : https://www.codechef.com/viewsolution/25405976
what is wrong , I can’ figure out
Thanks in advance