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

Solution (Python):
S = input()
L = len(S)
ans = float('inf')
for s in [chr(i) for i in range(97, 97+26)]:
    mx = 0
    cnt = 0
    for i in range(L):
        if S[i] == s:
            mx = max(mx,cnt)
            cnt = 0
        else:
            cnt += 1
    
    val = max(cnt , mx)
    ans = min(ans,val)

print(ans)

Solution (Python):
s = input()
chars = set(s)
ans = len(s)

for c in chars:
    max_partial_char_length = max(len(_) for _ in s.split(c))
    ans = min(ans, max_partial_char_length)

print(ans)

Solution (Python):
s = input()
ans = 10**5
def f(s,w):
    cnt = 0
    k = s.count(w)
    length = len(s)
    while True:
        if k==length:
            break
        s_=''
        for i in range(len(s)-1):
            if s[i+1]==w:
                s_+=w
            else:
                s_+=s[i]
        length-=1
        k = s_.count(w)
        s = s_
        cnt+=1
    return cnt
for s_ in s:
    ans = min(ans,f(s,s_))
print(ans)

Solution (Python):


import sys
from collections import Counter

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    s = SI()
    char_cnt = Counter(s)

    res = INF
    for c in char_cnt.keys():
        r = s[:]
        cnt = 0
        while len(set(r)) != 1:
            t = ''
            for ss in zip(r[:-1], r[1:]):
                if c in ss:
                    t += c
                else:
                    t += ss[0]
            cnt += 1
            r = t
            
        res = min(res, cnt)

    return res


print(main())

Solution (Python):
s = input()
L = []
for i in s:
  if i not in L:
    L.append(i)

Ans = 100
for i in L:
  cnt = 0
  ma = 0
  for j in s:
    if i != j:
      cnt += 1
    else:
      ma = max(ma, cnt)
      cnt = 0
  ma = max(ma, cnt)
  Ans = min(Ans, ma)

print(Ans)

Solution (Python):
s = input()
s_list = list(s)
minis = []
for k in set(s):
  a = [i for i, x in enumerate(s_list) if x == k]
  mini = max(a[0], 0)
  for m in range(len(a) - 1):
    mini = max(a[m+1] - a[m] - 1, mini)
  mini = max(len(s) - a[-1] - 1, mini)
  minis.append(mini)
print(min(minis))

Solution (Python):
L = [chr(i) for i in range(97, 123)]
s = list(input())
N = len(s)

ans = float("inf")
for i in L:
    c = 0
    X = s
    while True:
        if X.count(i) == N - c:
            break
        else:
            Y = []
            for j in range(N - c - 1):
                if X[j] == i or X[j + 1] == i:
                    Y.append(i)
                else:
                    Y.append(".")
            X = Y
        c += 1

    if c < ans:
        ans = c

print(ans)

Solution (Python):
S=input()
E=list(set(S))
print(min(max(len(s) for s in S.split(e)) for e in E))

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

Solution (Python):
from collections import Counter
S = input()
A = Counter(list(S)).most_common()

ans = float('inf')
for a in A:
    posi = -1
    interval = 0
    for i in range(len(S)):
        if S[i] == a[0]:
            interval = max(interval, i - posi - 1)
            posi = i
        if i == len(S) - 1:
            interval = max(interval, i - posi)
            posi = i
    
    ans = min(ans, interval)
        
print(ans)

Solution (Python):
s = input()
m = set(s)

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

ans = float('inf')
for k in m:
    cnt = 0
    tt = s
    while True:
        cnt += 1
        t = ''
        for i in range(len(tt)-1):
            if tt[i] == k or tt[i+1] == k:
                t += k
            else:
                t += tt[i+1]
        tt = t

        if len(set(tt)) == 1:
            break
    ans = min(ans,cnt)       
print(ans)

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

ans=1000

A=["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"]
Li=[]
li=[]
for i in range(26):
    li=copy.deepcopy(S)
    if li.count(A[i])==len(li):
        print(0)
        exit()
    else:
        Li=copy.deepcopy(li)
        li=[]
        for k in range(len(S)):
            for j in range(len(Li)-1):
                if Li[j]==A[i] or Li[j+1]==A[i]:
                    li.append(A[i])
                else:
                    li.append("1")
            
            if li.count(A[i])==len(li):
                if ans>len(S)-len(li):
                    ans=len(S)-len(li)
                break
            else:
                Li=copy.deepcopy(li)
                li=[]
