Mimi is playing with a dictionary when she gets a great idea! Throw random words together, give them a definition, and then make a problem about it!
For this problem, Mimi has decided to define a proper prefix palindrome of string as a proper prefix of which is also a palindrome. Given a string , find the length of the longest proper prefix palindrome which appears at least twice.
Constraints
Let denote the length of string .
Subtask 1 [10%]
Subtask 2 [20%]
Subtask 3 [70%]
Input Specification
The first and only line of input will contain a single string , consisting of only lowercase letters.
Output Specification
The length of the longest proper prefix palindrome which appears at least twice.
Sample Input 1
aaaa
Sample Output 1
3
Explanation for Sample Output 1
The longest proper prefix palindrome is aaa
.
Sample Input 2
abab
Sample Output 2
1
Explanation for Sample Output 2
The longest proper prefix palindrome is a
.
Comments
Wouldnt the output for case 2 be 3?
Isnt
aba
a proper prefix palindrome ofabab
Edit: nvm it's two occurrences
aba
is indeed a proper prefix palindrome, but it does not appear twice.is "proper prefix" any substring from ?
Any substring that is a prefix of is a "proper prefix".
For example
abcd
is a proper prefix ofabcdefg
, butdefg
is not.Furthermore, a proper prefix cannot be equal to the entire string nor can it be empty.