HELP in GARDENSQ?

https://www.codechef.com/viewsolution/33414098…plz Help me