#include <bits/stdc++.h>
#define MAXN 3010
using namespace std;

int dp[MAXN][MAXN];
int pref[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s; int n = s.size(); s = " " + s;
    int res = 0;
    /*cout << "   ";
    for(int i = 1; i <= n; i++)
        cout << "" << i << " ";
    cout << endl;*/
    for(int i = 1; i <= n; i++)
    {
        //cout << i << ": ";
        int sum = 0;
        //for(int k = 1; k < i; k++) cout << "  ";
        for(int j = i; j <= n; j++)
        {
            if(2*i-j-1 > 0 && s[j] == s[2*i-j-1]) sum++;
            if(i == j) dp[i][j] = pref[i-2][i-1] + sum;
            else{
                dp[i][j] = dp[i][j-1];
                if(2*i - j - 1 > 0) dp[i][j] = max(dp[i][j], pref[2*i-j-1][i-1] + sum);
            }
            res = max(res, dp[i][j]);
            pref[i][j] = max(pref[i-1][j], dp[i][j]);
            //cout << dp[i][j] << " ";
        } //cout << endl;
    } //cout << endl;
    cout << res << endl;


    return 0;
}