def Manacher(s): dummy = "@" s = dummy+dummy.join(s)+dummy i = j = 0 res = [-1]*len(s) while i < len(s): while i-j >= 0 and i+j < len(s) and s[i-j] == s[i+j]: j += 1 res[i] = j-1 k = 1 while i-k >= 0 and k+res[i-k]+1 < j: res[i+k] = res[i-k] k += 1 i += k j -= k return res def solve(): import sys def SI(): return sys.stdin.readline().rstrip() from random import randrange s = SI() n = len(s) BASE = randrange(128, 256) MOD = (1 << 61)-1 h = [0] pw = [1] for c in s: h += [h[-1]*BASE%MOD+ord(c)] pw += [pw[-1]*BASE%MOD] rh = [0] for c in s[::-1]: rh += [rh[-1]*BASE%MOD+ord(c)] def hash(h, l, r): return (h[r]-h[l]*pw[r-l]%MOD)%MOD dia = Manacher(s) def binary_search(l, r, i, j): if l > r: return 0 if l < 0: l = 0 r += 1 while l+1 < r: m = (l+r)//2 if hash(h, i-m, i) == hash(rh, n-(j+m), n-j): l = m else: r = m return l ans = 1 for i in range(1, n): r = min(i, n-i) if r*2 <= ans: continue d = dia[i*2]//2 if d*2 == n: print(n-1) exit() # delete left ni, nj = i-d-1, i+d r = min(ni, n-nj) if ni >= 0 and (d+r)*2 > ans: e = binary_search(ans//2-d, r, ni, nj) if (d+e)*2 > ans: ans = (d+e)*2 # delete right ni, nj = i-d, i+d+1 r = min(ni, n-nj) if nj <= n and (d+r)*2 > ans: e = binary_search(ans//2-d, r, ni, nj) if (d+e)*2 > ans: ans = (d+e)*2 for i in range(n-1): r = min(i, n-i-1) if r*2+1 <= ans: continue d = dia[i*2+1]//2 if d*2+1 == n: print(n-1) exit() # delete left ni, nj = i-d-1, i+1+d r = min(ni, n-nj) if ni >= 0 and (d+r)*2+1 > ans: e = binary_search((ans-1)//2-d, r, ni, nj) if (d+e)*2+1 > ans: ans = (d+e)*2+1 # delete right ni, nj = i-d, i+d+2 r = min(ni, n-nj) if nj <= n and (d+r)*2+1 > ans: e = binary_search((ans-1)//2-d, r, ni, nj) if (d+e)*2+1 > ans: ans = (d+e)*2+1 print(ans) solve()