#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][2];
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];
        }
    }
    dp[0][0] = 0;
    dp[0][1] = -1e9;
    for (int i = 1; i < n; i++) {
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][0] = dp[i - 1][1] + (s[i] == s[i - 1]);
        for (int j = i - 3; j >= 0; j -= 2) {
            if (s[i] != s[j]) continue;
            int m = i + j >> 1;
            dp[i][1] = max(dp[i][1], dp[m][1] + cost[m][i]);
        }
    }
    cout << dp[n - 1][1] << en;
    return 0;

}