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: Wrong Answer

Solution code:
def itoa(i):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z']
    return alphabet[i]
s = input()
score_list = []
for i in range(26):
    c = itoa(i)
    prev = 0
    score = 0
    flag=False
    for j in range(len(s)):
        if c==s[j]:
            score=max(j-prev-1,score)
            flag=True
            prev=j
    score = max(j-prev,score)
    if flag==False:
        score=10**3
    score_list.append(score)
    
print(min(score_list))

Submission status: Wrong Answer

Solution code:
from collections import Counter
s=input()
Cs=Counter(s)
M=Cs.most_common()
Mx=[]
for i in range(len(M)):
    if M[i][1]==M[0][1]:
        Mx.append(M[i][0])
    else:
        break
A=[]
for i in Mx:
    a=0
    My=s.split(i)
    for j in range(len(My)):
        if len(My[j])>a:
            a=len(My[j])
    A.append(a)
print(min(A))

Submission status: Wrong Answer

Solution code:
import sys


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


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

    flg = False

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

    print(dic)

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

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

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

s = input()
c = collections.Counter(s).most_common()
m = c[0][1]
maxi = 0
if m == 1:
    ans = 0
    use = s[len(s) // 2]
    while len(set(s)) != 1:
        a = ""
        for i in range(len(s) - 1):
            if s[i] == use or s[i + 1] == use:
                a += use
            else:
                a += s[i]
        ans += 1
        s = a
    print(ans)
else:
    use = [s[0], 0]
    for k in c:
        if k[1] == m and k[0] != s[0]:
            index = [i for i, x in enumerate(s) if x == k[0]]
            sa = [index[i + 1] - index[i] for i in range(m - 1)]
            if maxi < min(sa):
                use = k
                maxi = min(sa)
    ans = 0
    while len(set(s)) != 1:
        a = ""
        for i in range(len(s) - 1):
            if s[i] == use[0] or s[i + 1] == use[0]:
                a += use[0]
            else:
                a += s[i]
        ans += 1
        s = a
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

s = input()
c = collections.Counter(s).most_common()
m = c[0][1]
maxi = 0
if m == 1:
    print(len(s) // 2)
else:
    use = [s[0], 0]
    for k in c:
        if k[1] == m and k[0] != s[0]:
            index = [i for i, x in enumerate(s) if x == k[0]]
            sa = [index[i + 1] - index[i] for i in range(m - 1)]
            if maxi < min(sa):
                use = k
                maxi = min(sa)
    ans = 0
    while len(set(s)) != 1:
        a = ""
        for i in range(len(s) - 1):
            if s[i] == use[0] or s[i + 1] == use[0]:
                a += use[0]
            else:
                a += s[i]
        ans += 1
        s = a
    print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
import string
s = input()
result = 10**9
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
        print(t)
        t.pop()
        
    result = min(result, len(s) - len(t))
print(result)

Submission status: Wrong Answer

Solution code:
s=list(input())

s.sort()
anscount=1
count=0

for i in range(len(s)):
  if i==0:
    count=1
  elif s[i]==s[i-1]:
    count+=1
    anscount=max(anscount,count)
    print(anscount)
  else:
    count=1
    
print(int((len(s)-anscount+1)//(1+anscount)))

Submission status: Wrong Answer

Solution code:
#s = input()
s = "zzz"
s = "whbrjpjyhsrywlqjxdbrbaomnw"
f = {}
g = {}

chars = [c for c in s]
#print(chars)

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(f)
#print(g)
print(max_len_all-1)

Submission status: Wrong Answer

Solution code:
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
                elif j == len(s) - 1:
                    if max_c < j - i:
                        max_c = j - i

                    f_idx = j

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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] or j == len(s) - 1:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1

                    f_idx = j

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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():
    if v<max_v: break
    else:
        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)

Submission status: Wrong Answer

Solution code:
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:
  freq = 1
  for j in range(1,len(s)-1):
    if freq < s.count(s[j]):
      freq = s.count(s[j])
  targets = set()
  for z in range(1,len(s)-1):
    if s.count(s[z]) == freq:
      targets.add(s[z])
  mincount = 10**12
  for X in targets:
    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)

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from collections import Counter
s = input()
if len(set(s)) == 1:
    print(0)
else:
    counter = Counter(s)
    target = max([(v, k) for k, v in counter.items()])[1]
    s_list = s.split(target)
    print(max([len(item) for item in s_list]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import re

def find_index(char, text):
	pattern = r""+char
	iterator = re.finditer(pattern, text)
	temp = []
	for match in iterator:
		temp.append(match.start())
	return temp

origin = input()
t_len = len(origin)
counter = Counter(origin)
max_num = max([(v,k) for k,v in counter.items()])[0]
max_list = [k for k,v in counter.items() if v == max_num]



if max_num == t_len:
	result = 0
else:
	r_list = []
	for c in max_list:
		t = origin
		t_len = len(origin)
		calc = 0
		while t_len > 0:
			temp = ""
			for i in range(t_len-1):
				if t[i] == c or t[i+1] == c:
					temp += c
				else:
					temp += t[i]
			t = temp
			t_len = len(t)
			calc += 1
			#Check
			if t.count(c) == t_len:
				break
		r_list.append(calc)
		result = min(r_list)
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import re

def find_index(char, text):
	pattern = r""+char
	iterator = re.finditer(pattern, text)
	temp = []
	for match in iterator:
		temp.append(match.start())
	return temp

origin = input()
t_len = len(origin)
counter = Counter(origin)
max_num = max([(v,k) for k,v in counter.items()])[0]
max_list = [k for k,v in counter.items() if v == max_num]


if max_num == 1:
	result = int(t_len/2)
elif max_num == t_len:
	result = 0
else:
	r_list = []
	for c in max_list:
		t = origin
		t_len = len(origin)
		calc = 0
		while t_len > 0:
			temp = ""
			for i in range(t_len-1):
				if t[i] == c or t[i+1] == c:
					temp += c
				else:
					temp += t[i]
			t = temp
			t_len = len(t)
			calc += 1
			#Check
			if t.count(c) == t_len:
				break
		r_list.append(calc)
		result = min(r_list)
print(result)

Submission status: Wrong Answer

Solution code:

input1 = input()
array = list(input1)

count = [1]*len(input1)

for i in range(len(input1)):
  for j in range(i+1, len(input1)):
    if(input1[i] == input1[j]):
      count[i] += 1

# print (count) #その文字が自身を含め何回出てくるか

max_count = max(count)
max_char = []

for i in range(len(input1)):
  if(max_count == count[i]):
    max_char.append(array[i])

arr = [[]]*len(max_char)
char_index = []

for i in range(len(max_char)):
  index = []
  for j in range(max_count):
    index.append(array.index(max_char[i])) # ここが味噌
    array[array.index(max_char[i])] = "A"
  char_index.append(index)

# print (char_index)

char_distance = []

for i in range(len(max_char)):
  sub_arr = []
  for j in range(max_count+1):
    if(j == 0):
      sub = char_index[i][j]
    if(j != 0 and j != max_count):
      sub = char_index[i][j] - char_index[i][j-1]-1
    if(j == max_count):
      sub = len(array) - char_index[i][j-1] - 1
    sub_arr.append(sub)
  char_distance.append(sub_arr)

# print (char_distance)

# char_distance のうちブロックごとに最小値を計算する

char_dis_max = []

for i in range(len(char_distance)):
  char_dis_max.append(max(char_distance[i]))

# print (char_dis_max)
# print ("++++++++++++")
print (min(char_dis_max))

Submission status: Wrong Answer

Solution code:
s=input()
print(s)

Submission status: Wrong Answer

Solution code:
strings = input()
answers = []
temp_diff = 0

for s in strings:
    target_index = -1 
    answer = 0
    index = []
    while True:
        target_index = strings.find(s, target_index + 1)
        if target_index == -1:
            break
        else:
            index.append(target_index)
            if len(index) > 1:
                temp_diff = index[-1] - index[-2]
            else:
                temp_diff = index[0]
            if temp_diff > answer:
                answer = temp_diff
                
    answer -= 1
    temp_diff = len(strings) - index[-1] - 1
    if temp_diff > answer:
        answer = temp_diff
        
    answers.append(answer)

print(min(answers))

Submission status: Wrong Answer

Solution code:
s = input()
count_s = s.count(s[0])
word_s = s[0]
len_s = len(s)
word_list = []
word_tmp_list = []

if len_s == count_s:
    print("0")
else:
    for i in range(1, len_s):
        if count_s < s.count(s[i]):
            count_s = s.count(s[i])
    for i in range(len_s):
        if count_s == s.count(s[i]):
            word_s = s[i]
            word_tmp_list.append(s[i])
            if s[i] not in word_list:
                word_list.append(s[i])
    dis_list = []
    for word in word_list:
        num = 0
        flag = 0
        tmp_list = []
        for i in range(len_s):
            if word == s[i] and flag == 0:
                tmp_list.append(i)
                num = i
                flag = 1
            elif word == s[i]:
                tmp_list.append(i-num-1)
                num = i
        tmp_list.append(len_s-num-1)
        dis_list.append(tmp_list)
    max_dis = float("inf")
    for distance in dis_list:
        if max(distance) < max_dis:
            max_dis = max(distance)

    print(max_dis)

Submission status: Wrong Answer

Solution code:
strings = input()
answers = []
max_count = 1
max_string = []
target_index = -1
temp_diff = 0
index = []
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if strings.count(s) >= max_count:
        max_count = strings.count(s)

for s in alphabet:
    if max_count == strings.count(s):
        max_string.append(s)

for s in max_string:
    answer = 0
    while True:
        target_index = strings.find(s, target_index + 1)
        if target_index == -1:
            break
        else:
            index.append(target_index)
            if len(index) > 1:
                temp_diff = index[-1] - index[-2]
            else:
                temp_diff = index[-1]
            if temp_diff > answer:
                answer= temp_diff
                
    answer -= 1
    temp_diff = len(strings) - index[-1] - 1
    if temp_diff > answer:
        answer = temp_diff
        
    answers.append(answer)

print(min(answers))

Submission status: Wrong Answer

Solution code:
# import ipdb
from collections import Counter


def max_distance(indices):
    maximum = 0
    indices = [-1] + indices + [len(word)]
    for i in range(len(indices) - 1):
        a, b = indices[i:i+2]
        if b - a > maximum:
            maximum = b - a

    return maximum - 1

word = input()
c = Counter(word[1:])

char2freq = ((charactor, freq) for charactor, freq in c.most_common())
pre_ans = 1000
old_freq = 0
for char, freq in char2freq:
    if freq < old_freq: break
    old_freq = freq
    indices = [i for i, x in enumerate(word) if x == char]
    # ipdb.set_trace()
    cur_ans = max_distance(indices)

    if pre_ans > cur_ans:
        pre_ans = cur_ans

print(pre_ans)

Submission status: Wrong Answer

Solution code:
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

# extract letters which occur the most in s

l = [[] for i in range(len(s) + 1)]
[l[s.count(c)].append(c) for c in set(s)]
l = [i for i in l if i][-1]

print(min([shrink(c, s) for c in l]))

Submission status: Wrong Answer

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

    cnt = [None] * 26
    for i in range(97, 123):
        cnt[i-97] = S.count(chr(i))

    max_ = max(cnt)
    if max_ == len(S):
        print(0)
        return

    idxs = [i for i, x in enumerate(cnt) if x == max_]
    repeat = []
    for i in idxs:
        char = chr(i+97)
        repeat.append(operate(S, char))
    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()

Submission status: Wrong Answer

Solution code:
s_org = list(input())

list_set = set(s_org)


count = 0

result = len(s_org)

for value in list_set:
	new_s = s_org
	s = s_org
	while True:
		if new_s.count(value) == len(new_s):
			break
		new_s = ""
		for i in range(len(s) - 1):
			if s[i] == value:
				new_s += value
			elif s[i + 1] == value:
				new_s += value
			else:
				new_s += s[i]
				print (new_s)
		count += 1
		s = new_s

	result = min(result,count)
	count = 0

print (result)

Submission status: Wrong Answer

Solution code:
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 indexes:
    t= solve(a,chr(i+97))
    if t<an:
        an=t

print(an)

Submission status: Wrong Answer

Solution code:
s = input()
count_s = s.count(s[0])
word_s = s[0]
len_s = len(s)
word_list = []
word_tmp_list = []

if len_s == count_s:
    print("0")
else:
    for i in range(1, len_s):
        if count_s < s.count(s[i]):
            count_s = s.count(s[i])
    for i in range(len_s):
        if count_s == s.count(s[i]):
            word_s = s[i]
            word_tmp_list.append(s[i])
            if s[i] not in word_list:
                word_list.append(s[i])
    dis_list = []
    for word in word_list:
        num = 0
        tmp_list = []
        for i in range(len_s):
            if word == s[i] and num == 0:
                tmp_list.append(i)
                num = i
            elif word == s[i]:
                tmp_list.append(i-num-1)
                num = i
        tmp_list.append(len_s-num-1)
        dis_list.append(tmp_list)
        
    max_dis = float("inf")
    for distance in dis_list:
        if max(distance) < max_dis:
            max_dis = max(distance)

    print(max_dis)

Submission status: Wrong Answer

Solution code:
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)-2):
        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 indexes:
    t= solve(a,chr(i+97))
    if t<an:
        an=t

print(an)

Submission status: Wrong Answer

Solution code:
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)-2):
        if old[i]==d or old[i+1]==d:
            a+=d
        else :
            a+=old[i]
    print(a+":")
    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 indexes:
    print(chr(i+97)+"!!")
    t= solve(a,chr(i+97))
    if t<an:
        an=t

