#include <bits/stdc++.h>

#ifdef DEBUG
  #define D(X) X
#else
  #define D(X)
#endif // DEBUG


using namespace std;

int main()
{
    string s;
    cin>>s;
    int n=s.length();

    int dp[n+1][n+1]={0};
    int pre_calc[n][n]={0};

    for(int i=2;i<n-2;i++){
        pre_calc[i][0] = (s[i]==s[i+1]);
        for(int j=1;j<=min(i,n-1-i);j++){
            pre_calc[i][j] = pre_calc[i][j-1] + (s[i-j]==s[i+j+1]);
        }
    }

    D(
        for(int i=2;i<n-2;i++){
            for(int j=1;j<=min(i,n-1-i);j++){
                cout<<pre_calc[i][j]<<" ";
            }
            cout<<"\n";
        }
    )
    int res=0;
    /// e f g g f 1 2 3 4 5  f
    ///0 1 2 3 4 5 6 7 8 9 10
    for(int i=0;i<n;i++){
        dp[0][i]=0;
        dp[1][i]=0;
    }

    for(int i=2;i<n-2;i++){

        dp[i][1]=dp[i-1][2];
        res=max(res,dp[i][1]);
        for(int j=2;j<min(i+1,n-i);j++){

            dp[i][j]=max(max(dp[i][j-1],dp[i-j][2*j]),dp[i-j][j]+pre_calc[i][j]);
            res=max(res,dp[i][j]);

        }
    }

    cout << res << endl;
    return 0;
}