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:
# AGC016
import collections

s = list(input())
c = collections.Counter(s)
n = len(s)
check_word = []
if len(c) == n:
    ans = n // 2
else:
    common = c.most_common()
    cnt_list = []
    for i in range(len(c)):
        if common[i][1] == 1:
            break
        else:
            now_word = common[i][0]
            ##print(now_word)
            check_word.append(now_word)
            locate = [i for i, x in enumerate(s) if x == now_word]
            if 0 not in locate:
                locate.insert(0, 0)
            if n-1 not in locate:
                locate.append(n-1)
            ##print(locate)
            diff_locate = [0] * (len(locate) - 1)
            for l in range(len(locate) - 1):
                diff_locate[l] = locate[l+1] - locate[l]
            ##print(diff_locate)
            cnt_list.append(max(diff_locate) - 1)
            ##print(cnt_list)
            ##print("\n")
    if n % 2 == 1:
        if s[n // 2] in check_word:
            pass
        else:
            cnt_list.append(n // 2 )
    else:
        if s[n // 2] in check_word:
            pass
        if s[n // 2 - 1] in check_word:
            pass
        else:
            cnt_list.append(n // 2)
    ans = min(cnt_list)
print(ans)

Submission status: Wrong Answer

Solution code:
#import math
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    t=list(input())
    s=[]
    for i in range(len(t)):
        if t[i]!="":
            s.append(t[i])
    n=len(s)
    ans=n
    for e in s:
        M=0
        cnt=0
        for i in range(n):
            if s[i]==e:
                if M<=cnt:
                    M=cnt
                    cnt=0
            else:
                cnt+=1
        if M<=cnt:
            M=cnt
        if M<=ans:
            ans=M
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
#import math
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    t=list(input())
    s=[]
    for i in range(len(t)):
        if t[i]!="":
            s.append(t[i])
    n=len(s)
    ans=n
    for e in s:
        M=0
        cnt=0
        for i in range(n):
            if s[i]==e:
                if M<=cnt:
                    M=cnt
                    cnt=0
            else:
                cnt+=1
        if M<=cnt:
            M=cnt
        if M<=ans:
            print(ans)
            ans=M
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
import math
import sys
import bisect
input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    s=list(input())
    n=len(s)
    ans=n
    for e in s:
        M=0
        cnt=0
        for i in range(n):
            if s[i]==e:
                if M<=cnt:
                    M=cnt
                    cnt=0
            else:
                cnt+=1
        if M<=cnt:
            M=cnt
        if M<=ans:
            ans=M
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
S = input()

ans = float('inf')
for goal in S:
    dist = [float('inf')] * len(S)
    right = float('inf')
    for i in range(len(S))[:: -1]:
        s = S[i]
        if s == goal:
            right = i
        dist[i] = min(dist[i], abs(i - right))

    cost = float('inf')
    for i in range(1, len(S) + 1):
        lMax = max(dist[:i])
        if lMax == float('inf'):
            continue
        cost = min(cost, max(lMax, max(dist[:len(S) - lMax + 1])))
    ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

ans = float('inf')
for goal in S:
    dist = [float('inf')] * len(S)
    right = float('inf')
    for i in range(len(S))[:: -1]:
        s = S[i]
        if s == goal:
            right = i
        dist[i] = min(dist[i], abs(i - right))

    cost = float('inf')
    for i in range(1, len(S) + 1):
        lMax = max(dist[:i])
        if lMax == float('inf'):
            continue
        cost = min(cost, max(lMax, max(dist[:len(S) - lMax])))
    ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

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

for length in range(1,N-1):
  tmp = set([i for i in s])
  for left in range(N-length+1):
    right = left + length
    tmp = set(s[left:right]) & tmp
    #print(left,right)
    #print(tmp)
    #print("--------")
  else:
    #print(length, tmp)
    if len(tmp) > 0:
      print(length-1)
      exit()

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)

dp=[[0 for i in range(27)] for j in range(N+1)]

for i in range(1,N):
  for j in range(N-i+1):
    s=list(set(S[j:j+i]))
    for ss in s:
      #print(ss,ord(ss)-96)
      dp[i][ord(ss)-96]+=1
    for k in range(1,27):
      if dp[i][k]==N-i+1:
        #1
        print(i-1)
        exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = list(input())

c = Counter(s)
mc = c.most_common()
len_s = len(s)
ans = len_s
for l, n in mc:
    if n != mc[0][1]:
        break
    prev = 0
    x = 0
    for i in range(len_s):
        if s[i] == l:
            x = max(x, i - prev)
            prev = i + 1
    x = max(x, len_s - prev)
    ans = min(ans, x)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = list(input())

c = Counter(s)
mc = c.most_common()
len_s = len(s)
ans = len_s
for l, n in mc:
    if n != mc[0][1]:
        break
    prev = 0
    x = 0
    for i in range(len_s):
        if s[i] == l:
            x = max(x, i - prev)
            prev = i + 1
    ans = min(ans, x)
    print(l, n, x)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

s = input()

print(math.ceil((len(set(s)) - 1) / 2))

Submission status: Wrong Answer

Solution code:
import math

s = input()

d = dict()
for w in s:
	d[w] = d.get(w, 0) + 1

print(math.ceil((len(d) - 1) / 2))

Submission status: Wrong Answer

Solution code:
import math

s =[w for w in input()]
ma = 0

for w in set(s):
	ma = max(ma, s.count(w))
	
print(math.ceil((len(set(s))-1) / 2))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
C = set(S)
ans = N
for c in C:
    T = list(S)
    tmp = 0
    for i in range(N-1):
        if len(set(T))==1 : 
            ans = min(ans,tmp)
            break
        tmp += 1
        T = [c if T[j] == c else T[j+1] for j in range(N-1-i)]
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
N = len(s)

ans = 99
for i in range(1, N): #残す文字数
    tmp = 0 #残す文字以外の最大連続数
    count = 0 #残す文字以外が何文字続いているかをカウント
    for j in range(i):
        if s[j] == s[i]:
            tmp = max(tmp, count)
            count = 0
        else:
            count += 1
    tmp = max(tmp, count)
    ans = min(ans, max(tmp, N - i - 1))

print (ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = list(input())
c = Counter(s)
v = c.most_common(1)[0][1]
m = len(s)

k = m-v
if k%2==1: k+=1
print(k//2)

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
#print(s)
c = collections.Counter(s)
l = list(c.items())
l = sorted(l, key = lambda x : x[1], reverse=True)
#print(l)

h = []
tmp = l[0][1]

for i in range(len(l)):
     if l[i][1] >= tmp:
          h.append(l[i][0])
     else:
        break

#print(h)

ans = []

for i in range(len(h)):
    tmp = [_ for _, x in enumerate(s) if x == h[i]]
#    print(h[i])
#    print(tmp)
    lll = []
    for j in range(len(tmp)):
        if j == 0:
            lll.append(tmp[j])
        else:
            lll.append(tmp[j] - tmp[j-1] - 1)
    lll.append(len(s) - tmp[len(tmp) - 1] - 1)
    ans.append(max(lll))
#    print(lll)


#print(ans)
print(min(ans))

Submission status: Wrong Answer

Solution code:
s=input()
l=len(s)
a=[1]*(l+1)
c=[]
x=0
while(x<=l-1):
  if(a[x]==1):
    a[x]=0
    k=0
    b=[x-1]
    t=s+s[x]
    for i in range(x+1,l+1):
      if(t[x]==t[i]):
        b.append(k)
        a[i]=0
        k=0
      else:
        k+=1
    c.append(max(b))
  x+=1
print(min(c))

Submission status: Wrong Answer

Solution code:
s = input()
c = []
mabc = []
for i in range(len(s)):
    c.append(s.count(s[i]))
for i in range(len(c)):
    if c[i] == max(c):
        if not s[i] in mabc:
            mabc.append(s[i])
ans = []
for abc in mabc:
    sl = s.split(abc)
    sx = []
    for i in range(len(sl)):
        sx.append(len(sl[i]))
    count = 0
    while True:
        b = True
        for i in range(len(sx)):
            if sx[i]>0:
                b = False
        if b:
            break
        for i in range(len(sx)-1):
            sx[i] = max(0,sx[i]-1)
        if sx[-1]>sx[0]:
            sx[len(sx)-1] = max(0,sx[len(sx)-1]-1)
        else:
            sx[0] = max(0,sx[0]-1)
        count += 1
    ans.append(count)
print(min(ans))

Submission status: Wrong Answer

Solution code:
s = input()
c = []
mabc = []
for i in range(len(s)):
    c.append(s.count(s[i]))
for i in range(len(c)):
    if c[i] == max(c):
        if not s[i] in mabc:
            mabc.append(s[i])
ans = []
for abc in mabc:
    sl = s.split(abc)
    sx = []
    for i in range(len(sl)):
        sx.append(len(sl[i]))
    count = 0
    while True:
        b = True
        for i in range(len(sx)):
            if sx[i]>0:
                b = False
        if b:
            break
        for i in range(len(sx)-1):
            sx[i] = max(0,sx[i]-1)
        sx[len(sx)-1] = max(0,sx[len(sx)-1]-1)
        count += 1
    ans.append(count)
print(min(ans))

Submission status: Wrong Answer

Solution code:
# 2019/08/09
from collections import Counter
s=list(input())
n=len(s)
S=set(s)
if len(s)==len(S):
    print(n//2)
    exit()
if s.count(s[0])==len(s):
    print(0)
    exit()

c=Counter(s)

res=float('inf')
max_v=c.most_common(1)[0][1]
for k,v in c.most_common():
    if v<max_v:break
    r=0
    l=0
    cnt=0
    
    while l<=r<n:
        if s[r]==k:
            cnt=max(r-l-1,cnt)
            l=r
        r+=1
    if n==r:cnt=max(r-l-1,cnt)
    if cnt==0:continue
    res=min(res,cnt)
if res==float('inf'):
    print(0)
else:print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
s= (stdin.readline().rstrip())
f = lambda a, b: abs(a-b-1)
diff = lambda ls: map(f, ls[1:], ls)

ans = 100
for i in set(s):
    indexes = [j for j,x in enumerate(list(s)) if x == i]
    indexes = [0] + indexes + [len(s)]
    index_diff = list(diff(indexes))
    if i == s[0]:
      ans = min(ans,max(index_diff))
    elif i == s[-1]:
      ans = min(ans,max(index_diff)+1)
    else:
      ans = min(ans,max(index_diff))
if len(set(s)) == 1:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
s= (stdin.readline().rstrip())
f = lambda a, b: abs(a-b)
diff = lambda ls: map(f, ls[1:], ls)

ans = 100
for i in set(s):
    indexes = [j for j,x in enumerate(list(s)) if x == i]
    indexes = [0] + indexes + [len(s)]
    index_diff = list(diff(indexes))
    ans = min(ans,max(index_diff))
if len(set(s)) == 1:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
s= (stdin.readline().rstrip())
f = lambda a, b: abs(a-b-1)
diff = lambda ls: map(f, ls[1:], ls)

ans = 100
for i in set(s):
    indexes = [j for j,x in enumerate(list(s)) if x == i]
    indexes = [0] + indexes + [len(s)+1]
    index_diff = list(diff(indexes))
    ans = min(ans,max(max(index_diff),1))
if len(set(s)) == 1:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
s= (stdin.readline().rstrip())
f = lambda a, b: abs(a-b-1)
diff = lambda ls: map(f, ls[1:], ls)

ans = 100
for i in set(s):
    indexes = [j for j,x in enumerate(list(s)) if x == i]
    indexes = [0] + indexes + [len(s)]
    index_diff = list(diff(indexes))
    ans = min(ans,max(max(index_diff),1))
if len(set(s)) == 1:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from subprocess import*
with open('Main.java','w')as f:f.write(r'''
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");
		String[] v = {"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"};
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < 26; i++) {
			int tmp = 0;
			String[] u = s;
			loop: while (true) {
				boolean comp = true;
				for (int j = 0; j < u.length; j++)
					if (!u[j].equals(u[0])) {
						comp = false;
						break;
					}
				if (comp) {
					ans = Math.min(ans, tmp);
					break loop;
				}
				String[] w = new String[u.length - 1];
				for (int j = 0; j < w.length; j++) {
					if (u[j].equals(v[i]) || u[j + 1].equals(v[i]))
						w[j] = v[i];
					else
						w[j] = u[j];
				}
				u = w;
				tmp++;
			}
		}
		System.out.println(ans);
	}
}
''')
call(('javac','Main.java'))
call(('java','Main'))

Submission status: Wrong Answer

Solution code:
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");
		String[] v = {"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"};
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < 26; i++) {
			int tmp = 0;
			String[] u = s;
			loop: while (true) {
				boolean comp = true;
				for (int j = 0; j < u.length; j++)
					if (!u[j].equals(u[0])) {
						comp = false;
						break;
					}
				if (comp) {
					ans = Math.min(ans, tmp);
					break loop;
				}
				String[] w = new String[u.length - 1];
				for (int j = 0; j < w.length; j++) {
					if (u[j].equals(v[i]) || u[j + 1].equals(v[i]))
						w[j] = v[i];
					else
						w[j] = u[j];
				}
				u = w;
				tmp++;
			}
		}
		System.out.println(ans);
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Submission status: Wrong Answer

Solution code:
import collections

s = input()
sc = collections.Counter(s).most_common()
m = sc[0][1]
if m == 1:
    print(len(s) // 2)
else:
    a = {}
    for i in sc:
        if i[1] == m:
            a[i[0]] = []
            for j in range(len(s)):
                if s[j] == i[0]:
                    a[i[0]].append(j)
    use = 0
    mi = float("inf")
    for k, v in a.items():
        sa = []
        for i in range(len(v) - 1, -1, -1):
            if i == 0:
                sa.append(v[i])
            else:
                sa.append(v[i] - v[i - 1])
        if max(sa) - min(sa) < mi:
            use = max(sa)
            mi = max(sa) - min(sa)
    print(use - 1)

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2)
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

#enumerate input

def main():
    s=input()
    print(min(max(map(len,s.split(i)))for i in s))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

# n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# data = [stdin.readline().rstrip().split() for _ in range(n)]

ans = len(s)
for c in range(ord('a'), ord('z')+1):
    cnt, cntMax = 0, 0
    for i in range(0, len(s)-1):
        if s[i] == chr(c):
            cntMax = max(cnt, cntMax)
            cnt = 0
            continue
        cnt += 1
    cntMax = max(cnt, cntMax)
    ans = min(ans, cntMax)
print(ans, '\n')
# print(*data, sep='\n')

Submission status: Wrong Answer

Solution code:
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        print(tmp)
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

Submission status: Wrong Answer

Solution code:
s = input()
l = set(list(s))
N = len(s)
n = len(s)
ans = 0

for ll in l:
    S = s
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)

Submission status: Wrong Answer

Solution code:

s=input()
def change(s,x):
    t=s
    u=''
    for i in range(1,len(s)):
        for j in range(len(t)-1):
            if t[j]==x or t[j+1]==x:
                u+=x
            else:
                u+=t[j]
        if u.count(x)==len(u):
            return i
        t=u
        u=''
m=[]
for i in s:
    m.append(change(s,i))
print(min(m))

Submission status: Wrong Answer

Solution code:
inf = 10**10
import sys
input = sys.stdin.readline
from functools import reduce
 
s = input()
A = set()
ans = inf
for i in range(len(s)):
    A.add(s[i])
for v in A:
    cur = 0
    vstep = 0
    for i in range(len(s)):
        if s[i] != v:
            cur += 1
        else:
            vstep = max(cur,vstep)
            cur = 0
    vstep = max(cur,vstep)
    ans = min(ans,vstep)
print(ans)

Submission status: Wrong Answer

Solution code:
inf = 10**10
import sys
input = sys.stdin.readline
from functools import reduce

s = input()
A = set()
ans = inf
for i in range(len(s)):
    A.add(s[i])
for v in A:
    cur = 0
    vstep = 0
    for i in range(len(s)):
        if s[i] != v:
            cur += 1
        else:
            vstep = max(cur,vstep)
            cur = 0
    vstep = max(cur,vstep)
    ans = min(ans,vstep)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
L = []
for i in range(1,len(s)):
  if not s[i] in L:
    L.append(s[i])
ans = float('inf')
if len(L) == 1:
  print(0)
else:
  for i in range(len(L)):
    k = s
    sub = 0
    flag = False
    while flag == False:
      cur = ''
      cnt = 0
      for j in range(len(k)-2,-1,-1):
        if cnt == len(cur):
          if k[j] == L[i]:
            cur = L[i]*2 + cur
          else:
            cur = k[j] + cur
        else:
          if k[j] == L[i]:
            cur = L[i] + cur
          else:
            None
        cnt += 1
      check = L[i]*len(cur)
      sub += 1
      if check == cur:
        if sub <= ans:
          ans = sub
        flag = True
      else:
        k = cur
  print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())

AL = [chr(i) for i in range(ord('a'), ord('z')+1)]
ans = []
for al in AL:
    cnt = 0
    CNT = []
    for i in range(len(S)):
        if S[i] == al or i == len(S) - 1:
            CNT += [cnt]
            cnt = 0
        else:
            cnt += 1

    for i in range(1,len(CNT)-1):
        CNT[i] = (CNT[i] + 1) // 2

    for i in range(len(CNT)-1):
        if CNT == [0] * len(CNT):
            pass
        elif CNT[i] <= CNT[i+1]:
            CNT[i] += 1
        else:
            CNT[i+1] += 1
    if CNT == []:
        CNT = [1000]
    ans += [max(CNT)]
print(min(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())

AL = [chr(i) for i in range(ord('a'), ord('z')+1)]
ans = []
for al in AL:
    cnt = 0
    CNT = []
    for i in range(len(S)):
        if S[i] == al:
            CNT += [cnt]
        else:
            cnt += 1

    for i in range(1,len(CNT)-1):
        CNT[i] = (CNT[i] + 1) // 2

    for i in range(len(CNT)-1):
        if CNT[i] <= CNT[i+1]:
            CNT[i] += 1
        else:
            CNT[i+1] += 1
    if CNT == []:
        CNT = [0]
    ans += [max(CNT)]
print(max(ans))

Submission status: Wrong Answer

Solution code:
from collections import*;S=input();s=Counter(S);print(min(max(map(len,S.split(i[0])))for i in s.most_common(list(s.values()).count(max(s.values())))))

Submission status: Wrong Answer

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


def main():
    from collections import Counter

    s = input()
    ss = Counter(s).most_common()

    if len(ss) == 1:
        print(0)
    elif ss[0][1] == 1:
        print(len(s) // 2)
    else:
        ans = float('inf')
        freq = ss[0][1]

        for ssi, ss_count in ss:
            if ss_count == 1 or ss_count < freq:
                continue

            count = 0
            candidate = 0

            for si in s:
                if si == ssi:
                    candidate = max(candidate, count)
                    count = 0
                else:
                    count += 1

            ans = min(ans, candidate)

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8

from collections import Counter


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


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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

from collections import Counter


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


S = input()
C = Counter(S)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

inputs = list(input())

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

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

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

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

inputs = list(input())

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

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

if kinds == length:
    count = length // 2 + length % 2
elif kinds == 1:
    count = 0
else:
    counter_inputs = Counter(inputs).most_common()
    filter_inputs = list(filter(lambda x:x[1]==counter_inputs[0][1], counter_inputs))
    for counter_input in counter_inputs:
        item = inputs[:]
        total = 0
        while len(set(item)) != 1:
            item = list(cal(item, counter_input[0][0]))
            total += 1
        count = min(count, total)

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

inputs = list(input())

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

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

if kinds == length:
    count = length // 2 + length % 2
elif kinds == 1:
    count = 0
else:
    counter_inputs = Counter(inputs).most_common()
    filter_inputs = list(filter(lambda x:x[1]==counter_inputs[0][1], counter_inputs))
    counter_inputs.sort(key=lambda x:x[1], reverse=True)
    for counter_input in counter_inputs:
        item = inputs[:]
        total = 0
        while len(set(item)) != 1:
            item = list(cal(item, counter_input[0][0]))
            total += 1
        count = min(count, total)

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

inputs = list(input())

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

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

if kinds == length:
    count = length // 2 + length % 2
elif kinds == 1:
    pass
else:
    counter_inputs = Counter(inputs).most_common()
    filter_inputs = list(filter(lambda x:x[1]==counter_inputs[0][1], counter_inputs))
    counter_inputs.sort(key=lambda x:x[1], reverse=True)
    for counter_input in counter_inputs:
        item = inputs[:]
        total = 0
        while len(set(item)) != 1:
            item = list(cal(item, counter_input[0][0]))
            total += 1
        count = min(count, total)

print(count)

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 = -1
    score = 0
    flag=False
    for j in range(len(s)):
        if c==s[j]:
            score=max(j-prev-1,score)
            flag=True
            prev=j
    score = max(j-prev,score)
    if flag==False:
        score=10**3
    score_list.append(score)
    
print(min(score_list))
print(score_list)