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 = raw_input()
ans = len(s)
for i in range(len(s)):
    mx = i
    p = i
    q = i+1
    while q < len(s):
        if s[p] == s[q]:
            mx = max(q-p-1, mx)
            p = q
        q += 1
    mx = max(q-p-1, mx)
    ans = min(mx, ans)
print ans

Solution (Python):


def main():
    S = input()
    cnt = 0
    l = list(S)
    while 1:
        for i in set(''.join(l)):
            if all((1 if i in x else 0) for x in l):
                print(cnt)
                return
        cnt += 1
        l = [l[x]+S[x+cnt] for x in range(len(l)-1)]
    
if __name__ == '__main__':
    main()

Solution (Python):
S = input()
c = list(set(S))
res = min(max(len(si) for si in S.split(ci)) for ci in c)
print(res)

Solution (Python):
s = input()
def shrink(char, s):
    if len(set(s)) == 1:
        return 0
    shrinked = "".join((s[i] if s[i+1] != char else s[i+1] for i in range(len(s)-1)))
    return shrink(char, shrinked) + 1

print(min(shrink(char, s) for char in s))

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

    s = set(S)
    repeat = []
    for c in s:
        repeat.append(operate(S, c))

    ans = min(repeat)
    print(ans)

def operate(txt, char):
    n = len(txt)
    tmp = ''
    ret = 0
    while len(set(txt)) > 1:
        i = 0
        n -= 1
        while i < n:
            if txt[i] == char or txt[i+1] == char:
                tmp = tmp + char
            else:
                tmp = tmp + txt[i]
            i += 1
        txt = tmp
        tmp = ''
        ret += 1

    return ret

main()

Solution (Python):
import sys
import numpy as np
from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip()
    count = 0


    char_dict = {}
    for i in range(len(input_raw)):
        if input_raw[i] in char_dict:
            char_dict[input_raw[i]] += 1
        else:
            char_dict[input_raw[i]] = 1

    save_input_raw = input_raw
    min_count = sys.maxint
    for target_char in char_dict:
        input_raw = save_input_raw
        count = 0
        while 1:
            char_dict2 = {}
            for i in range(len(input_raw)):
                if input_raw[i] in char_dict2:
                    char_dict2[input_raw[i]] += 1
                else:
                    char_dict2[input_raw[i]] = 1

            if len(char_dict2) == 1:
                break;
            count += 1
            new_text = str(input_raw)

            for i in range(len(input_raw)):
                if new_text[len(input_raw) - 1 - i] != target_char:
                    new_lst = list(new_text)
                    new_lst.pop(len(input_raw) - 1 - i)
                    new_text = ''.join(new_lst)
                    break;


            for i in range(len(new_text) - 1):
                if (new_text[i] != target_char and
                    input_raw[i + 1] == target_char):
                    new_lst[i] = new_text[i + 1]
            new_text = ''.join(new_lst)
            input_raw = new_text
            
        if count < min_count:
            min_count = count

    print min_count


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    S = input()
    r = len(S)
    if len(set(S)) == 1:
        print(0)
    else:
        cnt = 0
        l = list(S)
        while cnt < 200:
            cnt += 1
            l = [l[x]+S[x+cnt] for x in range(len(l)-1)]
            for i in set(''.join(l)):
                if all((1 if i in x else 0) for x in l):
                    print(cnt)
                    return
    
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
def shrink(char, s):
    i = 0
    while len(set(s)) != 1:
        i += 1
        s = ''.join([s[i] if s[i+1] != char else s[i+1] for i in range(len(s)-1)])
    return i
print(min([shrink(c, s) for c in set(s)]))

Solution (Python):


import sys

def mx( a ):
    
    max = 0
    for k, v in a.items():
        if max < v:
            max = v
    return max

def remove_duplicates(x):
    y=[]
    for i in x:
        if i not in y:
            y.append(i)
    return y

def tryal( stdin, i ):
    
    atoz = {
    "a":0,
    "b":0,
    "c":0,
    "d":0,
    "e":0,
    "f":0,
    "g":0,
    "h":0,
    "i":0,
    "j":0,
    "k":0,
    "l":0,
    "m":0,
    "n":0,
    "o":0,
    "p":0,
    "q":0,
    "r":0,
    "s":0,
    "t":0,
    "u":0,
    "v":0,
    "w":0,
    "x":0,
    "y":0,
    "z":0
    }
    for j in range(len(stdin)-i):
        c = stdin[j:j+i+1]
        
        for c1 in list(remove_duplicates(c)):
            atoz[c1] = atoz[c1] + 1
            
    
    return mx( atoz )

