#include<bits/stdc++.h>
using namespace std;
#define el "\n"
#define ll long long
#define ull unsigned long long
#define se second
#define fi first
#define be begin()
#define en end()
#define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int main()
{
Faster;
string s; cin >> s;
int ans = 0;
for(int i = 0; i < s.size(); i++)
{
if(s.size() - i - 1 < ans) break;
unordered_map<char,int> mp;
for(int j = i; j < s.size();j++)
{
mp[s[j]]++;
int tmp = mp[s[i]], ok = 1;
for(pair<char,int> x : mp)
{
if(x.se != tmp)
{
ok = 0;
break;
}
}
if(ok == 1) ans = max(ans, j - i + 1);
}
}
cout << ans;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBlbCAiXG4iCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgdWxsIHVuc2lnbmVkIGxvbmcgbG9uZwojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgYmUgYmVnaW4oKQojZGVmaW5lIGVuIGVuZCgpCiNkZWZpbmUgRmFzdGVyIGNpbi50aWUoMCk7IGNvdXQudGllKDApOyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwoKaW50IG1haW4oKQp7CiAgICBGYXN0ZXI7CiAgICBzdHJpbmcgczsgY2luID4+IHM7CiAgICBpbnQgYW5zID0gMDsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzLnNpemUoKTsgaSsrKQogICAgewogICAgICAgIGlmKHMuc2l6ZSgpIC0gaSAtIDEgPCBhbnMpIGJyZWFrOwogICAgICAgIHVub3JkZXJlZF9tYXA8Y2hhcixpbnQ+IG1wOwogICAgICAgIGZvcihpbnQgaiA9IGk7IGogPCBzLnNpemUoKTtqKyspCiAgICAgICAgewogICAgICAgICAgICBtcFtzW2pdXSsrOwogICAgICAgICAgICBpbnQgdG1wID0gbXBbc1tpXV0sIG9rID0gMTsKICAgICAgICAgICAgZm9yKHBhaXI8Y2hhcixpbnQ+IHggOiBtcCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoeC5zZSAhPSB0bXApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgb2sgPSAwOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKG9rID09IDEpIGFucyA9IG1heChhbnMsIGogLSBpICsgMSk7CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBhbnM7CiAgICByZXR1cm4gMDsKfQo=