#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=3050;
char s[N];
int dp[N][N],pf[N][N],sf[N][N];

int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	dp[0][0]=0;
	rep(i,1,n+1) {
		int cc=0;
		rep(x,2,n+1) {
			int j=i+x-1;
			if (j>n) break;
			dp[j][x]=max(dp[j][x],pf[i-1][x]);
			if (i<=x) continue;
			if (x==2&&s[i]==s[i-1]) cc++;
			if (s[i+x-1]==s[i-x]) cc++;
			//if (i==9&&x==2) printf("3 puta lupam nogom i radim salto: %d %d\n",sf[i-1][x],cc);
			dp[j][x]=max(dp[j][x],sf[i-1][x]+cc);
		}
		//if (i==8) printf("vozim bus na:%d\n",dp[i][3]);
		per(x,2,n+1) {
			sf[i][x]=max(sf[i][x+1],dp[i][x]);
		}
		//printf("sledeci bus:%d\n",sf[i][3]);
		if (i==n) continue;
		cc=0;
		if (s[i]==s[i+1]) cc++;
		rep(x,2,n+1) {	
			if (i+x>n) continue;
			if (s[i-x+1]==s[i+x]) cc++;
			pf[i][x]=max(pf[i][x-1],dp[i][x]+cc);
		}
	}
	//printf("%d 8 2 \n",sf[8][2]);
	int ans=0;
	rep(i,1,n+1) ans=max(ans,dp[n][i]);
	printf("%d",ans);
}