In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
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 and are cyclically equivalent, whereas the strings and 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:
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.
In tests worth 30% of the points the condition holds in addition.
In tests worth 50% of the points the condition holds in addition.
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.
For the input data:
15 ababbabababbaab
the correct result is:
6
Task author: Jacek Tomasiewicz.