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):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
def sub(c):
    ss = s[:]
    ans = 0
    while True:
        if all(c==ss[i] for i in range(len(ss))):
            break
        ans += 1
        tmp = []
        for i in range(len(ss)-1):
            if c in (ss[i], ss[i+1]):
                tmp.append(c)
            else:
                tmp.append(ss[i])
        ss = "".join(tmp)
    return ans
ans = float("inf")
for c in set(s):
    ans = min(ans, sub(c))
print(ans)

Solution (Python):
from collections import Counter

S = input()

cnt = Counter(S).most_common()



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

anss = float('inf')
for c in cand:
    alp = c
    ans = 0
    tmp = 0
    for s in S:
        if s == alp:
            ans = max(ans, tmp)
            tmp = 0
        else:
            tmp += 1
    if tmp:
        ans = max(ans, tmp)
    anss = min(anss, ans)
print(anss)

Solution (Python):
s=input()


from collections import Counter

c=Counter(s)
if len(list(c.keys()))==1:
    print(0)
    exit(0)


cnt=101
targets=list(c.keys())

for t in targets:
    tmp_cnt=0
    prev=s
    minus=1
    while True:
        tmp=''
        tmp_cnt+=1
        for i in range(len(s)-minus):
            if prev[i]==t or prev[i+1]==t:
                tmp+=t
            else:
                tmp+=prev[i]

        tmp_c=Counter(tmp)
        if len(list(tmp_c.keys()))==1:
            break
        else:
            minus+=1
            prev=tmp

    cnt=min(cnt,tmp_cnt)

print(cnt)

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

min_cnt = float('inf')

for c in string.ascii_lowercase:
    if c not in s:
        continue
    cnt = 0
    s_ = s[:]
    while s_:
        m = len(s_) - 1
        is_same = True
        for d in s_:
            if d != c:
                is_same = False
                break
        if is_same:
            min_cnt = min(min_cnt, n - m-1)
        s_next = [''] * m
        for i in range(m):
            if s_[i] == c or s_[i + 1] == c:
                s_next[i] = c
            else:
                s_next[i] = s_[i]
        s_ = s_next

print(min_cnt)

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def solve(a, s):
    b = []
    for i in range(len(s)):
        if s[i] == a:
            b.append(i)
    if len(b) == 0:
        return len(s) - 1
    ans = 0
    for i in range(len(b)-1):
        ans = max(ans, (b[i+1] - b[i] - 1))
    ans = max(ans, b[0])
    ans = max(ans, len(s) - b[-1] - 1)
    return ans

def main():
    s = input()
    ans = len(s)
    for i in range(26):
        ans = min(ans, solve(chr(ord('a') + i), s))
    print(ans)
main()

Solution (Python):
S = input().strip()

ans = float("inf")

for i in range(26):
    tmp = 0
    current = 0
    for s in S:
        if s == chr(ord('a') + i):
            tmp = max(tmp, current)
            current = 0
        else:
            current += 1

    tmp = max(tmp, current)
    ans = min(ans, tmp)

print(ans)

Solution (Python):
S = input()
ans = len(S)
for i in range(26):
	c = chr(ord('a') + i)
	t = list(S)
	while not all(a==t[0] for a in t):
		u = []
		for a,b in zip(t,t[1:]):
			if a==c or b==c:
				u.append(c)
			else:
				u.append(a)
		t = u
	tmp = len(S) - len(t)
	ans = min(ans, tmp)
print(ans)

Solution (Python):
string = input()
start = len(string)
targets = set(string)
ans = float('inf')
for a in targets:
    prev = string
    while not all(c == a for c in prev):
        new = ''
        for idx in range(len(prev) - 1):
            if a in (prev[idx], prev[idx+1]):
                new += a
            else:
                new += prev[idx]
        prev = new
    score = start - len(prev)
    ans = min(ans, score)

print(ans)

Solution (Python):
s=input()
ans=100
for i in [chr(97+i)for i in range(26)]:
    a=b=0
    for j in s:
        if i!=j:
            a+=1
        else:
            a=0
        b=max(b,a)
    ans=min(ans,b)
