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 = list(input())
ls = list("abcdefghijklmnopqrstuvwxyz")
m_cnt = 10 ** 9
for t in ls:
    if t in s:
        ss = s.copy()
        cnt = 0
        while True:
            sss = [""] * (len(ss) - 1)
            b = True
            for i in range(len(sss)):
                if ss[i] == t or ss[i+1] == t:
                    sss[i] = t
                else:
                    sss[i] = ss[i]
                    b = False
            if b:
                m_cnt = min(m_cnt, cnt if cnt == 0 else cnt + 1)
                break
            else:
                ss = sss.copy()
                cnt += 1
print(m_cnt)

Solution (Python):
import collections

def simu(s,i):
    temp = s
    counter = 0
    while len(collections.Counter(temp)) != 1:
        another = []
        for k in range(len(temp)-1):
            if temp[k] == i or temp[k+1] == i:
                another.append(i)
            else:
                another.append(temp[k])
        temp = another
        counter += 1
    return counter

s = list(input())
c = collections.Counter(s)
mini = 10000
for i in c:
    a = simu(s,i)
    if mini > a:
        mini = a
print(mini)

Solution (Python):
w=input();print(min(max(len(p)for p in w.split(s))for s in w))

Solution (Python):
w=input()
a=[]
for s in set(list(w)):
	m=0
	for p in w.split(s):
		m=max(m,len(p))
	a.append(m)
print(min(a))

Solution (Python):

S = list(input())
N = len(S)
import collections
import sys
C = collections.Counter(S)
Ckey = C.keys()
ans = 10 ** 9 + 7
if len(Ckey) == 1:
    print(0)
    sys.exit()
for s in Ckey:
    post = S[:]
    for i in range(1,N):
        
        
        flag = True
        tmp = ['0'] * (N-i)
        for j in range(N-i):
            if post[j] == s or post[j+1] == s:
                tmp[j] = s
            else:
                tmp[j] = post[j]
                flag = False
        post = tmp[:]
        if (flag):
            break
    ans = min(ans,i)
print(ans)

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

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

print (ans)

Solution (Python):

s = input()
t = set(list(s))
ans = 1000
for i in t:
    S = s
    c = 0
    while len(set(S))!=1:
        c+=1
        ts = ""
        for  j,k in zip(S,S[1:]):
            if j == i or k == i:
                ts+=i
            else:
                ts+=k
        S = ts
    ans = min(ans,c)
    

print(ans)

Solution (Python):

s = input()
t = set(list(s))
ans = 1000
for i in t:
    S = s
    c = 0
    while len(set(S))!=1:
        c+=1
        ts = ""
        for  j,k in zip(S,S[1:]):
            if j == i or k == i:
                ts+=i
            else:
                ts+=k
        S = ts
    ans = min(ans,c)
    

print(ans)

Solution (Python):

t = "abcdefghijklmnopqrstuvwxyz"
s = input()
ans = 1000
for i in t:
    S = s
    c = 0
    while len(set(S))!=1:
        c+=1
        ts = ""
        for  j,k in zip(S,S[1:]):
            if j == i or k == i:
                ts+=i
            else:
                ts+=k
        S = ts
    ans = min(ans,c)
    

print(ans)

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

ans = len(s)

for c in char_set:
    tmp = s
    cnt = 0
    while any(a != c for a in tmp):
        cnt += 1
        _tmp = ''
        for a, b in zip(tmp, tmp[1:]):
            if a == c or b == c:
                _tmp += c
            else:
                _tmp += b
        tmp = _tmp
    ans = min(ans, cnt)

print(ans)

Solution (Python):
S = input()

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

Solution (Python):
s=input()
se=set(list(s))
x=len(s)
for i in se:
  a=b=0
  for j in s:
    if i==j:a=0
    else:a+=1;b=max(a,b)
  x=min(x,b)
print(x)

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

c = collections.Counter(s)
l = list(c.items())
l = sorted(l, key = lambda x : x[1], reverse=True)


h = []
tmp = l[0][1]

for i in range(len(l)):
          h.append(l[i][0])




ans = []

for i in range(len(h)):
    tmp = [_ for _, x in enumerate(s) if x == h[i]]


    lll = []
    for j in range(len(tmp)):
        if j == 0:
            lll.append(tmp[j])
        else:
            lll.append(tmp[j] - tmp[j-1] - 1)
    lll.append(len(s) - tmp[len(tmp) - 1] - 1)
    ans.append(max(lll))