print(ans)

Solution (Python):



def main():
    s = input()

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

    alphabets = [chr(ord('a') + i) for i in range(26)]
    ans = float('inf')

    for alphabet in alphabets:
        t = s
        count = 0

        while len(t) >= 2:
            t_dash = ''

            for i in range(len(t) - 1):
                if t[i] == alphabet or t[i + 1] == alphabet:
                    t_dash += alphabet
                else:
                    t_dash += t[i]

            count += 1
            t = t_dash

            if len(set(t_dash)) == 1:
                break

        ans = min(ans, count)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s = input().strip()
sset = set(s)
ans = pow(100, 3)
for ss in sset:
  tmps = s
  c = 0
  while tmps.count(ss) != len(tmps):
    _tmps = ''
    for ps, ns in zip(tmps, tmps[1:]):
      if ps == ss or ns == ss:
        _tmps += ss
      else:
        _tmps += ps
    tmps = _tmps
    c += 1
  if ans > c:
    ans = c
print(ans)

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

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
n = len(s)
chars = set(s)

ans = 10**18

for ci in chars:
    cur = s
    if len(set(s)) == 1 and s[0] == ci:
        ans = 0
        break
    
    cnt = 1
    for ln in range(n):
        nex = ""
        for idx in range(len(cur)-1):
            if cur[idx] == ci or cur[idx+1] == ci:
                nex += ci
            else:
                nex += cur[idx]
                
        if len(set(nex)) == 1 and nex[0] == ci:
            break
        
        cnt += 1
        cur = nex
        
    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
    cnt = 0
    s = S
    while any(a!=c for a in s):
        t = ''
        for a,b in zip(s,s[1:]):
            if c==a or c==b:
                t += c
            else:
                t += a
        s = t
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Solution (Python):
s=input()
ans=float('inf')
for c in set(s):
    ans=min(ans,max(map(len,s.split(c))))
print(ans)

Solution (Python):
s=input()
res=[]
for x in set(s):
    t=s
    while(len(set(t))>1):
        y=""
        for i in range(len(t)-1):
            if t[i]==x:
                y+=x
            elif t[i+1]==x:
                y+=x
            else:
                y+=t[i]
        t=y
    res.append(len(t))
print(len(s)-max(res))

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

ans = 1000
candidates = set(ss)
for s in candidates:
    count = 0
    t = list(ss)
    while True:
        if len(set(t))==1:
            ans = min(ans, count)
            break
        t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]
        count += 1
print(ans)

Solution (Python):
S = input()

min_cost = 10**18
for c in set(S):
    cost = max(map(len, S.split(c)))
    min_cost = min(min_cost, cost)

print(min_cost)

Solution (Python):
s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
if len(list(set(s)))==1:
    print(0)
else:
    for i in range(26):
        t=p[i]
        d=s[:]
        c=0
        while len(d)>0:
            c+=1
            for j in range(len(d)-1):
                if d[j]==t or d[j+1]==t:
                    d[j]=t
            else:
                d.pop(-1)
                if len(list(set(d)))==1 and d[0]==t:
                    break
        q=min(q,c)
    print(q)

Solution (Python):
s = input()
n = len(s)
alset = set()
mojiretsu = s
chuumoku = ""
cnt = 0
ans = float("INF")
for i in range(n):
    if s[i] not in alset:
        chuumoku = s[i]
        alset.add(chuumoku)
        while len(set(mojiretsu)) != 1:
            cpmojiretsu = mojiretsu
            mojiretsu = ""
            for j in range(len(cpmojiretsu) - 1):
                if cpmojiretsu[j] == chuumoku or cpmojiretsu[j + 1] == chuumoku:
                    mojiretsu += chuumoku
                else:
                    mojiretsu += s[j]
            cnt += 1
        if ans > cnt:
            ans = cnt
        cnt = 0
        mojiretsu = s
