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):
st = list(str(input()))
s = [st[i] for i in range(len(st))]
ans = []
lis = []
for k in range(len(s)):
  lis = st
  while lis != [s[k] for _ in range(len(lis))]:
    cou = []
    for i in range(len(lis)-1):
      if lis[i+1] == s[k] or lis[i] == s[k]:
        cou.append(s[k])
      else:
        cou.append("X")
    lis = cou
  ans.append(len(lis))
print(len(s)-max(ans))

Solution (Python):
s = input()

alphabet = ''
for i in range(26):
    alphabet += chr(ord('a')+i)

res = float('inf')
for c in alphabet:
    tmp = 0
    t = s
    while t!=t[0]*len(t):
        u = ''
        for d,e in zip(t[::-1],t[::-1][1:]):
            if d==c or e==c:
                u += c
            else:
                u += d
        tmp += 1
        t = u[::-1]
    res = min(res,tmp)
print(res)

Solution (Python):
def ope(s,c):
    ret = ""
    for i in range(len(s)-1):
        if s[i] == c or s[i+1] == c:
            ret += c
        else:
            ret += s[i]
    return ret

def is_filled(s,c):
    for i in s:
        if i != c:
            return False
    else:
        return True

def main():
    s = input()
    ans = 114514
    for i in range(97,97+26):
        c = chr(i)
        if not c in s: continue
        si = s

        turn = 0
        while not is_filled(si,c):
            si = ope(si,c)
            turn += 1
        
        ans = min(ans,turn)
    print(ans)

        
main()

Solution (Python):
from copy import deepcopy

s = input()
ans = len(s)-1
for i in range(26):
    tc = chr(ord("a")+i)
    tv = 0
    ts = deepcopy(s)
    for j in range(len(s)):
        if ts.count(tc) == len(ts):
            ans = min(ans, tv)
            break
        nxt = ""
        for k in range(len(ts)-1):
            if ts[k] == tc or ts[k+1] == tc:
                nxt += tc
            else:
                nxt += ts[k]
        tv += 1
        ts = deepcopy(nxt)
print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

S = input()
L = len(S)

def cal(s): return ord(s)-97

bits = [0]*L
for i,s in enumerate(S):
	bits[i] = 1<<cal(s)

ans = 0
while True:
	
	for x in range(26):
		flag = True
		for bit in bits:
			if not (bit>>x) & 1:
				flag = False
				break
		if flag:
			print(ans)
			sys.exit()

	
	for i in range(L-1):
		bits[i] |= bits[i+1]
	bits.pop(-1)
	L -= 1
	ans += 1

Solution (Python):
s = input()
ans = float("inf")
for i in range(len(s)):
  ls = [c for c in s]
  k = ls[i]
  if ls.count(k) == len(ls):
    ans = 0
    break
  for l in range(len(s)):
    ls1 =[]
    for j in range(len(ls)-1):
      if (ls[j] == k or ls[j+1] == k):
        ls1.append(k)
      else:
        ls1.append(0)
    ls = ls1
    if ls.count(k) == len(ls):
      ans = min(ans,l+1)
      break
print(ans)

Solution (Python):
s = input()
n = 0
ans = 10**10
for k in 'qwertyuiopasdfghjklzxcvbnm':
    l = [i if i == k else 0 for i in s]
    a = 0
    while l.count(k)!=len(l):
        for i in range(len(l)-1):
            if l[i]==k or l[i+1]==k:
                l[i] = k
        a += 1
        l.pop(-1)
    ans = min(ans,a)
    n += 1
print(ans)

Solution (Python):
'''
エディトリアル
https://atcoder.jp/img/agc016/editorial.pdf

解説動画
https://youtu.be/kdQtQSgIYPI?t=20m17s

シミュレーション
'''

s = input()
a = [chr(x) for x in range(97, 97 + 25 + 1)]

'''
a: chr(97)
z: chr(97 + 25)
'''

