#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

int main()
{
    string naslov;
    cin >> naslov;

    vector<int> slova[26];
    stack<pair<int,int>> bends;

    for(int i = naslov.length() - 1; i >= 0; i--){
        int slovo = ((int)naslov[i]) - 97;
        slova[slovo].push_back(i);
        bool added = false;
        for(int y = 0; y < slova[slovo].size() - 1; y++) if(slova[slovo].at(y) % 2 != i % 2) {
            int match = (slova[slovo].at(y) + i - 1) / 2;
            bends.push({match, i});
            added = true;
        }
        if(added) bends.push({-1, -1});
    }

    int res[naslov.length()] = {};
    int takeover[naslov.length()] = {};

    while(!bends.empty()){
        bends.pop();
        vector<pair<int, int>> nodes;
        while(!bends.empty() && bends.top().first != -1) {
            nodes.push_back(bends.top());
            bends.pop();
        }
        for(pair<int, int> node : nodes) {
            for(int i = 0; i < node.first-1; i++) if(res[i] != 0 && i < node.second) takeover[node.first] = max(takeover[node.first], res[i] + takeover[i]);
            res[node.first]++;
        }
    }

    int result = 0;
    for(int i = 0; i < naslov.length(); i++) result = max(result, res[i] + takeover[i]);
    cout << result;
}