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()
exitLower = list(set(list(s)))
m = len(s)

for alp in exitLower:
    SL = list(s)
    cnt = 0
    while len(set(SL)) > 1:
        for i in range(len(SL)-1):
            if SL[i+1] == alp:
                SL[i] = alp
        SL.pop()
        cnt += 1
    m = min(m,cnt)

print(m)

Solution (Python):
S = input()
A = list(set(S))
minv = len(S) // 2
for a in A:
	maxv = 0
	v = 0
	for c in S:
		if a == c:
			v = 0
		else:
			v += 1
			maxv = max(maxv, v)
	minv = min(minv, maxv)
print(minv)

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


abc_kind = set(s)
ans = n
for x in abc_kind:
    
    
    cnt = 0
    t = s
    while len(t) != t.count(x):
        t = ''.join([x if x in (a, b) else a for a, b in zip(t, t[1:])])
        cnt += 1
    if cnt < ans:
        ans = cnt
print(ans)

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


for i in range(n):
    
    
    table = [[0]*(n-i) for _ in range(26)]

    for j in range(n):
        x = s[j]
        x = ord(x)-ord('a')
        L = max(0, j-i)
        if table[x][L]:
            L += 1
        R = min(j+1, L+i+1, n-i)
        for k in range(L, R):
            table[x][k] = 1

    if any(0 not in row for row in table):
        print(i)
        break

Solution (Python):

import copy

s=list(input())
times=[0]*26

ans=float('inf')


for i in s:
  temp=copy.deepcopy(s)
  tempans=0
  while True:
    
    if temp.count(i)==len(temp):
      ans=min(ans,tempans)
      break
    else:
      for j in range(len(temp)-1):
        if temp[j+1]==i:
          temp[j]=i
      tempans+=1
      del temp[-1]
      
      
print(ans)

Solution (Python):
from collections import defaultdict

s = list(input())
n = len(s)

cnt = defaultdict(list)

for i in range(n):
    cnt[s[i]].append(i)
ans = float("inf")
for k, l in cnt.items():
    res = l[0]
    for i in range(1, len(l)):
        res = max(res, l[i] - l[i-1] - 1)
    res = max(res, n - l[-1] - 1)
    ans = min(ans, res)

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    ans = len(S)
    for i in range(len(S)):
        tmp = 0
        ma = 0
        for j in range(i + 1):
            if S[i] == S[j]:
                ma = max(ma, tmp)
                tmp = 0
            else:
                tmp += 1
        ans = min(ans, max(ma, len(S) - i - 1))

    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
S = input()
res = len(S)
kind_all = set(S)
for i in kind_all:
    temp = S.split(i)
    cnt = 0
    for j in temp:
        cnt = max(cnt,len(j))
    res = min(res,cnt)
print(res)

Solution (Python):
import collections

s = list(input())
c = collections.Counter(s)

lm = list()
for i in list(c.keys()):
    l = [-1]
    for j in range(len(s)):
        if s[j] == i:
            l.append(j)
    l.append(len(s))
    lm.append(max([l[k+1]-l[k]-1 for k in range(len(l)-1)]))

print(min(lm))

Solution (Python):
s = input()
ans = 10 ** 10
for i in range(26):
    c = chr(ord("a") + i)
    s_c = list(s)
    cnt = 0
    while len(set(s_c)) != 1:
        t = ""
        for i in range(len(s_c) - 1):
            if s_c[i + 1] == c:
                t += c
            else:
                t += s_c[i]
        cnt += 1
        s_c = t
    ans = min(ans, cnt)

print(ans)

Solution (Python):
s = input()
ans = 10 ** 10
for i in range(26):
    c = chr(ord("a") + i)
    s_c = list(s)
    cnt = 0
    while len(set(s_c)) != 1:
        t = ""
        for i in range(len(s_c) - 1):
            if s_c[i] == c or s_c[i + 1] == c:
                t += c
            else:
                t += s_c[i]
        cnt += 1
        s_c = t
    ans = min(ans, cnt)