cnt = float('inf')
for c in a:
    if c in s:
        t = s[:]
        t_cnt = 0
        while len(t) != t.count(c):
            b = ''
            for i in range(len(t) - 1):
                b += c if (t[i] == c) or (t[i + 1] == c) else t[i]
            t = b
            t_cnt += 1
        cnt = min(cnt, t_cnt)
print(cnt)

Solution (Python):
from collections import Counter

s = input()

cnt = Counter(s)

if len(cnt.keys()) == 1:
    print(0)
    
else:
    al_set = set(s)
    c = list(s)
    
    dic = {}
    for alpha in al_set:
        c_prev = [ci for ci in c]
        count = 0
        while any([ci != alpha for ci in c_prev]):
            c_new = []
            for j in range(len(c_prev) - 1):
                if c_prev[j] == alpha or c_prev[j+1] == alpha:
                    c_new.append(alpha)
                else:
                    c_new.append("0")
                    
            c_prev = c_new
            count += 1

            
        dic[alpha] = count
        
    print(min(dic.values()))

Solution (Python):
S = input()

ans = len(S)
for i in range(26):
    c = chr(ord('a') + i)
    t1 = S
    cnt = 0
    while any(list(map(lambda x:x!=c, t1))):
        t2 = ''
        for ca,cb in zip(t1,t1[1:]):
            if ca == c or cb == c:
                t2 += c
            else:
                t2 += ca
        t1 = t2
        cnt += 1
    ans = min(ans, cnt)

print(ans)

Solution (Python):
s = input()
g = set()
for i in s:
    g.add(i)
ans = 10**9
al = [chr(ord('a') + i) for i in range(26)]

for w in al:
    count = 0
    a = s
    flag = 0
    if not w in g:
        continue
    while flag == 0:
        flag = 1
        for i in a:
            if not i == w:
                flag = 0
        if flag:
            ans = min(ans, count)
        b = ""
        for i in range(len(a)-1):
            if a[i] == w or a[i+1] == w:
                b += w
            else:
                b += a[i]
        a = b
        count += 1

print(ans)

Solution (Python):
s=input()
v=1e9

for k in set(s):
  t=s
  c=0
  while len(set(t))>1:
    u=""
    for (i,j) in enumerate(t[:-1]):
      if t[i]==k or t[i+1]==k:
        u+=k
      else:
        u+=j
    c+=1
    t=u
  v=min(v,c)

print(v)

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

alpha = [chr(ord('a')+i) for i in range(26)]
def check(s, c, k):
    if len(set(s)) <= 1:
        return k

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

import copy
def solve(s):
    ans = 1000
    for a in alpha:
        ans = min(ans, check(copy.copy(s), a, 0))
    return ans
print(solve(s))

Solution (Python):
from string import ascii_lowercase
S=input()
ans = float('inf')
def sim(S, s):
    c = 0
    while len(set(S)) != 1:
        tmp = ''
        for i in range(len(S) - 1):
            if S[i] == s or S[i+1] == s:
                tmp += s
            else:
                tmp += S[i]
        c += 1
        S = tmp
    return c

for s in ascii_lowercase:
    ans = min(ans, sim(S, s))
print(ans)

Solution (Python):
a=list(input())
x=100
for i in set(a):
  k=0
  m=0
  for j in a:
    k+=1
    if i==j:
      k=0
    m=max(m,k)
  x=min(x,m)
print(x)

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

for i in a:
    count = 0
    b = s[:]
    c = []
    while len(b) != b.count(i):
        count += 1
        for j in range(len(b)-1):
            if b[j] == i or b[j+1] == i:
                c.append(i)
            else:
                c.append(b[j])
        b = c[:]
        c = []

    ans = min(ans,count)
print(ans)

Solution (Python):
s = input()
ans = float("INF")
from string import ascii_lowercase
for c in ascii_lowercase:
  cnt = 0
  st = s[:]
  while True:
    snew = ""
    if len(set(st))==1:
      break
    for i in range(len(st)-1):
      if st[i]==c or st[i+1]==c:
        snew += c
      else:
        snew += st[i]
    cnt+=1
    st = snew[:]
  ans = min(ans, cnt)
