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())
dis = [0 for i in range(26)]
mm = [-1 for i in range(26)]

for i in range(len(S)):
    wd = ord(S[i])-97
    dis[wd] = max(dis[wd],i-mm[wd]-1)
    mm[wd] = i

for i in range(26):
    dis[i] = max(dis[i],len(S)-mm[i]-1)
print(min(dis))

Solution (Python):
from copy import deepcopy as cp
s = input()
c = set(s)
ans = 10**9
for ch in c:
    
    k = cp(s)
    cand = 0
    while len(set(k)) > 1:
        t = ""
        for i in range(len(k)-1):
            if k[i] == ch or k[i+1] == ch:
                t += ch
            else:
                t += k[i]
        cand += 1
        k = cp(t)
    ans = min(cand, ans)
print(ans)

Solution (Python):


s=input()

alpha=[chr(i+97) for i in range(26)]
ans=[]

for chara in alpha:
    temp=s
    while len(temp)>temp.count(chara):
        rna=""
        for i in range(len(temp)-1):
            if temp[i+1]==chara:
                rna+=(temp[i+1])
            elif temp[i]==chara:
                rna+=(temp[i])
            else:
                rna+=(temp[i+1])
        temp=rna
        
    ans.append(len(s)-len(temp))

print(min(ans))

Solution (Python):
def main():
    S = input()
    from string import ascii_lowercase
    ans = 1000
    for tar in ascii_lowercase:
        T = [s for s in S]
        if tar not in T:
            continue
        cur = 0
        while len(set(T)) != 1:
            for i in range(len(T)-1):
                if T[i] == tar or (i + 1 < len(T) and T[i+1] == tar):
                    T[i] = tar
            if T:
                T.pop()
            cur += 1
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    s = input().rstrip()
    ans = -1
    for i in range(len(s)):
        for j in range(26):
            c = chr(ord("a") + j)
            f = True
            for k in range(len(s)-i):
                sf = True
                for l in range(i+1):
                    if s[k+l] == c:
                        sf = False
                        break
                if sf:
                    f = False
                    break
            if f:
                ans = i
                break
        if ans != -1:
            break
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

S = input()

import collections
c_indices_dict = collections.defaultdict(list)
for i, c in enumerate(S):
    c_indices_dict[c].append(i)

len_S = len(S)
ret = float('inf')
for indices in c_indices_dict.values():
    v = max(indices[0], len_S - indices[-1] - 1)
    
    for i in range(len(indices)-1):
        v = max(v, indices[i+1] - indices[i] - 1)
        
    ret = min(ret, v)
print(ret)

Solution (Python):
import collections
s=input()
l=[]
dist=[]
ma=0
cnt=0
s2=""
s3=""
l=list(set(s))

for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        
        if s[j]!=l[i]:
            cnt=cnt+1
        else:
            if (ma<=cnt):
                ma=cnt
            cnt=0
    if ma <= cnt:
        ma = cnt
    
    dist.append(ma)
dist.sort()
print(dist[0])

"""

l2=[]

for i in range(len(l)):
    c=l[i]
    k=0
    s2=s
    s3=""
    
    while True:
        if len(set(s2))==1:
            break
        else:
            for j in range(len(s2)-1):
                if (s2[j]==c)or(s2[j+1]==c):
                    s3="".join((s3,c))
                else:
                    s3 = "".join((s3, s2[j]))
            print(s3)
            s2=s3
            s3=""
            k=k+1
    l2.append(k)
l2.sort()

print(l2[0])
"""

Solution (Python):
s = input()

ans = 10**9

for cand in set(s):
  cnt = 0
  a = 0
  for tmp in s:
    if tmp != cand:
      cnt+=1
    else:
      if a < cnt:
        a = cnt
      cnt = 0
  if a < cnt:
    a = cnt
  if ans > a:
    ans = a
    
print(ans)

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

from collections import Counter
chars = [chr(i) for i in range(ord('a'), ord('z')+1)]