print(ans)

Solution (Python):
s = input()

ans = 100
for i in range(97, 123):
    c = chr(i)
    
    t = s
    while True:
        if t.count(c) == len(t):
            ans = min(ans, len(s) - len(t))
            break
        new = ""
        for j in range(len(t) - 1):
            if t[j] == c or t[j + 1] == c:
                new += c
            else:
                new += t[j]
        t = new
print(ans)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    s = list(input())

    l = len(s)
    ans = l // 2

    for i in range(97, 97 + 26):
        word = chr(i)
        cnt = 0
        tmp_max = -1
        for j in range(l):
            if s[j] != word:
                cnt += 1
            else:
                tmp_max = max(tmp_max, cnt)
                cnt = 0
        ans = min(ans, max(tmp_max, cnt))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
l=[chr(i) for i in range(ord("a"),ord("z")+1)]
a=100
for i in l:
    t=0
    c=0
    for j in s:
        if j!=i:
            c+=1
        else:
            if t<c:
                t=c
            c=0
    t=max(t,c)
    if a>t:
        a=t
print(a)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    

    s = input().rstrip()
    ss = set(s)

    def test(s, ss):
        res = 0
        while len(set(s)) > 1:
            temp = ''
            for i in range(len(s)-1):
                if s[i] == ss or s[i+1] == ss:
                    temp += ss
                else:
                    temp += s[i]
            s = temp[:]
            res += 1

        return res

    res = 10000000000
    for i in ss:
        res = min(res, test(s, i))
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
ans = 100
for i in range(26):
    cur = 0
    c = chr(ord('a') + i)
    t = s
    if(not c in t): continue
    t2 = ""
    while(t.count(c) != len(t)):
        for j in range(len(t) - 1):
            if(t[j] == c or t[j + 1] == c):
                t2 += c
            else:
                t2 += 'A'
        cur += 1
        t = t2
        t2 = ""
    ans = min(cur, ans)
print(ans)

Solution (Python):
S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1


for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    cnt += 1
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        if i < L-1:
          newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if i < L-1 and not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)

Solution (Python):
s = input()
from string import ascii_lowercase as abc
ans = 1000
for i in abc:
    ans = min(ans, max(list(map(len, s.split(i)))))
print(ans)

Solution (Python):
s = input()
r = 100;
for x in range(97, 97+26):
  cnt = 0
  m = 0
  for c in s:
    if c == chr(x):
      m = max(m, cnt)
      cnt = 0
    else:
      cnt += 1
  m = max(m, cnt)
  r = min(r, m)
print(r)

Solution (Python):
S = str(input())
ans = 10 ** 9 + 7
for i in range(ord('a'), ord('z')+1):
    ans = min(ans, max([len(s) for s in S.split(chr(i))]))

print(ans)

Solution (Python):
import copy
s = input()
ans=10000
for i in range(26):
    now = chr(97+i)
    a = copy.copy(s)
   
    count=0
    while len(set(a))!=1:
        a_now=""
        for i in range(len(a)-1):
            if a[i] == now or a[i+1] == now:
                a_now += now
            else:
                a_now += a[i]
        
        a = copy.copy(a_now)
        count+=1
    
    ans=min(ans,count)
print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

S = readline().rstrip()

ans = 10 ** 10
for i in range(ord("a"),ord("z") + 1):
  ans = min(ans, max(map(len,S.split(chr(i)))))
  
print(ans)

Solution (Python):




import sys
readline = sys.stdin.readline

S = readline().rstrip()

a = ord("a")
z = ord("z")

ans = 10 ** 10
for i in range(a,z + 1):
  arr = S.split(chr(i))
  maxlen = 0
  for a in arr:
    if len(a) > maxlen:
      maxlen = len(a)
  if maxlen < ans:
    ans = maxlen
  
print(ans)

