#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3002;

short n,a[N];
short dp[N][N];
short pok[N][N];
short najv[N][N]; /// najv[A][B] - najvece dp[j][i-j] tkd i=A, a da j ide od 0 do B

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    n = s.size();
    for(int i = 1; i <= n; i++) a[i] = s[i-1]-'a'+1;

    for(int i = 1; i <= n; i++){
        int d = min(i,n-i);
        for(int j = 1; j <= d; j++) pok[i][j] = pok[i][j-1]+(a[i-j+1] == a[i+j]);
        for(int j = d+1; j <= n; j++) pok[i][j] = pok[i][j-1];
    }

    for(int i = 1; i <= n; i++){
        /// prvo za sve r >= i
        int s = 0;
        for(int j = 0; j < i; j++){
            s = max(s,dp[j][i-j]+pok[i][i-j]);
        }
        for(int r = i; r <= n-i; r++) dp[i][r] = s;

        /// pa za 0 <= r < i
        vector <int> v = {0};
        for(int j = i-1; j >= 0; j--){ /// i-j ide od 1 do i
            int res = dp[j][i-j]+pok[i][i-j];
            v.push_back(max(v.back(),res));
        }

        for(int h = 1; h <= n; h++){ /// povuci maksimume
            najv[i][h] = max(najv[i][h],najv[i][h-1]);
        }

        for(int r = 0; r < i; r++){
            int s1 = v[r]; /// kada je i-j <= r
            int s2 = pok[i][r]+najv[i][i-r-1]; /// kada je i-j > r

            dp[i][r] = max(s1,s2);
        }


        /// update maksimume
        for(int r = 0; r <= n-i; r++){
            najv[i+r][i] = max(najv[i+r][i],dp[i][r]);
        }


        /*for(int r = 0; r <= n-i; r++){
            int s = 0;
            for(int j = 0; j < i; j++){
                s = max(s,dp[j][i-j]+pok[i][min(i-j,r)]);
            }
            dp[i][r] = s;
        }*/
    }

    cout << dp[n][0] << "\n";
}