print(min(ans))

Solution (Python):
s=input()
l=len(s)
a=[1]*(l+1)
c=[]
x=0
while(x<=l-1):
  if(a[x]==1):
    a[x]=0
    k=0
    b=[x]
    t=s+s[x]
    for i in range(x+1,l+1):
      if(t[x]==t[i]):
        b.append(k)
        a[i]=0
        k=0
      else:
        k+=1
    c.append(max(b))
  x+=1
print(min(c))

Solution (Python):
s = input()
abc = []
for i in range(len(s)):
    if not s[i] in abc:
        abc.append(s[i])
ans = []
for c in abc:
    count = 0
    x = s
    y = ""
    while True:
        if x.count(x[0]) == len(x):
            break
        for i in range(len(x)-1):
            if x[i] == c or x[i+1] == c:
                y+=c
            else:
                y+=x[i]
        x = y
        y = ""
        count += 1
    ans.append(count)
print(min(ans))

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

s = sys.stdin.readline()
s = s[:-1]
if len(Counter(s)) == 1:
    print(0)
    quit()
n = len(s)
ans = float('inf')
for i in range(n):
    x = s[i]
    t = s
    cnt = 0
    while 1:
        t_ = ''
        for j in range(len(t)-1):
            if t[j] == x or t[j+1] == x:
                t_ += x
            else:
                t_ += t[j]
        t = t_
        cnt += 1
        if len(Counter(t)) == 1:
            ans = min(ans,cnt)
            break
print(ans)

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

S = input().rstrip()

def F(S,target):
    cnt = 0
    while S.count(target) != len(S):
        cnt += 1
        S = ''.join(y if x != target else x for x,y in zip(S[:-1],S[1:]))
    return cnt

answer = min(F(S,t) for t in set(S))
print(answer)

Solution (Python):



from collections import Counter
s=list(input())
n=len(s)
S=set(s)
"""
if len(s)==len(S):
    print(n//2)
    exit()"""
if s.count(s[0])==len(s):
    print(0)
    exit()


res=float('inf')
for e in S:
    r=0
    l=0
    cnt=0
    
    while l<=r<n:
        if s[r]==e:
            if l==0:
                cnt=max(r-l,cnt)
            else:
                cnt=max(r-l-1,cnt)
            l=r
        r+=1
    if n==r:cnt=max(r-l-1,cnt)
    if cnt==0:continue
    res=min(res,cnt)
if res==float('inf'):
    print(0)
else:print(res)

Solution (Python):
s=input()

numdict={}
c=set(s)
for i in c:
    numdict[i]=[]

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

cnt=len(s)
for i in c:
    x=0
    
    x=max(numdict[i][0],len(s)-numdict[i][-1]-1)
    for j in range(len(numdict[i])-1):
        x=max(x,numdict[i][j+1]-numdict[i][j]-1)
        
    
    cnt=min(cnt,x)
print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

s = input()
atoz = [chr(i) for i in range(97,97+26)]
ans = 10000
for c in atoz:
    cnt = 0
    t = s
    while 1:
        if len(Counter(t)) == 1:
            ans = min(ans, cnt)
            break
        td = ''
        for i in range(len(t)-1):
            if t[i] == c or t[i+1] == c:
                td += c
            else:
                td += t[i]
        t = td
        cnt += 1
print(ans)

Solution (Python):
s = input()
s_set = set(s)
def shrink(r,s):
    s = list(s)

    t = 0
    while True:

        if len(set(s)) == 1:
            break
        else:
            t += 1

        new_s = []
        for i in range(len(s)-1):
            if s[i] == r or s[i+1] == r:
                new_s.append(r)
            else:
                new_s.append(s[i])
        s = new_s
    return t

ans_list = [ shrink(i,s) for i in s_set]
print(min(ans_list))

Solution (Python):


