Lizards and Basement codeforces 6-D

Can anyone explain me how to solve Lizards and basement problem?

Here is the link to the problem : http://codeforces.com/contest/6/problem/D

Can you be more precise? It almost seems like you are asking for the complete solution, which you probably are not. Maybe share your logic that you have up to a certain point?