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.



Sample input:
serval


Sample output:
3

Submission status: Accepted

Solution code:
s=input()
s2=[]
for i in range(len(s)):
    s2.append(s[i])
s3=sorted(list(set(s2)))
ans=10**9
for x in range(len(s3)):
    memo=s3[x]
    cnt=0
    t=s
    p=len(s.replace(memo,""))
    while p!=0:
        t2=""
        l=len(t)
        k=0
        while k<l-1:
            if t[k]==memo or t[k+1]==memo:
                t2=t2+memo
            else:
                t2=t2+t[k]
            k+=1
        t=t2
        cnt+=1
        p=len(t2.replace(memo,""))
    if cnt<ans:
        ans=cnt
print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = float('inf')
for x in s:
    cnt = 0
    temp = s
    while len(set(temp))!=1:
        t = ''
        for i in range(len(temp)-1):
            if temp[i+1]==x:
                t += temp[i+1]
            else:
                t += temp[i]
        temp = t
        cnt += 1
    ans = min(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
S = input()

slist = "abcdefghijklmnopqrstuvwxyz"

tmp = 0
tmps = []
ans = len(S)
for char in set(S):
    for s in S:
        if s != char:
            tmp += 1
        else:
            tmps.append(tmp)
            tmp = 0
    tmps.append(tmp)
    ans = min(ans,max(tmps))
    tmps = []
    tmp = 0

print(ans)

Submission status: Accepted

Solution code:
def myAnswer(s:list) -> int:
   setS = set(s)
   if(len(setS) == 1): return 0
   ans = 10**9
   while len(setS) != 0:
      target = setS.pop()
      counter = 0
      tmp = s[:]
      while True:
         pre = tmp.pop(0)
         N = len(tmp)
         for i in range(N):
            now = tmp.pop(0)
            if(pre == target or now==target):
               tmp.append(target)
            else:
               tmp.append(now)
            pre = now
         counter += 1
         if(len(set(tmp))==1):
            break
      ans = min(ans,counter)
   return ans



def modelAnswer():
   return
def main():
   s = list(input())
   print(myAnswer(s[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 1000
for t in set(s):
    ans = min(ans, max([len(l) for l in s.split(t)]))
print(ans)

Submission status: Accepted

Solution code:
S = input()
chrs = set(S)

if len(chrs) == 1:
    ans = 0
else:
    ans = len(S)
    for c in chrs:
        cnt = 0
        cur = S
        while True:
            new = ""
            for i in range(len(cur) - 1):
                if cur[i] == c or cur[i + 1] == c:
                    new += c
                else:
                    new += "*"
            cnt += 1
            if len(set(new)) == 1:
                break
            cur = new

        if cnt < ans:
            ans = cnt

print(ans)

Submission status: Accepted

Solution code:
import math
s = input()
s_li = list(s)

import collections
c = collections.Counter(s_li)
common_li = c.most_common()
# [('a', 4), ('c', 2), ('b', 1)]
sp_li = s.split(common_li[0][0])

#print(sp_li)
def check(sp_li):
    count = []
    if len(sp_li)==0:
        return 0
    else:
        count = []
        for i,s in enumerate(sp_li):
            count.append(len(s))
        return max(count)


all_li = []
kaisuu = 0
for i,c in enumerate(common_li):
    #print(common_li,c[0],c[1])
    sp_li = s.split(c[0])
    all_li.append(check(sp_li))

#print(all_li)
print(min(all_li))

Submission status: Accepted

Solution code:
s = input()
ans = 10**18

for i in range(26):
    #print(chr(i+65+32))
    cnt = 0
    tmp = 0
    if s.count(chr(i+65+32)) == 0:
        continue
    #print(chr(i+65+32))
    for j in range(len(s)):
        if s[j] == chr(i+65+32):
            tmp = max(tmp,cnt)
            cnt = 0
        else:
            cnt += 1
    tmp = max(tmp,cnt)
    #print(tmp,cnt,ans)
    ans = min(ans,tmp)
            
print(ans)

Submission status: Accepted

Solution code:
s = input()

ans = 1000
for c in set(s):
    ans = min(ans, max([len(si) for si in s.split(c)]))
print(ans)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
ans = 1000
for t in set(s):
  ans = min(ans, max([len(l) for l in s.split(t)]))
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
a = ord('a')

al = [chr(i) for i in range(ord('a'), ord('z')+1)]
ans = 100

for c in al:
    L = list(s.split(c))
    x = 0
    for y in L:
        x = max(x,len(y))
    ans = min(x,ans)

print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans = 1e100
for i in range(26):
    t = chr(ord('a') + i)
    if t not in S:continue
    tmp = 0
    cnt = 0
    for s in S + t:
        if s == t:
            tmp = max(tmp, cnt)
            cnt = 0
        else:
            cnt += 1
    ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

def check(c):
    if c not in s:
        return float('inf')

    cnt = 0
    ans = 0
    for i in s:
        if i==c:
            cnt = 0
        else:
            cnt += 1
        ans = max(ans, cnt)
    return ans

ans = float('inf')
for i in range(97, 97+26):
    c = chr((i))
    ans = min(ans, check(c))

print(ans)

Submission status: Accepted

Solution code:
s = input()

if len(set(s)) == len(s):
    print(len(s)//2)
    exit()

ans = len(s)
for ml in [chr(i) for i in range(ord('a'), ord('z')+1)]:
    tmp = -1
    tmp_ans = 0
    for i in range(len(s)):
        if s[i] == ml:
            tmp_ans = max(tmp_ans, i - tmp - 1)
            tmp = i
    tmp_ans = max(tmp_ans, len(s) - tmp - 1)
    ans = min(ans, tmp_ans)

print(ans)

Submission status: Accepted

Solution code:
#AGC016-A Shrinking
"""
毎回消去される文字は選べるもんだと思っていたら、必ず最後尾
の文字が無くなる感じだった。
出現する文字全てに対し最も長いところが答え。
"""
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')

dic1 = defaultdict(int)
for i in s:
    dic1[i] += 1

lst1 = []
for i,j in dic1.items():
    lst1.append([j,i])
lst1.sort(reverse=True)

ans = 10**10
for i,j in lst1: #i,出現回数,j:文字
    target = j
    res = []
    res2 = 0
    for k in s:
        if k==target:
            res.append(res2)
            res2 = 0
        else:
            res2+=1
    res.append(res2)
    ans_res = max(res)
    ans = min(ans,ans_res)

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = set(s)
ans = 10**10
for c in t:
  cnt = 0
  x = s
  while len(set(x))!=1:
    ns = ''
    for i in range(len(x)-1):
      if x[i]==c or x[i+1]==c:
        ns += c
      else:
        ns += x[i]
    if ns==x:
      break
    x = ns
    cnt += 1
  else:
    ans = min(cnt,ans)
print(ans)

Submission status: Accepted

Solution code:
def calc(s,char):
  cnt=0
  while s.count(char)<len(s):
    t=""
    for i in range(len(s)-1):
      if char in s[i:i+2]:
        t+=char
      else:
        t+="0"
    s=t
    cnt+=1
  return cnt

s=input()
ans=100
for i in range(26):
  char=chr(ord('a')+i)
  ans=min(ans,calc(s,char))
print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 10 ** 9
for alpha in range(97,123):
    a = chr(alpha)
    cnt = 0
    ret = 0
    for i in range(len(s)):
        if s[i] == a:
            ret = max(ret,cnt)
            cnt = 0
        else:
            cnt += 1
    ret = max(ret,cnt)
    ans = min(ans,ret)
print(ans)

Submission status: Accepted

Solution code:
import collections
s = list(input())
t = list(enumerate(s[:]))
eng = [chr(ord('a') + i) for i in range(26)]
u = len(s)

ans = []
for i in eng:
    kar = [-1]
    kar.extend([j for j, v in t if v == i])
    kar.append(u)
    tyu = len(kar)
    if tyu == 2:
        continue
    f = 0
    for j in range(tyu-1):
        f = max(f,kar[j+1]-kar[j]-1)
    ans.append(f)

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=10**4
    s=list(input())
    ss=Counter(s)
    if len(ss)==1:
        ans=0
    else:
        for k in ss.keys():
            l=copy(s)
            cnt=0

            while True:
                for i in range(len(l)-1):
                    if l[i]==k or l[i+1]==k:
                        l[i]=k
                    else:
                        continue
                l=l[:-1]
                cnt+=1
                if len(set(l))==1:
                    ans=min(ans,cnt)
                    break
    print(ans)




resolve()

Submission status: Accepted

Solution code:
s = input()

def func(st,char):
    ans = [None] * (len(st) - 1)
    for i in range(len(ans)):
        if st[i] == c or st[i + 1] == c:
            ans[i] = c
        else:
            ans[i] = st[i]
    # print(ans)
    return ''.join(ans)
m = 10 ** 5
for i in range(26):
    work = s
    c = chr(ord('a') + i)
    # print(c)
    cnt = 0
    while len(set(list(work))) != 1:
        work = func(work, c)
        cnt += 1
        # print(s, len(set(list(s))))
    m = min(m, cnt)
print(m)

Submission status: Accepted

Solution code:
s = input()
d = {}
ans = float("inf")
for i, a in enumerate(s):
    if a not in d:
        d[a] = [i + 1]
    else:
        d[a].append(i + 1)
for k in d.keys():
    c = 0
    for i in range(1, len(d[k])):
        c = max(c, d[k][i] - d[k][i - 1] - 1)
    ans = min(ans, max(c, d[k][0] - 1, len(s) - d[k][-1]))
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
u = list(set(s))
ans = inf
for c in u:
    strt = s.index(c)
    res = strt
    cnt = 0
    for i in range(strt + 1, len(s)):
        if s[i] == c:
            res = max(res, cnt)
            cnt = 0
        else:
            cnt += 1
    res = max(res, cnt)
    ans = min(ans, res)
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 100
for s in S:
  n=list(map(len,S.split(s)))
  ans=min(ans,max(n))

print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    s = list(input().strip())

    def solve(c, s):
        if c not in s:
            return float('inf')
        ret = 0
        while s != [c] * len(s):
            f = True
            ret += 1
            s_ = [''] * (len(s)-1)
            for i in range(len(s)-1):
                if s[i] == c or s[i+1] == c:
                    s_[i] = c
                else:
                    s_[i] = s[i]
                    f = False
            s = s_[:]
            if f:
                break
        
        return ret
        
    ret = float('inf')
    for c in 'abcdefghijklmnopqrstuvwxyz':
        ret = min(ret, solve(c, s[:]))

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
# sを最後に残す文字にして全探索してみる
cnt = 10 ** 9
for s in S:
    nex = list(S)
    tmp = 0
    while len(set(nex)) > 1:
        tmp += 1
        L = len(nex)
        now = nex
        nex = []
        for i in range(L-1):
            if s in now[i:i+2]:
                nex.append(s)
            else:
                nex.append(now[i])
    cnt = min(cnt, tmp)
print(cnt)

Submission status: Accepted

Solution code:
s = input()
l = list(set(s))

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

min_c = 10**8
for i in l:
    old_s = s
    new_s = ''
    idx = 1
    c = 0
    
    while True:
        for j in range(len(s)-idx):
            if old_s[j] == i or old_s[j+1] == i:
                new_s += i
            
            else:
                new_s += old_s[j]
        
        idx += 1
        c += 1
        
        if len(set(new_s)) == 1:
            break
        
        else:
           old_s = new_s
           new_s = ''
    
    min_c = min(min_c,c)

print(min_c)

Submission status: Accepted

Solution code:
s = input() #sys.stdin.readlineは最後が改行

count = 0
ans=len(s)
tmp=0
for cc in list(set(s)):

    for i in range(len(s)):
        if s[i]==cc:
            tmp = max(tmp,count)
            count = 0
        else:
            count+=1

    tmp = max(tmp,count)

    ans = min(ans,tmp)
    tmp=0
    count=0

print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')

    ans = 1000
    for i in range(26):
        t = chr(i+97)
        if S == t*len(S):
            print(0)
            exit()
        if t not in S:
            continue
        cnt = 0
        S_tmp = S[:]
        while True:
            ok = 1
            cnt += 1
            new = []
            for j in range(len(S_tmp)-1):
                if S_tmp[j] != t and S_tmp[j+1] != t:
                    ok = 0
                    new.append(S_tmp[j])
                else:
                    new.append(t)
            if ok:
                break
            S_tmp = ''.join(new)
        ans = min(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
n2a = lambda c: chr(c+64).lower()
ans=100
n=len(s)
for i in range(1,27):
  al=n2a(i)
  sc= s.count(al)
  if sc==0:
    continue
  f=0
  l=[-1]
  for _ in range(sc):
    li=s.find(al,f)
    l.append(li)
    f=li+1
  if len(l)==1:
    continue
  l.append(n)
  d=0
  for j in range(1,len(l)):
    d=max(d,l[j]-l[j-1]-1)
  ans=min(ans,d)
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
ans = INF
for x in set(s):  # xとの距離を調べる
	ans = min(ans, max([len(l) for l in s.split(x)]))

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
N = len(s)
se = set(s)
ans = INF
for x in se:  # xとの距離を調べる
	tmp = 0
	ans = min(ans, max([len(l) for l in s.split(x)]))

print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 1e9
for c in range(ord('a'), ord('a') + 26):
    c = chr(c)
    res = []
    for i, s in enumerate(S):
        if c == s:
            res.append(i)
    if len(res) == 0:
        continue
    if len(res) > 1:
        D = [res[i + 1] - res[i] - 1 for i in range(0, len(res) - 1)]
        res1 = max(D)
    else:
        res1 = 0
    res2 = max(res[0], len(S) - res[-1] - 1)
    ans = min(ans, max(res1, res2))

print(ans)

Submission status: Accepted

Solution code:
s=input()
A=list(set(s))
ans=100
for i in A:
  B=s+i
  C=[]
  pre=-1
  for j in range(len(s)+1):
    if B[j]==i:
      C.append(j-pre-1)
      pre=j
  ans=min(ans,max(C))
print(ans)

Submission status: Accepted

Solution code:
s  = input()
ans = 10**7
alp = [chr(ord('a') +i) for i in range(26)]
for x in alp:
    char = x
    res = 0
    p = s
    np = ""
    while p.count(char) != len(p):
        np  =""
        for i in range(len(p)-1):
        
            if p[i] == char or p[i+1] == char:
                np +=char
                
            else:
                np+=p[i]
        p = np
        res+=1
        if res >=50:break
    ans = min(res,ans)
print(ans)

Submission status: Accepted

Solution code:
s=input()

x=dict()
for i in range(len(s)):
    S=s[i]
    if S in x:
        x[S]+=1
    else:
        x[S]=1
M=0
cnt=0
for idx in x:
    M=max(M,x[idx])
    cnt+=1
if cnt==1:
    print(0)
    exit()
#y=sorted(x.items(),key=lambda x:x[1],reverse=True)
ans=10**10
#print(y)
for idy in x:
    t=s
    tmp=t
    count1=0
    count2=0
    cnt=0
    #print(idy)
    while(1):
        p=tmp
        tmp=""
        flag=True
        #print(p)
        for i in range(len(p)-1):
            if p[i]==idy or p[i+1]==idy:
                tmp=tmp+idy
                #count1+=1
                #print(tmp)
            else:
                tmp=tmp+p[i]
                #count2+=1
                flag=False
                #print(tmp)
        #print(tmp)
        cnt+=1
        if flag:
            break
    #cnt=count1+count2

    ans=min(cnt,ans)
print(ans)

Submission status: Accepted

Solution code:
def BFS(t):
    inf=10**3
    D=[inf for _ in range(n)]
    D[-1]=1

    for i in range(n):
        if s[i]==t:D[i]=0

    for i in range(1,n)[::-1]:
        if D[i-1]==inf:D[i-1]=D[i]+1

    return max(D)


s=input()
n=len(s)
ans=10**4
for i in range(26):
    ans=min(ans,BFS(chr(97+i)))
print(ans)

Submission status: Accepted

Solution code:
S = input()

alphabets = set(S)

ans = 100
for s in alphabets:
    ans = min(ans, max(list(map(len, S.split(s)))))

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = float('inf')
for s in S:
    T = (S + 'a')[:-1]
    # print(id(S) == id(T))
    cnt = 0
    while T.count(s) < len(T):
        D = []
        for i in range(len(T)-1):
            D.append(s if T[i] == s or T[i+1] == s else T[i])
        T = ''.join(D)
        # print(T)
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
#def main():　if __name__ == "__main__":　main()
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
l = len(S)
#d = defaultdict(int)

#for m in S:
    #d[m] += 1

#d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
#e = (d2[i][0] for i in range(len(d2)))

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

ans = l
for a in alpha:
    cnt = 0
    num_list = []
    for m in S:
        if m != a:
            cnt += 1
        else:
            num_list.append(cnt)
            cnt = 0
    num_list.append(cnt)
    #print(a, num_list)
    ans = min(ans, max(num_list))

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
#def main():　if __name__ == "__main__":　main()
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
l = len(S)
d = defaultdict(int)

for m in S:
    d[m] += 1

d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
if d2[0][1] > 1:
    e = []
    i = 0
    for i in range(len(d2)):
        e.append(d2[i][0])
else:
    e = [S[l//2]]

ans = l
for a in e:
    cnt = 0
    num_list = []
    for m in S:
        if m != a:
            cnt += 1
        else:
            num_list.append(cnt)
            cnt = 0
    num_list.append(cnt)
    #print(a, num_list)
    ans = min(ans, max(num_list))

print(ans)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

ans = 100
for key in dic:
    temp = list(s)
    cnt = 0
    while temp.count(temp[0]) < len(temp):
        new = [0]*(len(temp)-1)
        for i in range(len(temp)-1):
            if temp[i] == key or temp[i+1] == key:
                new[i] = key
            else:
                new[i] = temp[i]
        cnt += 1
        temp = new
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
#d = {}
#for si in s:
#  if si in d:
#    d[si] += 1
#  else:
#    d[si] = 1
#mx = 0
#for k,v in d.items():
#  if v > mx:
#    mx = v
#t = []
#for k,v in d.items():
#  if v == mx:
#    t.append(k)
t = set(s)
#print(t)

s = ''.join(s)
ans = 101
for ti in t:
  s1 = s
  cnt = 0
  while(s1.count(ti) != len(s1)):
    #print(ti,cnt,s1)
    s2 = ''
    for i in range(len(s1)-1):
      if s1[i] == ti or s1[i+1] == ti:
        s2 += ti
      else:
        s2 += s[i]
    s1 = s2
    cnt += 1
  ans = min(cnt,ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter, defaultdict
import numpy as np


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = list(input())
    C = Counter(S)
    K = C.keys()
    answer = []
    for k in K:
        cnt = 0
        counter = []
        for s in S:
            if s == k:
                counter.append(cnt)
                cnt = 0
            else:
                cnt += 1
        counter.append(cnt)
        answer.append(max(counter))
    print(min(answer))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s  = input()
se = set(s)

l = [max([len(j) for j in s.split(i)])for i in se]
print(min(l))

Submission status: Accepted

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

cnt = Counter(c for c in s)

ans = 100100
for c in cnt.keys():
    len_m = max([len(a) for a in s.split(c)])
    ans = min(ans, len_m)

print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
s = list(input())    
N = len(s)
count= 0
counter = []
ans = []
real = deepcopy(s)
syurui = set(s)
for j in syurui:
    while True:
        #終了条件
        if N == s.count(j):
            counter.append(count)
            count = 0
            s = deepcopy(real)
            N = len(s)
            break

        for i in range(N-1):
            if s[i]==j or s[i+1]==j:
                ans.append(j)
            else:
                ans.append(s[i])
        #値の更新
        N = len(ans)
        s = deepcopy(ans)
        count += 1

        #変数のリセット
        ans = []
print(min(counter))

Submission status: Accepted

Solution code:
s = str(input())

from collections import Counter
cntr = Counter(c for c in s)

ans = 100100
for ch in cntr.keys():
  len_max = max([len(arr) for arr in s.split(ch)])
  ans = min(ans, len_max)

print(ans)

Submission status: Accepted

Solution code:
s = input()
al = set(list(s))    
ans = 100

for c in al:
    L = list(s.split(c))
    tmp = 0
    for st in L:
        tmp = max(tmp, len(st))
    #tmp = max(tmp, len(L[0]))
    #tmp = max(tmp, len(L[-1]))
    ans = min(tmp, ans)
    #print(ans)
print(ans)

Submission status: Accepted

Solution code:
s = input()
al = set(list(s))
ans = 100
for c in al:
    L = list(s.split(c))
    tmp = 0
    for st in L:
        tmp = max(tmp,len(st))
    tmp = max(tmp,len(L[0]))
    tmp = max(tmp,len(L[-1]))
    ans = min(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
counter = Counter(s)
mc = counter.most_common()
max_c = mc[0][1]
ret = len(s)
# print(mc)

for t in mc:
    # if t[1] < max_c: break
    # print(s.split(t[0]))
    sp = max(map(len, s.split(t[0])))
    
    if ret > sp:
        ret = sp
        
print(ret)

Submission status: Accepted

Solution code:
s = input()

import string
ans = 9999
for char in string.ascii_lowercase:
    count = 0
    maxi = 0
    for j in range(len(s)):
        if s[j] == char:
            maxi = max(count, maxi)
            count = 0
        else:
            count += 1
        maxi = max(count, maxi)
    ans = min(ans, maxi)

print(ans)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
#3
#入力
s=input()

#処理
X={}

for i in range(len(s)):
    if s[i] in X:
        X[s[i]]+=1
    else:
        X[s[i]]=1
    
Y=[kv[0] for kv in X.items()]
z=float('inf')

for i in Y:
    x=0
    t=s
    while t!=i*len(t):
        l=""
        for j in range(len(t)-1):
            if t[j]==i or t[j+1]==i:
                l=l+i
            else:
                l=l+t[j]
        x+=1
        t=l
    
    if z>x:
        z=x
print(z)

Submission status: Accepted

Solution code:
s = input()
a = 10000
for i in range(0, 26):
  n = 0
  t = 0
  b = True
  for j in range(0, len(s)):
    if s[j] != chr(ord("a")+i):
      t += 1
    elif b:
      n = max(n, t)
      t = 0
    else:
      n = max(n, (t+1)//2)
      t = 0
  n = max(n, t)
  a = min(a, n)
print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict
s = input()
d = defaultdict(list)
for i in range(len(s)):
    d[s[i]].append(i)
cnt= 10000000000
ans = 0
for x in d.values():
    ans = 0
    ans = max(ans, x[0])
    ans = max(ans, len(s)-1-x[-1])
    for i in range(len(x)-1):
        ans = max(ans, x[i+1]-x[i]-1)
    cnt = min(cnt, ans)
print(cnt)

Submission status: Accepted

Solution code:
s = list(input())
N = len(s)
ans = float("INF")
for c in set(s):
  i, cnt = 0, 0
  s1 = s
  while len(set(s1)) != 1:
    ns = []
    for i in range(len(s1)-1):
      if s1[i] == c or s1[i+1] == c:
        ns.append(c)
      else:
        ns.append(s1[i])
    s1 = ns
    cnt += 1
  ans = min(ans, cnt)
print(ans)

Submission status: Accepted

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

s = input()
len_s = len(s)
cnt = [0] * 26
al = [chr(ord('a') + i) for i in range(26)]
ans = [''] * (len_s + 1)
ans[0] = s
for i in range(26):
    check = list(s)
    if al[i] in check:
        ans[0] = s
        while any([al[i] != a for a in check]):
            cnt[i] += 1
            for j in range(len_s - cnt[i]):
                if ans[cnt[i] - 1][j + 1] == al[i]:
                    ans[cnt[i]] += al[i]
                else:
                    ans[cnt[i]] += ans[cnt[i] - 1][j]
            check = list(ans[cnt[i]])
            ans[cnt[i] - 1] = ''
if all(cnt[i] == 0 for i in range(26)):
    print(0)
else:
    cnt = sorted(set(cnt))
    if cnt[0] == 0:
        print(cnt[1])
    else:
        print(cnt[0])

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input()[:-1]
print(min(max(map(len, s.split(a))) for a in s))