stdin = sys.stdin.readline().strip()

for i in range(len(stdin)+1):
    t = tryal( stdin, i )
    if t == len(stdin)-i:
        print str(i)
        break

Solution (Python):
S = input()
N = len(S)
maxim = (N + 1) // 2

def judge1(cnt):
    for i in range(cnt+1):
        if judge2(i, cnt):
            return cnt
    else: return False

def judge2(i, cnt):
    if i + cnt + 1 >= N:
        return True
    for j in range(i+1, i+2 + cnt):
        if S[i] == S[j]:
            return judge2(j, cnt)
    return False


if len(set(S)) == 1:
    print("0")
else:
    for i in range(0, maxim):
        c = 0
        ans = judge1(i)
        if ans:
            print(str(ans))
            c = 1
            break
    if c == 0:
        print(str(maxim))

Solution (Python):
def solve (a , d):
    c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    old =a
    a=""
    for i in old:
        c[ord(i)-97]+=1
    if len(old) == max(c):
            return 0
    for i in range(len(old)-1):
        if old[i]==d or old[i+1]==d:
            a+=d
        else :
            a+=old[i]
    return solve(a,d)+1

a=input()
b=True

an =9999999999
c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in a:
    c[ord(i)-97]+=1
indexes = [i for i, x in enumerate(c) if x == max(c)]
for  i in a:
    t= solve(a,i)
    if t<an:
        an=t

print(an)

Solution (Python):
import sys

s = input()

if s.count(s[0]) == len(s):
    print(0)
    sys.exit()

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

m = 100
for v in dic.values():
    v.append(len(s))
    dist = v[0]
    for i in range(len(v))[1:]:
        dist = max(dist, v[i] - v[i-1] - 1)
    m = min(m, dist)

print(m)

Solution (Python):
a = input()
min = 10000
for target in set(a):
    s = a
    j = 0
    while(1):
        
        if len(set(s)) == 1:
            break
        new_s = ""
        for i in range(len(s)-1):
            if s[i] == target or s[i+1] == target:
                new_s +=target
            else:
                new_s += s[i]
        j+=1;
        if j > min:
            break
        s = new_s
    if min > j:
        min = j

print(min)

Solution (Python):
import numpy as np

a=raw_input()

b=[]
for k in range(len(a)):
    b.append(a[k])

b=np.array(b)

alp='abcdefghijklmnopqrstuvwxyz'

al=[]
for k in range(len(alp)):
    al.append(alp[k])

res=[]
for aa in al:
    if aa in b:
        res.append(np.where(b==aa))

m=[]
for k in range(len(res)):
    zz=np.hstack([np.array([-1]),res[k][0],np.array([len(a)])])
    z=np.diff(zz)
    
    if len(z)>0:
        m.append(np.max(z))
if len(m)>0:
    ans=np.min(m)
else:
    ans=len(a)

ans=ans-1

print(ans)

Solution (Python):
import numpy as np

s = input()
s_uniq = list(set(s))
s_sp = list()
count = [0]*len(s_uniq)

for x in s_uniq:
	s_sp.append(s.split(x))
	
for i in range(len(s_uniq)):
	for j in range(len(s_sp[i])):
		s_sp[i][j] = len(s_sp[i][j])

for i in range(len(s_uniq)):
	while max(s_sp[i]) > 0:
		if s_sp[i][-1] > 0:
			s_sp[i][-1] -= 1
		for j in range(len(s_sp[i]) - 1):
			if s_sp[i][j] > 0:
				s_sp[i][j] -= 1
		count[i] += 1

print(min(count))

Solution (Python):




t = input()
t_uniq = list(set(t))



def solve(t_list, c):
    li = t_list.split(c)
    ret = 0
    for i in li:
        ret = max(ret, len(i))
    return ret




ans = 101
for uniq in list(set(t)):
    ans = min(ans, solve(t, uniq))
print(ans)

Solution (Python):

import sys

S = input()
N = len(S)

d = {}
for i in S:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1