print(ans)

Solution (Python):
S=input()

def solve(s,c):
  ch=True
  for i in range(len(s)-1):
    if s[i]!=s[i+1]:
      ch=False
  if ch:
    return 0
  else:
    ans=""
    for i in range(len(s)-1):
      if s[i]==c or s[i+1]==c:
        ans+=c
      else:
        ans+=s[i]
    return solve(ans,c)+1
  
ans=100
for i in range(len(S)):
  ans=min(ans,solve(S,S[i]))

print(ans)

Solution (Python):
s = input()
n = len(s)
ans = 101

for i in range(n):
    move = 0
    r = -1
    for j in range(n):
        if s[j] == s[i]:
            move = max(move, j-r-1)
            r = j

    move = max(move, n-r-1)
    ans = min(ans, move)

print(ans)

Solution (Python):
S = input()

CHARS = [chr(ord("a") + i) for i in range(26)]

xs = dict((c, -1) for c in CHARS)
ms = dict((c, -1) for c in CHARS)

for i, c in enumerate(S):
    p = xs[c]
    ms[c] = max(i - p - 1, ms[c])
    xs[c] = i

for c in CHARS:
    ms[c] = max(len(S) - xs[c] - 1, ms[c])

result = min(ms.values())

print(result)

Solution (Python):
from collections import Counter

s = list(input())
ss = s

ans = float("inf")

for target in list(set(s)):
	s = ss
	num = 0
	while len(set(s)) > 1:
		t = []
		for i in range(len(s)-1):
			if s[i] == target or s[i+1] == target:
				t.append(target)
			else:
				t.append(s[i])
		s = t
		num += 1
	if num < ans:
		ans = num

print(ans)

Solution (Python):
s = input()
f = {}
g = {}

chars = [c for c in s]


for char in chars:
    f[char] = []
    f[char].append(-1)
    for i, c in enumerate(s):
        if(c==char):
            f[char].append(i)
    f[char].append(len(s))

max_len_all = len(s)
for char in chars:
    max_len = 0
    for i in range(len(f[char])-1):
        max_len = max(max_len, f[char][i+1]-f[char][i])
    g[char] = max_len
    if(g[char]<max_len_all):
        ans = char
        max_len_all = g[char]





print(max_len_all-1)

Solution (Python):
s = input()
ans = float('Inf')
def f(c):
  global ans
  temp = s
  i = 0
  while True:
    t = ''
    flag = False
    if temp.count(temp[0]) == len(temp):
      ans = min(ans, i)
      break
    
    for j in range(len(temp)-1, -1, -1):
      if not temp[j] == c and flag == False:
        flag = True
        continue
      elif j <= len(temp)-2 and temp[j+1] == c:
        t += c
      else:
        t += temp[j]
    temp = t
    i += 1

for i in range(97, 123):
  f(chr(i))

print(ans)

Solution (Python):
def a_shrinking(S):
    import string
    ans = float('inf')

    
    for chr in string.ascii_lowercase:
        if chr not in S:
            
            
            continue
        t = list(S)
        t_prime = []
        count = 0  
        while len(set(t)) > 1:  
            for k in range(len(t) - 1):
                
                
                if t[k + 1] == chr:
                    t_prime.append(chr)
                else:
                    t_prime.append(t[k])
            count += 1
            t = t_prime
            t_prime = []
        ans = min(ans, count)
    return ans

S = input().strip()
print(a_shrinking(S))

Solution (Python):
import collections
import copy

s = input()

s_dict = dict(collections.Counter(list(s)))
s_dict = sorted(s_dict.items(), key=lambda x:x[1], reverse= True)
tmp = s_dict[0][0]

resres = float("inf")

