def main(): import sys s = sys.stdin.readline().strip() n = len(s) if n <= 1: print(0) return # Check if the entire string is a palindrome is_full_palindrome = True for i in range(n // 2): if s[i] != s[n - 1 - i]: is_full_palindrome = False break if is_full_palindrome: print(n - 1) return max_len = 0 # Check for possible max palindrome by removing one character for i in range(n): left = i - 1 right = i + 1 current = 0 while left >= 0 and right < n and s[left] == s[right]: current += 1 left -= 1 right += 1 max_len = max(max_len, 2 * current + 1) left = i right = i + 1 current = 0 while left >= 0 and right < n and s[left] == s[right]: current += 1 left -= 1 right += 1 max_len = max(max_len, 2 * current) # Now check for removing each character and expanding around i-1 and i+1 for i in range(1, n-1): if s[i-1] == s[i+1]: left = i - 1 right = i + 1 current_length = 2 while left > 0 and right < n-1 and s[left-1] == s[right+1]: current_length += 2 left -= 1 right += 1 max_len = max(max_len, current_length) print(max_len) if __name__ == "__main__": main()