#include <bits/stdc++.h>

using namespace std;

const int N = 3e3+10;

int dp[N][N], Cnt[N][N], sufix[N][N], prefix[N][N];;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    s = "!" + s;
    for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = 0;
    for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) Cnt[i][j] = 0;
    for(int i = 1; i <= n; i++) {
    	Cnt[i][i] = (s[i] == s[i-1]);
    	for(int j = i+1; j <= n; j++) {
    		Cnt[i][j] = Cnt[i][j-1] + (i-(j-i)-1 >= 1 && s[j] == s[i-(j-i)-1]);
    	}
    }
    for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) prefix[i][j] = sufix[i][j] = 0;
    for(int i = 1; i <= n; i++) {
    	for(int j = 1; j < i; j++) {
    		dp[i][j] = max(sufix[j-1][max(1, j-(i-j)-1)], prefix[j-1][max(0, j-(i-j)-2)] + Cnt[j][i]);
    	}
    	prefix[i][1] = dp[i][1];
    	for(int j = 2; j < i; j++) prefix[i][j] = max(prefix[i][j-1], dp[i][j]);
    	int cnt = (i+1 <= n && s[i] == s[i+1]) + (i+2 <= n && s[i-1] == s[i+2]);
    	sufix[i][i-1] = dp[i][i-1] + cnt;
    	for(int j = i-2; j >= 1; j--) {
    		if(i+i-j+1 <= n) cnt += (s[j] == s[i+i-j+1]);
    		sufix[i][j] = max(sufix[i][j+1], dp[i][j] + cnt);
    	}
    }
    int rez = 0;
    for(int i = 0; i <= n; i++) rez = max(rez, dp[n][i]);
    cout << rez;
    return 0;
}