#include <bits/stdc++.h>
using namespace std;
int br_istih[2000][2000];
int dp[2000][2000];
string str;
int f(int i, int j, int x)
{
    if(j < x) return br_istih[i][j];
    return br_istih[i - j + x][x];
}
int main()
{
    ios_base::sync_with_stdio(false);
    int ans = 0, n, i, j, x;
    cin >> str;
    n = str.size();
    for(i = 1; i <= n; i++)
        for(j = 1; j <= n; j++)
            if(i >= 2*j && str[i - 1] == str[i - 2*j]) br_istih[i][j] = br_istih[i - 1][j - 1] + 1;
                else br_istih[i][j] = br_istih[i - 1][j - 1];

    for(i = 1; i <= n; i++)
        for(j = 2; j <= i; j++)
            for(x = 2; x <= i - j; x++)
                dp[i][j] = max(dp[i][j], dp[i - j][x] + f(i, j, x));

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