The koalas are having fun together at the annual Easter festival. Unfortunately, their festival is interrupted by the muttering of a strange koala witch. The koalas don't understand at first, but they eventually notice a pattern. The witch mutters
Now that the koalas know the rule, they devise a game. They will listen to the witch's string and predict
A palindrome is a string that is the same as its reverse. For example, strings tacocat
, noon
, x
, and bbbb
are palindromes, while strings abab
and osuhow
are not.
Constraints
All characters in string
Input Specification
The first line contains the integer
The second line contains the string
Output Specification
Output an integer
Sample Input 1
6
dababy
Sample Output 1
2
Explanation for Sample 1
We arrange the above string into bybada
and split it into byb
and ada
, giving us
Sample Input 2
20
whentheimposterissus
Sample Output 2
8
Comments
AMOGUS
whentheimposterissus
I love how a simple observation drastically simplifies the time complexity from way too big for 2 seconds to linear!
Why can't you split
dababy
intodab
andaby
, giving no palindromes?All of the strings you split into need to be palindromes. Splitting into
dab
andaby
is invalid since neither are palindromes.Thanks, solved!
I don't even want to imagine a koala muttering "whentheimposterissus". Would defenitely be... interesting
this problem is sus