import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()

from functools import *

@lru_cache(None)
def rec(i, j):
    if abs(i - j) <= 1:
        return 0

    res = 0
    if S[i] != S[j - 1] and rec(i + 1, j - 1) == j - i - 2:
        res = j - i

    for m in range(i + 1, j):
        res = max(res, rec(i, m) + rec(m, j))
    return res

print(rec(0, len(S)))