Cipher Key
Time limit2sMemory limit1024 MB
Given a lowercase string s of length up to 500000, find the maximum of |t| + f(t)^2 over all substrings t, where f(t) is the longest proper border of t.
- Level
Hard8 of 10
- Topics
- String, String matching
- Solved
- No attempts yet
Statement
Hercule Poirot is currently exposing an international criminal syndicate that smuggles works of art. Police working with Poirot intercepted an encrypted letter with the place and time of an upcoming deal, which the head of the syndicate will attend. To stop the deal and arrest the head, the intercepted letter must be decrypted.
Hercule knows that the key to the cipher is computed from a string . For a string , let be the length of the longest suffix of that is not equal to and is also a prefix of . For example, , , . The key is the maximum of over all substrings of . Help Hercule compute the key.
Input
The only line contains the string , consisting of lowercase Latin letters ().
Output
Print a single integer, the key to the cipher.