print(ans)

Solution (Python):
import string


def solve(S):
    ans = 1000
    for v in string.ascii_lowercase:
        tans = 0
        s = S
        while s.count(v) < len(s):
            tans += 1
            ns = []
            for i in range(len(s) - 1):
                if s[i] == v or s[i + 1] == v:
                    ns.append(v)
                else:
                    ns.append(s[i])
            s = "".join(ns)
        ans = min(ans, tans)

    return ans

if __name__ == "__main__":
    print(solve(input()))

Solution (Python):
from collections import Counter


def solve(s, ch):
    ret = 0
    dist = -1
    n = len(s)
    l = [0]*n
    for i in reversed(range(n)):
        if s[i] == ch:
            dist = 0
        elif dist == -1:
            l[i] = dist
        else:
            dist += 1
            l[i] = dist
    if max(l) > l.count(-1):
        ret = max(l)
    else:
        ret = l.count(-1)
    return ret


s = input()
C = Counter(s)
ans = len(s)+2
for i, v in C.most_common():
    ans = min(ans, solve(s, i))
print(ans)

Solution (Python):
S = input()

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

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

c = Counter(S)
ans = INF

for k, v in c.items():
    S2 = list(S)
    others = len(S2) - S.count(k)
    cnt = 0
    
    while others > 0:
        for i in range(len(S2)):
            if i == 0: continue
            
            if S2[i] == k:
                if S2[i-1] != k:
                    S2[i-1] = k
                    others -= 1
        if S2[-1] != k:
            others -= 1
        
        S2.pop(-1)
        cnt += 1
    
    ans = min(cnt, ans)
print(ans)

Solution (Python):
def check(array, c):
    for i in array:
        if i != c:
            return False
    return True

def generate(s, c):
    ret = s[:-1]
    for i in range(len(s)-1):
        if s[i] == c or s[i+1] == c:
            ret[i] = c
    return ret

s = input()

ans = float("inf")
for c in set(list(s)):
    use = list(s)
    ans_tmp = 0
    while not check(use, c):
        use = generate(use, c)
        
        ans_tmp += 1
    ans = min(ans, ans_tmp)
print(ans)

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

mina = float('inf')
for c in range(97, 123):
    c = chr(c)
    if c not in s:
        continue
    maxa = 0
    tmpa = 0
    for i in range(len(s)):
        if s[i] == c:
            maxa = max(maxa, tmpa)
            tmpa = 0
        else:
            tmpa += 1
    else:
        maxa = max(maxa, tmpa)
    mina = min(mina, maxa)
print(mina)

Solution (Python):
import string

s = input()
n = len(s)
ans = n

for chara in set(s):
    left_max = 0
    right_max = 0
    ri = 0
    temp = 0
    for index, c in enumerate(s):
        if c == chara:
            left_max = max(temp, left_max)
            temp = 0
            ri = index
        else:
            temp += 1
    right_max = n - ri - 1
    ans = min(max(right_max, left_max), ans)
print(ans)

Solution (Python):
import string

s = input()
n = len(s)
ans = n
for chara in string.ascii_lowercase:
    left_max = 0
    right_max = 0
    ri = 0
    temp = 0
    for index, c in enumerate(s):
        if c == chara:
            left_max = max(temp, left_max)
            temp = 0
            ri = index
        else:
            temp += 1
    right_max = n - ri - 1
    ans = min(max(right_max, left_max), ans)
print(ans)

Solution (Python):
s = input()
len_s = len(s)
alp =  [0]*26
for i,j in enumerate(s):
  alp_index = ord(j) - ord("a")
  if alp[alp_index] == 0:
    alp[alp_index] = [i]
  else:
    alp[alp_index].append(i)
max_k = []
for i in alp:
  if i != 0:
    i.append(len_s)
    k = [i[0]]
    for j,l in enumerate(i[1:]):
      k.append(i[j+1]-i[j]-1)
    max_k.append(max(k))
     
print(min(max_k))

Solution (Python):
s = input()

al = list(set(s))

al_ans = 100

