MAXPR - getting WA

I am getting WA in the following code. I tried most of the possible test cases and it is giving the correct answers but getting WA still. Can someone help me, what I am missing ?

Thanks in advance :slight_smile:

link to problem :
link to code :

At each iteration you are doing,
cnt = cnt + dp[i];
Ideally, you should be taking modulus at each step.
So, try doing “%MAX” at each iteration.

It is taking modulus at each step… see the next lines
" if (cnt >= MAX)
cnt -= MAX;
it will automatically take the modulus!