print(ans)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
 
s = input()
ans = math.inf
for x in s:
    t = s.split(x)
    tmp = 0
    for i in range(len(t)):
        tmp = max(tmp, len(t[i]))
    ans = min(ans, tmp)
print(ans)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
ans = math.inf
for x in s:
    t = s.split(x)
    tmp = 0
    for i in range(len(t)):
        tmp = max(tmp, len(t[i]))
    ans = min(ans, tmp)
print(ans)

Solution (Python):
import string
def func(a):
    a = a[::-1]
    return a[::-1]
s=input()
s = func(s)
ans=10**9+1
for value in set(s):
    enumerater_value=value+s+value
    var2=0
    var=0
    for i,key in enumerate(enumerater_value):
        if key==value:
            if var2<i-var-1: 
                var2=i-var-1
            var=i
    if ans>var2: 
        ans=var2
print(ans)

Solution (Python):
S = input()
val = 10**9
 
voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)
 
    while True:
        if all([w == c for w in tmp]):
            val = min(cnt, val)
            break
        cnt += 1
        for u in range(len(tmp)-1):
            tmp[u] = c if tmp[u] == c or tmp[u+1] == c else tmp[u]    
        tmp.pop()
 
 
print(val)

Solution (Python):
S = input()
ans = 10e9

voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)

    while True:
        if all([w == c for w in tmp]):
            ans = min(cnt, ans)
            break
        cnt += 1
        for u in range(len(tmp)-1):
            tmp[u] = c if tmp[u] == c or tmp[u+1] == c else tmp[u]    
        tmp.pop()


print(ans)

Solution (Python):
s = input()
l = set(s)
ans = 10 ** 10
for x in l:
    cnt, cnt_max = 0, 0
    for i in s:
        if i != x:
            cnt += 1
        else:
            cnt_max = max(cnt_max, cnt)
            cnt = 0
    cnt_max = max(cnt_max, cnt)
    ans = min(cnt_max, ans)
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
s=input().rstrip()
ans=1000
for i in range(26):
    x=chr(97+i)
    temp=0
    pre=list(s)
    while True:
        check=True
        for j in pre:
            if j!=x:
                check=False
        if check:
            ans=min(ans,temp)
            break
        temp+=1

        post=[]
        for j in range(len(pre)-1):
            if pre[j]==x or pre[j+1]==x:
                post.append(x)
            else:
                post.append('!')
        pre=post

print(ans)

Solution (Python):

from collections import Counter 
s = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

result = []
if len(set(s)) == 1:
    result.append(0)
for i in alphabet:
    s_tmp = s 
    cnt = 0
    for k in range(len(s_tmp)):
        s_new= ""
        for j in range(len(s_tmp)-1):
            if s_tmp[j] == i or s_tmp[j+1] == i:
                s_new += i
            else:
                s_new += s_tmp[j]
        cnt += 1
        if len(set(s_new)) == 1:
            result.append(cnt)
            break        

        s_tmp = s_new
        
            
 


print(min(result))

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

res = 10 ** 9

for x in l:
    
    
    tmp, chk = 0, 0
    
    for s in S:
        
        if s != x:
            tmp += 1
        else:
            chk = max(chk, tmp)
            tmp = 0
    
    chk = max(chk, tmp)
    
    res = min(chk, res)
print(res)

Solution (Python):
s = input()
l = set(s)
ans = 10 ** 10
for x in l:
    cnt, cnt_max = 0, 0
    for i in s:
        if i != x:
            cnt += 1
        else:
            cnt_max = max(cnt_max, cnt)
            cnt = 0
    cnt_max = max(cnt_max, cnt)
    ans = min(cnt_max, ans)
print(ans)

Solution (Python):
s = input()
def simulate(c):
    W = list(s[:])
    cnt = 0
    while len(set(W)) > 1:
        for i,w in enumerate(W):
            if w==c and i >= 1:
                W[i-1] = c
        cnt += 1
        W.pop()
    return cnt

ans = len(s)
for c in set(s):
    ans = min(ans, simulate(c))

print(ans)

Solution (Python):
from collections import Counter

