S = eval(input())

ans = len(S)

for tgt in set(S):

    T = S

    while len(T) != T.count(tgt):

        U = ''

        for ab in zip(T, T[1:]):

            U += tgt if tgt in ab else ab[0]

        T = U

    ans = min(ans, len(S) - len(T))

print(ans)
S = eval(input())

ans = len(S)

for c in [chr(i + 97) for i in range(26)]:

    if c not in S:

        continue

    ma = max(list(map(len, S.split(c))))

    ans = min(ans, ma)

print(ans)
S = eval(input())
ans = len(S)
for tgt in set(S):
    T = S
    while len(T) != T.count(tgt):
        U = ""
        for ab in zip(T, T[1:]):
            U += tgt if tgt in ab else ab[0]
        T = U
    ans = min(ans, len(S) - len(T))
print(ans)

S = eval(input())
ans = len(S)
for c in [chr(i + 97) for i in range(26)]:
    if c not in S:
        continue
    ma = max(list(map(len, S.split(c))))
    ans = min(ans, ma)
print(ans)

-for tgt in set(S): -    T = S -    while len(T) != T.count(tgt): -        U = "" -        for ab in zip(T, T[1:]): -            U += tgt if tgt in ab else ab[0] -        T = U -    ans = min(ans, len(S) - len(T)) +for c in [chr(i + 97) for i in range(26)]: +    if c not in S: +        continue +    ma = max(list(map(len, S.split(c)))) +    ans = min(ans, ma)