// I may fail a thousand times
// But there is no giving up
// IOI - here I come
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=3e3+5;
int dp[N][N];
int lps[N][N];
int main(){
	char *s=(char *)malloc(N*sizeof(char));scanf("%s",s);int n=strlen(s);
	for(int i=1;i<=n;i++){
		int j=0,k=0;
		for(;i+j<=n&&i-j-1>=1;){
			k+=(s[i+j-1]==s[i-j-1-1]);
			lps[i-j-1][i+j]=k;
			j++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=n;j>=2;j--){
			dp[i][j]=max({dp[i][j],dp[i-1][j],dp[i-1][j-1],dp[i][j+1]});
			if(i+1+j-1<=n&&i-j+1>=0)dp[i+1+j-1][j]=max(dp[i+1+j-1][j],dp[i][j]+lps[i-j+1][i+1+j-1]);
			ans=max(ans,dp[i][j]);
		}
	}
	printf("%d\n",dp[n][2]);
  return 0;
}