print(an)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def main():
    s = input()
    d = {}
    l = []
    cnt = 0
    ans = []
    for i in s:
        d[i] = 0
    for i in s:
        d[i] += 1

    for i in s:
        cnt = max(cnt, d[i])
    for i in s:
        if d[i] == cnt:
            l.append(i)

    l = list(set(l))
    for i, x in enumerate(l):
        sp = s.split(x)
        ans.append(max(0, max([len(x) for x in sp])))

    print(min(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
a = []
b = []
c = []
l = 0
x = []

for i in range(97,123):
	a.append(s.count(chr(i)))

m = max(a)
if m == 1:
	k = len(s) // 2
	print(k)
	exit()
elif m == len(s):
	print(0)
	exit()

n = a.count(m)
if n == 1:
	l = a.index(m)

	i = 0
	while i >= 0:
		b.append(s.find(chr(l+97), i))
		i = s.find(chr(l+97), i) + 1
		if i == 0:
			break

	for i in range(1,len(b)):
		c.append(b[i]-b[i-1]-1)

	c.append(b[0])
	c.append(len(s)-max(b)-1)

	print(max(c))
else:
	for i in range(n):
		l = a.index(m, l)

		i = 0
		while i >= 0:
			b.append(s.find(chr(l+97), i))
			i = s.find(chr(l+97), i) + 1
			if i == 0:
				break

		for i in range(1,len(b)):
			c.append(b[i]-b[i-1]-1)

		c.append(b[0])
		c.append(len(s)-max(b)-1)
		x.append(max(c))
		l += 1
		b = []
		c = []

	print(min(x))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def main():
    s = input()
    d = {}
    l = []
    cnt = 0
    ans = []
    for i in s:
        d[i] = 0
    for i in s:
        d[i] += 1

    for i in s:
        cnt = max(cnt, d[i])
    for i in s:
        if d[i] == cnt:
            l.append(i)

    for i, x in enumerate(l):
        sp = s.split(x)
        ans.append(max(0, max([len(x) for x in sp])))

    print(min(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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)+1])])
    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-=1

