QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 64 MB Total points: 100

#13311. Prefixuffix

الإحصائيات

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 $t$ consisting of $n$ letters is given. We are looking for its prefix $p$ and suffix $s$ of equal length such that:

  • $p$ and $s$ are cyclically equivalent,
  • the common length of $p$ and $s$ does not exceed (i.e., the prefix $p$ and the suffix $s$ do not overlap in $t$), and
  • the common length of $p$ and $s$ is maximized.

Input Format

The first line of the standard input contains a single integer $n$ ($1 ≤ n ≤ 1\,000\,000$) denoting the length of the string $t$. The second line of input contains the string $t$ itself, consisting of $n$ 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 $p$ and the suffix $s$ that we are looking for.

Example

Input

15
ababbabababbaab

Output

6

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.