How to solve- A puzzle game problem code: H1

Please guide in this question on how to solve. Problem Link- H1 Problem - CodeChef

i found this might help you
link text