PIyush and magical park questin

I am not able to think for the logic which i need to use in this question
please help

Hi @vaibhavgupta.1919,
see in this question in the sample input after first row the resulting strength would be 16 which is greater than 5 then, in second row you can only traverse till 2nd column as in second column there is # so resulting strength is 13 which is still greater than 5, then after traversing third row strength is 16 which is still greater than 5, then in fourth row you can only traverse till 2nd column as in second column there is # so resulting strength is 13 which is greater than 5.
Therefore the answer is yes and resulting strength is 13.
so like this just check in every case that if you get a ‘.’ character then decrease your size by 2 else if you find’*’ increase your size by 5 and like that check for other characters.and keep in mind that when you are going from one step to another then also your energy is decreasing that’s how I have been able to calculate the energies.