for tmp in s:
    res = 0
    tmp_s = copy.copy(s)
    while True:
        if len(set(tmp_s)) == 1:
            break
        _len = len(tmp_s)
        for i in range(_len-1):
            if tmp_s[i+1] == tmp:
                tmp_s = tmp_s[:i] + tmp + tmp_s[i+1:]
        res += 1
        tmp_s = tmp_s[:-1]
    if res < resres:
        resres = res

print(resres)

Solution (Python):
S = input()

d = dict()

for i in range(26):
    alphabet = chr(ord('a') + i)
    d[alphabet] = []

for idx in range(len(S)):
    d[S[idx]].append(idx)

ans = len(S)

for i in range(26):
    alphabet = chr(ord('a') + i)
    if len(d[alphabet]) != 0:
        max_op = 0
        for idx in range(len(d[alphabet])):
            if idx != 0:
                max_op = max(max_op, d[alphabet][idx] - d[alphabet][idx-1] - 1)
            else:
                max_op = max(max_op, d[alphabet][idx])
        max_op = max(max_op, len(S) - d[alphabet][-1] - 1)
        ans = min(ans, max_op)

print(ans)

Solution (Python):


s = input()


def min_shrink(a):
    ind = [-1] + [i for i, x in enumerate(s) if x == a] + [len(s)]
    x = []
    for i in range(len(ind)-1):
        x.append(ind[i+1]-ind[i]-1)
    
    return max(x)

ans = 1000
for a in "abcdefghijklmnopqrstuvwxyz":
    ans = min(ans, min_shrink(a))

print(ans)

Solution (Python):
import string
t=input()
n=len(t)
ans=float("inf")
for i in string.ascii_lowercase:
    cnt=0
    s=list(t)
    while s.count(i)!=n-cnt:
        for j in range(1,len(s)):
            if s[j]==i or s[j-1]==i:
                s[j-1]=i
            else:
                s[j-1]=s[j-1]
        cnt+=1
        s.pop()
    ans=min(ans,cnt)
print(ans)

Solution (Python):
import string
t=input()
n=len(t)
ans=[]
for i in string.ascii_lowercase:
    cnt=0
    s=list(t)
    while s.count(i)!=n-cnt:
        for j in range(1,len(s)):
            if s[j]==i or s[j-1]==i:
                s[j-1]=i
            else:
                s[j-1]=s[j-1]
        cnt+=1
        s.pop()
    ans.append(cnt)
print(min(ans))

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

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j]:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1
                    f_idx = j

                elif j == len(s) - 1:
                    if max_c < j - f_idx:
                        max_c = j - f_idx

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()

Solution (Python):
"""AtCoder Grand Contest 016 - Shrinking.

https://agc016.contest.atcoder.jp/tasks/agc016_a

"""


import string

def solve(s):
    ans = float('inf')
    for char in string.ascii_lowercase:
        new_str = s
        count = 0
        while len(set(new_str)) > 1:
            tmp = ''
            for j in range(len(new_str) - 1):
                tmp += char if char in new_str[j:j+2] else new_str[j]
            new_str = tmp
            count += 1
        ans = min(ans, count)
    return ans


def main():
    s = input().strip()
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
def solve(s):
    mm = 1e9
    for i in range(26):
        char = chr(ord('a') + i)
        ss = s
        c = 0
        while len(set(ss)) > 1:
            sss = ''
            for j in range(len(ss) - 1):
                if ss[j] == char or ss[j + 1] == char:
                    sss += char
                else:
                    sss += ss[j]
            ss = sss
            c += 1
        mm = min(mm, c)
    return mm


def main():
    s = input().strip()
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
L = set([x for x in S])

ans = 101
for t in L:
    N = S
    T = ""
    c = 0
    while len(set([x for x in N])) > 1:
        c += 1
        for k in range(len(N)-1):
            if N[k] == t or N[k+1] == t:
                T += t
            else:
                T += S[k]
        N = T
        T = ""
    ans = min(ans,c)