def trans(t, a):
    s = ''
    for i in range(len(t)-1):
        if t[i] == a or t[i+1] == a:
            s += a
        else:
            s += t[i+1]
    return s


min_val = 1000
for k in d.keys():
    s = S
    n = 0
    while s.count(k) != len(s):
        s = trans(s, k)
        n += 1
    if n < min_val:
        min_val = n

print(min_val)

Solution (Python):
s = raw_input()

operate = []
for letter in set(s):
    index = [i for i, x in enumerate(s) if x == letter]
    temp = [-1]
    index.append(len(s))
    temp.extend(index)
    index[:] = temp[:]
    diff = [(index[i + 1] - index[i] - 1) for i in range(len(index) - 1)]
    operate.append(max(diff))
result = min(operate)
print(result)

Solution (Python):
S = input()
D = {chr(i):[] for i in range(97,123)}
def main():
	max_c = 0
	for d in D:
		i = 0
		while i != -1 :
			t = S[i:].find(d)
			if t != -1:
				t += i
				D[d].append(t)
				i = t + 1 
			else:
				break
		max_c = max(len(D[d]),max_c)
	if max_c == 1:
		return len(S) // 2
	else:
		ans = len(S) // 2
		for d in D:
			if len(D[d]) < 2:
				continue
			if min(D[d]) >= len(S)//2 or max(D[d]) < len(S) // 2:
				continue
			max_len = D[d][0]
			for j in range(len(D[d]) -1):
				max_len = max(max_len,D[d][j + 1] - D[d][j] - 1)
			max_len = max(max_len,len(S) - D[d][-1] - 1)
			ans = min(max_len,ans)
		return ans
print(main())

Solution (Python):
s=input()

ans=int(len(s)/2)
for i in range(26):
	temp=0
	tempAns=0
	if s.count(chr(i+97))!=0:
		for j in s:
			if j==chr(i+97):
				tempAns=max(temp,tempAns)
				temp=0
			else:
				temp+=1
		tempAns=max(temp,tempAns)
		ans=min(ans,tempAns)
		
print(ans)

Solution (Python):
s = list(str(input()))
cl = []
for i in set(s):
    tar = i
    temp = s[:]
    count = 0
    while len(set(temp)) != 1:
        for j in range(len(temp)):
            if j < len(temp)-1:
                if temp[j + 1] == tar:
                    temp[j] = tar
            else:
                temp.pop()
        count += 1
    cl.append(count)
print(min(cl))

Solution (Python):
textList = list(input())
textVer = set(textList)

textMax = {}
for t in textVer:
    maxlist = []
    maxcounter = 0
    for i in range(len(textList)):
        if textList[i] != t:
            maxcounter += 1
        else: 
            maxlist.append(maxcounter)
            maxcounter = 0
    maxlist.append(maxcounter)
    maxlist.sort()
    maxlist.reverse()
    
    textMax[t] = maxlist[0]
timeMin = sorted(textMax.items(), key=lambda x: x[1])
print(timeMin[0][1])

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))


abc = "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".split()

string = rls()
ans = 114514810931

for j in abc:
    s = string[:]
    count = 0
    if(len(set(s)) == 1):
        ans = 0
        break
    while(count <= 10000):
        t = []
        count += 1
        for i in range(len(s)-1):
            if(s[i] == j or s[i+1] == j):
                t.append(j)
            else:
                t.append(s[i])
        if(set(t) == {j}):
            ans = min(ans, count)
            break
        elif(set(t) == set()):
            break
        s = t[:]

print(ans)

Solution (Python):
s=str(input())
ans=int(len(s)/2)

for i in range(97, 97+26):
  if chr(i) in s:
    ct= s.count(chr(i))
    place=[0]*ct
    for j in range(ct-1):
      place[0]=s.find(chr(i))+1
      place[j+1]=s[place[j]:].find(chr(i))+place[j]+1
    haba=max(len(s)-place[ct-1],place[0]-1)
    for j in range(ct-1):
      haba=max(haba,place[j+1]-place[j]-1)
    ans=min(ans,haba)

print(ans)

Solution (Python):
import collections
s = input()
n = len(s)
count_dict = collections.Counter(s)
p = len(count_dict)
critical = [0]*p
def manupulation(str,string,k):
        ans = ['1']*(k-1)
        for i in range(k-1):
            if string[i] == str or string[i+1] == str:
                ans[i] = str
        return "".join(ans)