Solution (Python):
s = input()
ans = len(s)
for c in set(s):
    new_s = s
    while len(set(new_s)) > 1:
        tmp = ""
        for i in range(len(new_s) - 1):
            tmp += c if new_s[i] == c or new_s[i + 1] == c else new_s[i]
        new_s = tmp
    ans = min(ans, len(s) - len(new_s))
print(ans)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    st = set(s)
    mi = 10**18
    for i in st:
        ma = 0
        nr = 0
        for j in s:
            if j == i:
                if ma < nr:
                    ma = nr
                nr = 0
            else:
                nr += 1
        if nr > ma:
            ma = nr
        if mi > ma:
            mi = ma
    print(mi)

    return

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
S = list(input())
abc = [chr(ord('a') + i) for i in range(26)]

ans = 100000
for s in abc:
    result = S
    count = 0
    while len(set(result)) > 1:
        count += 1
        tmp = ["dd"] * (len(result) - 1)
        for i in range(len(result)-1):
            if result[i] == s or result[i+1] == s:
                tmp[i] = s
            else:
                tmp[i] = result[i]
        result = tmp
    ans = min(ans, count)

print(ans)

Solution (Python):
s = input()
L = []

ans = float('inf')
for l in s:
    cnl = 0
    anl = 0
    for s_ in s:
        if l == s_:
            anl = max(anl, cnl)
            cnl = 0
        else:
            cnl += 1
    anl = max(anl, cnl)
    ans = min(ans, anl)

print(ans)

Solution (Python):
from collections import Counter
s = input()
c = Counter(s)
ans = float("inf")
for i in c.keys():
    t = list(s)
    while t != [i]*len(t):
        u = []
        for j in range(len(t)-1):
            if t[j] == i or t[j+1] == i:
                u.append(i)
                continue
            u.append(t[j])
        t = u
    ans = min(ans,len(s)-len(t))
print(ans)

Solution (Python):




import math
import sys
import bisect
import heapq  
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

s = input()

al=[chr(ord('a') + i) for i in range(26)]
ans = inf
for c in al:
    pre = 0
    maxpre = 0
    for now in s:
        if c == now:
            maxpre = max(pre, maxpre)
            pre = 0
        else:
            pre += 1
    maxpre = max(pre, maxpre)
    ans = min(ans, maxpre)
print(ans)

Solution (Python):
s = input()
def f(s,c):
    result = 0
    while len(set(s)) != 1:
        t = ""
        for i in range(len(s)-1):
            
            if s[i] == c or s[i+1] == c:
                
                t += c
            else:
                t += s[i]
        
        s = t
        result += 1
    return result
result = float('inf')
for c in set(s):
    result = min(result, f(s,c))
print(result)

Solution (Python):
s = input();
a = "abcdefghijklmnopqrstuvwxyz"
b = [0]*26
c = [0]*26
for i in s:
  for j in range(26):
    if i == a[j]:
      c[j] = max(c[j],b[j])
      b[j] = 0
    else:
      b[j] += 1
print(min([max(i,j) for i,j in zip(b,c)]))

Solution (Python):
s = input()
s_str = set(list(s))
ans = 101
for char in s_str:
    t = s
    count = 0
    while len(set(list(t))) > 1:
        next_t = ''        
        for i in range(len(t) - 1):
            if (t[i] == char) | (t[i + 1] == char):
                next_t += char
            else:
                next_t += t[i]
        t = next_t
        count += 1
    ans = min(ans, count)
print(ans)

Solution (Python):
alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

s=input()
for i in range(1,len(s)):
    if s[i]!=s[0]:
        break
else:
    print(0)
    exit()

ans=100
for moji in alphabetlist:
    count=0
    test=s
    while test:
        new=""
        flag=True
        for i in range(0,len(test)-1):
            if test[i]!=moji and test[i+1]!=moji:
                new+=test[i]
                flag=False
            else:
                new+=moji
        count+=1
        test=new
        if flag:
            break
    ans=min(ans,count)