print(ans)

Solution (Python):
from collections import Counter

S = input()
C = Counter(S).most_common()
max_v = C[0][1]
min_count = 9999
for key_string,v in Counter(S).most_common():
    
    
    T = S
    count = 0
    while(len(Counter(T))>1):
        TT = ""
        for i in range(len(T)-1):
            temp = T[i:i+2]
            if key_string in temp:
                TT += key_string
            else:
                TT += temp[0]
        T = TT
        count += 1
    if min_count>count:
        min_count = count
            
print(min_count)

Solution (Python):
s=input()
import string
ans=float("inf")
for i in string.ascii_lowercase:
    t=list(s)
    while not all(j== i for j in t):
        for k in range(len(t)):
            if i in t[k:k+2]:
                t[k]=i
        t.pop()
    ans=min(ans,len(s)-len(t))
print(ans)

Solution (Python):
def solve( s , c ):
    cnt = int(0)
    while 1 :

        if len(s) == 0 :
            return cnt

        f = True

        for i in range(len(s)):
            if s[i] != c:
                f = False
                break
        
        if f :
            return cnt


        s2 = ""
        for i in range(len(s)-1):
            if s[i] == c or s[i+1] == c:
                s2 += c
            else:
                s2 += s[i]
         
        s = s2
        cnt += 1

    return cnt;



s = input()
a = [0 for i in range(26)]

for i in range(len(s)):
    a[ord(s[i])-ord('a')] += 1

ans = 0x7FFFFFFF
for i in range(26):
    if(a[i] > 0 ):
        ans = min( ans , solve(s, chr( i + ord('a') ) ) )

print(ans)

Solution (Python):


import sys, math, copy




HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    s = input()
    n = len(s)
    mind = HUGE
    for a in ABC:
        s_halo = a + s + a
        d = 0
        maxd = 0
        for c in s_halo:
            if c == a:
                d = 0
            else:
                d += 1
                maxd = max(maxd, d)
        mind = min(mind, maxd)
    print(mind)

main()

Solution (Python):
s = input()
alphabets = [chr(i) for i in range(ord("a"), ord("a")+26)]

ans = float('inf')
for alphabet in alphabets:
    if alphabet not in s:
        continue
    oldS = s
    newS = ""
    cnt = 0
    while len(set(list(oldS))) > 1:
        for i in range(len(oldS)-1):
            if oldS[i] == alphabet or oldS[i+1] == alphabet:
                newS += alphabet
            else:
                newS += oldS[i]
        cnt += 1
        oldS = newS
        newS = ""

    ans = min(ans, cnt)

print(ans)

Solution (Python):
S=input()
M=100
flag0=0
for i in range(1,len(S)):
    if S[0]!=S[i]:
        flag0=1
if flag0==0:
    print(0)
    exit()
for i in range(26):
    T=S
    t=chr(i+97)
    k=1
    while(True):
        U=""
        for i in range(len(T)-1):
            if T[i]==t:
                U+=t
            elif T[i+1]==t:
                U+=t
            else:
                U+=T[i]
        flag=0
        for i in U:
            if i!=t:
                flag=1
                break
        if flag==0:
            break
        k+=1
        T=U
    if k<M:
        M=k
print(M)

Solution (Python):
alph="abcdefghijklmnopqrstuvwxyz"
s=input()
sb=s
n=len(s)
nb=n
ch=set(list(s))
mi=1000
for cha in ch:
  s=sb
  n=nb
  coun=0
  while(1):
    x=set(list(s))
    if(len(x)==1):break
    t=""
    for i in range(n-1):
      if(s[i]==cha):
        t+=s[i]
      elif(s[i+1]==cha):
        t+=s[i+1]
      else:
        t+=s[i]
    n-=1
    s=t
    coun+=1
  mi=min(coun,mi)
print(mi)

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

