#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
const int N = 3e3 + 2;
const ll mod = 1e9 + 7;
int cost[N][N], dp[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j += 2) {
            if (s[i] != s[j]) continue;
            int m = i + j >> 1;
            cost[m][j] += 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            cost[i][j] += cost[i][j - 1];
        }
    }
    for (int i = 0; i < n; i++) {
        if (i > 0) dp[i] = dp[i - 1];
        for (int j = i - 1; j >= 0; j -= 2) {
            if (s[i] != s[j]) continue;
            int m = i + j >> 1;
            dp[i] = max(dp[i], dp[m] + cost[m][i]);
        }
    }
    cout << dp[n - 1] << en;
    return 0;

}