#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];

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++){
            int s1 = 0;
            for(int j = 1; j < i; j++){
                s1 = max(s1,dp[j][i-j]+pok[i][min(i-j,r)]);
            }
            int s2 = pok[i][min(i,r)];
            dp[i][r] = max(s1,s2);
        }
    }

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