Partially correct answer

I don’t know why my code for the problem https://www.codechef.com/IARCSJUD/problems/LOPreformatted textNGPALI
is giving partially correct answer .Please help me .My code : https://ideone.com/6CxroI.
Thanks in advance.

5000
aaaaa… aa [5000 times]

Your are doing a BF ! Optimize …

Can you help me for this?

Might help : here

thanks for help