def main():
    S = input().rstrip()
    T = set(S)
    ans = float("inf")
    for t in T:
        cnt = 0
        x = S
        while len(set(x)) != 1:
            cnt += 1
            tmp = ""
            for i in range(len(x) - 1):
                tmp += t if x[i] == t else x[i + 1]
            x = tmp
        ans = min(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
s= (stdin.readline().rstrip())
f = lambda a, b: abs(a-b-1)
diff = lambda ls: map(f, ls[1:], ls)

ans = 100
for i in set(s):
    ans = min(ans,max([len(j) for j in s.split(i)]))
print(ans)

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

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

Solution (Python):
S=list(input())
nmin=len(S)
for c in set(S):
    arr=S[:]
    for n in range(len(S)):
        if all([cc==c for cc in arr]):
            nmin=min(nmin, n)
            break
        for i in range(len(arr)-1):
            if arr[i]!=c and arr[i+1]==c:
                arr[i]=c
        arr=arr[:-1]
print(nmin)

Solution (Python):
s=input()
sets=set(s)
ans=[]
for i in sets:
    cnt=0
    temp=list(s)
    if len(set(temp))==1:
        ans.append(0)
    else:
        while(True):
            temp2=[]
            for j in range(len(temp)-1):
                if temp[j]==i or temp[j+1]==i:
                    temp2.append(i)
                else:
                    temp2.append(None)
            cnt+=1
            if len(set(temp2))==1:
                ans.append(cnt)
                break
            temp=temp2
print(min(ans))

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

dic = {}
for i, s in enumerate(S):
    if not s in dic.keys():
        dic[s] = [i]
    else:
        dic[s].append(i)

all = True
for i in range(N-1):
    if S[i] != S[i+1]:
        all = False


ans = N

for m in dic.keys():
    if all:
        ans = 0
        break
    q = list(S)
    c = 0
    allm = False
    while not allm:
        n = len(q)
        qq = []
        allm = True
        for i in range(n-1):
            if q[i] == m or q[i+1] == m:
                qq.append(m)
            else:
                allm = False
                qq.append(q[i])
        c += 1
        q = qq
    ans = min(ans, c)

print(ans)

Solution (Python):
from collections import defaultdict
s = input()
di = defaultdict(int)
ans = float('inf')
for i in s:
    di[i]+=1
if(len(di)==1):
    print(0)
else:
    for i in di:
        cnt = 0
        now_s = s
        for _ in range(len(s)):
            next_s = ''
            flag = True
            for ind,ss in enumerate(now_s[:-1]):
                if(ss==i or now_s[ind+1]==i):
                    next_s+=i
                else:
                    flag = False
                    next_s+=ss
            cnt+=1
            if(flag):
                break
            else:
                now_s=next_s
        ans = min(cnt,ans)
    print(ans)

Solution (Python):
s = input()
print( min(max(len(j) for j in s.split(i)) for i in set(s)) )

Solution (Python):
S=input()

setS=set(S)

ans=101
for s in setS:
    c=max(map(len,S.split(s)))
    ans=min(ans,c)

print(ans)

Solution (Python):
s=input()
a=list(set(s))
l=[]
for i in a:
  b=s+i
  m=0
  c=0
  for j in range(len(b)):
    c+=1
    if b[j]==i:
      if c>m:
        m=c
      c=0
  l.append(m)
print(min(l)-1)

Solution (Python):
S  = [inp for inp in input()]
dic = {}
for s in S:
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = float('inf')
N = len(S)
for alphabet in dic.keys():
    tempN = N
    copyS = S.copy()
    count = 0
    while True:
        if copyS.count(alphabet) == tempN:
            break
        count += 1
        for i in range(tempN-1):
            copyS[i] = copyS[i] if copyS[i] == alphabet else copyS[i+1]
        copyS.pop(-1)
        tempN -= 1
    if count < ans:
        ans = count
print(ans)

Solution (Python):
s=input()
ans=len(s)
for i in "abcdefghijklmnopqrstuvwxyz":
  t=a=0
  for j in s:
    if j==i:a=max(a,t);t=0
    else:t+=1
  a=max(a,t)
  ans=min(ans,a)
print(ans)

Solution (Python):
s = input()

c = 0
while True:
    l = len(s)-c
    key = list(s[:c+1])
    for i in range(1,l):
        new_key = []
        for k in key:
            if k in s[i:i+c+1]:
                new_key.append(k)
        key = new_key
        if key == []:
            break
    if key != []:
        break
    c += 1
print(c)

Solution (Python):
def main():
    s = input()
    prev = [0] * 26
    space = [0] * 26
    for i, c in enumerate(s):
        x = ord(c) - ord('a')
        space[x] = max(space[x], i - prev[x])
        prev[x] = i + 1
    for i in range(26):
        space[i] = max(space[i], len(s) - prev[i])
    ans = min(space)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
ans = 9999
S = input()
cands = list(set(list(S)))
for c in cands:
    temp = max(list(map(len,S.split((c)))))
    ans = min(ans,temp)
print(ans)

Solution (Python):
def convert(t, c):
    res = 0
    while len(set(t)) > 1:
        n = len(t)
        s = list(t)[:-1]
        for i in range(n-1):
            if (t[i] == c) or (t[i+1] == c):
                s[i] = c
        res += 1
        t = "".join(s)
    return res
def solve(t):
    ans = len(t)
    for c in set(t):
        ans = min(ans, convert(t, c))
    return ans
s = input()
print(solve(s))

Solution (Python):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)






