Help me find whats wrong with the code

Here are problems link https://www.codechef.com/problems/NNN
Here is my solution link https://www.codechef.com/viewsolution/28007698
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.