#P4287. [SHOI2011] 双倍回文

    ID: 3221 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2011各省省选上海回文自动机 PAM

[SHOI2011] 双倍回文

Description

Let the reversal of a string ww be denoted by wRw^{\mathsf R}. For example, (abcd)R=dcba\tt (abcd)^{\mathsf R}=dcba, (abba)R=abba\tt (abba)^{\mathsf R}=abba.

For a string xx, if xx satisfies xR=xx^{\mathsf R}=x, it is called a palindrome. For example, abba\tt abba is a palindrome, while abed\tt abed is not.

If xx can be written in the form wwRwwRww^{\mathsf R} ww^{\mathsf R}, it is called a "double palindrome". In other words, for xx to be a double palindrome, the length of xx must be a multiple of 44, and xx, its first half, and its second half must all be palindromes. For example, abbaabba\tt abbaabba is a double palindrome, while abaaba\tt abaaba is not, because its length is not a multiple of 44.

  • A substring of xx is a string formed by a consecutive segment of characters in xx. For example, be\tt be is a substring of abed\tt abed, while ac\tt ac is not.
  • A palindromic substring of xx is a substring of xx that is a palindrome.
  • A double palindromic substring of xx is a substring of xx that is a double palindrome.

Your task is to compute the length of the longest double palindromic substring of the given string.

Input Format

The input consists of two lines.

  • The first line contains an integer NN, the length of the string.
  • The second line contains a string of lowercase English letters, which is the content of the string.

Output Format

Output a single line: the length of the longest double palindromic substring of the input string. If no double palindromic substring exists, output 00.

16
ggabaabaabaaball
12

Hint

Constraints

For all testdata, 1N5000001 \le N \le 500000.

Translated by ChatGPT 5