S = input()


def f(c):
    s = list(S)
    cnt = 0
    while s.count(c) != len(s):
        newS = [None] * (len(s) - 1)
        for i in range(len(s) - 1):
            if s[i] == c or s[i + 1] == c:
                newS[i] = c
            else:
                newS[i] = s[i]
        s = newS
        cnt += 1
    return cnt


ans = float('inf')
for s in set(S):
    ans = min(ans, f(s))

print(ans)

Solution (Python):
def shrink(s, char):
    while len(set(s)) > 1:
        temp = ''
        for i in range(len(s) - 1):
            if s[i] == char or s[i+1] == char:
                temp += char
            else:
                temp += s[i]
        s = temp
    return s

S = input()
ans = 10 ** 9
for c in set(S):
    ans = min(ans, len(S) - len(shrink(S, c)))
print(ans)

Solution (Python):

s = input()

strs = set(s)


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

ans = 1000
tmp = 0
for moji in strs:
  s1 = s
  s2 = [""] * (len(s)-1)
  tmp = 0
  flag = True
  while flag == True:
    for i in range(len(s2)):
      if s1[i] == moji or s1[i+1] == moji:
        s2[i] = moji
      else:
        s2[i] = s1[i]
      
    tmp += 1
    s1 = s2
    s2 = [""] * (len(s1)-1)

    if len(set(s1)) == 1:
      flag = False
  ans = min(ans, tmp)   
 
print(ans)

Solution (Python):
S = input()
l = len(S)
D = dict()
for i in range(l):
    if S[i] not in D:
        D[S[i]] = []
    D[S[i]].append(i)
res = 1000
for v in D.values():
    v = [-1]+v+[l]
    lv = len(v)
    tmp = 0
    for i in range(1,lv):
        tmp = max(tmp,v[i]-v[i-1]-1)
    res = min(res,tmp)
print(res)

