Description


顺序和逆序读起来完全一样的串叫做回文串。比如 acbca 是回文串,而 abc 不是( abc 的顺序为 “abc” ,逆序为 “cba” ,不相同)。
输入长度为 n 的串 S ,求 S 的最长双回文子串 T, 即可将 T 分为两部分 X , Y ,( |X|,|Y|≥1 )且 X 和 Y 都是回文串。


Input



一行由小写英文字母组成的字符串S。


Output



一行一个整数,表示最长双回文子串的长度。


Sample Input


baacaabbacabb


Sample Output



12


Hint



样例说明

从第二个字符开始的字符串aacaabbacabb可分为aacaa与bbacabb两部分,且两者都是回文串。

对于100%的数据,2≤|S|≤10^5



2015.4.25新加数据一组


正反来两次回文树,统计最大和即可

#pragma comment(linker, "/STACK:102400000,102400000")
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int a[maxn];
char s[maxn];

struct PalindromicTree
{
const static int maxn = 1e5 + 10;
const static int size = 26;
int next[maxn][size], sz, tot;
int fail[maxn], len[maxn], last;
char s[maxn];
void clear()
{
len[1] = -1; len[2] = 0;
fail[1] = fail[2] = 1;
last = (sz = 3) - 1; tot = 0;
memset(next[1], 0, sizeof(next[1]));
memset(next[2], 0, sizeof(next[2]));
}
int Node(int length)
{
memset(next[sz], 0, sizeof(next[sz]));
len[sz] = length; return sz;
}
int getfail(int x)
{
while (s[tot] != s[tot - len[x] - 1]) x = fail[x];
return x;
}
int add(char pos)
{
int x = (s[++tot] = pos) - 'a', y = getfail(last);
if (next[y][x]) { last = next[y][x]; }
else {
last = next[y][x] = Node(len[y] + 2);
fail[sz] = len[sz] == 1 ? 2 : next[getfail(fail[y])][x];
++sz;
}
return len[last];
}
}solve;

int main()
{
while (scanf("%s", s) != EOF)
{
int len = strlen(s), ans = a[0] = 0;
solve.clear();
for (int i = 0; s[i]; i++) a[i + 1] = solve.add(s[i]);
solve.clear();
for (int i = len; i; i--)
{
ans = max(ans, solve.add(s[i - 1]) + a[i - 1]);
}
printf("%d\n", ans);
}
return 0;
}