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
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.