S = eval(input())



ans = len(S)

for i in range(26):

    c = chr(ord('a') + i)

    if not c in S: continue

    s = S

    ope = 0

    while any(a!=c for a in s):

        t = ''

        for a,b in zip(s,s[1:]):

            if a==c or b==c:

                t += c

            else:

                t += '-'

        s = t

        ope += 1

    ans = min(ans, ope)

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



ans = len(S)

for i in range(26):

    c = chr(ord('a') + i)

    if c not in S: continue

    cnt = 0

    s = S

    while any(a!=c for a in s):

        t = ''

        for a,b in zip(s,s[1:]):

            if c==a or c==b:

                t += c

            else:

                t += a

        s = t

        cnt += 1

    ans = min(ans, cnt)

print(ans)
S = eval(input())
ans = len(S)
for i in range(26):
    c = chr(ord("a") + i)
    if not c in S:
        continue
    s = S
    ope = 0
    while any(a != c for a in s):
        t = ""
        for a, b in zip(s, s[1:]):
            if a == c or b == c:
                t += c
            else:
                t += "-"
        s = t
        ope += 1
    ans = min(ans, ope)
print(ans)

S = eval(input())
ans = len(S)
for i in range(26):
    c = chr(ord("a") + i)
    if c not in S:
        continue
    cnt = 0
    s = S
    while any(a != c for a in s):
        t = ""
        for a, b in zip(s, s[1:]):
            if c == a or c == b:
                t += c
            else:
                t += a
        s = t
        cnt += 1
    ans = min(ans, cnt)
print(ans)

-    if not c in S: +    if c not in S: +    cnt = 0 -    ope = 0 -            if a == c or b == c: +            if c == a or c == b: -                t += "-" +                t += a -        ope += 1 -    ans = min(ans, ope) +        cnt += 1 +    ans = min(ans, cnt)