def compute_lps(s): # Manacher's algorithm to find the maximum LPS length transformed = '#' + '#'.join(s) + '#' n = len(transformed) P = [0] * n C = R = 0 max_len = 0 for i in range(n): mirror = 2*C - i if i < R: P[i] = min(R - i, P[mirror]) a, b = i + (1 + P[i]), i - (1 + P[i]) while a < n and b >= 0 and transformed[a] == transformed[b]: P[i] += 1 a += 1 b -= 1 if i + P[i] > R: C = i R = i + P[i] max_len = max(max_len, P[i]) return max_len def main(): import sys s = sys.stdin.readline().strip() n = len(s) if n == 0: print(0) return # Compute the maximum LPS max_lps = compute_lps(s) # Compute M: maximum expansion by deleting one character max_m = 0 for i in range(n): left = i - 1 right = i + 1 cnt = 0 while left >= 0 and right < n and s[left] == s[right]: cnt += 1 left -= 1 right += 1 current_m = cnt * 2 if current_m > max_m: max_m = current_m # Determine the answer if max_lps == n: print(n - 1) else: print(max(max_lps, max_m)) if __name__ == "__main__": main()