def check(arr):
    e = arr[0]
    return len(arr) == arr.count(e)


ans = float('inf')
for c in chars:
    cnt = 0
    t = S
    while not check(t):
        u = ''
        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(ans, cnt)

print(ans)

Solution (Python):
from collections import Counter

s = input()
if len(set(list(s)))==1:
    print(0)
    exit()
    
c = dict(Counter(s))
res = []
for k,v in c.items():
    tmp_s = k + s + k
    idx_num = [e for e,w  in enumerate(list(tmp_s)) if w==k]
    lst = []
    for j in range(1, len(idx_num)):
        lst.append(idx_num[j] - idx_num[j-1])
    tmp = max(lst)
    res.append(tmp)
print(max(min(res)-1, 0))

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

from collections import Counter
chars = [chr(i) for i in range(ord('a'), ord('z')+1)]

def check(arr):
    e = arr[0]
    return len(arr) == arr.count(e)


ans = float('inf')
for c in chars:
    SL = list(S)
    cnt = 0
    while not check(SL):
        for i, si in enumerate(SL):
            if i == 0:
                continue
            if si == c:
                SL[i-1] = c
        SL = SL[:-1]
        cnt += 1
        
    ans = min(ans, cnt)

print(ans)

Solution (Python):
s=input()
n=len(s)
ans=n
for i in range(97, 97+26):
    x=chr(i)
    cnt=s.count(x)
    if cnt==n:
        ans=0
        break
    if cnt!=0:
        t=list(s)
        for j in range(n-1):
            u=[""]*(n-1-j)
            for k in range(n-1-j):
                if t[k]==x or t[k+1]==x:
                    u[k]=x
                else:
                    u[k]=t[k]
            if u.count(x)==n-1-j:
                ans=min(ans,j+1)
                break
            else:
                t=u
print(ans)

Solution (Python):
os = input()
import  collections
c = collections.Counter(os)
res = 99999
for k in c:
    s = os
    cnt = 0
    while True:
        
        if len(collections.Counter(s)) == 1:
            break
        ss = ""
        for i in range(len(s) - 1):
            if s[i] == k or s[i+1] == k:
                ss += k
            else:
                ss += s[i]
        cnt += 1
        s = ss
    res = min(res, cnt)
print(res)

Solution (Python):
alpha = "abcdefghijklmnopqrstuvwxyz"
s = list(input())
from copy import deepcopy
ans = 10**9
for c in s:
    s_c = deepcopy(s)
    counter = 0
    while set(s_c) != {c}:
        counter += 1
        new = []
        for i in range(len(s_c)-1):
            if s_c[i] == c or s_c[i+1] == c:
                new.append(c)
            else:
                new.append(0)
        s_c = new
    ans = min(ans, counter)
print(ans)

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

s = set(S)

ans = 1000
for w in s:
    old = S.copy()
    cnt = 0
    while True:
        if len(set(old)) == 1:
            ans = min(ans, cnt)
            break
        new = []
        cnt += 1
        for i in range(len(old) - 1):
            if old[i] == w or old[i + 1] == w:
                new.append(w)
            else:
                new.append(old[i])

        old = new.copy()

print(ans)

Solution (Python):
s = input()
a = 100
for i in s:
    c = 0
    s_t = s
    s_ = s
    while i * len(s_t) != s_:
        c += 1
        s_ = ""
        for j in range(len(s_t) - 1):
            if s_t[j] == i or s_t[j+1] == i: s_ += i
            else: s_ += s_t[j]
        s_t = s_
    a = min(a, c)
print(a)

Solution (Python):
S=input()
ans = len(S)
for a in [chr(i+ord("a"))for i in range(26)]:
    if a not in S:
        continue
    I = [-1]+[i for i,s in enumerate(S) if s==a]+[len(S)]
    ans=min(ans, max(j-i-1 for i,j in zip(I,I[1:])))
print(ans)

Solution (Python):
s = input()
r = 101
for i in set(s):
    r = min(r, max(list(map(len, s.split(i)))))