s = input()

d = Counter(s)
ans = 101

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

for item in d.keys():
    st = item
    tmp = list(s)
    n = len(s)

    while n>0:
        gen = []
        flag = True
        for i in range(n-1):
            if tmp[i] == st or tmp[i+1] == st:
                gen.append(st)
            else:
                gen.append(tmp[i])
                flag = False

        if flag: break
        else: 
            tmp = gen.copy()
            n -= 1
    ans = min(ans,len(s)-len(gen))
print(ans)

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

alpha = "abcdefghijklmnopqrstuvwxyz"
ans = float("inf")
for tar in alpha:
    t = s
    cnt = 0
    flag = True
    while flag:
        nt = ""
        cnt += 1
        flag = False
        for i in range(len(t)-1):
            if t[i] == tar or t[i+1] == tar:
                nt += tar
            else:
                nt += t[i]
                flag = True
        t = nt
    ans = min(ans, cnt)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

s = ins()


def solve():
    ss = set(s)
    ans = 10000
    ach = None
    for c in range(26):
        ch = chr(ord("a") + c)
        if ch not in ss:
            continue
        msk = sk = 0
        for i, x in enumerate(s):
            if x == ch:
                if msk < sk:
                    msk = sk
                sk = 0
            else:
                sk += 1
        if msk < sk:
            msk = sk
        if ans > msk:
            ans = msk
            ach = ch

    return ans


print(solve())

Solution (Python):
S = input()
k = 1000 
for i in range (len(S)):
    x = y = 0
    for j in range (1, len(S) + 1):
        if S[i] == S[len(S)-j]:
            x = 0
        else:
            x += 1
        y = max(x,y)
    k = min(k,y)
print(k)

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()

cnter=Counter(s)

ans=float('inf')
for a in al:
    if cnter[a]==0:
        continue
    tmp=s[:]
    cnt=0
    while 1:
        flag=1
        for i in range(len(tmp)):
            if a!=tmp[i]:
                flag=0
        if flag==1:
            break
        tmp1=""
        for i in range(len(tmp)-1):
            if tmp[i]==a or tmp[i+1]==a:
                tmp1+=a
            else:
                tmp1+=tmp[i]
        cnt+=1
        tmp=tmp1[:]
    ans=min(ans,cnt)
print(ans)

Solution (Python):
def main():
    S = input()
    ST = set(S)
    ans = 100
    for st in ST:
        count = 0
        T = list(S)
        tmp = ''
        while len(set(T)) > 1:
            for i in range(len(T) - 1):
                if st in [T[i], T[i + 1]]:
                    tmp += st
                else:
                    tmp += T[i]
            T = tmp
            tmp = ''
            count += 1
        ans = min(ans, count)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
m = 10**9 + 1

for alpha in set(s):
    temp = alpha + s + alpha
    M = 0
    now = 0
    for i, key in enumerate(temp):
        if key == alpha:
            if M < i - now - 1:
                M = i - now - 1
            now = i
    if m > M:
        m = M

print(m)

Solution (Python):
s = str(input())
def strop(s,c):
    
    count = 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
        
        count += 1
    return count
            
mn = 10**9
for i in range(len(set(s))):
    mn = min(mn,strop(s,list(set(s))[i]))
print(mn)

Solution (Python):
s=input()
m=10**9+1
for alpha in set(s):
    temp=alpha+s+alpha
    M=0
    now=0
    for i,key in enumerate(temp):
        if key==alpha:
            if M<i-now-1: M=i-now-1
            now=i
    if m>M: m=M

print(m)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = np.array(list(read().rstrip().decode()))

def f(S, a):
    S = S == a
    if not np.any(S):
        return len(S)
    for n in range(len(S)):
        if np.all(S):
            return n
        S = S[1:] | S[:-1]

x = min(f(S, a) for a in S)
print(x)

Solution (Python):
import string
d = {}
alph = string.ascii_lowercase
for i in range(len(alph)):
    d[alph[i]] = i
s = list(input())


count = [0 for _ in range(len(alph))]
for letter in s:
    count[d[letter]] += 1


