AUSAG-Getting TLE (KMP algorithm)

Problem Link- AUSAG Problem - CodeChef

It is a question based on KMP-algorithm.
My solution matches exactly what is told in it’s editorial, but still getting TLE.

My solution: CodeChef: Practical coding for everyone