Prefixuffix

No attempts yetTime limit3sMemory limit512 MB

Problem

In this problem we only consider strings made of lowercase letters of the English alphabet. An initial fragment of a string is called a prefix, and a final fragment is called a suffix. In particular, the empty string is both a prefix and a suffix of every string.

Two strings are cyclically equivalent when one can be turned into the other by taking some suffix of it and moving that suffix from the end to the front. For example, ababba and abbaab are cyclically equivalent, whereas ababba and ababab are not. Every string is cyclically equivalent to itself.

You are given a string tt of length nn. Find a prefix pp and a suffix ss of tt, both of the same length, such that:

  • pp and ss are cyclically equivalent,
  • their common length is at most n2\frac{n}{2} (so that pp and ss do not overlap in tt), and
  • their common length is as large as possible.

Input

The first line contains one integer nn, the length of the string tt. (1n1061 \le n \le 10^6)

The second line contains the string tt itself, consisting of nn lowercase letters of the English alphabet.

Output

Print one integer: the largest common length of a prefix pp and a suffix ss that satisfy the conditions above.