#P3546. [POI 2012] PRE-Prefixuffix
[POI 2012] PRE-Prefixuffix
Description
We consider strings consisting of lowercase letters of the English alphabet in this problem. An initial fragment of a given string is called its prefix. A final (terminal) fragment of a given string is called its suffix. In particular, the empty string is both a prefix and a suffix of any string. Two strings are cyclically equivalent if one of them can be obtained from another by moving its certain suffix from the end of the string to its beginning. For example, the strings ababba and abbaab are cyclically equivalent, whereas the strings ababba and ababab are not. In particular, every string is cyclically equivalent to itself.
A string consisting of letters is given. We are looking for its prefix and suffix of equal length such that:
- and are cyclically equivalent,
- the common length of and does not exceed (i.e., the prefix and the suffix do not overlap in ), and
- the common length of and is maximized.
Input Format
The first line of the standard input contains a single integer () denoting the length of the string .
The second line of input contains the string itself, consisting of lowercase letters of the English alphabet.
Output Format
Your program should print a single integer in the first and only line of the standard output, namely the common length of the prefix and the suffix that we are looking for.
15
ababbabababbaab
6
Hint
In tests worth of the points the condition holds in addition.
In tests worth of the points the condition holds in addition.
京公网安备 11011102002149号