// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x) long long
#define here cerr<<"---------------------------\n"
#include <bits/stdc++.h>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
using namespace std;
#define maxn 3005
ll a[maxn];
ll dp[maxn][maxn];
ll p[maxn];
ll n;
string s;
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> s;
    n = sz(s);
    for(ll i = 1;i<=n;i++) a[i] = (s[i-1]-'a');
    for(ll i = 1;i<=n;i++){
        for(ll j = i-2;j>=0;j--){
            ll id = j+2;
            ll cnt = 0;
            if(a[j+1]==a[j]) cnt++;
            for(ll k = j-2;k>=0;k--){
                if(id<=i&&a[id]==a[k+1]) cnt++;
                id++;
                if(k==1) continue;
                dp[i][j] = max(dp[j][k]+cnt,dp[i][j]);
            }
        }
    }
    ll ans = 0;
    for(ll i = 0;i<=n;i++) ans = max(ans,dp[n][i]);
    cout<<ans<<endl;
	return 0;
}