https://www.codechef.com/viewsolution/29981397
Maybe this testcase will help you: 1 6 baabaa answer: YES 2
yes. got the mistake. Thanks @v1ncent