for ma in al:

    now = 0
    ans = 0

    for i in range(len(s)):
        if s[i]==ma:
            if ans<now:
                ans = now
            now = 0
        else:
            now = now+1
    else:
        if ans<now:
            ans = now
            
    if ans<al_ans:
        al_ans = ans
    
print(al_ans)

Solution (Python):


from collections import Counter


def inpl(): return list(map(int, input().split()))


S = input()
C = Counter(S)
if len(S) == 1:
    print(0)
    exit()

ans = 100
for key in C.keys():
    prev_S = list(S)
    cnt = 0
    t = len(S) - 1
    while t > 0:
        if all([1 if s == key else 0 for s in prev_S]):
            ans = min(ans, cnt)
            break
        SS = []
        for i in range(t):
            if key in prev_S[i: i + 2]:
                SS.append(key)
            else:
                SS.append(prev_S[i])
        cnt += 1
        t -= 1
        prev_S = SS[:]
    

print(ans)

Solution (Python):

s=input()
c=[]
for i in range(len(s)):
    if not s[i] in c:
        c.append(s[i])
count_max_list = []
for a in c:
    count=0
    count_max = 0
    for i in range(len(s)):
        if a==s[i]:
            count_max=max(count,count_max)
            count=0
        else:
            count+=1
    count_max=max(count,count_max)
    count_max_list.append(count_max)
print(min(count_max_list))

Solution (Python):
s = input()
ans = 100
count = 0
a = []

for i in range(97, 97+26):
    for j in range(len(s)):
        if s[j] != chr(i):
            count += 1
        else:
            a.append(count)
            count = 0

    a.append(count)
    maax = max(a)
    if ans > maax:
        ans = maax
    count = 0
    a.clear()

print(ans)

Solution (Python):
from collections import Counter

inputs = list(input())

count = 10 ** 15
kinds = len(set(inputs))

def cal(inputs, item):
    re = ''
    for index in range(len(inputs)-1):
        if inputs[index] == item or inputs[index+1] == item:
            re += item
        else:
            re += inputs[index]
    return re

if kinds == 1:
    count = 0
else:
    set_inputs = set(inputs)
    for set_input in set_inputs:
        item = inputs[:]
        total = 0
        while len(set(item)) != 1:
            item = list(cal(item, set_input))
            total += 1
        count = min(count, total)

print(count)

Solution (Python):
def itoa(i):
    alphabet = ['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']
    return alphabet[i]
s = input()
score_list = []
for i in range(26):
    c = itoa(i)
    prev = -1
    score = 0
    flag=False
    for j in range(len(s)):
        if c==s[j]:
            score=max(j-prev-1,score)
            flag=True
            prev=j
    score = max(j-prev,score)
    if flag==False:
        score=10**3
    score_list.append(score)

print(min(score_list))

Solution (Python):
s = input()
res = 10**9

for alp in set(list(s)):
    t = s
    cnt = 0
    while t!=t[0]*len(t):
        new_t = ''
        for i in range(len(t)-1):
            if alp in (t[i], t[i+1]):
                new_t += alp
            else:
                new_t += '!'
        t = new_t
        cnt += 1
    res = min(res, cnt)
print(res)

Solution (Python):
S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c in S)
print(ans)

Solution (Python):
S = input()
ans = len(S)
for c in [chr(i + 97) for i in range(26)]:
    if c not in S:
        continue
    ma = max(map(len, S.split(c)))
    ans = min(ans, ma)
print(ans)

Solution (Python):
S = input()
ans = len(S)
for tgt in set(S):
    T = S
    while len(T) != T.count(tgt):
        U = ''
        for ab in zip(T, T[1:]):
            U += tgt if tgt in ab else ab[0]
        T = U
    ans = min(ans, len(S) - len(T))
print(ans)

Solution (Python):
import collections

S = input()

dic = collections.Counter(S)

ans = len(S)

for k in dic.keys():
    tmp = S
    tmp_ans = 0
    while True:
        ch = ''
        lens = len(tmp)

        for i,s in enumerate(tmp):
            if ch == '' or ch == s:
                ch = s
            else:
                break

        else:
            break

        for i in range(len(tmp)-1):
            if tmp[i+1] == k:
                tmp = tmp[:i] + k + tmp[i+1:]

        tmp = tmp[:-1]
        tmp_ans += 1


    ans = min(ans,tmp_ans)