def hantei(str,string,k):
    l = 1
    for i in range(k):
        if string[i] != str:
            l = 0
            break
    return l

i=0
for k1 in count_dict:
    kaisuu = 0
    k0 = k1
    string1 = s
    while hantei(k0,string1,n-kaisuu) == 0:
        string1 = manupulation(k0,string1,n-kaisuu)
        kaisuu +=1
    critical[i] = kaisuu
    i += 1
print(min(critical))

Solution (Python):
import string


S = input()

N = len(S)
if N == 1:
    print(0)
    exit()

se = set(list(S))
if len(se) == 1:
    print(0)
    exit()

ans = 1e9
for target in string.ascii_lowercase:
    new_S = list(S)
    tmp = 0
    while True:
        if len(set(new_S)) == 1:
            ans = min(ans, tmp)
            break
        tmp_S = []
        for i in range(N - tmp - 1):
            if new_S[i] == target or new_S[i + 1] == target:
                tmp_S.append(target)
            else:
                tmp_S.append(new_S[i + 1])
        new_S = list(tmp_S)
        tmp += 1
print(ans)

Solution (Python):
S= input()
"""
serval 
ssrra
sssa

"""

N = len(S)
"""
pre = set()
suf = set()
i=0
while not (len((suf&pre)) and 2*i>N):
    suf.add(S[i])
    pre.add(S[-i-1])
    print(i,suf,pre, S[i+1:-i-2])
    if S[i+1:-i-2]==S[i+1]*len(S[i+1:-i-2]) and S[i-1] in suf&pre:
        print("break")
        break
    i+=1
print(i)

"""
min_val = 999999
for i in range(26):
    char = chr(ord("a")+i)
    min_val = min(min_val , max(map(len,S.split(char))))



print(min_val)

Solution (Python):
S = input()

c = list(set(list(S)))
res = min(max(len(si) for si in S.split(ci)) for ci in c)
print(res)

Solution (Python):
str=input()
s=list(str)
alp=list(set(s))

res=10**6
for a in alp:
    idx=[]
    bidx=-1
    max=0
    s.append(a)
    for i in range(len(s)):
        if s[i]==a:
            tmp=i-bidx-1
            
            
            if max<tmp:
                max=tmp
            bidx=i
    s.pop()
    if res>max:
        res=max

print(res)

Solution (Python):

rawS = input()
abc = []
for s in rawS:
    abc.append(s)

abc = set(abc)

answer = 100
for a in abc:
    tmp = 0
    score = 0
    for s in rawS:
        if a == s:
            score = max(score, tmp)
            tmp = 0
        else:
            tmp += 1
    score = max(score, tmp)
    answer = min(answer, score)

print(answer)

Solution (Python):
ans = 999
s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
    ls = [list(s)]
    j = 0
    while True:
        if ls[j] == list(abc[i]*(len(s)-j)):
            break
        ls.append([])
        for k in range(len(ls[j])-1):
            if ls[j][k] == abc[i] or ls[j][k+1] == abc[i]:
                ls[j+1].append(abc[i])
            else:
                ls[j+1].append(ls[j][k])
        j += 1
        
        
    ans = min(ans, len(ls)-1) 
        
print(ans)

Solution (Python):
s = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
def geti(k,s):
  l = [-1]
  for i in range(len(s)):
    if s[i] == k:
      l.append(i)
  return l

def count(l,s):
  if l == [-1]:
    return 1000
  leng = len(s)
  if leng not in l:
    l.append(leng)
  c = 0
  for i in range(len(l)-1):
    if l[i+1] - l[i] - 1 > c:
      c = l[i+1] - l[i] - 1
  return c

ans = 1000
for a in alpha:
  if count(geti(a,s),s) < ans:
    ans = count(geti(a,s),s)
print(ans)

Solution (Python):
s = raw_input()

def check(s):
	if len(s) == 0:
		return True
	x = s[0]
	for z in s:
		if z != x:
			return False
	return True

in_s = s
answer = len(s)

for x in in_s:
	s = in_s
	cur_ = 0
	for it_ in range(len(in_s) + 2):
		if check(s):
			cur_ = it_
			break
		new_s = ""
		for i in range(len(s) - 1):
			if s[i] == x or s[i + 1] == x:
				new_s = new_s + x
			else:
				new_s = new_s + s[i]
		s = new_s
	answer = min(answer, cur_)
