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

short n,a[N];
short dp[N][N][N];
short pok[N][N];

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++){
        for(int r = 0; r <= n-i; r++){
            dp[i][i][r] = 0;
            if(r) dp[i][i][r] += pok[i][1];
            if(i > 1) dp[i][i][r] += pok[i-1][1];
        }
    }

    for(int i = n; i >= 1; i--){
        for(int j = i+1; j <= n; j++){
            for(int r = 0; r <= n-j; r++){
                int s1 = 0;
                for(int k = i; k < j; k++){
                    int res1 = dp[i][k][j-k]+pok[j][min(j-k,r)]; /// poslednji prekid je iza k
                    s1 = max(s1,res1);
                }

                int s2 = /*pok[i-1][min(l,j-i+1)]+*/pok[j][min(j-i+1,r)]; /// nema prekida na celom segmentu - vrednost za levi kraj ovog se dodaje kad se gleda desni kraj proslog

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

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