#include <bits/stdc++.h>

using namespace std;

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