#include <iostream>
#include <unordered_map>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

int max(int a, int b) {
    return (a > b) ? a : b;
}

int odds(std::string pal) {
    std::unordered_map<char, int> a;
    int res = 0;
    for (int i = 0; i < pal.length(); i++) {
        if (a[pal[i]] % 2 == 0) {
            res++;
        }
        else {
            res--;
        }
        a[pal[i]]++;
    }
    return res;
}

int evalScore(std::vector<std::string> r) {
    std::unordered_map<int, std::unordered_map<int, char>> score;
    int index1 = 0;
    for (int i = 0; i < r.size(); i++) {
        std::string str = r[i];
        int coef = 1;
        if (i % 2 == 1) {
            coef = -1;
        }
        for (int j = 0; j < str.length(); j++) {
            //std::cout << i << " " << index1 << " " <<  str[i] << std::endl;
            score[i][index1] = str[j];
            index1 += coef;
        }
        index1 -= coef;

    }
    int res = 0;
    int it = 0;
    for (auto i = score.begin(); i != score.end(); i++) {
        int level = i->first;
        if (level == r.size() - 1) continue;
        auto score1 = i->second;
        for (auto j = score1.begin(); j != score1.end(); j++) {
            //std::cout << level << " " << j->first << " " << score[level][j->first] << " " << score[level + 1][j->first] << std::endl;
            if (j->second == score[level + 1][j->first] && score[level + 1][j->first] != 0) {
                res++;
            }
        }
        it++;
    }
    return res;
}


std::vector<std::string> ress;
std::unordered_map<std::string, int> memory;

int maxx = 0;
int eval(std::string a, std::vector<std::string> res) {
    int p = 0;
    if (memory[a] != 0) {
        return memory[a];
    }
    for (int i = 0; i < a.length(); i++) {
        int k = i+1;
        while (/*k <= i + (a.length()) / 2 + 1 && */ k < a.length()) {
            if (a[k] == a[i]) {
                //std::cout << i << " " << k << " " << a[i] << std::endl;
                std::string a1 = a.substr(0, i + (k - i) / 2 + 1), a2 = a.substr(i + (k - i) / 2 + 1, a.length() - (k - i) / 2 - 1);
                auto res2(res);
                res2.push_back(a1);
                //std::cout << a1 << " " << a2 << " " << a[i] << std::endl;
                int nM = eval(a2, res2);
                if (nM > maxx) {
                    maxx = nM;
                }
                p++;
                //std::cout <<"End for " << a1 << " " << a2 << " " << a[i] << " " << max << std::endl;
            }
            k+= 2;
        }
        if (/*k >(a.length() + i) / 2 + 1 || */k >= a.length()) {
            continue;
        }
        //std::vector<std::string> a = eval(a2);
        
    }
    memory[a] = maxx;
    if (p == 0) {
        res.push_back(a);
        int r = evalScore(res);
        memory[a] = r;
        /*for (int l = 0; l < res.size(); l++) {
            std::cout << res[l] << " ";
        }
        std::cout << r << std::endl;*/
        return r;
    }
    return maxx;
}

int main()
{
    std::string a;
    std::cin >> a;
    int max = 0;
    std::cout << /*evalScore({ "has", "talavi", "sta" })*/eval(a, {}) << std::endl;;
}