target = []
for i in range(len(alph)):
    if count[i] == max(count):
        target.append(alph[i])


answer = []
for t in s:
    time = 0
    size = len(s)
    line = list(s)
    ifOK = True
    while ifOK:
        
        ifOK = False
        new_line = ""
        for i in range(size-1):
            if (line[i] == t or t == line[i+1]) and not line[i] == line[i+1]:
                new_line += t
                ifOK = True
            else:
                new_line += line[i]
        line = list(new_line)
        size -= 1
        time += 1
    answer.append(time)
print(min(answer)-1)

Solution (Python):
from collections import Counter

A = list(input())
S = A
MIN = 2000
for t in set(A):
    count = 0
    S = A
    while count <= MIN:
        if len(set(S)) == 1:
            MIN = min(count,MIN)
            break
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1


print(MIN)

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

s_set = set(s)

cnt = 101
for l in s_set:
    indexs = set([i for i, x in enumerate(s) if x == l])
    i = len(s)
    while len(indexs) < i:
        indexsList = list(indexs)
        for j in range(len(indexs)):
            n = indexsList[j]
            if n == 0:
                pass
            elif n == i - 1:
                indexs.remove(n)
                indexs.add(n-1)
            else:
                indexs.add(n-1)
        i -= 1
    cnt = min(cnt, len(s)-i)

print(cnt)

Solution (Python):
S = input()

tmp = 0
length = 0
ans = 100
for s in S:
    for t in S:
        if t != s:
            tmp += 1
        else:
            length = max(tmp, length)
            tmp = 0
    else:
        length = max(tmp, length)
        tmp = 0
    ans = min(ans, length)
    length = 0

print(ans)

Solution (Python):
INF = int(1e9+7)
s = input()
d = list('abcdefghijklmnopqrstuvwxyz')
ans = INF
for i in d:
    lis = [-1]
    for j in range(len(s)):
        if s[j] == i:
            lis.append(j)
    lis.append(len(s))
    val = 0
    for j in range(1,len(lis)):
        val = max(val,lis[j]-lis[j-1]-1)
    ans = min(ans,val)
print(ans)

Solution (Python):
s = input()
l = set(s)
ans = 10**10
for x in l:
    tmp, chk = 0, 0
    for i in s:
        if i != x:
            tmp += 1
        else:
            chk = max(chk, tmp)
            tmp = 0
    chk = max(chk, tmp)
    ans = min(chk, ans)
print(ans)

Solution (Python):
S = input()


ans = 10**9  
alphabet = []
for i in range(26):
    alphabet.append(chr(ord("a")+i))

hoge = set(S)
for character in alphabet:  
    if character not in hoge:
        continue
    tmp = 0
    copy_s = list(S).copy()
    
    
    while set(copy_s) != set(character):
        copy_s_dash = []
        for i in range(len(copy_s)-1):
            if copy_s[i] == character or copy_s[i+1] == character:
                copy_s_dash.append(character)
            else:
                copy_s_dash.append("?")
        
        copy_s = copy_s_dash.copy()
    ans = min(ans, len(S)-len(copy_s))
print(ans)

Solution (Python):



def main():
    S = list(input())
    sr = set(S)
    ret = 100
    for s in sr:
        max_cnt = 0
        cnt = 0
        for t in S:
            if s!=t:
                cnt += 1
            else:
                max_cnt = max(max_cnt, cnt)
                cnt = 0
        max_cnt = max(max_cnt, cnt)

        ret = min(ret, max_cnt)
    print(ret)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



s = list(input())
alphabets = [chr(ord('a')+i) for i in range(26)]

ans = float('inf')
for a in alphabets:
    t = s[:]
    count = 0
    while True:
        b = []
        if t == [a]*len(t):
            ans = min(ans,count)
            break
        else:
            for i in range(len(t)-1):
                if t[i] == a or t[i+1] == a:
                    b.append(a)
                else:
                    b.append('A')
            count += 1
            t = b[:]

print(ans)

Solution (Python):
from collections import Counter

S = input()
S1 = S

st = set(S)
rlt = 1000