print(ans)

Submission status: Wrong Answer

Solution code:
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([0]),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-=1

print(ans)

Submission status: Wrong Answer

Solution code:
Al=[0]*26
def c(st):
    if st=="a":
        Al[0]+=1
    elif st=="b":
        Al[1]+=1 
    elif st=="c":
        Al[2]+=1
    elif st=="d":
        Al[3]+=1 
    elif st=="e":
        Al[4]+=1
    elif st=="f":
        Al[5]+=1 
    elif st=="g":
        Al[6]+=1
    elif st=="h":
        Al[7]+=1 
    elif st=="i":
        Al[8]+=1
    elif st=="j":
        Al[9]+=1 
    elif st=="k":
        Al[10]+=1
    elif st=="l":
        Al[11]+=1 
    elif st=="m":
        Al[12]+=1
    elif st=="n":
        Al[13]+=1 
    elif st=="o":
        Al[14]+=1
    elif st=="p":
        Al[15]+=1
    elif st=="q":
        Al[16]+=1 
    elif st=="r":
        Al[17]+=1
    elif st=="s":
        Al[18]+=1 
    elif st=="t":
        Al[19]+=1
    elif st=="u":
        Al[20]+=1 
    elif st=="v":
        Al[21]+=1
    elif st=="w":
        Al[22]+=1 
    elif st=="x":
        Al[23]+=1
    elif st=="y":
        Al[24]+=1 
    elif st=="z":
        Al[25]+=1
