#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
using namespace std;

const char nl='\n';
const int MOD=1000000007;
const int N=3005;

int n,dp[N][N],mx[N],pr[N][N];
string s;

int preklop(int id,int d){
    int poi1=id-d+1;
    int poi2=poi1-1;
    int br=0;
    for(int i=1;i<=d;i++){
        if(s[poi1]==s[poi2])br++;
        poi1++;
        poi2--;
    }
    return br;
}

void solve(){
    cin>>s;
    n=sz(s);
    s="?"+s;
    for(int i=1;i<=n;i++){
        int p1=i;
        int p2=i+1;
        int id1=p2;
        int id2=1;
        while(id1<=n and id2<=n){
            pr[id1][id2]=pr[id1-1][id2-1];
            if(p1>=1 and p2<=n){
                if(s[p1]==s[p2])pr[id1][id2]++;
            }
            id1++;id2++;
            p1--;p2++;
        }
    }
    if(n<=500){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                dp[i][j]=mx[i-j]+preklop(i,j);
            }
            for(int j=1;j<=n;j++){
                mx[i]=max(mx[i],dp[i][j]);
            }
        }
    }
    else{
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                dp[i][j]=mx[i-j]+pr[i][j];
            }
            for(int j=1;j<=n;j++){
                mx[i]=max(mx[i],dp[i][j]);
            }
        }

    }
    cout<<mx[n]<<nl;
}
int main () {
cin.tie(NULL);
ios_base::sync_with_stdio(false);

int T=1;
//cin>>T;
while(T--){
    solve();
}

return 0;
}