print(ans)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def main():
    s = IS()
    cnt = len(s)
    for c in set(s):
        dist = 0
        max_d = 0
        for si in s:
            if c != si:
                dist += 1
            else:
                max_d = max(max_d, dist)
                dist = 0
        cnt = min(cnt, max(max_d, dist))
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

MOD=10**9+7

import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
import string

def main():
    s = IS()
    n = len(s)
    sc = set(s)
    ans = 10**9
    for c in string.ascii_lowercase:
        if c not in sc: continue
        cnt = 0
        t = s
        for l in range(n):
            u = ''
            if set(t) == {c}: break
            for i in range(len(t)-1):
                if t[i] == c or t[i+1] == c:
                    u += c
                else:
                    u += t[i]
            cnt += 1
            t = u
        ans = min(cnt, ans)
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
s = input()
a = [[-1] for i in range(26)]

for i in range(len(s)):
    a[ord(s[i])-ord('a')].append(i)

for i in range(26):
    a[i].append(len(s))

ans = float('inf')
for i in range(26):
    ma = 0
    for j in range(1,len(a[i])):
        dis = a[i][j]-a[i][j-1]-1
        ma = max(dis,ma)
    ans = min(ma,ans)

print(ans)

Solution (Python):
S = input()
N = len(S)
s_set = set(S)
if len(s_set) == 1:
  print(0)
  quit()

ans = 100

def change_to_s(s):
  flag = True
  T = S
  while flag:
    _T = ''
    flag = False
    for i in range(len(T)-1):
      if s in [T[i], T[i+1]]:
        _T += s
      else:
        _T += T[i]
        flag = True
    T = _T
  return N - len(_T), _T

for s in s_set:
  n, t = change_to_s(s)
  ans = min(ans, n)

print(ans)

Solution (Python):
from collections import Counter
s = input()
c = Counter(s)
ans = float("inf")
for i in c.keys():
    s2 = list(s)
    cnt = 0
    while s2:
        if len(set(s2)) == 1:
            break
        for j in range(len(s2) - 1):
            if s2[j] == i or s2[j + 1] == i:
                s2[j] = i
            else:
                continue
        s2 = s2[:-1]
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Solution (Python):
s = input().strip()
l = len(s)

def f(s,c,l,v=1):
    n = 0
    for i in range(l-1):
        if s[i] != c:
            if s[i+1] == c:
                s = s[:i] + c + s[i+1:]
                n += 1
        else:
            n += 1
    
    if n < l-1:
        return f(s[:-1], c, l-1, v+1)
    else:
        return v

if s.count(s[0]) == l:
    print(0)
    exit()

min = l 
for i in set(s):
    x = f(s, i, l)
    if min > x:
        min = x
print(min)

Solution (Python):
from collections import Counter

s = input()
s_len = len(s)
c = Counter(s)
ans = float('inf')
for k in c.keys():
    tmp = list(s)
    cnt = 0
    while True:
        if len(set(tmp)) == 1:
            break
        for i in range(len(tmp)-1):
            if tmp[i] == k:
                tmp[i] = k
            elif tmp[i+1] == k:
                tmp[i] = k
            else:
                continue
        else:
            tmp = tmp[:-1]
            cnt += 1
    ans = min(ans,cnt)
print(ans)

Solution (Python):
s = input()
set_s = set(s)
ss = s[:]
t = []
_min = 10**7

for j in set_s:
    ss = s[:]
    t = []
    cnt = 0
    while len(set(ss)) != 1:
        for i in range(len(ss) - 1):
            if ss[i] == j or ss[i+1] == j:
                t.append(j)
            else:
                t.append(ss[i+1])
        ss = t[:]
        t.clear()
        cnt += 1
    
    _min = min(_min,cnt)    
print(_min)

Solution (Python):
s = input()


sl = list(s)


ans = 101

