#include<bits/stdc++.h>
using namespace std;
string s;
int n;
int dp[3010][3010];
int f(int i, int j, int x, int y)
{
    int p=0;
    int br=0;
    while (p<=min(j-i,y-x))
    {
        if (s[x+p]==s[x-1-p])
            br++;
        p++;
    }
    return br;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    n=s.length(); //abccbbcaac
    /*int i,j,x,y;
    cin >> i >> j >> x >> y;
    cout << f(i,j,x,y);*/
    for (int i=2; i<n-1; i++)
        for (int k=i+1; k<n; k++)
            for (int p=0; p<i-1; p++)
                dp[i][k]=max(dp[i][k],dp[p][i-1]+f(p,i-1,i,k));


            //dp[i][k]=max(dp[i][k], dp[min(k-i-1,i-2)][i-1]+f(min(k-i-1,i-2),i-1,i,k));
    int x=0;
    for (int i=0; i<n-1; i++)
        x=max(x,dp[i][n-1]);
    cout << x;
    return 0;
}