if len(Counter(st)) == 1:
  print(0)
  exit()
  
for s in st:
  S = S1
  t = 0
  while len(Counter(S)) > 1:
    tmp = ''
    for i in range(1,len(S)):
      if S[i-1] == s or S[i] == s:
        tmp += s
      else:
        tmp += S[i]
    t += 1
    S = tmp

  if t < rlt:
    rlt = t
    
print(rlt)

Solution (Python):


import math



from collections import deque
from collections import Counter




s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s_set:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef
        dic.append(max(delta,res))
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))

Solution (Python):
s=str(input())
l=len(s)
ans=99999999999
for j in s:
  temp=j
  a=0
  cnt=0
  for i in range(l):
    if s[i]!=temp:
      cnt=cnt+1
    else:
      a=max(a,cnt)
      cnt=0
  a=max(a,cnt)
  ans=min(a,ans)
print(ans)

Solution (Python):
def find_idx(s, c):
  idx_lst = []
  while c in s:
    idx = s.index(c)
    idx_lst += [idx]
    s = s[idx+1:]
  else:
    idx_lst += [len(s)]
  return idx_lst

s = input()
res = float('inf')
for i in range(97, 97 + 26):
  tmp = find_idx(s, chr(i))
  if tmp:
    res = min(res, max(tmp))
print(res)

Solution (Python):
import sys
S = list(sys.stdin.readline().rstrip())
chars = [chr(ord("a") + i) for i in range(26)]
ans = 10**5
for c in chars:
    if c not in S:
        continue
    cnt = 0
    S_copy = S.copy()
    while len(set(S_copy)) > 1:
        S_tmp = []
        for i in range(len(S_copy) - 1):
            if S_copy[i] == c or S_copy[i + 1] == c:
                S_tmp.append(c)
            else:
                S_tmp.append(S[i])
        S_copy = S_tmp.copy()
        cnt += 1
    ans = min(ans, cnt)
print(ans)

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

def f(s, c):
    n = len(s)
    if not c in s:
        return n-1
    else:
        longest = 0
        last = -1
        i = 0
        while i < n:
            l = 0
            while i < n and s[i]!=c:
                l+=1 
                i+=1
            if i < n and s[i]==c:
                last = i
                longest = max(longest, l)
            i+=1
        return max(n-last-1, longest)

ans = float('inf')
for i in range(26):
    c = chr(ord('a')+i)
    ans = min(ans, f(s, c))
print(ans)

Solution (Python):
s = input()
s_array = list(set(s))
if len(s_array) == 1:
    print(0)
    exit()

ans = float('inf')
s_len = len(s)
for target in s_array:
    s_check = s
    for i in range(1,s_len):
        count = 0
        s_dosh = [""] * (s_len-i)
        for j in range(s_len-i):
            if s_check[j] == target or s_check[j+1] == target:
                s_dosh[j] = target
            else:
                s_dosh[j] = s[j]
                count = 1
        s_check = ''.join(s_dosh)
        
        if count == 0:
            ans = min(ans,i)
            break

print(ans)

Solution (Python):
l = list(input())
ans = 10000000
for let in range(26):
    cur = chr(let+97)
    temp = l[:]
    cnt = 0
    while len(set(temp)) > 1:
        for i in range(len(temp)-1):
            if temp[i] == cur or temp[i+1] == cur:
                temp[i] = cur
            else:
                temp[i] = l[i]
        temp.pop()
        cnt += 1
    ans = min(ans, cnt)
    
print(ans)

Solution (Python):
s=list(input())
S=list(set(s))
ans=100
for c in S:
  kari=0
  tmp=0
  for w in s:
    if w==c:
      kari=max(tmp, kari)
      tmp=0
    else:
      tmp+=1
  kari=max(tmp,kari)
  ans=min(ans, kari)
print(ans)

Solution (Python):
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)//2
for a in A:
    ans_max=0
    p=0
    for s in S:
        if a==s:
            ans_max=max(p,ans_max)
            p=0
        else:
            p+=1
    ans_max=max(p,ans_max)
    minimum=min(ans_max,minimum)
print(minimum)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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 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 make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