print answer

Solution (Python):
s=raw_input()
idx=[[-1] for _ in xrange(26)]
for i in xrange(len(s)):
    idx[ord(s[i])-ord('a')].append(i)
for i in xrange(26):
    idx[i].append(len(s))
ans=float("inf")
for i in xrange(26):
    tmp=0
    if len(idx[i])==2:continue
    for j in xrange(len(idx[i])-1):
        tmp=max(tmp,max(0,idx[i][j+1]-idx[i][j]-1))
    ans=min(ans,tmp)
print ans

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

dict = {}
i = 0
for c in S:
    if c not in dict:
        dict[c] = [False for _ in range(n)]
    dict[c][i] = True
    i += 1

suniq = set(S)

k = 0
for _ in range(n):
    end = False
    for c in suniq:
        end_c = True
        for j in range(len(dict[c]) - k):
            if not dict[c][j]:
                end_c = False
        if end_c:
            end = True
    if end:
        break
    
    k += 1

    for c in suniq:
        for j in range(len(dict[c]) - 1):
            if dict[c][j + 1]:
                dict[c][j] = True
    
print(k)

Solution (Python):
s = input()
if len(set(s)) <= 1:
    print(0)
    import sys
    sys.exit()

def resolve(target):
    depth = 0
    now = s
    while len(set(now)) > 1:
        result = list(now[:-1])
        for i, x in enumerate(now[:-1]):
            result[i] = now[i + 1] if now[i + 1] == target else now[i]
        now = "".join(result)
        depth += 1
    return "".join(result), depth


print(min([resolve(chr(target)) for target in range(ord("a"), ord("x") + 1)], key=lambda x: x[1])[1])

Solution (Python):
import copy

if __name__ == '__main__':
    s = list(input())

    char_list = set(s)

    


    ans = 1000
    for target_char in char_list:
        tmp_s = copy.deepcopy(s)
        tmp_ans = 0
        while True:
            if len(set(tmp_s)) == 1:
                ans = min(ans, tmp_ans)
                break

            
            
            for i in range(0, len(tmp_s) - 1):
                
                if tmp_s[i + 1] == target_char:
                    tmp_s[i] = target_char

            tmp_s.pop(len(tmp_s) - 1)
            tmp_ans += 1


    print(ans)

Solution (Python):
A = input()
B = []
for i in range(len(A)):
    B.append( max([len(x) for x in A.split(A[i])]))
print(min(B))

Solution (Python):
s = input()
s2 = s
ans = 10000000000
for k in s2:
    s = k + s2 + k
    t = 0
    u = 0
    m = 0
    for i, l in enumerate(s):
        if(l == k):
            t = u
            u = i
            m = max(u-t-1,m)
    ans = min(ans, m)
print(ans)

Solution (Python):


import sys
import math

s = sys.stdin.readline().rstrip()
mins = [
    [len(s)*2 for _ in range(len(s))]
    for _ in range(26)
]

for i in range(len(s)):
    code = ord(s[i]) - ord("a")
    for j in range(i, -1, -1):
        mins[code][j] = min( mins[code][j], i-j)


print(min(max(max(tries[:len(s)-i]), i) for i in range(len(s)) for tries in mins))

exit(0)

Solution (Python):
from collections import Counter
s = raw_input()
hist = Counter(s)

min_count = 1000
for alpha in hist.keys():
    count = 0
    tmp = s[:]
    while(tmp != alpha * len(tmp)):
        tmp2 = ''
        for i in range(len(tmp) - 1):
            if tmp[i] == alpha or tmp[i+1] == alpha:
                tmp2 += alpha
            else:
                tmp2 += tmp[i]
        tmp = tmp2
        count += 1
    min_count = min(count, min_count)
print min_count

Solution (Python):
s = raw_input()
slist = set(list(s))
result = len(s)
for c in slist:
    result = min([max(map(len, s.split(c))), result])
print result

Solution (Python):

def convertList(strList, c):
    time = 0
    tmpList = list(strList)
    while tmpList.count(c) != len(tmpList):
        newList = []
        for i in range(len(tmpList[:])-1):
            newList.append(c if (tmpList[i] == c or tmpList[i+1] == c) else tmpList[i])
        tmpList = list(newList)
        time += 1
    return time

