#include <bits/stdc++.h>

const int alphabet = 26;

bool inside(int x, int l, int r) {
    return l <= x && x <= r;
}

int main() {
    freopen("strings.in", "r", stdin);
    freopen("strings.out", "w", stdout);
    std::string s;
    getline(std::cin, s);
    int n = (int)s.size();
    for (int i = 0; i < n; i++)
        s[i] -= 'a';
    
    std::vector <int> cnt(alphabet, 0);
    for (int i = 0; i < n; i++)
        cnt[s[i]]++;
    int maxCnt = *max_element(cnt.begin(), cnt.end());
    int maxLength = 0;
    for (int c = 0; c < alphabet; c++) {
        if (cnt[c] != maxCnt)
            continue;
        std::vector <int> p, p0;
        for (int i = 0; i < n; i++) {
            if (s[i] == c) {
                p.push_back(i);
                p0.push_back(i);
            }
        }

        int length = 1;
        for (int dx = -1; dx <= 1; dx += 2) {
            while (true) {
                bool can = true;
                char needc = -1;
                for (size_t i = 0; i < p.size(); i++) {
                    if (!inside(p[i] + dx, 0, (int)s.size() - 1) || 
                        (needc != -1 && s[p[i] + dx] != needc) || 
                        (inside(i + dx, 0, (int)p.size() - 1) && p0[i + dx] == p[i] + dx)
                        )
                        can = false;
                    else
                        needc = s[p[i] + dx];
                }
                if (!can)
                    break;
                ++length;
                for (size_t i = 0; i < p.size(); i++)
                    p[i] += dx;
            }
            for (size_t i = 0; i < p.size(); i++)
                p[i] = p0[i];
        }
        if (length > maxLength)
            maxLength = length;
    }
    printf("%d\n", maxLength);
    return 0;
}