for i in range(26):
    cur_char = chr(ord('a') + i)

    if not cur_char in sl:
        continue

    sl_cp = sl.copy()

    while not len(set(sl_cp)) == 1:

        for i in range(len(sl_cp)-1):
            if sl_cp[i+1] == cur_char:
                sl_cp[i] = cur_char

        sl_cp.pop()

    ans = min(ans, len(sl) - len(sl_cp))

print(ans)

Solution (Python):
s = str(input())
S = list(set(s))
d = {}
for v in S:
    x = s
    cnt = 0
    while x.count(v) < len(x):
        new_x = [0] * (len(x) - 1)
        for i in range(len(x) - 1):
            if x[i] == v or x[i + 1] == v:
                new_x[i] = v
        cnt += 1
        x = new_x
    d[v] = cnt
print(min(d.values()))

Solution (Python):
s = list(input())
al = [chr(i) for i in range(97, 97+26)]
ans = []

for a in al:
    c = 0
    if s.count(a) == 0:
        continue
    temp = s.copy()
    while not all(i == a for i in temp):
        c += 1
        n_temp = temp.copy()
        for n, j in enumerate(temp):
            if n == 0 and j == a:
                continue
            elif j == a:
                n_temp[n-1] = a
        temp = n_temp[:len(temp)-1]
    ans.append(c)
print(min(ans))

Solution (Python):
s = input()
ans = 10**18
for i in range(97,97+26):
  x = chr(i)
  ls = []
  tt = 0
  for j in s:
    if j != x:
      tt += 1
    else:
      ls.append(tt)
      tt = 0
  ls.append(tt)
  ans = min(ans,max(ls))
print(ans)

Solution (Python):
import copy
S = list(map(str, input().rstrip()))

vari = set(S)

ans = float("inf")

for v in vari:
    s = copy.deepcopy(S)
    while len(s) != s.count(v):
        for i in range(1, len(s)):
            if s[i] == v:
                s[i - 1] = v
        s = s[:-1]
    ans = min(ans, len(S) - len(s))

print(ans)

Solution (Python):
s = input()
ans = 1000
for c in 'abcdefghijklmnopqrstuvwxyz':
    t = s
    if c not in t:
        continue
    tmp = 0
    while len(set(t)) > 1:
        res = ''
        for i in range(len(t)-1):
            if t[i] == c or t[i+1] == c:
                res += c
            else:
                res += '0'
        t = res
        tmp += 1
    ans = min(ans, tmp)

print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

s = ns()
c = Counter(s)

ans = inf
for i in c.keys():
    ns = i + s + i
    j = 1
    cur = 0
    res = 0
    while j < len(ns):
        if ns[j] == i:
            res = max(res, j - cur - 1)
            cur = j
        j += 1
    ans = min(ans, res)

print(ans)

Solution (Python):
s = input()
n = len(s)
chk = [[0] for i in range(n)]
cc = set()
d = {}
cnt = 0
for i,si in enumerate(s):
  if not si in cc:
    d[si] = cnt
    cnt += 1
    cc.add(si)
  chk[d[si]].append(i+1)

ans = n//2
for j in chk:
  p = 0
  j = j + [n+1]
  for k in range(len(j)-1):
    p = max(p,j[k+1]-j[k]-1)
    if p >= ans:
      break
    if k == len(j)-2:
      ans = min(p,ans)
print(ans)

Solution (Python):
def solve():
    S = input()
    ans = float('inf')

    for ch in set(S):
        dist = list(map(lambda x: len(x), S.split(ch)))
        ans = min(max(dist),ans)

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
import collections
s = input()
dic = collections.defaultdict(list)
for i in range(len(s)):
    dic[s[i]].append(i)
ans = 10000
for key in dic.keys():
    ls = [-1] + dic[key] + [len(s)]
    diff = []
    for i in range(len(ls)-1):
        diff.append(ls[i+1] - ls[i]-1)
    
    ans = min(max(diff),ans)
print(ans)

