How to solve- A puzzle game problem code: H1

Please guide in this question on how to solve. Problem Link- https://www.codechef.com/problems/H1

i found this might help you
link text

//