Comments

Thank you! I understand your solution. It's too difficult for SAM to solve it. I want to use SAM because ... my friend that took part in Nanjing regional contest told me: "There was a problem using SAM in this contest, I couldn't accept it because I have not learned it." So I try SAM all the time orz. And finally I think I should use prefix automation but I have not learned it LOL.

M is too difficult for me TAT. How to solve it using SAM? I know I should use manacher first, and then I can do nothing using SAM qwq.