s = input().strip() n = len(s) if n < 2: print(1) exit() # Precompute palindrome table pal = [[False] * n for _ in range(n)] for i in range(n - 1, -1, -1): for j in range(i, n): if i == j: pal[i][j] = True elif j == i + 1: pal[i][j] = (s[i] == s[j]) else: pal[i][j] = (s[i] == s[j]) and pal[i + 1][j - 1] # Initialize dp arrays dp0 = [-1] * (n + 1) # dp0[i] represents the case where the first i characters form a palindrome without splitting dp1 = [-1] * (n + 1) # dp1[i] represents the case where at least one split is made dp0[0] = 0 # Base case: zero characters # Fill dp0: check if the substring from 0 to i-1 is a palindrome for i in range(1, n + 1): if pal[0][i - 1]: dp0[i] = i else: dp0[i] = -1 # Fill dp1 for i in range(1, n + 1): max_val = -1 for j in range(1, i): # j ranges from 1 to i-1 to split into two non-empty parts if pal[j][i - 1]: current_max = -1 if dp0[j] != -1: current_max = max(dp0[j], i - j) if dp1[j] != -1: candidate = max(dp1[j], i - j) if candidate > current_max: current_max = candidate if current_max != -1 and current_max > max_val: max_val = current_max dp1[i] = max_val print(dp1[n] if dp1[n] != -1 else 0)