fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s = read1::<String>().chars().collect::<Vec<char>>();
    let n = s.len();
    let mut dp = vec![vec![0; n]; n];

    for k in 1..n {
        for i in 0..n {
            if i + k >= n {
                continue;
            }
            let j = i + k;
            if j - i == 1 {
                if s[i] != s[j] {
                    dp[i][j] = 2;
                } else {
                    dp[i][j] = 0;
                }
            } else {
                if dp[i+1][j-1] == j - i - 1 && s[i] != s[j] {
                    dp[i][j] = j - i + 1;
                } else {
                    let mut m = 0;
                    for jj in i+1..j {
                        m = std::cmp::max(m, dp[i][jj] + dp[jj+1][j]);
                    }
                    dp[i][j] = m;
                }
            }
        }
    }

    println!("{}", dp[0][n-1]);
}