Problem:
 Score : 300 points    Problem Statement Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:   For each i ( 1 ≤ i ≤ N - 1 ), the i -th character of t' must be either the i -th or (i + 1) -th character of t .   There is a string s consisting of lowercase English letters.
Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.
Find the minimum necessary number of operations.      Constraints  1 ≤ |s| ≤ 100  s consists of lowercase English letters.         Input Input is given from Standard Input in the following format:  s       Output Print the minimum necessary number of operations to achieve the objective.        Sample Input 1 serval      Sample Output 1 3  One solution is: serval → srvvl → svvv → vvv .       Sample Input 2 jackal      Sample Output 2 2  One solution is: jackal → aacaa → aaaa .       Sample Input 3 zzz      Sample Output 3 0  All the characters in s are the same from the beginning.       Sample Input 4 whbrjpjyhsrywlqjxdbrbaomnw      Sample Output 4 8  In 8 operations, he can change s to rrrrrrrrrrrrrrrrrr .

Solution (Python):
s = input()
ans = []
for i in s:
    cnt = 0
    t = s
    while t.count(i) < len(t):
        cnt += 1
        tmp = ''
        for j in range(len(t)-1):
            if t[j] != i and t[j+1] != i:
                tmp = tmp+t[j]
            else:
                tmp = tmp+i
        t = tmp
    ans.append(cnt)
print(min(ans))

Solution (Python):
s = input()
lon = len(s)
lis = list(s)
ans = 10000

for i in s:
    cnt=0
    lef = []

    ind = [j for j, x in enumerate(lis) if x==i]
    pre=0
    for ma in ind:
        lef.append(ma-pre)
        pre = ma+1
    lef.append(lon-ma-1)
    ans_ten = max(lef)
    ans = min(ans,ans_ten)

print(ans)

Solution (Python):
S = input()

ans = len(S)
for i, s in enumerate(S[::-1]):
    
    m, n = 0, 0
    for j, c in enumerate(S[:-(i+1)][::-1]):
        if c == s:
            n = max(m, n)
            m = 0
        else:
            m += 1
    n = max(m, n)
    ans = min(ans, max(i, n))
    
print(ans)

Solution (Python):
S = input()
alphabets = [chr(ord('a') + x) for x in range(26)]