S = input()
strList = list(S)
strSet = set(strList)
minTime = 1000000 
for c in strSet:
    time = convertList(strList, c)
    if minTime > time:
        minTime = time
print(minTime)

Solution (Python):
a2z = "abcdefghijklmnopqrstuvwxyz"
s_org = input()
ret = len(s_org)
for c in a2z:
    if(s_org.count(c) == 0):
        continue
    s = s_org
    steps = 0
    while s.count(c) != len(s):
        s_prime = ""
        for i in range(len(s)-1):
            if(s[i] == c or s[i+1] == c):
                s_prime += c
            else:
                s_prime += s[i]
        s = s_prime
        steps += 1
    ret = min([steps, ret])
print(ret)

Solution (Python):
s = input()
base = ord('a')
col = [-1 for x in range(26)]
check = [0 for x in range(26)]
maxi = [0 for x in range(26)]
for index, i in enumerate(s):
    check[ord(i) - base] = 1
    if index - col[ord(i) - base] - 1  > maxi[ord(i) - base]:
        maxi[ord(i) - base] = index - col[ord(i) - base] - 1
    col[ord(i) - base] = index
leng = len(s)
out = [10**9 for x in range(26)]
min = 10**9

for i in range(26):
    if check[i] != 0:
        store = 0
        if maxi[i] > leng - 1 - col[i]:
            store = maxi[i]
        else:
            store = leng - 1 - col[i]
        if min > store:
            
            min = store
print(min)

Solution (Python):
s = raw_input()

ans = 100
for ci in range(97,123):
    c = chr(ci)
    ss = list(s)
    count = 0

    while len(ss) > 0:
      if all(c == cs for cs in ss):
        ans = min(ans, count)
        break

      ss_ = ss[:len(ss)-1:]
      for i in range(len(ss)-1):
        if ss[i+1] == c:
          ss_[i] = c
      ss = ss_
      count += 1

print ans

Solution (Python):
s = input()

ans = len(s) // 2

for c in [chr(i + 97) for i in range(26)]:
    if c not in s:
        continue
    ma = 0
    for part in s.split(c):
        ma = max(ma, len(part))
    ans = min(ans, ma)

japaripark = ans
print(japaripark)

Solution (Python):
s = input()


init_c = 'a'
ans_len = 101
for i in range(26):
    max_len = 0
    l = 0
    tc = chr(ord(init_c) + i)
    for c in s:
        if c == tc:
            l = 0
        else:
            l += 1
        if l > max_len:
            max_len = l
    if ans_len > max_len:
        ans_len = max_len

print(ans_len)

Solution (Python):
s = input()
sets = set(s)
ls = list(s)
count = 100
if len(set(ls)) == 1:
    print(0)
else:
    for c in sets:
        tmp = ls.copy()
        cnt = 0
        while True:
            cnt += 1
            for i in range(len(tmp) - 1):
                if c in (tmp[i], tmp[i+1]):
                    tmp[i] = c
            tmp = tmp[:-1]
            if len(set(tmp)) == 1:
                break
        count = min(cnt, count)
    print(count)

Solution (Python):
import sys
from collections import Counter

from functools import reduce




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


def read_int_list():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


s = read_str()
n = len(s)
c = [set() for l in s]
for i in range(n, 0, -1):
    d = n - i
    for j in range(i):
        c[j].add(s[j + d])
    intersection = reduce(lambda x, y: x & y, c[:i])
    if intersection:
        print(d)
        break

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

def solve(s):
    rec = len(s)
    for c in 'abcdefghijklmnopqrstuvwxyz':
        if s == c * len(s):
            return 0
        if c not in s:
            continue
        rec = min(rec, solve_core(s, c))
    return rec

def solve_core(s, c):
    count = 0
    flag = True
    while (flag):
        count += 1
        news = []
        flag = False
        for i in range(0, len(s) - 1):
            if (s[i] == c or s[i + 1] == c):
                news.append(c)
            else:
                news.append('@')
                flag = True
        s = ''.join(news)
    return count


print(solve(s))

Solution (Python):
s = input().strip()
l = len(s)
d, a = {}, {}
for i, c in enumerate(s):
    if c in d:
        d[c] = max(d[c], i - a[c])
    else:
        d[c] = i
    a[c] = i + 1
for c, v in d.items():
    d[c] = max(v, l - a[c])
