Please tell me how to solve this problem ( problem link in description ) ( A puzzle game )

please help https://www.codechef.com/problems/H1

Good question.