Finding the number of substrings from a given string

Problem-https://www.codechef.com/problems/AUSAG?fbclid=IwAR0FFY3WTmfvcFB-Lk18fEiVz4LN6lK893WJgk6KAvBTPXbeY8iyLrP3qgs
I really cant find the problem in my code. I have already spent 2 weeks trying to fiigure out why the submission is giving me WA.
My code- https://pastebin.com/tP2eWyn5