Solution (Python):
s=input()
n=len(s)
ans=100000
l=["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+="a"
for i in l:
    s=s[0:n]+i
    c=0
    p=0
    for j in range(n+1):
        if s[j]==i:
            p=max(c,p)
            c=0
        else:
            c+=1
    ans=min(ans,p)
print(ans)

Solution (Python):
s = input().rstrip()
chars = set(s)

ans = 1000
for char in chars:
    max_left = 0
    val = 0
    for i, c in enumerate(s):
        if c is not char:
            max_left += 1
        else:
            val = max(val, max_left)
            max_left = 0
    val = max(val, max_left)
    ans = min(ans, val)
print(ans)

Solution (Python):
s = str(input())
a = list(s)
alpha = set(s)
temp = ""
temp2 = ""
ans = 0
answers = []
if(len(alpha) > 1):
    for letter in alpha:
        temp = s
        ans = 0;
        while(True):
            ans += 1
            for i in range(len(temp)-1):
                if temp[i] == letter or temp[i+1] == letter:
                    temp2 += letter
                else:
                    temp2 += temp[i]
            temp = temp2
            temp2 = ""
            lettercount = 0;
            for i in range(len(temp)):
                if temp[i] == letter:
                    lettercount += 1
            if lettercount == len(temp):
                break
        answers.append(ans)
    print(min(answers))
else:
    print(0)

Solution (Python):


from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul
from bisect import* 
from heapq import* 
from math import factorial
from copy import deepcopy
import sys

sys.setrecursionlimit(10**6)



def main():
    s=input()
    print(min(max(map(len,s.split(i)))for i in s))

if __name__ == '__main__':
    main()

Solution (Python):
"""
与えられた長さNのtをt'にする方法
各iについて、t'のi文字目はtのi,i+1文字目のどちらかである

単一文字のt'に持っていく最小操作回数

文字間差分の最大値が最も小さい文字が強い
"""

S = input()

Sset = set(S)
ans = 1000
for s in Sset:
    string  = s+S+s
    diff = 0
    tmp = 0
    for i,st in enumerate(string): 
        if s == st:
            diff = max(diff, i-tmp) 
            tmp = i
    ans = min(ans,diff)
print(ans-1)

Solution (Python):
s = input()

ans = 101
for i in range(26):
    a = chr(i+97)
    txt = s
    count = 0
    if txt.count(a) == len(txt):
        ans = 0
        break
    for j in range(len(s)-1):
        newtext = ""
        count += 1
        for k in range(len(txt)-1):
            if txt[k] == a or txt[k+1] == a:
                newtext += a
            else:
                newtext += txt[k]
        if newtext.count(a) == len(newtext):
            anstemp = count
            ans = min(anstemp, ans)
            break
        else:
            txt = newtext
print(ans)

Solution (Python):
from sys import stdin


s = stdin.readline().rstrip()



ans = len(s)
for c in range(ord('a'), ord('z')+1):
    cnt, cntMax = 0, 0
    for i in range(0, len(s)):
        if s[i] == chr(c):
            cntMax = max(cnt, cntMax)
            cnt = 0
            continue
        cnt += 1
    cntMax = max(cnt, cntMax)
    ans = min(ans, cntMax)
print(ans, '\n')

Solution (Python):
from collections import Counter
s=input()
cs=Counter(s).most_common()
if len(cs)==1:print(0)
else:
    a=float("inf")
    for i,_ in cs:
        si=s[:]
        x=0
        while len(set(si))>1:
            sic=""
            for j in range(len(si)-1):
                if si[j]==i or si[j+1]==i:sic+=i
                else:sic+=si[j]
            si=sic.replace(i*2,i)
            x+=1
        a=min(a,x)
    print(a)

Solution (Python):
s=input()
ans=50
for i in "qwertyuiopasdfghjklzxcvbnm":
    t=0
    a=0
    for c in s:
        if(i==c):
            a=max(a,t)
            t=0
        else:
            t+=1
    a=max(a,t)
    ans=min(ans,a)
print(ans)

Solution (Python):
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

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

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

Solution (Python):

"""
A - Shrinking
https://atcoder.jp/contests/agc016/tasks/agc016_a

"""
import sys


def solve(s):
    ans = []
    for ch in set(s):
        t = list(s)
        x = 0
        while len(set(t)) > 1:
            t = [ch if a == ch or b == ch else a for a, b in zip(t, t[1:])]
            x += 1
        ans.append(x)
    return min(ans)


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

for i in range(26):
  c = chr(97+i)
  m = 0
  b = -1
  
  for j in range(n):
    if s[j] == c:
      
      m = max(j-b,m)
      b = j
  
  m = max(n-b,m)
  r = min(m,r)
print(r-1)

Solution (Python):
from collections import Counter

S = list(input())
C = Counter(S)

o = []

for a in C.keys():
    j = 0
    m = 0
    for b in S:
        if a == b:
            j = 0
        else:
            j += 1
            m = max(m,j)
    o.append(m)

print(min(o))

Solution (Python):
S = [ ord(i)-ord('a') for i in input() ]

ms = 100000000000
for i in range(26):
  if i not in S:
    continue
  V = [ 1 if (i==j) else 0 for j in S ]
  
  s = 0
  for c in range(1000):
    if ( len(V)==sum(V) ):
      s = c
      break
    Vn = [0]*( len(V)-1 )
    for j in range( len(V)-1 ):
      Vn[j]=max(V[j],V[j+1])
    V = Vn
  
  ms = min(s,ms)
print (ms)

Solution (Python):
s = input()
s = list(s)
ans = 1 << 99
for c in range(ord('a'), ord('z') + 1):
    c = chr(c)
    t = s.copy()
    while not all(c == cc for cc in t):
        for i in range(len(t)):
            if c in t[i:i+2]:
                t[i] = c
        t.pop()
    ans = min(ans, len(s) - len(t))
print(ans)

Solution (Python):
import collections
s = input()
anss = collections.defaultdict(int)
ans = 100
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    cnt = 0
    for j in s:
        if i == j:
            anss[i] = max(cnt, anss[i])
            cnt = 0
        else:
            cnt += 1
    anss[i] = max(cnt, anss[i])
    
for c in anss.values():
    if ans > c:
        ans = c
print(ans)

Solution (Python):

s=input()
def change(s,x):
    if s.count(x)==len(s):
        return 0
    t=s
    u=''
    for i in range(1,len(s)):
        for j in range(len(t)-1):
            if t[j]==x or t[j+1]==x:
                u+=x
            else:
                u+=t[j]
        if u.count(x)==len(u):
            return i
        t=u
        u=''
m=[]
for i in s:
    m.append(change(s,i))
print(min(m))

Solution (Python):
import collections
s = input()
anss = collections.defaultdict(int)
ans = 100
for i in s:
    if i not in anss:
        cnt = 0
        for j in s:
            if i == j:
                anss[i] = max(cnt, anss[i])
                cnt = 0
            else:
                cnt += 1
        anss[i] = max(cnt, anss[i])
        
for c in anss.values():
    if ans > c:
        ans = c
print(ans)

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

Solution (Python):
S = input()

mi = 1e10
for c in [chr(ord('a') + i) for i in range(26)]:
    count = 0
    T = S[:]
    while len(T) > T.count(c):
        U = ""
        for i in range(len(T) - 1):
            if c in T[i:i+2]:
                U += c
            else:
                U += T[i]
        T = U
        count += 1
    mi = min(mi, count)

print(mi)

Solution (Python):
S=input()
N=100
for i in range(26):
	N = min(N, max([ len(x) for x in S.split(chr(97+i)) ]))
print(N)

Solution (Python):
s = input()

l = list(set(list(s)))

ans = 100

for x in l:
    a = [-1]
    for i in range(len(s)):
        if s[i]==x:
            a.append(i)
    a.append(len(s))
    b = 0
    for j in range(len(a)-1):
        b = max(b,a[j+1]-a[j]-1)
    ans = min(ans,b)

print(ans)

Solution (Python):
s=input()
S=set(s)
ans=float("inf")
for x in S:
  count=0
  t=s
  n=len(set(t))
  while n>1:
    count+=1
    tt=""
    for i in range(len(t)-1):
      if t[i]==x or t[i+1]==x:
        tt+=x
      else:
        tt+=t[i]
    t=tt
    n=len(set(t))
  ans=min(ans,count)
print(ans)

Solution (Python):
S = input()

chars = set(S)

res = len(S)
for char in chars:
    max_c = 0
    c = 0
    for s in S:
        if s != char:
            c += 1
        else:
            max_c = max(c, max_c)
            c = 0
    max_c = max(c, max_c)
    res = min(res, max_c)

print(res)

Solution (Python):
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
pos=[[0] for _ in range(26)]
for i in range(l):
  for j in range(26):
    if s[i]==check[j]:
      pos[j].append(i+1)
ans=10**9
for i in range(26):
  tmp=0
  for j in range(len(pos[i])-1):
    tmp=max(tmp,pos[i][j+1]-pos[i][j]-1)
  tmp=max(tmp,l-pos[i][-1])
  ans=min(ans,tmp)
print(ans)

Solution (Python):
q = input()
p = set(q)

ans = 100
for i in p:
    count = 0
    S = q
    while len(set(S)) != 1:
        count += 1
        N = len(S)
        t = ''
        for j in range(N-1):
            if S[j] == i or S[j+1] == i:
                t += i
            else:
                t += S[j]
        S = t
    ans = min(ans,count)
print(ans)

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

ans = 100
for i in p:
    mc = max([len(w) for w in S.split(i)])
    ans = min(ans,mc)
print(ans)

Solution (Python):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from collections import Counter
inf = 10**10
from functools import reduce

s = input()
ans = len(s)
for i in set(s):
    t = s.split(i)
    c = 0
    for j in t:
        c = max(c,len(j))
    ans = min(ans,c)
print(ans)

Solution (Python):
s = input()
ans = len(s)
for v in set(s):
    cur = 0
    vstep = 0
    for i in range(len(s)):
        if s[i] != v:
            cur += 1
        else:
            vstep = max(cur,vstep)
            cur = 0
    vstep = max(cur,vstep)
    ans = min(ans,vstep)
print(ans)

Solution (Python):
s = input()
ans = len(s)
for i in set(s):
    t = s.split(i)
    c = 0
    for j in t:
        c = max(c,len(j))
    ans = min(ans,c)
print(ans)

Solution (Python):
S = input()

chars = set()
for s in S:
    chars.add(s)

res = len(S)
for char in chars:
    max_c = 0
    c = 0
    for s in S:
        if s != char:
            c += 1
        else:
            max_c = max(c, max_c)
            c = 0
    max_c = max(c, max_c)
    res = min(res, max_c)

print(res)

Solution (Python):
s = input()
characters = 'abcdefghijklmnopqrstuvwxyz'

answer = 100
for c in characters:
  if c in s:
    mc = max([len(w) for w in s.split(c)])
    answer = min(answer, mc)
print(answer)

Solution (Python):
S = input()
n = len(S)
d = [str(chr(i+97)) for i in range(26)]
ans = float('inf')
for dd in d:
    s = S
    t = ''
    m = 0
    while True:
        if s.count(dd) == len(s):
            break
        for i in range(len(s)-1):
            if s[i] == dd or s[i+1] == dd:
                t = t + dd
            else:
                t = t + s[i]
        s = t
        t = ''
        m += 1
    ans = min(ans,m)
print(ans)

Solution (Python):
s = input()
se = set("".join(s))
ans = 10**10
for m in se:
    t = s
    tans = 0
    for i in range(len(s)):
        if len(set("".join(t))) == 1 and m in t:
            break
        tt = ""
        for j in range(len(t)-1):
            if t[j] == m or t[j+1] == m:
                tt += m
            else:
                tt += t[j]
        tans += 1
        t = tt
    ans = min(ans , tans)
print(ans)

Solution (Python):
s = input()
n = len(s)
a = list(set(list(s)))
ans = 1000
for x in a:
    t = 0
    l = r = 0
    while l < n:
        while r < n and s[r] != x:
            r += 1
        t = max(t, r - l)
        l = r + 1
        r = l
    ans = min(ans, t)
print(ans)

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

for i in range(1,N+1):   
    s = {x for x in S}
    for j in range(N+1-i):
        s &= {x for x in S[j:j+i]}
        if s==set():
            break
    else:
        break   
print(i-1)

Solution (Python):
s = input()
L = []
for i in range(len(s)):
  if not s[i] in L:
    L.append(s[i])
ans = float('inf')
if len(L) == 1:
  print(0)
else:
  for i in range(len(L)):
    k = s
    sub = 0
    flag = False
    while flag == False:
      cur = ''
      cnt = 0
      for j in range(len(k)-2,-1,-1):
        if cnt == len(cur):
          if k[j] == L[i]:
            cur = L[i]*2 + cur
          else:
            cur = k[j] + cur
        else:
          if k[j] == L[i]:
            cur = L[i] + cur
          else:
            None
        cnt += 1
      check = L[i]*len(cur)
      sub += 1
      if check == cur:
        if sub <= ans:
          ans = sub
        flag = True
      else:
        k = cur
  print(ans)

Solution (Python):
from string import ascii_lowercase
s=input()
ans=100
for c in ascii_lowercase:
    ans=min(ans,max([len(x)for x in s.split(c)]))
print(ans)

Solution (Python):
s = list(input())
ans = 10**5
for i in set(list(s)):
  q = s[:]
  cnte = 0
  while len(set(q)) > 1:
    new = [""]*(len(q)-1)
    for j in range(len(q)-1):
      if q[j] == i or q[j+1] == i:
        new[j] = i
      else:
        new[j] = q[j]
    q = new
    cnte += 1
  if cnte < ans:
    ans = cnte
print(ans)

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 copy
S = input()
a = "abcdefghijklmnopqrstuvwxyz"
A = list(a)
ans = []
for a in A:
    tmp = copy.copy(S)
    cnt = 0
    while len(list(set(tmp))) > 1:
        tmp1 = []
        cnt += 1
        for i in range(len(tmp) - 1):
            if tmp[i] == a:
                tmp1.append(a)
            elif tmp[i+1] == a:
                tmp1.append(a)
            else:
                tmp1.append(tmp[i])
        tmp = copy.copy(tmp1)
    ans.append(cnt)
print(min(ans))