print(r)

Solution (Python):
S = input()
type = sorted(set(S))
count = [0] * len(type)

for i,t in enumerate(type):
  sen = S
  con = 0
  while True:
    tmp = ""
    if len(set(sen)) == 1:
      count[i] = con
      break
    for j in range(len(sen) - 1):
      if (sen[j] == t) or (sen[j + 1] == t):
        tmp += t
      else:
        tmp += sen[j]
    con += 1
    sen = tmp

print(min(count))

Solution (Python):
s = input()
import collections
ans=10**9
for cand in set(s):
    cnt=0
    a=0
    for tmp in s:
        if tmp!=cand:
            cnt+=1
        else:
            if a<cnt:
                a=cnt
            cnt=0
    if a<cnt:
        a=cnt
    if ans>a:
        ans=a

print(ans)

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

A = {}
for s in S:
    if s not in A:
        A[s] = 1
    else:
        A[s] += 1

B = [(a, A[a]) for a in A]
B.sort(reverse=True, key=lambda x: x[1])


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

max_num = B[0][1]

if max_num == 1:
    print(lens // 2)
    exit()

ans = 100
for i in range(len(B)):
    b = B[i][0]
    count = 0
    sub_ans = 0
    for s in S:
        if s != b:
            count += 1
        else:
            sub_ans = max(sub_ans, count)
            count = 0
    else:
        sub_ans = max(sub_ans, count)
    ans = min(sub_ans, ans)
print(ans)

Solution (Python):
import copy
s = list(input())
ans = len(s) // 2
if ("".join(s) == s[0]*len(s)):
  ans = 0
for i in range(97, 97+26):
  c = chr(i)
  c_s = copy.copy(s)
  cnt = 0
  for j in range(len(s)-1):
    cnt += 1
    for k in range(len(s)-1-j):
      if (c_s[k] == c or c_s[k+1] == c):
        c_s[k] = c
    l = len(s)-1-j
    if (c*l == "".join(c_s[:l])):
      ans = min(ans,cnt)
print(ans)

Solution (Python):
s = raw_input()

ans = len(s)
for c in range(26):
  c = chr(ord("a")+c)
  t = s
  n = 0
  while True:
    if t==c*len(t):
      break
    x = ""
    for i in range(len(t)-1):
      if t[i+1]==c:
        x += t[i+1]
      else:
        x += t[i]
    t = x
    n += 1
  ans = min(ans, n)
print ans

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

s = read().decode().rstrip()

ans = len(s)


for i in range(97, 97+26):
    c = chr(i)
    cnt = 0
    acc = s
    while len(acc) != acc.count(c):
        s_ = ""
        for j, _ in enumerate(acc):
            if j == len(acc)-1:
                break
            if acc[j:j+2].count(c) > 0:
                s_ += c
            else:
                s_ += acc[j]
        cnt += 1
        acc = s_
    ans = min(ans, cnt)

print(ans)

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

ans = len(s)

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

for j in range(len(c)):
    cnt = 0
    t = ''
    if c[j] in s:
        m = s
        while(1):
            t = ''
            for i in range(len(m)-1):
                if m[i] == c[j]:
                    t = t + c[j]
                elif m[i+1] == c[j]:
                    t = t + c[j]
                else:
                    t = t + m[i]
            m = t
            cnt += 1
            if len(set(t)) == 1:
                break
        ans = min(cnt, ans)

print(ans)

Solution (Python):
from collections import Counter

def solve(s):
    cs = Counter(s)
    m = len(s)
    for c in cs:
        news = list(s)
        size = len(s)
        count = 0
        while len(Counter(news[:size])) > 1:
            for i in range(size - 1):
                if news[i] != c[0] and news[i + 1] == c[0]:
                    news[i] = c[0]
            size -= 1
            count += 1
        if count < m:
            m = count
    return m

_s = input()
print(solve(_s))

Solution (Python):
from collections import Counter

def solve(s):
    cs = Counter(s).most_common()
    m = len(s)
    for c in cs:
        news = list(s)
        size = len(s)
        count = 0
        while len(Counter(news[:size]).most_common()) > 1:
            for i in range(size - 1):
                if news[i] != c[0] and news[i + 1] == c[0]:
                    news[i] = c[0]
            size -= 1
            count += 1
        if count < m:
            m = count
    return m

_s = input()
print(solve(_s))

Solution (Python):
from collections import Counter
s = input()
sc = Counter(s)
ans = float('inf')
for i in sc.keys():
    s2 = s
    while len(Counter(s2).keys()) != 1:
        for j in range(len(s2)-1):
            if s2[j+1] == i:
                s2 = s2[:j] + s2[j+1]+ s2[j+1:]
        s2 = s2[:-1]
    ans = min(ans,len(s)-len(s2))
print(ans)

Solution (Python):
S = input()

N = len(S)
dist = [[N for i in range(N)] for j in range(26)]
dist[ord(S[-1]) - 97][-1] = 0
for i in range(26):
    for j in reversed(range(N - 1)):
        if ord(S[j]) == 97 + i:
            dist[i][j] = 0
        else:
            dist[i][j] = dist[i][j + 1] + 1

ans = N - 1
for i in range(26):
    for j in range(1, N + 1):
        ans = min(ans, max(N - j, max(dist[i][0:j])))
print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    S = Scanner.string()
    ans = INF
    for c in string.ascii_lowercase:
        T = S
        N = len(T)
        cnt = 0
        while T.count(c) != N:
            N -= 1
            U = [""] * (N)
            for i in range(N):
                U[i] = T[i]
                if T[i+1] == c:
                    U[i] = T[i+1]
            T = U
            cnt += 1
        ans = min(ans, cnt)
    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
import sys


def main():
    S = str(input())
    ans = 10**3
    for i in list(set(S)):
        count = 0
        now = 0
        for j in S:
            if i != j:
                count += 1
            else:
                count = 0
            now = max(now,count)
        ans = min(ans,now)
    
    print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
from string import ascii_lowercase

s = input()

result = len(s)

for c in ascii_lowercase:
    t = s

    count_c = t.count(c)
    if count_c == 0:
        continue

    n_operations = 0

    while len(t) > count_c:
        t_next = [None] * (len(t) - 1)
        count_c_next = 0
        for i in range(len(t_next)):
            if t[i] == c or t[i + 1] == c:
                t_next[i] = c
                count_c_next += 1
            else:
                t_next[i] = '0'
        t = t_next
        count_c = count_c_next
        n_operations += 1

    result = min(result, n_operations)

print(result)

Solution (Python):
s = list(input())
set_s = set(list(s[:]))
n = len(s)

ans = float("inf")
if len(set_s) == 1:
    print(0)
    exit()
for target in set_s:
    l = s[:]
    for i in range(n):
        for j in range(n-1-i):
            if l[j] == target or l[j+1] == target:
                l[j] = target
        l = l[:-1]
        if len(set(list(l))) == 1:
            break
    ans = min(ans, i+1)
print(ans)

Solution (Python):
S = str(input())

if len(set(S)) == 1:
  print(0)
else:
  ans = pow(10,5)
  for s in set(S):
    l = S
    num = 0 
    while len(set(l)) > 1:
      tmp = ""
      for i in range(len(l)-1):
        if l[i] == s:
          tmp += l[i]
        else:
          tmp += l[i+1]
      l = tmp
      num += 1
    ans = min(num, ans)
  print(ans)

Solution (Python):
from sys import stdin
import string

t = stdin.readline().rstrip()
alpha = string.ascii_lowercase
mi = 10**10
if len(set(t)) == 1:
    print(0)
    exit() 
for target in alpha:
    s = t
    cnt = 0
    while True:
        cnt += 1
        sin = ""
        for i in range(len(s)-1):
            sin += s[i] if s[i] == target else s[i+1]
        s = sin
        if s.count(target) == len(s):
            break
    mi = min(mi,cnt)

print(mi)

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

ks = set(s)
ans = 100000

for k in ks:
    count = 0
    t = s[:]
    while True:
        if len(set(t)) <= 1:
            break

        new_t = []
        for i in range(len(t)-1):
            if t[i] == k or t[i+1] == k:
                new_t.append(k)
            elif s[i+1] != k:
                new_t.append(s[i+1])
        t = new_t[:]
        count += 1
    ans = min(ans, count)

print(ans)

Solution (Python):
import sys
s = input()
best = 10**18
for _s in list(set(s)):
    cnt = 0
    _max = 0
    for x in s[::-1]:
        if x == _s:
            cnt = 0
        else:
            cnt += 1
        _max = max(_max, cnt)
    best = min(_max, best)
print(best)

Solution (Python):
s = input()

ans = float("inf")
for i in range (26):
    a = chr(ord("a")+i)
    if  s.count(a) == 0 :
        pass
    else:
        tmp = s
        c = 0
        while set(tmp) != {a}:
            t = ""
            for j in range(len(tmp)-1):
                if tmp[j] == a or tmp[j+1] == a:
                    t += a
                else:
                    t += tmp[j]
            c += 1
            tmp = t
        ans = min(c, ans)

print(ans)

Solution (Python):
s=list(input())
ans=1000
tmp=s
for i in s:
    l=[]
    cnt=0
    for j in s:
        if j!=i:
            cnt+=1
        else:
            l.append(cnt)
            cnt=0
    l.append(cnt)
    if max(l)<=ans:
        ans=max(l)
print(ans)

Solution (Python):
from collections import Counter

s = input()


def convert(st, toS, cou):
    if st.count(st[0]) == len(st):
        return cou
    for i in range(len(st)):
        if i+1 < len(st) and st[i+1] == toS:
            st[i] = toS
    return convert(st[:-1], toS, cou+1)


ans = 200
for j in set(s):
    ans = min(ans, convert(list(s), j, 0))
print(ans)

Solution (Python):
s = input()
ans = float("inf")
for i in range(26):
  c = chr(ord("a")+i)
  if c not in s:
    continue
  temp = s
  count = 0
  while set(temp) != {c}:
    t = ""
    for j in range(len(temp)-1):
      if temp[j] == c or temp[j+1] == c:
        t += c
      else:
        t += "
    temp = t
    count += 1
  ans = min(ans, count)
print(ans)

Solution (Python):
s=input()
ans = len(s)
then = [s]
for i in s:
    cnt = 0
    while len(set(then[0])) >1:
        cnt += 1
        tmp = then.pop()
        empty=""
        for j in range(len(tmp)-1):
            if tmp[j]==i or tmp[j+1]==i:
                empty += i
            else:
                empty += tmp[j]
        then.append(empty)
    ans=min(ans,cnt)
    then=[s]
print(ans)

Solution (Python):
s = input()

C = list(set(list(map(str, s))))

ans = len(s)
for c in C:
	tmp = 0
	cnt = 0
	for i in range(len(s)):
		if s[i] == c:
			tmp = max(tmp, cnt)
			cnt = 0
		else:
			cnt += 1

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

print(ans)

Solution (Python):
def main(c,S):
    count=0
    while S.count(c)!=len(S):
        T=""
        count+=1
        for i in range(len(S)-1):
            if c in [S[i],S[i+1]]:
                T+=c
            else:
                T+=S[i]
        S=T
    return(count)


S=input()
lst=[chr(i) for i in range(ord("a"),ord("z")+1) if chr(i) in S]
print(min([main(i,S) for i in lst]))

Solution (Python):
s = input()
A = [chr(i) for i in range(97,97+26)]
ans = float('inf')
for a in A:
    count = 0
    a_count = 0
    for i in range(len(s)):
        if s[i] == a:
            a_count = max(count,a_count)
            count = 0
        else:
            count += 1
        if i == len(s)-1:
            a_count = max(count,a_count)
    ans = min(ans,a_count)
print(ans)

Solution (Python):

S = input()
st = set(S)
ans = 1e+9
for s in st:
  ls_strg = list(S.split(s))
  mx = 0
  for strg in ls_strg:
    mx = max(mx,len(strg))
  ans = min(mx, ans)
print (ans)

Solution (Python):
s = list(input())
ans = 100
tmp = s
for i in s:
    l = []
    count = 0
    for j in s:
        if j != i:
            count += 1
        else:
            l.append(count)
            count = 0
    l.append(count)
    if max(l) <= ans:
        ans = max(l)
print(ans)

Solution (Python):
s = input()
n = len(s)
ls = [[0] for i in range(26)]
for i in range(n):
  x = ord(s[i])-97
  ls[x].append(i+1)
for i in range(26):
  ls[i].append(n+1)
ans = n
for i in range(26):
  ans = min(ans,max([ls[i][j]-ls[i][j-1] for j in range(1,len(ls[i]))]))
print(ans-1)

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

def chk(i):
    A = [len(a) for a in S.split(chr(i+97))]
    return max(A+[0])

print(min([chk(i) for i in range(26)]))

Solution (Python):
import collections
import copy

S = list(input())
len_s = len(S)
S_count = collections.Counter(S)

ans = {}

for key in S_count:
    if len(set(S)) == 1:
        ans[key] = 0
    else:
        new_S = copy.copy(S)
        count = 0
        while len(set(new_S)) != 1:
            count += 1
            old_S = copy.copy(new_S)
            new_S = []
            for i in range(len(old_S)-1):
                if old_S[i] == key or old_S[i+1] == key:
                    new_S.append(key)
                else:
                    new_S.append(old_S[i])

        ans[key] = count
print(min(ans.values()))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    s = S()
    d = defaultdict(list)
    for i in range(27):
        d[chr(ord("a")+i)].append(-1)
    for i in range(len(s)):
        d[s[i]].append(i)
    for i in range(27):
        d[chr(ord("a") + i)].append(len(s))
    ans = inf
    for key, value in d.items():
        tmp = 0
        for v in range(len(value) - 1):
            tmp = max(tmp, value[v + 1] - value[v]-1)
        ans = min(tmp, ans)
    print(ans)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
S=input();print(min(max(map(len,S.split(c)))for c in"abcdefghijklmnopqrstuvwxyz"))

Solution (Python):
s = input()
ans = 105
from string import ascii_lowercase
for c in ascii_lowercase:
    t = s
    anstemp = 0
    while True:
        tmp = ''
        if t.count(c) == len(t): break
        for i in range(len(t)-1):
            if c in t[i:i+2]: tmp += c
            else: tmp += t[i]
        anstemp += 1
        t = tmp
    if anstemp < ans: ans = anstemp
print(ans)

Solution (Python):
def is_all(x):
    for i in range(len(x)-1):
        if x[i]!=x[i+1]:
            return False
    return True
s=input()
n=len(s)
dic={}
for i in range(n):
    if not s[i] in dic:
        dic[i]=s[i]
a=n
for i in range(len(dic)):
    t=[s[j] for j in range(n)]
    for j in range(n-1,-1,-1):
        if t[j]==dic[i]:
            ans=n-j-1
            break
        else:
            t[j]=dic[i]
    cnt=0
    while not is_all(t):
        cnt+=1
        for j in range(1,n):
            if t[j]==dic[i]:
                t[j-1]=dic[i]
    a=min(max(cnt,ans),a)
print(a)

Solution (Python):
s = input().strip()
n = len(s)
D = {chr(i):[] for i in range(97,123)}
for i in range(97,123):
    for j in range(n):
        if s[j]==chr(i):
            D[chr(i)].append(j)
cntmin = 1000
for i in range(97,123):
    if len(D[chr(i)])==1:
        d = D[chr(i)][0]
        cntmin = min(cntmin,max(d,n-1-d))
    elif len(D[chr(i)])>1:
        A = []
        for j in range(len(D[chr(i)])):
            if j==0:
                A.append(D[chr(i)][0])
            if j<len(D[chr(i)])-1:
                A.append(D[chr(i)][j+1]-D[chr(i)][j]-1)
        A.append(n-1-D[chr(i)][-1])
        cntmin = min(cntmin,max(A))
print(cntmin)

Solution (Python):
s = input()

ans = 100
for _ in 'abcdefghijklmnopqrstuvwxyz':
    S = list(s)
    cnt = 0
    for i in range(len(S)):
        if len(set(S)) == 1:
            ans = min(ans, cnt)
            break
        T = []
        for j in range(len(S)-1):
            if S[j] == _ or S[j+1] == _:
                T.append(_)
            else:
                T.append(S[j])
        cnt += 1
        S = T

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



import numpy as np

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

def F(S,x):
    A = (S == x)
    t = 0
    while True:
        if np.all(A):
            return t
        A = (A[:-1] | A[1:])
        t += 1

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

Solution (Python):
def examA():
    Alpha = [chr(i) for i in range(97, 97+26)]
    S = SI(); N = len(S)
    ans = -1
    for i in range(N):
        for s in Alpha:
            cur = [s for s in S]
            for l in range(i):
                for k in range(N-1):
                    if cur[k+1]==s:
                        cur[k]=s
 
            if len(Counter(cur[:N-i]))==1:
                ans = i
                break
        if ans>=0:
            break
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(s: str):
    from collections import Counter
    c = Counter(s)

    N = len(s)
    ans = INF


    for k in c.keys():
        c = 0
        sc = s
        for j in range(N):
            ls = []
            for i in range(len(sc)-1):
                if sc[i] == k or sc[i+1] == k:
                    ls.append(k)
                else:
                    ls.append(sc[i])
            c += 1
            
            if all([j == k for j in sc]):
                break

            sc = ''.join(ls)
        ans = min(ans, c-1)

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(s: str):
    from collections import Counter
    c = Counter(s)

    N = len(s)
    ans = INF


    for k in c.keys():
        
        c = 0
        sc = s
        for j in range(N):
            ls = []
        
            for i in range(len(sc)-1):
                if sc[i] == k or sc[i+1] == k:
                    ls.append(k)
                else:
                    ls.append(sc[i])
                
            c += 1
            
            if all([j == k for j in sc]):
                break

            sc = ''.join(ls)
        ans = min(ans, c-1)

    print(ans)


    
    
    
        
    
    
    
    
    
    
    
    
    
    


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):
s = input()

