#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

const int N = 3000;

int dp[N+5][N+5];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string s;
    cin >> s;
    int n = s.size();
    for(int i=2; i<n-1; i++){
        int res = 0, same = (s[i-1] == s[i]);
        for(int j=1; j<i-1; j++) dp[j][i-1] = max(dp[j][i-1], dp[j-1][i-1]);
        for(int j=i+1; j<n; j++){
            int lv = i-1 - (j-i+1) + 1;
            if(lv >= 0) same += (s[lv] == s[j]);
            if(lv >= 0) res = max(res, same + dp[lv][i-1]);
            dp[i][j] = res;
        }
    }
    int res = 0;
    for(int i=0; i<n-1; i++) res = max(res, dp[i][n-1]);
    cout << res << "\n";
    return 0;
}