Need help in debugging my code for Dec cook off question YVSTR

Can someone tell me why my solution is failing.
Could not figure it out after even after comparing AC solution and mine for many test cases.

Question Link: https://www.codechef.com/COOK101A/problems/YVSTR/

Link to my solution: https://www.codechef.com/viewsolution/22069286

Try this case:
1
20
aabbbaaaaabbaaaaabbb

answer should be 38.

1 Like