print(min(d.values()))

Solution (Python):
from collections import Counter

s = input()

s = list(s)

res = float("inf")
for c in s:
	l = s[:]
	n = 0
	while 1:
		if len(set(l)) == 1:
			break
		else:
			n+=1
			for i in range(len(l)-1):
				if l[i]==c or l[i+1]==c:
					l[i] = c
			l.pop()
	res = min(res, n)

print(res)

Solution (Python):

import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    S = str(input())
    return (S,)


def solve(S):
    before_dict = collections.defaultdict(list)
    before_ind_dict = collections.defaultdict(int)
    for ind, char in enumerate(S):
        if char not in before_ind_dict:
            before_ind_dict[char] = ind
            before_dict[char].append(ind)
        else:
            before = before_ind_dict[char]
            before_dict[char].append(ind - before - 1)
            before_ind_dict[char] = ind

    len_s = len(S)
    for key, val in before_ind_dict.items():
        before_dict[key].append(len_s - val - 1)

    l_max = [max(v) for v in before_dict.values()]
    ans = min(l_max)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):









s = input()

ans = 10000
for i in range(26):
	c = chr(ord('a') + i)
	if c in s:
		res = 0
		cnt = 0
		for now in s:
			if now == c:
				res = max(res, cnt)
				cnt = 0
			else:
				cnt += 1

		cnt = 0
		while s[-(cnt+1)] != c:
			cnt += 1
		res = max(res, cnt)

		ans = min(ans, res)
print(ans)

Solution (Python):
s = input()
n = len(s)
min_t = float('inf')
for i in range(n):
    target = s[i]
    pre = -1
    max_t = 0
    for j in range(n):
        if s[j] == s[i]:
            max_t = max(max_t, j-pre-1)
            pre = j
    max_t = max(max_t, n - pre-1)
    if max_t < min_t:
        min_t = min(min_t, max_t)
print(min_t)

Solution (Python):
def check(ss):
    flag = True
    for i in range(1, len(ss)):
        if ss[i] != ss[0]:
            flag = False
            break
    return flag

s = input()

g = [0] * 200
ans = 1000000000
sss = s
for x in s:
    if g[ord(x)]:
        continue
    g[ord(x)] = 1
    tot = 0
    s = sss
    while not check(s):
        ss = ""
        has = False
        for j in range(len(s) - 1):
            if s[j] == x or s[j + 1] == x:
                ss += x
            else:
                ss += s[j]
        tot += 1
        s = ss
    ans = min(tot, ans)
print(ans)

Solution (Python):
s=raw_input()

def calc(c):
    ma=0
    count=0
    fi=True
    for i in range(len(s)):
        if s[i] == c:
            if not fi:
                count = (count+1)/2
            if count > ma:
                ma = count
            count=0
        else:
            count+=1
    if count > ma:
        ma = count
    return ma

mi=1000
for c in "abcdefghijklmnopqrstuvwxyz":
    if c not in s:
        continue
    m=calc(c)
    if m < mi:
        mi = m
print mi

Solution (Python):
from operator import and_
s = raw_input().strip()
n = len(s)
for i in xrange(n):
    x = reduce(and_, [set(s[j:j+i+1]) for j in xrange(n - i)])
    if x:
        print i
        break

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

cs = set(s)
ans = 100
for c in cs:
    t = s
    while 1 < len(set(t)):
        tmp = ''
        for i in range(len(t) - 1):
            if t[i] == c or t[i + 1] == c:
                tmp += c
            else:
                tmp += t[i]
        t = tmp
    ans = min(ans, len(s) - len(t))

print(ans)

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

for i in xrange(0, N):
    r = i + 1
    s = [set() for _ in xrange(N - i)]
    for j in xrange(N-i):
        for k in xrange(r):
            s[j].add(S[j + k])
    for j in xrange(1, N-i):
        s[0] &= s[j]
    if len(s[0]) > 0:
        print i
        exit()

Solution (Python):
def do(x, c):
    if len(x) == 1 or x.count(c) == len(x):return 0
    res = ""
    for i in range(len(x) - 1):
        if(x[i] == c or x[i+1] == c):res += c
        else: res += x[i]
    return 1 + do(res, c)

s = raw_input()

ans = 100
for c in "abcdefghijklmnopqrstuvwxyz":
    ans = min(ans, do(s, c))

print ans