Help me find whats wrong with the code

Here are problems link NNN Problem - CodeChef
Here is my solution link CodeChef: Practical coding for everyone
There is no error in code and all of the sample input’s output is correct but when I submit the solution the answer seems somewhere wrong. Can anyone run a few of their own test cases and tell me what’s wrong.

If I understand correctly, the fact that a squirrel can only carry one nut means that the answer to

1
5 5
S N N N N

is 1.