/* -- Defined Functions -- */ #define For(a,x,y) for (int a = x; a <= y; ++a) #define Forw(a,x,y) for (int a = x; a < y; ++a) #define Bak(a,y,x) for (int a = y; a >= x; --a)
/* -- Defined Words -- */
usingnamespacestd;
namespace FastIO {
inlineintgetint(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; } inlinevoid __basic_putint(int x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) __basic_putint(x / 10); putchar(x % 10 + '0'); }
int n, external[MAXN]; char s[MAXN], str[MAXN << 1];
voidPre(){ str[0] = str[1] = '~'; for (int i = 0; i < n; ++i) { str[i * 2 + 2] = s[i]; str[i * 2 + 3] = '~'; } n = n * 2 + 2; str[n] = 0; }
voidManacher(){ int maxRight = 0, mid = 0; // mid 初值无所谓 for (int i = 1; i < n; ++i) { if (i < maxRight) { external[i] = std::min(external[(mid << 1) - i], external[mid] + mid - i); } else { external[i] = 1; } for (; str[i + external[i]] == str[i - external[i]]; ++external[i]); if (external[i] + i > maxRight) { maxRight = external[i] + i; mid = i; } } }
voidWork(){ cin >> s; n = (int) strlen(s); Pre(); Manacher(); int ans = 1; for (int i = 0; i < n; ++i) ans = std::max(ans, external[i]); cout << ans - 1 << endl; } }