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

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

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

                        int res2 = dp[k+1][j][k-i+1][r]+pok[i-1][min(l,k-i+1)];
                        s2 = max(s2,res2);
                    }
                    dp[i][j][l][r] = max(s1,s2);
                }
            }
        }
    }

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