Return of the Gargoyle King - Codechef

Not able to solve this please help:
https://www.codechef.com/PELT2019/problems/GARGOYLE