S = eval(input())



ans = len(S)

for i in range(26):

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

    t1 = S

    cnt = 0

    while any(list([x!=c for x in t1])):

        t2 = ''

        for ca,cb in zip(t1,t1[1:]):

            if ca == c or cb == c:

                t2 += c

            else:

                t2 += ca

        t1 = t2

        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

    if all([c==a for a in S]):

        print((0))

        exit()

    arr = list(S)

    tmp = 0

    while 1:

        arr2 = []

        diff = False

        tmp += 1

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

            if a==c or b==c:

                arr2.append(c)

            else:

                arr2.append(a)

                diff = True

        if not diff:

            break

        arr = arr2

    ans = min(ans, tmp)

print(ans)
S = eval(input())
ans = len(S)
for i in range(26):
    c = chr(ord("a") + i)
    t1 = S
    cnt = 0
    while any(list([x != c for x in t1])):
        t2 = ""
        for ca, cb in zip(t1, t1[1:]):
            if ca == c or cb == c:
                t2 += c
            else:
                t2 += ca
        t1 = t2
        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
    if all([c == a for a in S]):
        print((0))
        exit()
    arr = list(S)
    tmp = 0
    while 1:
        arr2 = []
        diff = False
        tmp += 1
        for a, b in zip(arr, arr[1:]):
            if a == c or b == c:
                arr2.append(c)
            else:
                arr2.append(a)
                diff = True
        if not diff:
            break
        arr = arr2
    ans = min(ans, tmp)
print(ans)

-    t1 = S -    cnt = 0 -    while any(list([x != c for x in t1])): -        t2 = "" -        for ca, cb in zip(t1, t1[1:]): -            if ca == c or cb == c: -                t2 += c +    if not c in S: +        continue +    if all([c == a for a in S]): +        print((0)) +        exit() +    arr = list(S) +    tmp = 0 +    while 1: +        arr2 = [] +        diff = False +        tmp += 1 +        for a, b in zip(arr, arr[1:]): +            if a == c or b == c: +                arr2.append(c) -                t2 += ca -        t1 = t2 -        cnt += 1 -    ans = min(ans, cnt) +                arr2.append(a) +                diff = True +        if not diff: +            break +        arr = arr2 +    ans = min(ans, tmp)