ans = float('inf')
t = list(S)
for c in C:
    cnt = 0
    while True:
        if len(set(t)) != 1:
            td = []
            cnt += 1
            for i in range(len(t)-1):
                if t[i]==c or t[i+1]==c:
                    td.append(c)
                else:
                    td.append(t[i])
            t = td.copy()
        else:
            ans = min(ans, cnt)
            break
    t = list(S)

print(ans)

Solution (Python):
S = input()
C = [chr(ord("a")+i) for i in range(26)]

ans = float('inf')
for c in C:
    ans = min(ans, max([len(s) for s in S.split(c)]))

print(ans)

Solution (Python):
s = input()
x = "abcdefghijklmnopqrstuvwxyz"
y,y2,z = [[-1,0] for i in range(26)],[],len(s)
for i in range(z):
	a = x.find(s[i])
	y[a][0],y[a][1] = i,max(i-y[a][0]-1,y[a][1])
for i in y:
	if i[1]!=0: y2.append(max(i[1],z-i[0]-1))
if y2==[]: print(0)
else: print(min(y2))

Solution (Python):
import math
s = input().rstrip()
alpha = set()
for i in range(len(s)):
  alpha.add(s[i])
if len(alpha) == len(s):
  print(math.ceil(len(s)//2))
elif len(alpha) == 1:
  print(0)
else:
  mincount = 10**12
  for X in alpha:
    tmp = list(s[::1])
    count = 0
    while 1:
      count += 1
      work = []
      alpha2 = set()
      for k in range(len(tmp)-1):
        if tmp[k] == X or tmp[k+1] == X:
          work.append(X)
          alpha2.add(X)
        else:
          work.append(tmp[k])
          alpha2.add(tmp[k])
      if len(alpha2) == 1:
        break
      else:
        tmp = work
    mincount = min(count,mincount)    
  print(mincount)

Solution (Python):
from collections import defaultdict
s = input()
s_set = set(s)

count_min = 100
count = 0
for i in s_set:
    s_copy = s
    while True:
        t = ""
        if s_copy == i*len(s_copy):
            break
        for j in range(len(s_copy)-1):
            if s_copy[j] == i or s_copy[j+1] == i:
                t += i
            else:
                t += "?"
        s_copy = t
        count += 1
    count_min = min(count_min,count)
    count = 0
print(count_min)

Solution (Python):



s=input()[::-1]
mincount=99999999
for i in range(len(s)):
    
    check=s[i]
    count=0
    _count=-1
    for j in range(i+1,len(s)):
        if s[j]!=check:
            count+=1
        else:
            _count=max(_count,count,i)
            count=0
    _count=max(_count,count,i)
    if _count!=-1:
        mincount=min(mincount,_count)
print(mincount)

Solution (Python):
*s, = map(ord, input())
l = len(s)
ans = l
for c in range(95, 123):
    res = 0
    cnt = 0
    for i in range(l):
        if s[i] == c:
            res = max(res, cnt)
            cnt = 0
        else:
            cnt += 1
    res = max(res, cnt)
    ans = min(ans, res)
print(ans)

Solution (Python):
def calc(c, s):
    itr, maxa = -1, 0
    for i in range(len(s)):
        if(s[i] == c):
            maxa = max(i - itr - 1, maxa)
            itr = i
    maxa = max(maxa, len(s) - 1 - itr)
    return maxa


s = input()
mini = 1 << 30
for c in range(ord('a'), ord('z') + 1):
    mini = min(calc(chr(c), s), mini)
print(mini)

Solution (Python):
S = raw_input()
ans = len(S)
for i in range(len(S)):
    ans = min(ans, max(map(len, S.split(S[i]))))
print ans

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def solve(c, s):
    if s == c * len(s):
        return 0
    t = ""
    for i in range(len(s) - 1):
        if s[i] == c or s[i + 1] == c:
            t += c
        else:
            t += s[i]
    return solve(c, t) + 1


def main():
    s = input()
    ans = INF
    for c in set(s):
        ans = min(ans, solve(c, s))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import string
s = input()
result = float('inf')
for last in string.ascii_lowercase:
    t = list(s)
    while not all(c == last for c in t):
        for i in range(len(t)):
            if last in t[i : i + 2]:
                t[i] = last
        t.pop()
    result = min(result, len(s) - len(t))
print(result)

Solution (Python):
def shrinking():
	s = list(raw_input())
	ans = []
	possible_chars = list(set(s))

	for ch in possible_chars:
		a = 0
		
		_s = list(s)
		while len(list(set(_s)))!=1:
			for i in range(1, len(_s)):
				if _s[i] == ch:
					_s[i - 1] = ch
			a+=1
			_s = _s[:-1]
		ans.append(a)
	print min(ans)


if __name__ == "__main__":
	shrinking()

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

S = str(input())
T = S

m = 1000
for s in S:
    num = 0
    T = S
    while (check(s, T)):
        num += 1
        K = []
        for i in range(0, len(T) - 1):
            if s == T[i+1]:
                K.append(T[i+1])
            else:
                K.append(T[i])
        T = K
    m = min(m, num)

print(m)

Solution (Python):
import copy

def same(items):
    return all(x == items[0] for x in items)

s = list(raw_input())
d = dict()
for c in s:
    if c in d:
        d[c] += 1
    else:
        d[c] = 1
if max(d.values()) == 1:
    print len(s)/2
else:
    steps = []
    for c in d.keys():
        ss = copy.copy(s)
        cnt = 0
        while not same(ss):
            cnt += 1
            for i in range(len(ss) - 1):
                if ss[i+1] == c:
                    ss[i] = c
            ss.pop()
        steps.append(cnt)
    print min(steps)

Solution (Python):
def calc(x, S):
    res = set(S)
    cnt = 0
    while (len(res) != 1):
        cnt += 1
        t = ""
        N = len(S)
        for y in range(N - 1):
            if (S[y] == x):
                t += x
            elif (y + 1 < len(S) and S[y + 1] == x):
                t += x
            else:
                t += S[y]
        S = t
        res = set(S)
    return cnt


if __name__ == "__main__":
    S = input()
    res = set(S)
    result = 2 ** 50
    for x in res:
        result = min(result, calc(x, S))
    print (result)

Solution (Python):
s = input()




cnt = float('inf')
for alpha in [chr(i + ord('a')) for i in range(26)]:
    if not alpha in s:
        continue
    ss = s[:]
    c = 0
    while True:
        check = True
        for i in range(len(ss) - 1):
            if ss[i] != ss[i + 1]:
                check = False
                break
        if check:
            break
        t = ''
        for i in range(len(ss) - 1):
            if ss[i] == alpha or ss[i+1] == alpha:
                t += alpha
            else:
                t += ss[i]
        c += 1
        ss = t
    cnt = min(cnt, c)

print(cnt)

Solution (Python):
from collections import Counter
s = input()
count = Counter(s).most_common()
ans = 100
for c,n in count:
    ss = s
    cnt = 0
    while any(ssi != ss[0] for ssi in ss):
        ss_new = ""
        for i in range(len(ss)-1):
            if ss[i] != c and ss[i+1] == c:
                ss_new += c
            else:
                ss_new += ss[i]
        ss = ss_new
        cnt += 1
    if cnt < ans:
        ans = cnt

print(ans)

Solution (Python):


s=raw_input()
ch=set(s)
res=len(s)
for c in ch:
 temp=max(len(x) for x in s.split(c))
 res=min(res,temp)
print res

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

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

print(ans)

Solution (Python):
import string
s = input()
ret = 100000000000000
for c in string.ascii_lowercase:
    if c not in s:
        continue;
    x = s.split(c)
    m = 0
    for ss in x:
        m = max(m, len(ss))
    ret = min(ret, m)

print(ret)

Solution (Python):

s = list(input())
alphabet = [ chr(tmp) for tmp in range(97, 97+26) ]
candinate = []
for tmp1 in alphabet:
    if tmp1 not in s:
        pass
    else:
        sentence = [ a for a in s ]
        ans = 0
        while True:
            if ''.join([tmp1 for tmp3 in range(len(sentence))]) == ''.join(sentence):
                candinate.append(ans)
                break
            for tmp2 in range(len(sentence)-1):
                if sentence[tmp2] == tmp1:
                    pass
                elif sentence[tmp2+1] == tmp1:
                    sentence[tmp2] = sentence[tmp2+1]
                else:
                    pass
            sentence.pop()
            ans += 1
print(min(candinate))

Solution (Python):

s = input()
candidates = []
for i in set(s):
    candidates.append( max( list( map( len, s.split(i) ) ) ) )
print(min(candidates))

Solution (Python):
s=input()

minCost=len(s)
char_set=set(s)
for char in char_set:
    m=max([len(_) for _ in s.split(char)])
    if m<minCost:
        minCost=m
print(minCost)

Solution (Python):
s = input()
c_list = [chr(i) for i in range(97, 123)]
min_loop = len(s)

for c in c_list:
    str_list = s.split(c)
    loop = max(len(str) for str in str_list)
    min_loop = min(min_loop, loop)

print(min_loop)

Solution (Python):
import copy

s = input()

c_list = ["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"]

min_loop = len(s)
for c in c_list:
    if s.count(c) == 0:
        continue
    s_ = copy.copy(s)
    new_s = copy.copy(s)
    loop = 0
    while new_s.count(c) != len(new_s):
        len_s_ = len(s_)
        new_s = ""
        for i in range(len_s_ - 1):
            if s_[i] == c or s_[i+1] == c:
                new_s += c
            else:
                new_s += s_[i]
        loop += 1
        s_ = copy.copy(new_s)
    if loop < min_loop:
        min_loop = loop

print(min_loop)

Solution (Python):


import sys

input = sys.stdin.readline().replace('\n','')
ans  = 1000

for c in input:
	s = input.split(c)
	ma = 0
	for i in range(len(s)):
		if ma < len(s[i]):
			ma = len(s[i])
	
	if ans > ma:
		ans = ma
		
print(ans,end='')

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

ans = N - 1
for i in range(26):
    cnt = 0
    now_S = S[:]
    for j in range(N - 1):
        if all(x == i for x in now_S):
            break
        for k in range(N - j - 1):
            if now_S[k + 1] == i:
                now_S[k] = i
        now_S.pop()
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Solution (Python):
s = raw_input()
ans = len(s)
for ch in set(s):
    t = ch + s + ch
    occ = [i for i in range(len(t)) if t[i] == ch]
    d = [occ[i+1] - occ[i] - 1  for i in range(len(occ)-1)]
    ans = min(ans, max(d))
print ans

Solution (Python):
a = list(str(input()))
b = list(set(a))
c = len(b)
c_ = []

if c == 1:
    print(0)
else:
    for i in b: 
        count = 0
        a_ = a[:]
        while len(list(set(a_)))!=1:
            for j in range((len(a_)-1)):
                if a_[(1+j)] == i:
                    a_[j] = i
            del a_[-1]
            count+=1
        c_.append(count)
    c_.sort()
    print(c_[0])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    s = S()
    d = collections.defaultdict(list)
    l = len(s)
    for i in range(l):
        d[s[i]].append(i)

    r = inf
    for c in d.keys():
        t = -1
        rc = 0
        for i in d[c]:
            if rc < i - t - 1:
                rc = i - t - 1
            t = i
        if rc < l - t - 1:
            rc = l - t - 1
        if r > rc:
            r = rc

    return r


print(main())

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

ans = 100
for l in set(s_l):
    tmp = 0
    score = 0
    for word in s:
        if l == word:
            score = max(score,tmp)
            tmp = 0
        else:
            tmp += 1
    score = max(score, tmp)
    ans = min(ans, score)

print(ans)