Where am I going wrong?

@abhi18sinha
hey its not working for cases like
3
bababababaaaab
ans:10
try and debug your code for this