int N, mr, p, f[maxn * 2], Len; char s[maxn * 2]; voidinit(char *c){ int l = strlen(c + 1); s[0] = '~'; for (int i = 1; i <= l; ++i) s[i * 2] = c[i], s[i * 2 - 1] = '#'; N = 2 * l + 1; s[N] = '#'; }
voidmanacher(){ for (int i = 1; i <= N; ++i) { if (i < mr) f[i] = min(f[2 * p - i], mr - i); while (s[i + f[i]] == s[i - f[i]]) ++f[i]; --f[i]; if (f[i] + i > mr) mr = i + f[i], p = i; Len = max(Len, f[i]); } }
int l[maxn], r[maxn];
int ans; intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> c + 1; n = strlen(c + 1); init(c); manacher(); for (int i = 1; i <= N; ++i) { int L = i - f[i] + 1 >> 1, R = i + f[i] - 1 >> 1; if (!f[i]) continue; l[L] = max(l[L], f[i]); r[R] = max(r[R], f[i]); } for (int i = 1; i <= n; ++i) l[i] = max(l[i], l[i - 1] - 2); for (int i = n - 1; i; --i) r[i] = max(r[i], r[i + 1] - 2); for (int i = 1; i < n; ++i) ans = max(ans, r[i] + l[i + 1]); cout << ans << "\n"; return0; }
int N, mr, p, f[maxn * 2], Len; char s[maxn * 2]; voidinit(char *c){ int l = strlen(c + 1); s[0] = '~'; for (int i = 1; i <= l; ++i) s[i * 2] = c[i], s[i * 2 - 1] = '#'; N = 2 * l + 1; s[N] = '#'; }
voidmanacher(){ for (int i = 1; i <= N; ++i) { if (i < mr) f[i] = min(f[2 * p - i], mr - i); while (s[i + f[i]] == s[i - f[i]]) ++f[i]; --f[i]; if (f[i] + i > mr) mr = i + f[i], p = i; Len = max(Len, f[i]); } }
int l[maxn * 2], r[maxn * 2];
int ans; intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> c + 1; n = strlen(c + 1); init(c); manacher(); for (int i = 1; i <= N; ++i) { l[i - f[i]] = max(l[i - f[i]], f[i]); r[i + f[i]] = max(r[i + f[i]], f[i]); } for (int i = 3; i <= N; i += 2) l[i] = max(l[i], l[i - 2] - 2); for (int i = N - 2; ~i; i -= 2) r[i] = max(r[i], r[i + 2] - 2); for (int i = 1; i <= N; i += 2) if (l[i] && r[i]) ans = max(ans, r[i] + l[i]); cout << ans << "\n"; return0; }