print(ans)

Solution (Python):
from collections import Counter
s = input()
S = set(s)
A = []

for i in S:
    a = 0
    p = s.split(i)
    
    for j in range(len(p)):
        if len(p[j]) > a:
            a = len(p[j])
    A.append(a)

print(min(A))

Solution (Python):
from collections import Counter
s=input()
S=set(s)
A=[]
for i in S:
    a=0
    My=s.split(i)
    for j in range(len(My)):
        if len(My[j])>a:
            a=len(My[j])
    A.append(a)
print(min(A))

Solution (Python):
s = list(input())
s_ord = [ord(e) for e in s]
s_ord_ele = sorted(list(set(s_ord)))

def operate(list1,str_ord,count):
    if len(list(set(list1))) == 1:
        return count
    for i in range(len(list1) - 1):
        if list1[i+1] == str_ord:
            list1[i] = list1[i+1]
    del list1[-1]
    return operate(list1,str_ord,count+1)
min_count = 100
for e in s_ord_ele:
    count = operate(s_ord[:],e,0)
    if count < min_count:
        min_count = count
print(min_count)

Solution (Python):
s = input()
ans = 1e9
for alpha in "abcdefghijklmnopqrstuvwxyz":
    cur = list(s)
    cnt = 0
    while len(set(cur))>1:
        
        for i in range(1,len(cur)):
            if cur[i]==alpha:
                cur[i-1]=alpha
        cur.pop()
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Solution (Python):
import string

S = input()
ret = 1000

for c in string.ascii_letters:
    if c not in S:
        continue

    k = 0
    t = S
    nt = ""

    while t.count(c) != len(t):
        k += 1
        nt = ""
        for i in range(len(t) - 1):
            if t[i] == c or t[i + 1] == c:
                nt += c
            else:
                nt += t[i]
        t = nt

    ret = min(ret, k)

print(ret)

Solution (Python):
n = input()






score = 1000
left = 0
for i in range(len(n)):
    alpha = n[i] 
    _left = 0
    left = 0
    for j in range(len(n)):
        if n[j] != alpha:
            _left += 1
        else:
            left = max(left, _left)
            _left = 0
    left = max(left, _left)
    score = min(score, left)
print(score)

Solution (Python):
s = input()
N = len(s)
table = {}
for i in range(N):
    table[s[i]] = table.get(s[i], [])
    table[s[i]] += [i]
ans = 100
for k, nums in table.items():
    ans = min(ans, max([nums[0], N - 1 - nums[-1]] +
                       [(nums[i + 1] - nums[i] - 1) for i in range(len(nums) - 1)]))
print(ans)

Solution (Python):
s=input()
d=[set(i) for i in s]
ans=0
for i in range(101):
    if len(d)==1: break
    tmp=d[0]
    for  j in range(1,len(d)):
        tmp=tmp&d[j]

    if len(tmp)>=1: break
    for j in range(len(d)-1):
        d[j]=d[j]|d[j+1]
    d.pop()
    ans+=1
print(ans)

Solution (Python):
s = input()
ans = 100
for i in s:
    dis = 0
    td = 0
    for j in s:
        if i == j:
            dis = max(dis, td)
            td = 0
        else:
            td += 1
        dis = max(dis, td)
    ans = min(ans, dis)
print(ans)

Solution (Python):
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def main() -> None:
    s = next_str()
    dic = [set() for _ in range(len(s))]

    flg = False

    for i in range(len(s)):
        dic[i].add(s[i])

    while True:
        for c in range(ord('a'), ord('z') + 1):
            for i in range(len(dic)):
                if chr(c) not in dic[i]:
                    break
            else:
                flg = True

        for i in range(len(dic) - 1):
            dic[i] |= dic[i + 1]

        if flg: break
        dic = dic[:-1]

    print(len(s) - len(dic))


if __name__ == '__main__':
    main()

Solution (Python):
S = input()