AtoZ = "abcdefghijklmnopqrstuvwxyz"
S = S()
N = len(S)
MIN = INF
for l in AtoZ:
  indexes = [i for i, x in enumerate(S) if x == l]
  indexes = [-1]+indexes+[N]
  dif = [indexes[i+1]-indexes[i] for i in range(len(indexes)-1)]
  MIN = min(MIN,max(dif)-1)
print(MIN)

Solution (Python):
import sys

sys.setrecursionlimit(10**6)

def handling(string, letter):
    global cnt
    cnt += 1; nxt = []
    for i in range(len(string)-1):
        s1, s2 = string[i], string[i+1]
        if s1 == letter:
            nxt.append(s1)
        elif s2 == letter:
            nxt.append(s2)
        else:
            nxt.append(s1)
    if len(set(nxt)) != 1:
        handling(nxt, letter)

def main():
    global cnt
    s = list(input())
    sletter = set(s)
    if len(sletter) == 1:
        print(0)
        return
    ans = 101
    for l in sletter:
        cnt = 0
        t = s.copy()
        handling(t, l)
        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
s=input()

n=10000000
for i in range(26):
    lis=[-1]
    for c in range(len(s)):
        if s[c]==chr(ord("a")+i):
            lis.append(c)
    if len(lis)>1:
        ni=0
        for j in range(len(lis)-1):
            ni=max(ni,lis[j+1]-lis[j]-1)
        ni=max(ni,len(s)-1-lis[len(lis)-1])
        n=min(n,ni)

print(n)

Solution (Python):
s = input()
al = 'abcdefghijklmnopqrstuvwxyz'
cou = 10**7
for i in range(26):
  s1 = s
  s2 = s
  w = al[i]
  cou_now = 0
  while len(set(s2))!=1:
   
    cou_now += 1
    s1 = str("".join(s2))
    s2 = []
    for j in range(len(s1)-1):
      if s1[j]==w or s1[j+1]==w:
        s2.append(w)
      else:
        s2.append(s1[j])
  cou = min(cou,cou_now)
print(cou)

Solution (Python):
S = input()

if len(set(S)) == 1:
    print(0)
else:
    alpha = list(set(S))
    cnt = float("inf")
    for word in alpha:
        t = S[:]
        for i in range(1, len(S)):
            tmp = ""
            for j in range(len(t)-1):
                if t[j] == word or t[j+1] == word:
                    tmp += word
                else:
                    tmp += t[j]
            if len(set(tmp)) == 1:
                cnt = min(cnt, i)
                break
            t = tmp[:]
    print(cnt)

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def is_all(list_s, c):
	for cs in list_s:
		if cs != c:
			return False
	return True

def dd(s, c):
	t=list(s)
	p=0
	while not is_all(t, c):
		nt=['']*(len(t)-1)
		for i, _ in enumerate(nt):
			if t[i]==c or t[i+1]==c:
				nt[i]=c
			else:
				nt[i]=t[i]
		t=nt
		p+=1
	return p
	
	

def main():
	
	
	s = input()
	ret = mod
	for c in list(set(list(s))):
		
		r = dd(s, c)
		ret = min(ret, r)
	print(ret)
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
def main():
    s = input()
    l = len(s)
    alp = set(s)

    ans = float('inf')
    for char in alp:
        sp = max(map(len, s.split(char)))
        ans = min(ans, sp)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from string import ascii_lowercase as a2z

input = sys.stdin.readline


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

    ans = 100
    for al in a2z:
        if al not in S:
            continue
        i = 0
        max_cost = 0
        for j, s in enumerate(S + al):
            if s == al:
                cost = j - i
                if cost > max_cost:
                    max_cost = cost
                i = j + 1
        if max_cost < ans:
            ans = max_cost

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
string = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
ans = 100
for a in alpha:
    tmp = 0
    ans_tmp = 0
    for s in string:
        if s == a:
            ans_tmp = max(ans_tmp, tmp)
            tmp = 0
        else:
            tmp += 1
    ans_tmp = max(ans_tmp, tmp)
    ans = min(ans, ans_tmp)
print(ans)