Solution (Python):
s = input()
a_z = [chr(i) for i in range(97, 97 + 26)]
ans = len(s)
for alp in a_z:
    cnt = 0
    step = 0
    for char in s:
        if char == alp:
            cnt = max(cnt, step)
            step = 0
        else:
            step += 1
    ans = min(max(cnt, step), ans)
print(ans)

Solution (Python):
from collections import Counter, deque

s = input()
n = len(s)
d = deque([{char} for char in s])
c = Counter(s)

if s[0] * n == s:
    print(0)
    exit()

for i in range(1, n):
    for j in range(n - i):
        char_j = s[j]
        char_right = s[j + i]
        set_j = d[j]
        if char_right not in set_j:
            set_j.add(char_right)
            c[char_right] += 1
    rightest = d.pop()
    for char in rightest:
        c[char] -= 1
    if max(c.values()) == n - i:
        print(i)
        exit()
print('oops, something wrong')

Solution (Python):
s=input()
ans=1000
import string
ss=string.ascii_lowercase
for c in list(ss):
    temp=s
    p=0
    nex=""
    while len(set(list(temp)))!=1:
        for i in range(len(temp)-1):
            if c in (temp[i],temp[i+1]):
                nex+=c
            else:nex+=temp[i]
        p+=1
        temp=nex
        nex=""
    ans=min(p,ans)
print(ans)

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


if len(se) == 1:
    print(0)
    exit()


def f(v):
    s_list = s.split(v)
    s_list = [len(i) for i in s_list if i]
    return max(s_list)


ans = 1000
for i in se:
    v = f(i)
    ans = min(ans, v)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





arr=list(ss())
mat=list(Counter(arr))
ans=10**100
for i in mat:
    tmp=deepcopy(arr)
    p=0
    while len(Counter(tmp))!=1:
        aa=[]
        for j in range(len(tmp)-1):
            if tmp[j] ==i or tmp[j+1]==i:
                aa.append(i)
            else:
                aa.append(tmp[j])
        tmp=deepcopy(aa)
        p+=1
    ans=min(ans,p)
print(ans)

Solution (Python):
S = input()
alphabet = [[-1] for a in range(26)]
for n,c in enumerate(S):
    s = ord(c) - 97
    alphabet[s].append(n)

ans = float("inf")
for A in alphabet:
    A.append(len(S))
    cur = max([abs(A[l] - A[l+1]) for l in range(len(A)-1)])
    ans = min(cur,ans)
print(max(ans -1 , 0))

Solution (Python):
s = list(input())
ans = len(s)
for c in set(s):
    dist = 0
    dists = []
    for d in s:
        if c != d:
            dist += 1
        else:
            dists.append(dist)
            dist = 0
    ans = min(ans, max(dists + [dist]))
print(ans)

Solution (Python):
s = list(input())
ans = len(s)
for c in s:
    dist = 0
    dists = []
    for d in s:
        if c != d:
            dist += 1
        else:
            dists.append(dist)
            dist = 0
    ans = min(ans, max(dists + [dist]))
print(ans)

Solution (Python):
from copy import copy
from string import ascii_lowercase


s = list(input())
ans = len(s)
for c in ascii_lowercase:
    t = copy(s)
    for i in range(len(s), 0, -1):
        if t == [c] * i:
            ans = min(ans, len(s) - i)
            break
        u = copy(t[:-1])
        for j in range(i - 1):
            if t[j] == c or t[j + 1] == c:
                u[j] = c
            else:
                u[j] = t[j]
        t = u
print(ans)

Solution (Python):


import numpy as np
import math
s = input()
def chang(st,string):
    cnt = 0    
    while True:
        if len(set(list(string))) == 1:
            
            return cnt
            break
        
        else:
            stn = ""
            for i in range(len(string)-1):
                if string[i]==st or string[i+1] ==st:
                    stn+=st
                else:
                    stn+=string[i]
            else:
                cnt+=1
                string = stn
                