ans = len(S)
for i in range(26):
    c = chr(ord('a') + i)
    if not c in S: continue
    if all([c==a for a in S]):
        print(0)
        exit()
    arr = list(S)
    tmp = 0
    while 1:
        arr2 = []
        diff = False
        tmp += 1
        for a,b in zip(arr,arr[1:]):
            if a==c or b==c:
                arr2.append(c)
            else:
                arr2.append(a)
                diff = True
        if not diff:
            break
        arr = arr2
    ans = min(ans, tmp)
print(ans)

Solution (Python):

d = set()
s = list(input())
n = len(s)
for c in s:
    d.add(c)

res = 10**5
for c in d:
    cnt = 0
    ss = list(s)
    nn = n
    
    while True:
        if len(set(ss))==1:
            break
        cnt += 1
        for i in range(nn-1):
            if ss[i+1]==c:
                ss[i] = c
        ss.pop()
        nn -= 1
    res = min(res, cnt)
print(res)

Solution (Python):

def main():
    buf = input()
    s = buf
    characters = []
    for i in s:
        if not i in characters:
            characters.append(i)
    min_iter_count = 999
    for i in characters:
        iter_count = 0
        t = s
        while True:
            flag = False
            new_t = ""
            for j in range(len(t) - 1):
                if t[j] == i:
                    new_t += i
                elif t[j+1] == i:
                    new_t += i
                    flag = True
                else:
                    new_t += t[j]
                    flag = True
            if t[-1] != i:
                flag = True
            t = new_t
            if flag:
                iter_count += 1
            else:
                break
        if iter_count < min_iter_count:
            min_iter_count = iter_count
    print(min_iter_count)

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
S = len(s)
Words = {}
for i in range(len(s)):
    if s[i] not in Words:
        Words[s[i]] = [j for j, x in enumerate(s) if x == s[i]]
Ans = float("inf")
for w in Words:
    Indexes = Words[w]
    change = Indexes[0]
    for i in range(1, len(Indexes)):
        change = max(change, Indexes[i] - Indexes[i-1] - 1)
    change = max(change, S - Indexes[-1] - 1)
    Ans = min(Ans, change)
print(Ans)

Solution (Python):
def main():
    s = input()

    dic = {}
    for i in range(len(s)):
        if s[i] in dic:
            dic[s[i]].append(i)
        else:
            dic[s[i]] = [i]

    ans = 101
    for k in dic:
        dic[k].append(-1)
        dic[k].append(len(s))
        dic[k].sort()

        mx = -1
        for j in range(len(dic[k])-1):
            mx = max(mx, dic[k][j+1]-dic[k][j]-1)

        ans = min(ans, mx)

    print(ans)


if __name__ == '__main__':
    main()

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

str = list("abcdefghijklmnopqrstuvwxyz")
ans = 1e9

for ch in str:
  if not ch in S:
    continue
  
  T = copy.copy(S)

  L = len(T)
  flg = True
  for i in range(L):
    if T[i] != ch:
      flg = False
      break
      
  if flg:
    print(0)
    exit(0)
    
  for cnt in range(1,100):
    flg = True
    for i in range(L-1):
      if T[i+1] == ch:
        T[i] = ch
      elif T[i] == ch:
        pass
      else:
        flg = False
        
    L -= 1
    
    if flg:
      
      ans = min(ans, cnt)
      break
      
print(ans)

Solution (Python):
S = input()
print(min([len(max(S.split(s), key=lambda x: len(x))) for s in set(S)]))

Solution (Python):
S = input()
if len(set(S)) == 1:
    print(0)
    exit()
ans = len(S)
for i in range(26):
    seq = [s for s in S]
    p = chr(ord('a')+i)
    for j in range(len(S)-1):
        for k in range(len(S)-j-1):
            if seq[k+1] == p:
                seq[k] = seq[k+1]
        for k in range(len(S)-j-1):
            if seq[k] != p:
                break
        else:
            ans = min(ans, j+1)
            break
print(ans)

Solution (Python):
S = input()
P = list(set(S))
ANS = []
for i in range(len(P)) :
    T = list(S.split(P[i]))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))

Solution (Python):
S = input()
ANS = []
for i in range(ord("a"),ord("z")+1) :
    p = chr(i)
    T = list(S.split(p))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))