S=list(input())
N=len(S)
#print (N)
for i in range (N):
    c(S[i])
#    print (Al)
M=0
for i in range (26):
    if M<Al[i]:
        M=Al[i]
N-=M
if N%2!=0:
    N+=1
N//=2
print (N)

Submission status: Wrong Answer

Solution code:
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)+1)
    dist = v[0]
    for i in range(len(v))[1:]:
        dist = max(dist, v[i] - v[i-1])
    m = min(m, dist)

print(m-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
counter = Counter(s)
target = counter.most_common()[0][0]
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;
    s = new_s
print(j)

Submission status: Wrong Answer

Solution code:

import sys

S = input()
N = len(S)

d = {}
for i in S[1:-1]:
    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]
    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)

Submission status: Wrong Answer

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

def judge(cnt):
    k = N // (cnt + 1)
    flag = 1
    for i in range(cnt + 1):
        for j in range(1,k):
            if S[i] in S[j * (cnt + 1): j * (cnt + 1) + cnt + 1]:
                continue
            else: flag *= 0
        if flag == 1:
            return cnt
    return False

for i in range(maxim):
    c = 0
    if judge(i) is not False:
        print(str(judge(i)))
        c = 1
        break

if c == 0:
    print(str(maxim))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def main():
    s = input()
    d = {}
    poyo = ''
    cnt = 0
    c = ''

    for i in s:
        d[i] = 0
    for i in s:
        d[i] += 1

    for i in s:
        cnt = max(cnt, d[i])
    for i in s:
        if d[i] == cnt:
            poyo += i
    
    if cnt == 1:
        c = s[int(len(s) / 2)]
    for i in s[int((len(s) + cnt - 1) / cnt):]:
        if i in poyo:
            c = i
            break
    
    a = {}
    r = 0
    while True:
        if len({i for i in s}) == 1:
            break
        else:
            for i, e in enumerate(s):
                if e == c:
                    t = list(s)
                    t[i-1] = c
                    s = "".join(t)
            s = s[:len(s)-1]
            r += 1
        if r == 10:
            break

    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
