#include using namespace std; struct RollingHash { int n; long long base1, base2, mod1, mod2; vector hash1, hash2, pow1, pow2; RollingHash(const string &s) : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) { n = s.size(); hash1.assign(n + 1, 0); hash2.assign(n + 1, 0); pow1.assign(n + 1, 1); pow2.assign(n + 1, 1); for(int i = 0; i < n; i++) { hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1; hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2; pow1[i + 1] = pow1[i] * base1 % mod1; pow2[i + 1] = pow2[i] * base2 % mod2; } } pair get(int l, int r) { long long t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1; long long t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2; return {t1, t2}; } int LCP(int l, int r){ int len = n - r, low = -1, high = len + 1; while(high - low > 1){ int mid = (low + high) / 2; if(get(l, l + mid) == get(r, r + mid)) low = mid; else high = mid; } return low; } }; vector manacher(string &s){ int i = 0, j = 0; vector res(s.size()); while (i < s.size()) { while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) ++j; res[i] = j; int k = 1; while (i - k >= 0 && i + k < s.size() && k + res[i - k] < j) res[i + k] = res[i - k], ++k; i += k; j -= k; } return res; } int main(){ int ans = 0; string s, t = "$"; cin >> s; for(int i = 0; i < s.size(); i++){ t += s[i]; t += "$"; } s = t; vector len = manacher(s), left(s.size()), right(s.size()); for(int i = 0; i < len.size(); i++){ len[i]--; left[i] = i - len[i]; right[i] = i + len[i]; } string sr = s; reverse(sr.begin(), sr.end()); string ssr = s + "#" + sr; RollingHash rh(ssr); vector d; for(int i = 0; i < s.size(); i++){ if(right[i] + 1 <= s.size() - 1){ int rightStart = right[i] + 3; int leftStart = ssr.size() - 1 - (left[i] - 1); int lcp = rh.LCP(rightStart, leftStart); d.push_back(len[i] + lcp); } if(left[i] - 1 >= 0){ int rightStart = right[i] + 1; int leftStart = ssr.size() - 1 - (left[i] - 3); int lcp = rh.LCP(rightStart, leftStart); d.push_back(len[i] + lcp); } } sort(d.rbegin(), d.rend()); ans = d[0]; cout << ans << endl; }