Solution (Python):
s = input()

ans = [0 for i in range(ord('z')-ord('a')+1)]
for i in range(ord('a'),ord('z')+1):
    c = chr(i)
    s2 = s.split(c)
    ans[i-ord('a')] = max([len(ss) for ss in s2])
print(min(ans))

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

Solution (Python):
from collections import Counter
s = input()
x = Counter(s).most_common()
ans = 100
for p in x:
    ch = p[0]
    t = list(s)
    num = 0
    while set(t) != set(ch):
        num += 1
        temp = tuple(t)
        k = len(t)
        for i in range(k-1):
            if temp[i+1] == ch:
                t[i] = ch
        t = t[:-1]
    ans = min(num, ans)
print(ans)

Solution (Python):
N = input()

from collections import Counter

counter = Counter(N)
answer = float("inf")

for c in counter:

    margin = 0

    items = list(N.split(c))

    margin = 0
    for item in items:
        margin = max(margin, len(item))

    answer = min(answer, margin)

print(answer)

Solution (Python):
N = input()

from collections import Counter

counter = Counter(N)
answer = float("inf")

for c in counter:

    margin = 0

    items = list(N.split(c))
    first = items.pop(0)
    last = items.pop()
    margin = max(len(first), len(last))

    for item in items:
        margin = max(margin, len(item))

    answer = min(answer, margin)

print(answer)

Solution (Python):
s=list(input())
l=[chr(i) for i in range(97,97+26)]
lc=[]
for j in l:
  if j in s:
    c=0
    t=s
    while len(set(t))!=1:
      u=[]
      for k in range(len(t)-1):
        if t[k]==j or t[k+1]==j:u.append(j)
        else:u.append(t[k])
      t=u
      c+=1
    lc.append(c)
print(min(lc))

Solution (Python):
ss = input()

ans = []
for c in 'abcdefghijklmnopqrstuvwxyz':
    ansC = 0
    num = 0
    for s in ss:
        if s != c:
            num += 1
        else:
            ansC = max(ansC, num)
            num = 0
    ansC = max(ansC, num)
    ans.append(ansC)

print(min(ans))

Solution (Python):
s=raw_input()
result=len(s)
for i in range(0, 26):
	cur_result=0
	ch=chr(ord("a")+i)
	s+=ch
	cur=-1
	while True:
		next=s.find(ch, cur+1)
		if next==-1:
			break
		cur_result=max(cur_result, next-cur-1)
		cur=next
	s=s[:-1]
	result=min(result, cur_result)
print result

Solution (Python):
s_ = input()
answ = float("inf")
for i in s_:
    s = s_
    ans = 0
    while len(set(s)) != 1:
        a = ""
        for j in range(len(s) - 1):
            if s[j] == i or s[j + 1] == i:
                a += i
            else:
                a += s[j]
        ans += 1
        s = a
    answ = min(answ, ans)
print(answ)

Solution (Python):
ans_dict = {}
s = str(input())
list_s = list(s)
list_al = list("abcdefghijklmnopqrstuvwxyz")
for i in range(26):
    ans_dict[list_al[i]] = [-1]

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

for i in range(26):
    ans_dict[list_al[i]].append(len(list_s))
for key, value in ans_dict.items():
    ans_dict[key] = max([(value[i] - value[i-1]) for i in range(1,len(value))]) - 1

print(min(ans_dict.values()))

Solution (Python):
def c(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
s = list(input())
ass = 1000000
for i in range(len(s)):
    r = c(s,s[i])
    ans = 0
    for i in range(len(r)-1):
        ans = max(ans,r[i+1]-r[i]-1)
    ans = max(r[0],ans,len(s)-1-r[-1])
    
    ass = min(ass,ans)
    
if len(list(set(s))) == 0:
    print(0)
else:
    print(ass)

Solution (Python):
s = input()

from collections import Counter

count = Counter(s)

ans = float('inf')

for c in count:
    
    m_l = 0

    items = list(s.split(c))

    first = items.pop(0)
    last = items.pop()

    m_l = max(len(first),len(last))

    for item in items:
        m_l = max(m_l,len(item))

    ans = min(ans,m_l)

print(ans)