ret = float('inf')
for c in set(s) :
  tmp = 0
  t = s[::]
  u = ''
  while t.count(c) != len(t) :
    tmp += 1
    for i in range(len(t) - 1) :
      if t[i] == c or t[i+1] == c :
        u += c
      else :
        u += t[i]
    t = u[::]
    u = ''
  ret = min(ret, tmp)
  
print(ret)

Solution (Python):
s = input()
c = "abcdefghijklmnopqrstuvwxyz"
a = len(s)
for i in c:
  sl = s
  count = 0
  while len(sl) != sl.count(i):
    nsl = ""
    for j in range(len(sl)-1):
      if sl[j] == i or sl[j+1] == i:
        nsl += i
      else:
        nsl += sl[j]
    sl = nsl
    count += 1
  a = min(a,count)
print(a)

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

ans = float('inf')
for s in set(S):  
  ini_idx = S.find(s)
  tmp_ans = ini_idx
  prv_idx = ini_idx
  while 1:
    tmp_idx = S[prv_idx+1:].find(s)
    if tmp_idx == -1:
      break
    else:
      tmp_idx += prv_idx + 1
      tmp_ans = max(tmp_ans, tmp_idx - prv_idx - 1)
      prv_idx = tmp_idx
    
  tmp_ans = max(tmp_ans, len(S) - prv_idx - 1)
  ans = min(ans,tmp_ans)
print(ans)