a = []
b = []
c = []

for i in range(97,123):
	a.append(s.count(chr(i)))

m = max(a)
if m == 1:
	k = len(s) // 2
	print(k)
	exit()
elif m == len(s):
	print(0)
	exit()

l = a.index(m)

i = 0
while i >= 0:
	b.append(s.find(chr(l+97), i))
	i = s.find(chr(l+97), i) + 1
	if i == 0:
		break

for i in range(1,len(b)):
	c.append(b[i]-b[i-1]-1)

c.append(b[0])
c.append(len(s)-max(b))

print(max(c))

Submission status: Wrong Answer

Solution code:
a = str(input())
b = len(list(set(a)))
c = b/2
if c < 1:
    print(0)
else:
    print(int(c))

Submission status: Wrong Answer

Solution code:
a=input()
b=True

ans =0
while b:
    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
    for i in old:
        c[ord(i)-97]+=1
    if len(old) == max(c):
        break
    d = chr(c.index(max(c))+97)
    a=""
    for i in range(len(old)-2):
        if old[i]==d or old[i+1]==d:
            a+=d
        else :
            a+=old[i]
    ans=ans+1
print(ans)

Submission status: Wrong Answer

Solution code:
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]-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)

Submission status: Wrong Answer

Solution code:
ans = 999
s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
    ls = [s]
    j = 0
    while True:
        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
        if ls[j] == list(abc[i]*(len(s)-j)):
            break
        
    ans = min(ans, len(ls)-1) 
        
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(raw_input())
n = len(set(s))
if n == 1:
    print "0"
else:
    a = n / 2
    print a

Submission status: Wrong Answer

Solution code:
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))
#print idx
ans=float("inf")
for i in xrange(26):
    tmp=0
    for j in xrange(len(idx[i])-1):
        tmp=max(tmp,idx[i][j+1]-idx[i][j]-1)
    #print i,tmp
    ans=min(ans,tmp)
print ans

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()

s = list(s)

counter = Counter(s).most_common()
most = []

maxnum = counter[0][1]

for i in counter:
	if i[1] == maxnum:
		most.append(i[0])

res = float("inf")
for c in most:
	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)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

from functools import reduce

# sys.stdin = open('a1.in')


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, 1, -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