#include <bits/stdc++.h>

#define MAXN 3010

using namespace std;

int dp[MAXN][MAXN];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;
    int n = s.size();
    
    for(int cut = 2; cut < n; cut++) {
        int pre[n], suf[n], temp[n], x = 0;
        for(int i = 0; i < n; i++)
            pre[i] = suf[i] = temp[i] = 0;
        for(int i = 2; i < cut - 1; i++)
            pre[i] = max(pre[i - 1], dp[cut - 1][i]);
        
        for(int i = 0; i < cut; i++) {
            int index = cut + cut - i - 1;
            if(index >= n)
                continue;
            
            temp[i] = dp[cut - 1][i] - x;
            x += s[i] == s[index];
        }
        for(int i = cut - 2; i >= 2; i--)
            suf[i] = max(suf[i + 1], temp[i]);
        for(int i = cut + 1; i < n; i++) {
            // dp[i][cut] - resenje za prefix do i kada je poslednje secenje na cut
            int temp1 = 0, temp2 = suf[0];
            if(cut - (i - cut + 1) - 1 >= 0)
                temp1 = pre[cut - (i - cut + 1) - 1];
            if(cut - (i - cut + 1) >= 0)
                temp2 = suf[cut - (i - cut + 1)];
            dp[i][cut] = max(temp1, temp2) + x;
        }
    }

    int ans = INT_MIN;
    for(int i = 2; i < n - 1; i++)
        ans = max(ans, dp[n - 1][i]);
    cout << ans << endl;
    return 0;
}