ans = 10000
for c in alphabets:
    ans = min(ans, max([len(f) for f in S.split(c)]))
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    s=input()
    len_s=len(s)
    sc=list(Counter(s).items())
    sc.sort(key=itemgetter(1),reverse=True)
    if sc[0][1]==1:
        print(len_s//2)
        sys.exit()
    ans=100
    for scc in sc:
        dp=[[False]*len_s for _ in range(len_s)]
        for i,ss in enumerate(s):
            if ss==scc[0]:
                dp[0][i]=True
        dp[1][-1]=True
        for sosa in range(len_s):
            if all(dp[sosa]):
                ans=min(ans,sosa)
                break
            for i in range(len_s-1,-1,-1):
                if dp[sosa][i]==True:
                    dp[sosa+1][i]=True
                    if i>0:dp[sosa+1][i-1]=True
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    s=input()
    len_s=len(s)
    sc=list(Counter(s).items())
    sc.sort(key=itemgetter(1),reverse=True)
    if sc[0][1]==1:
        print(len_s//2)
        sys.exit()
    ans=100
    for scc in sc:
        dp=[[False]*len_s for _ in range(len_s)]
        for i,ss in enumerate(s):
            if ss==scc[0]:
                dp[0][i]=True
        dp[1][-1]=True
        for sosa in range(len_s):
            if all(dp[sosa]):
                ans=min(ans,sosa)
                break
            for i in range(len_s-1,-1,-1):
                if dp[sosa][i]==True:
                    dp[sosa+1][i]=True
                    if i>0:dp[sosa+1][i-1]=True
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
s=input()
ans=10**5
for a in set(list(s)):
  t=s
  for i in range(len(s)):
    u=''
    for j in range(len(t)-1):
      if t[j+1]==a or t[j]==a:
        u+=a
      else:
        u+=t[j+1]
    t=u
    if len(set(list(u)))==1:
      ans=min(ans,i+1)
      break
if len(set(list(s)))==1:
  ans=0
print(ans)

Solution (Python):
s=list(input())

x=[[] for i in range(26)]
n=len(s)
for i in range(n):
    v=ord(s[i])-97
    x[v].append(i)

for i in range(26):
    x[i]=[-1]+x[i]+[n]


ans=float('inf')
for i in range(26):
    cnt=0
    for j in range(1,len(x[i])):
        cnt=max(x[i][j]-x[i][j-1]-1,cnt)
    ans=min(cnt,ans)
print(ans)

Solution (Python):
INF = 10 ** 8
def main():
    s = input()
    word = list(set(s))
    output = INF
    for c in word:
        t = s
        cnt = 0
        while len(set(t)) > 1:
            l = []
            for i in range(len(t)-1):
                if t[i] == c or t[i+1] == c: l.append(c)
                else: l.append(t[i])
            t = ''.join(l)
            cnt += 1
        output = min(output, cnt)
    print(output)
    return

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
ans = len(S)
for c in set(S):
    maxi = count = 0
    for s in S:
        if s != c:
            count += 1
        else:
            maxi = max(maxi, count)
            count = 0
    maxi = max(maxi, count)
    ans = min(ans, maxi)
print(ans)

Solution (Python):
import math
import fractions



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rln(s):
    return range(len(s))










ss = input()
n = len(ss)

ans = 99999999999
ok = 1

for i in range(26):
    s = ss
    letter = chr(ord('a')+i)
    while(len(s)>=1):
        ok = 1
        for i in s:
            ok *= 1 if i==letter else 0
        if(ok==1):
            break
        text = ""
        for j in range(len(s)-1):
            if(s[j+1] == letter):
                text+= letter
            else:
                text+=s[j]
        s = text
    ans = min(ans,n-len(s))

print(ans)

Solution (Python):


from collections import Counter
s = input()
c = Counter(s)
ans = float('inf')
for k, v in c.items():
    
    
    t = [-1]
    for i in range(len(s)):
        if s[i] == k:
            t.append(i)
    t.append(len(s))
    temp = []
    for j in range(len(t) - 1):
       temp.append(t[j + 1] - t[j] - 1)
    ans = min(ans, max(temp))
print(ans)

Solution (Python):
ans = {}
t = input()
for i in range(len(t)):
    if t[i] not in ans:
        ans[t[i]] = i + 1

    for j in range(i+1, len(t)):
        if t[i] == t[j]:
            if t[i] in ans:
                ans[t[i]] = max(ans[t[i]], abs(j - i))
            else:
                ans[t[i]] = abs(j - i)
            
            break
    
        if j == len(t) - 1:
            ans[t[i]] = max(ans[t[i]], abs(j + 1 - i))


print(min(ans.values()) - 1)

Solution (Python):
S = input()
result = 10**4
for c in set(S):
    work = []
    temp = 0
    for s in S:
        if s == c:
            work.append(temp)
            temp = 0
        else:
            temp += 1
    work.append(temp)
    result = min(result, max(work))
print(result)

Solution (Python):
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def rle(s, tar):
    ans = []
    hoge = 0
    for i in range(len(s)):
        if s[i] != tar:
            hoge += 1
        else:
            ans.append(hoge)
            hoge = 0
    ans.append(hoge)
    return ans

def solve():
    s = list(input())
    ele = sorted(list(set(s)))
    le = len(ele)
    n = len(s)
    cost = [0]*le
    for i in range(le):
        cost[i] = max(rle(s, ele[i]))
    print(min(cost))
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from collections import Counter
s=input()
c=Counter(s).most_common()
ans=10**10
top=c[0][1]
for k,x in c:
    N=len(s)
    m=k
    cnt=0
    tmp=s
    for i in range(100):
        cn=Counter(tmp).most_common()
        if(cn[0][1]==len(tmp)):
            ans=min(ans,cnt)
            break
        l=''
        for j in range(N-1):
            if(tmp[j]==m or tmp[j+1]==m):
                l+=m
            else:
                l+=s[j]
        tmp=l
        cnt+=1
        N-=1
print(ans)

Solution (Python):
s = '_'+input()
l = len(s)
dist_lst = [0]*26
idx_lst = [0]*26
for i in range(1,l):
    c = ord(s[i])%26
    dist_lst[c] = max(dist_lst[c],i-idx_lst[c])
    idx_lst[c] = i
for c in range(26):
    dist_lst[c] = max(dist_lst[c],l-idx_lst[c])

print(min(dist_lst)-1)

Solution (Python):
s = input()
ans = len(s)
for i in range(26):
    c0 = chr(ord('a')+i)
    tmp = 0
    ma = 0
    for c in s:
        if c==c0:
            ma = max(ma, tmp)
            tmp = 0
        else:
            tmp += 1
    ma = max(ma, tmp)
    ans = min(ans, ma)
print(ans)

Solution (Python):
from collections import Counter
import sys
s = input()
n = len(s)

b = Counter(s)
c = list(b)
ssc = []
for i in range(n):
    ssc.append(s[i])

ans = 114514191933-4

if len(b) == 1:
    print(0)
    sys.exit()

for l in c:
    a = 0
    s2 = ssc
    ss = []
    for i in range(n-1):
        k = len(s2)
        for j in range(k-1):
            if s2[j] == l or s2[j+1] == l:
                ss.append(l)
            else:
                ss.append(s2[j+1])
                
        d = Counter(ss)
        if d[l] == k-1:
            ans = min(n-len(ss),ans)
            break
            
        s2 = ss
        ss = []
    
print(ans)

Solution (Python):
string=list(input())
n=len(string)
s=set()
ans=10**4

for target in string:
    if target in s:
        continue
    
    cnt=0
    tmp_max=0
    for i in string:
        if i!=target:
            cnt+=1
        else:
            tmp_max=max(tmp_max,cnt)
            cnt=0
    tmp_max=max(tmp_max,cnt)
    ans=min(ans,tmp_max)
        
print(ans)

Solution (Python):
s = list(input())

A = list(set(s))

B = []

for i in range(len(A)):
    C = []
    for j in range(len(s)):
        if A[i] == s[j]:
            C.append(j)
    C.append(-1)
    C.append(len(s))
    C = sorted(C)
    D = []
    for i in range(len(C) - 1):
        D.append(C[i+1] - C[i] - 1)
    
    B.append(max(D))
print(min(B))

Solution (Python):
s = input()
n = len(s)

chars = [chr(i) for i in range(97, 97+26)]

res = 1 << 30
for c in chars:
	cnt = 0
	t = s
	while len(set(list(t))) > 1:
		u = []
		for i in range(len(t) - 1):
			if t[i] == c or t[i + 1] == c:
				u.append(c)
			else:
				u.append(t[i])
		cnt += 1
		t = ''.join(u)
	res = min(res, cnt)

print(res)

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
mx = [0]*26
cur = [0]*26
for c in s:
    for j in range(26):
        d = chr(ord('a')+j)
        if c==d:
            cur[j] = 0
        else:
            cur[j] += 1
            mx[j] = max(mx[j],cur[j])
    
    
    
print(min(mx))

Solution (Python):
from _collections import defaultdict
s=input()
X=defaultdict(int)
l=len(s)
for i in s:
    X[i]+=1
ANS=[]
for key in X.keys():
    a=0
    cnt=0
    for i in range(l):
        if s[i]==key:
            a=max(a,cnt)
            cnt=0
        else:
            cnt+=1
    ANS.append(max(a,l-s.rfind(key)-1))
print(min(ANS))

Solution (Python):
s = list(input())

S = set(s)
res = 0
for k in S:
	t = s[::]
	while len(set(t)) != 1:
		t.pop()
		for i in range(len(t) - 1):
			if t[i] == k or t[i + 1] == k:
				t[i] = k
			else:
				t[i] = t[i]
	ma = len(t)
	res = max(res, len(t))

print(len(s) - res)

Solution (Python):
from collections import Counter
from copy import deepcopy
def main():
    s = list( input())
    N = len(s)
    C = Counter(s)
    ans = 100
    for i in range(26):
        S = deepcopy(s)
        a = chr( ord("a") + i)
        t = N
        c = C[a]
        if c == 0:
            continue
        
        while t > c:
            t -= 1
            for j in range(t):
                if S[j] != a and S[j+1] == a:
                    S[j] = a
                    c += 1
            if S[t] == a:
                c -= 1
        
        if N-t < ans:
            ans = N-t
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
S = str(input())
ans = 10**18
alp = list(set(S))

for i in alp:
  count = 0
  eff = 0
  for j in S:
    if i != j:
      count += 1
    else:
      eff = max(eff,count)
      count = 0
  eff = max(eff, count)
  ans = min(ans, eff)
  
print(ans)

Solution (Python):
s=list(input())
cnt=100
for i in range(26):
    x=chr(97+i)
    if x not in s:
        continue
    tmp=0
    dummy=s+[]
    while len(set(dummy))>1:
        tmp+=1
        newdum=[]
        for j in range(len(dummy)-1):
            if dummy[j]==x or dummy[j+1]==x:
                newdum.append(x)
            else:
                newdum.append(dummy[j])
        dummy=[]+newdum
    cnt=min(cnt,tmp)
print(cnt)

Solution (Python):
s=list(input())
cnt=100
for i in range(26):
    x=chr(97+i)
    if x not in s:
        continue
    tmp=0
    dummy=s+[]
    while len(set(dummy))>1:
        tmp+=1
        newdum=[]
        for j in range(len(dummy)-1):
            if dummy[j]==x or dummy[j+1]==x:
                newdum.append(x)
            else:
                newdum.append(dummy[j])
        dummy=[]+newdum
    cnt=min(cnt,tmp)
print(cnt)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



s = input()
x = "abcdefghijklmnopqrstuvwxyz"
ans = INF
for i in x:
    s2 = s
    s3 = ""
    cnt = 0
    while len(set([k for k in s2])) > 1:
        for j in range(len(s2) - 1):
            if s2[j + 1] == i:
                s3 += i
            else:
                s3 += s2[j]
        cnt += 1
        s2 = s3
        
        s3 = ""
    ans = min(ans, cnt)
print(ans)

Solution (Python):
import collections
s = input()
ss = set(s)

ans = float('inf')

for c in ss:
    cnt = 0
    back = 0
    
    for si in s:
        if c != si:
            cnt += 1
        else:
            back = max(back, cnt)
            cnt = 0
    back = max(back, cnt)
    ans = min(ans, back)
    
print(ans)

Solution (Python):
s=input()
s2=[]
for i in range(len(s)):
    s2.append(s[i])
s3=sorted(list(set(s2)))
ans=10**9
for x in range(len(s3)):
    memo=s3[x]
    cnt=0
    t=s
    p=len(s.replace(memo,""))
    while p!=0:
        t2=""
        l=len(t)
        k=0
        while k<l-1:
            if t[k]==memo or t[k+1]==memo:
                t2=t2+memo
            else:
                t2=t2+t[k]
            k+=1
        t=t2
        cnt+=1
        p=len(t2.replace(memo,""))
    if cnt<ans:
        ans=cnt
print(ans)

Solution (Python):
s = input()
ans = float('inf')
for x in s:
    cnt = 0
    temp = s
    while len(set(temp))!=1:
        t = ''
        for i in range(len(temp)-1):
            if temp[i+1]==x:
                t += temp[i+1]
            else:
                t += temp[i]
        temp = t
        cnt += 1
    ans = min(ans,cnt)
print(ans)

Solution (Python):
S = input()

slist = "abcdefghijklmnopqrstuvwxyz"

tmp = 0
tmps = []
ans = len(S)
for char in set(S):
    for s in S:
        if s != char:
            tmp += 1
        else:
            tmps.append(tmp)
            tmp = 0
    tmps.append(tmp)
    ans = min(ans,max(tmps))
    tmps = []
    tmp = 0

print(ans)

Solution (Python):
def myAnswer(s:list) -> int:
   setS = set(s)
   if(len(setS) == 1): return 0
   ans = 10**9
   while len(setS) != 0:
      target = setS.pop()
      counter = 0
      tmp = s[:]
      while True:
         pre = tmp.pop(0)
         N = len(tmp)
         for i in range(N):
            now = tmp.pop(0)
            if(pre == target or now==target):
               tmp.append(target)
            else:
               tmp.append(now)
            pre = now
         counter += 1
         if(len(set(tmp))==1):
            break
      ans = min(ans,counter)
   return ans



def modelAnswer():
   return
def main():
   s = list(input())
   print(myAnswer(s[:]))
if __name__ == '__main__':
   main()

Solution (Python):
s = input()
n = len(s)
ans = 1000
for t in set(s):
    ans = min(ans, max([len(l) for l in s.split(t)]))
print(ans)

Solution (Python):
S = input()
chrs = set(S)

if len(chrs) == 1:
    ans = 0
else:
    ans = len(S)
    for c in chrs:
        cnt = 0
        cur = S
        while True:
            new = ""
            for i in range(len(cur) - 1):
                if cur[i] == c or cur[i + 1] == c:
                    new += c
                else:
                    new += "*"
            cnt += 1
            if len(set(new)) == 1:
                break
            cur = new

        if cnt < ans:
            ans = cnt

print(ans)

Solution (Python):
import math
s = input()
s_li = list(s)

import collections
c = collections.Counter(s_li)
common_li = c.most_common()

sp_li = s.split(common_li[0][0])


def check(sp_li):
    count = []
    if len(sp_li)==0:
        return 0
    else:
        count = []
        for i,s in enumerate(sp_li):
            count.append(len(s))
        return max(count)


all_li = []
kaisuu = 0
for i,c in enumerate(common_li):
    
    sp_li = s.split(c[0])
    all_li.append(check(sp_li))


print(min(all_li))

Solution (Python):
s = input()
ans = 10**18

for i in range(26):
    
    cnt = 0
    tmp = 0
    if s.count(chr(i+65+32)) == 0:
        continue
    
    for j in range(len(s)):
        if s[j] == chr(i+65+32):
            tmp = max(tmp,cnt)
            cnt = 0
        else:
            cnt += 1
    tmp = max(tmp,cnt)
    
    ans = min(ans,tmp)
            
print(ans)

Solution (Python):
s = input()

ans = 1000
for c in set(s):
    ans = min(ans, max([len(si) for si in s.split(c)]))
print(ans)

Solution (Python):
s = input()
N = len(s)
ans = 1000
for t in set(s):
  ans = min(ans, max([len(l) for l in s.split(t)]))
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
a = ord('a')

al = [chr(i) for i in range(ord('a'), ord('z')+1)]
ans = 100

for c in al:
    L = list(s.split(c))
    x = 0
    for y in L:
        x = max(x,len(y))
    ans = min(x,ans)

print(ans)

Solution (Python):
S = input()
n = len(S)
ans = 1e100
for i in range(26):
    t = chr(ord('a') + i)
    if t not in S:continue
    tmp = 0
    cnt = 0
    for s in S + t:
        if s == t:
            tmp = max(tmp, cnt)
            cnt = 0
        else:
            cnt += 1
    ans = min(ans, tmp)
print(ans)

Solution (Python):
s = list(input())

def check(c):
    if c not in s:
        return float('inf')

    cnt = 0
    ans = 0
    for i in s:
        if i==c:
            cnt = 0
        else:
            cnt += 1
        ans = max(ans, cnt)
    return ans

ans = float('inf')
for i in range(97, 97+26):
    c = chr((i))
    ans = min(ans, check(c))

print(ans)

Solution (Python):
s = input()

if len(set(s)) == len(s):
    print(len(s)//2)
    exit()

ans = len(s)
for ml in [chr(i) for i in range(ord('a'), ord('z')+1)]:
    tmp = -1
    tmp_ans = 0
    for i in range(len(s)):
        if s[i] == ml:
            tmp_ans = max(tmp_ans, i - tmp - 1)
            tmp = i
    tmp_ans = max(tmp_ans, len(s) - tmp - 1)
    ans = min(ans, tmp_ans)

print(ans)

Solution (Python):

"""
毎回消去される文字は選べるもんだと思っていたら、必ず最後尾
の文字が無くなる感じだった。
出現する文字全てに対し最も長いところが答え。
"""
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')

dic1 = defaultdict(int)
for i in s:
    dic1[i] += 1

lst1 = []
for i,j in dic1.items():
    lst1.append([j,i])
lst1.sort(reverse=True)

ans = 10**10
for i,j in lst1: 
    target = j
    res = []
    res2 = 0
    for k in s:
        if k==target:
            res.append(res2)
            res2 = 0
        else:
            res2+=1
    res.append(res2)
    ans_res = max(res)
    ans = min(ans,ans_res)

print(ans)

Solution (Python):
s = input()
t = set(s)
ans = 10**10
for c in t:
  cnt = 0
  x = s
  while len(set(x))!=1:
    ns = ''
    for i in range(len(x)-1):
      if x[i]==c or x[i+1]==c:
        ns += c
      else:
        ns += x[i]
    if ns==x:
      break
    x = ns
    cnt += 1
  else:
    ans = min(cnt,ans)
print(ans)

Solution (Python):
def calc(s,char):
  cnt=0
  while s.count(char)<len(s):
    t=""
    for i in range(len(s)-1):
      if char in s[i:i+2]:
        t+=char
      else:
        t+="0"
    s=t
    cnt+=1
  return cnt

s=input()
ans=100
for i in range(26):
  char=chr(ord('a')+i)
  ans=min(ans,calc(s,char))
print(ans)

Solution (Python):
s = input()
ans = 10 ** 9
for alpha in range(97,123):
    a = chr(alpha)
    cnt = 0
    ret = 0
    for i in range(len(s)):
        if s[i] == a:
            ret = max(ret,cnt)
            cnt = 0
        else:
            cnt += 1
    ret = max(ret,cnt)
    ans = min(ans,ret)
print(ans)

Solution (Python):
import collections
s = list(input())
t = list(enumerate(s[:]))
eng = [chr(ord('a') + i) for i in range(26)]
u = len(s)

ans = []
for i in eng:
    kar = [-1]
    kar.extend([j for j, v in t if v == i])
    kar.append(u)
    tyu = len(kar)
    if tyu == 2:
        continue
    f = 0
    for j in range(tyu-1):
        f = max(f,kar[j+1]-kar[j]-1)
    ans.append(f)

print(min(ans))

Solution (Python):
S = input()
print(min(max(map(len, S.split(s))) for s in S))

Solution (Python):

from collections import Counter, deque 
from copy import copy, deepcopy











import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=10**4
    s=list(input())
    ss=Counter(s)
    if len(ss)==1:
        ans=0
    else:
        for k in ss.keys():
            l=copy(s)
            cnt=0

            while True:
                for i in range(len(l)-1):
                    if l[i]==k or l[i+1]==k:
                        l[i]=k
                    else:
                        continue
                l=l[:-1]
                cnt+=1
                if len(set(l))==1:
                    ans=min(ans,cnt)
                    break
    print(ans)




resolve()

Solution (Python):
s = input()

def func(st,char):
    ans = [None] * (len(st) - 1)
    for i in range(len(ans)):
        if st[i] == c or st[i + 1] == c:
            ans[i] = c
        else:
            ans[i] = st[i]
    
    return ''.join(ans)
m = 10 ** 5
for i in range(26):
    work = s
    c = chr(ord('a') + i)
    
    cnt = 0
    while len(set(list(work))) != 1:
        work = func(work, c)
        cnt += 1
        
    m = min(m, cnt)
print(m)

Solution (Python):
s = input()
d = {}
ans = float("inf")
for i, a in enumerate(s):
    if a not in d:
        d[a] = [i + 1]
    else:
        d[a].append(i + 1)
for k in d.keys():
    c = 0
    for i in range(1, len(d[k])):
        c = max(c, d[k][i] - d[k][i - 1] - 1)
    ans = min(ans, max(c, d[k][0] - 1, len(s) - d[k][-1]))
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
u = list(set(s))
ans = inf
for c in u:
    strt = s.index(c)
    res = strt
    cnt = 0
    for i in range(strt + 1, len(s)):
        if s[i] == c:
            res = max(res, cnt)
            cnt = 0
        else:
            cnt += 1
    res = max(res, cnt)
    ans = min(ans, res)
print(ans)

Solution (Python):
S = input()

ans = 100
for s in S:
  n=list(map(len,S.split(s)))
  ans=min(ans,max(n))

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    s = list(input().strip())

    def solve(c, s):
        if c not in s:
            return float('inf')
        ret = 0
        while s != [c] * len(s):
            f = True
            ret += 1
            s_ = [''] * (len(s)-1)
            for i in range(len(s)-1):
                if s[i] == c or s[i+1] == c:
                    s_[i] = c
                else:
                    s_[i] = s[i]
                    f = False
            s = s_[:]
            if f:
                break
        
        return ret
        
    ret = float('inf')
    for c in 'abcdefghijklmnopqrstuvwxyz':
        ret = min(ret, solve(c, s[:]))

    print(ret)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()

cnt = 10 ** 9
for s in S:
    nex = list(S)
    tmp = 0
    while len(set(nex)) > 1:
        tmp += 1
        L = len(nex)
        now = nex
        nex = []
        for i in range(L-1):
            if s in now[i:i+2]:
                nex.append(s)
            else:
                nex.append(now[i])
    cnt = min(cnt, tmp)
print(cnt)

Solution (Python):
s = input()
l = list(set(s))

if len(set(s)) == 1:
    print(0)
    exit()

min_c = 10**8
for i in l:
    old_s = s
    new_s = ''
    idx = 1
    c = 0
    
    while True:
        for j in range(len(s)-idx):
            if old_s[j] == i or old_s[j+1] == i:
                new_s += i
            
            else:
                new_s += old_s[j]
        
        idx += 1
        c += 1
        
        if len(set(new_s)) == 1:
            break
        
        else:
           old_s = new_s
           new_s = ''
    
    min_c = min(min_c,c)

print(min_c)

Solution (Python):
s = input() 

count = 0
ans=len(s)
tmp=0
for cc in list(set(s)):

    for i in range(len(s)):
        if s[i]==cc:
            tmp = max(tmp,count)
            count = 0
        else:
            count+=1

    tmp = max(tmp,count)

    ans = min(ans,tmp)
    tmp=0
    count=0

print(ans)