#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll MAXN=3005,LINF=1e18,MOD=1e9+7,INF=1e9;
const double EPS=1e-9;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),a.end()
#define mod 1000000007LL
#define pb push_back
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }

ll n,m,k,q,x,y,z,l,res=0;
string s,t;
ifstream in;
ofstream out;

#ifdef ONLINE_JUDGE
    #define in cin
    #define out cout
#endif

ll dp[MAXN][MAXN];
ll d[MAXN][MAXN];

void solve(){
    cin>>s;
    n=sz(s);
    s.insert(0,"$");
    memset(dp,0,sizeof(dp));
    for(int j=1;j<=n;j++){
        for(int k=1;k<=j && j+k<=n;k++){
            d[j][k]=d[j][k-1]+(s[j-k+1]==s[j+k]);
        }
    }
    /*
    for(int j=1;j<n;j++){
        for(int k=1;k<=j && j+k<=n;k++){
            cout<<s.substr(j-k+1,k)<<endl;
            string t=s.substr(j+1,k);
            reverse(all(t));
            cout<<t<<endl;
            cout<<"d["<<j<<"]["<<k<<"]="<<d[j][k]<<endl;
        }
    }
    */
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i-1;j++){
            for(int k=1;k<=j-1;k++){
                dp[i][j]=max(dp[i][j],dp[j][k]+d[j][min(j-k,i-j)]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        res=max(dp[n][i],res);
    }
    cout<<res<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        in.open("D:\\UROS\\Programiranje\\input.in",ios::in);
        out.open("D:\\UROS\\Programiranje\\output.out",ios::trunc | ios::out);
    #endif
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    int t;
    ///cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}