d = set(list(s))
ans = 100
for i in d:
    ans = min(ans , chang(i,s))
print(ans)

Solution (Python):
s=input()
ans=1000
for i in range(26):
  if chr(97+i) not in s:continue
  S=s
  cnt=0
  while(len(set(S)))!=1:
    cnt+=1
    t=""
    for j in range(len(S)-1):
      if S[j] == chr(97+i) or S[j+1] == chr(97+i):
        t+=chr(97+i)
      else:
        t+=S[j]
    S=t
  ans=min(cnt,ans)
print(ans)

Solution (Python):
S=list(input())
ans=103
for i in range(26):
  A=[-1]
  for j in range(len(S)):
    if S[j]==chr(i+97):
      A.append(j)
  A.append(j+1)
  a=0
  for j in range(len(A)-1):
    a=max(a,A[j+1]-A[j]-1)
  if a<ans:
    ans=a
print(ans)

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



char_li = set(s)
ans=float('inf')
for char in char_li:
    ans=min(ans,max([len(l) for l in s.split(char)]))

print(ans)

Solution (Python):


s = input()
N = len(s)
ans = 1000

for i in range(N):
    count = count_max = 0
    for j in range(1,N+1):
        if s[i]==s[N-j]:
            count = 0
        else:
            count += 1
        count_max = max(count, count_max)
    ans = min(count_max, ans)

print(ans)

Solution (Python):
def check(S):
    cond=True
    for i in range(len(S)-1):
        if S[i]!=S[i+1]:
            cond=False
    return cond

def shrink(t,s):
    tt=[]
    for i in range(len(t)-1):
        if t[i+1]==s:
            tt.append(t[i+1])
        else:
            tt.append(t[i])
    return tt

S=input()
N=len(S)
ans=N

for i in range(N):
    s=S[i]
    t=list(S)
    for j in range(N):
        if check(t):
            break
        t=shrink(t,s)
    ans=min(ans,j)
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy


def moji_list(a, b):
    
    
    
    
    
    
    return [chr(i) for i in range(a, b)]


s = list(read().rstrip().decode())
ans = float('inf')
for al in moji_list(97, 123):
    cnt = 0
    check_s = deepcopy(s)
    while len(set(check_s)) > 1:
        cnt += 1
        ss = []
        for bf, af in zip(check_s, check_s[1:]):
            ss.append(af if af == al else bf)
        check_s = ss
    ans = min(ans, cnt)
print(ans)

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

a = ord('a')

check = [[False for j in range(26)] for i in range(N)]

for i in range(N):
    check[i][ord(s[i])-a] = True

for j in range(26):
    same = True
    for i in range(N):
        if not check[i][j]:
            same = False
    if same:
        print(0)
        exit()

ans = 1
while True:
    for i in range(N-ans):
        for j in range(26):
            if check[i][j] or check[i+1][j]:
                check[i][j] = True
    for j in range(26):
        same = True
        for i in range(N-ans):
            if not check[i][j]:
                same = False
        if same:
            print(ans)
            exit()
    ans += 1

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

a = ord('a')

check = [[False for j in range(26)] for i in range(N)]

for i in range(N):
    check[i][ord(s[i])-a] = True

for j in range(26):
    same = True
    for i in range(N):
        if not check[i][j]:
            same = False
    if same:
        print(0)
        exit()

ans = 1
while True:
    for i in range(N-ans):
        for j in range(26):
            if check[i][j] or check[i+1][j]:
                check[i][j] = True
    for j in range(26):
        same = True
        for i in range(N-ans):
            if not check[i][j]:
                same = False
        if same:
            print(ans)
            exit()
    ans += 1

Solution (Python):
import numpy as np

S = input()
ss = set(S) 
mx = len(S)
for s in ss:
    m = [i for i, si in enumerate(S) if si == s ]
    m.insert(0, -1)
    m.append(len(S))
    mx = min(mx, max(np.diff(m)-1))

print(mx)