#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];
    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++) {
    		int cnt = (s[j] == s[j-1]);
    		for(int k = j-2; k >= 1; k--) {
    			if(j+j-k-1 <= i) cnt += (s[k] == s[j+j-k-1]);
    			dp[i][j] = max(dp[i][j], dp[j-1][k] + cnt);
    		}
    	}
    }
    int rez = -1e9;
    for(int i = 0; i <= n; i++) rez = max(rez, dp[n][i]);
    cout << rez;
    return 0;
}