CF981A.Antipalindrome

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Antipalindrome

A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.

A substring s[lr]s[l \ldots r] (1lrs1 \leq l \leq r \leq |s|) of a string s=s1s2sss = s_{1}s_{2} \ldots s_{|s|} is the string slsl+1srs_{l}s_{l + 1} \ldots s_{r}.

Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word ss is changed into its longest substring that is not a palindrome. If all the substrings of ss are palindromes, she skips the word at all.

Some time ago Ann read the word ss. What is the word she changed it into?

Input

The first line contains a non-empty string ss with length at most 5050 characters, containing lowercase English letters only.

Output

If there is such a substring in ss that is not a palindrome, print the maximum length of such a substring. Otherwise print 00.

Note that there can be multiple longest substrings that are not palindromes, but their length is unique.

Note

"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is 33.

The string "uffuw" is one of the longest non-palindrome substrings (of length 55) of the string "wuffuw", so the answer for the second example is 55.

All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is 00.

Samples

mew
3
wuffuw
5
qqqqqqqq
0

在线编程 IDE

建议全屏模式获得最佳体验