#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(a) (int)(a).size()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 3005; 

int n;
string s;

int dp[mxN][mxN];
int pref[mxN][mxN];
int kol[mxN];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> s; n = sz(s);
    s = ' ' + s;

    ff(i,2,n){

        int br = 0;
        ff(j,1,n){
            if(i + j - 1 > n || i - j < 1)break;
            br += (s[i + j - 1] == s[i - j]);

            if(j == 1)continue;

            // ff(l,1,i - j){
            //     // ff(k,1,i - l)dp[i][j] = max(dp[i][j], dp[l][k] + br);
            //     dp[i][j] = max(dp[i][j], pref[l][i - l] + br);
            // }

            dp[i][j] = kol[i - j] + br;

            // pref[1][i - 1], pref[2][i - 2], pref[3][i - 3], ..., pref[i - j][j]
            // ja sam sve ove pref-ove vec pre izracunao

        }

        ff(j,1,n)pref[i][j] = max(dp[i][j], pref[i][j - 1]);

        ff(j,1,i)kol[j] = 0;
        ff(j,1,i)kol[j] = max(kol[j - 1], pref[j][i - j + 1]);


    }

    // cout << endl;
    // ff(i,1,n){
    //     ff(j,1,n)cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    int rez = 0;
    ff(i,1,n)ff(j,1,n)rez = max(rez, dp[i][j]);
    cout << rez << '\n';

    return 0;
}
/*
 
aa
 
// probati bojenje sahovski
*/