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:
import sys
import numpy as np
from collections import defaultdict
from collections import Counter
import math

S = list(map(str, input().rstrip()))

if Counter(S).most_common()[0][1] == 1:
    print(math.ceil(len(S) / 2))
    sys.exit()

d = defaultdict(list)

for i, s in enumerate(S):
    if d[s].count(0) == 0:
        d[s].append(0)
    d[s].append(i + 1)

for i in d:
    if d[i].count(len(S)) == 0:
        d[i].append(len(S))

for i in d:
    d[i] = list(np.diff(np.array(d[i])))

li = list(d.values())

ans = min([max(x) for x in li]) - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

s = list(map(str, input().rstrip()))

length = len(s)

c = Counter(s)
c = c.most_common()[0][1]

if c == 1:
    print(math.ceil(length / 2))
else:
    ans = math.ceil((length - c) / c)
    print(ans)

Submission status: Wrong Answer

Solution code:


ss = input()
n = len(ss)

ans = 99999999999
for i in range(26):
    s = ss
    letter = chr(ord('a')+i)
    while(len(s)>=1):
        text = ""
        for j in range(len(s)-1):
            if(s[j+1] == letter):
                text+= letter
            else:
                text+=s[j]
        s = text
        ok = 1
        for i in s:
            ok *= 1 if i==letter else 0
        if(ok==1):
            break
    ans = min(ans,n-len(s))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s=input()
c=Counter(s).most_common()
ans=10**10
top=c[0][1]
for k,x in c:
    if x!=top:
        break
    N=len(s)
    m=k
    cnt=0
    tmp=s
    for i in range(100):
        cn=Counter(tmp).most_common()
        if(cn[0][1]==len(tmp)):
            ans=min(ans,cnt)
            break
        l=''
        for j in range(N-1):
            if(tmp[j]==m or tmp[j+1]==m):
                l+=m
            else:
                l+=s[j]
        tmp=l
        cnt+=1
        N-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
S = str(input())
alp = list("abcdefghijklmnopqrstuvwxyz")
s = ''
c = 1
for i in alp:
  SC = S.count(i)
  c = max(c,SC)
  if c == SC:
    s = i
print(ceil((len(S)-S.count(s))/2))

Submission status: Wrong Answer

Solution code:
def myAnswer(s:list) -> int:
   N = len(s)
   dic = {}
   for string in s:
      if(string in dic.keys()):
         dic[string] += 1
      else:
         dic[string] = 1
   if(len(dic) == 1): return 0
   ans = (1 + max(dic.values()))
   # print(N,dic,ans)
   return N // ans + N % ans

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

Submission status: Wrong Answer

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

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

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


all_li = []
kaisuu = 0
for i,c in enumerate(common_li):
    #print(common_li,c[0],c[1])
    if i == 0:
        kaisuu = c[1]
    else:
        #print(type(c[1]),type(kaisuu),'aaaaaaaa')
        if c[1]!=kaisuu:
            break
    sp_li = s.split(c[0])
    all_li.append(check(sp_li))

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

Submission status: Wrong Answer

Solution code:
s = list(input())

import collections

S = collections.Counter(s)
max_s = max(S.values())
A = []
for i in S:
    D = []
    if S[i] == max_s:
        start = 0
        for j in range(len(s)):
            if s[j] == i:
                D.append(j - start)
                start = j+1
        D.append(len(s) - start)
        A.append(max(D))
print(min(A))

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
cnt = Counter(s).most_common()
print(cnt)

mins = len(s) - 1
for k, v in cnt:
    if v != 1:
        ind = 0
        dist = []
        for i in range(len(s)):
            if k == s[i]:
                dist.append(i-ind+1) 
                ind = i
        mins = min(max(dist), mins)
print(mins)

Submission status: Wrong Answer

Solution code:
#AGC016-A Shrinking
"""
len(s)<=100なので特段効率を考える必要はない
最も多く出てくる文字を基準にして、
消す文字は全ての変更処理が終わったあとで
一番うしろの基準文字以外の文字
最も長く連続する基準文字以外の文字列でランダムに1つ選ぶ
の優先順位で消す。
これで漏れがあるようならa~z全てを試す
(target v)
serval
32
ervvl
21
vvvl
1
vvv
"""
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')

dic1 = defaultdict(int)
for i in s:
    dic1[i] += 1
kijun = ord("a")
for i in range(kijun,kijun+26):
    if not chr(i) in dic1:
        dic1[chr(i)] = 0

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

ans = 10**10

for i,j in lst1: #i,出現回数,j:文字
    target = j
    res = []
    res2 = 0
    for k in s:
        if k==target:
            res.append(res2)
            res2 = 0
        else:
            res2+=1
    res.append(res2)
    flag = 0 #最後尾がtargetなら1
    if res[-1] == 0:
        flag = 1
    res = list(filter(lambda x: x>0,res))
    #flag = 0である限り消去する文字は一番うしろを最優先
    ans_res = 0
    while not flag:
        for i in range(len(res)):
            res[i] -= 1
        if not len(res) or res[-1]==0:
            flag = 1
        ans_res += 1
        res = list(filter(lambda x: x>0,res))
    while len(res):
        if res == [2]: #最後に2残ったときは例外で、これを1ターンで消すことはできない
            ans_res += 2
            break
        for i in range(len(res)):
            res[i] -= 1
        res.sort(reverse=True)
        res[0] -= 1 #消去
        ans_res += 1
        res = list(filter(lambda x: x>0,res))

        

    ans = min(ans,ans_res)

print(ans)

Submission status: Wrong Answer

Solution code:
#AGC016-A Shrinking
"""
len(s)<=100なので特段効率を考える必要はない
最も多く出てくる文字を基準にして、
消す文字は全ての変更処理が終わったあとで
一番うしろの基準文字以外の文字
最も長く連続する基準文字以外の文字列でランダムに1つ選ぶ
の優先順位で消す。
これで漏れがあるようならa~z全てを試す
(target v)
serval
32
ervvl
21
vvvl
1
vvv
"""
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')

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

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

ans = 10**10

for i,j in lst1: #i,出現回数,j:文字
    target = j
    res = []
    res2 = 0
    for k in s:
        if k==target:
            res.append(res2)
            res2 = 0
        else:
            res2+=1
    res.append(res2)
    flag = 0 #最後尾がtargetなら1
    if res[-1] == 0:
        flag = 1
    res = list(filter(lambda x: x>0,res))
    #flag = 0である限り消去する文字は一番うしろを最優先
    ans_res = 0
    while not flag:
        for i in range(len(res)):
            res[i] -= 1
        if not len(res) or res[-1]==0:
            flag = 1
        ans_res += 1
        res = list(filter(lambda x: x>0,res))
    while len(res):
        if res == [2]: #最後に2残ったときは例外で、これを1ターンで消すことはできない
            ans_res += 2
            break
        for i in range(len(res)):
            res[i] -= 1
        res.sort(reverse=True)
        res[0] -= 1 #消去
        ans_res += 1
        res = list(filter(lambda x: x>0,res))

        

    ans = min(ans,ans_res)

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(min_c)

Submission status: Wrong Answer

Solution code:
s=input()

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

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

Submission status: Wrong Answer

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

S = input()
d = defaultdict(int)

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

d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
num = d2[0][1]
if num > 1:
    e = []
    i = 0
    while  i < len(d2) and d2[i][1] == num:
        e.append(d2[i][0])
        i += 1
else:
    e = [S[len(S)//2]]

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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


sys.setrecursionlimit(10 ** 9)


def main():
    S = list(input())
    C = Counter(S)
    A = C.most_common()
    key = [a[0] for a in A if a[1] == A[0][1]]
    if A[0][1] == 1:
        print(len(S) // 2)
    else:
        cnt = [[] for _ in range(len(key))]
        count = np.array([0 for _ in range(len(key))])
        for s in S:
            if s in key:
                cnt[key.index(s)].append(count[key.index(s)])
                count += 1
                count[key.index(s)] = 0
            else:
                count += 1
        for i in range(len(key)):
            cnt[i].append(count[i])
        answer = []
        for i in range(len(key)):
            answer.append(max(cnt[i]))
        print(min(answer))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Submission status: Wrong Answer

Solution code:
a = input()
print(3)

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()
moji = Counter(S).most_common()[0][0]
res = 0
while len(set(S)) != 1:
    res += 1
    new_S = ""
    for i in range(len(S)-1):
        new_S += moji if moji in [S[i],S[i+1]] else S[i]
    S = new_S
print(res)

Submission status: Wrong Answer

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

#処理
X={}
ss=s[1:]
for i in range(len(ss)):
    if ss[i] in X:
        X[ss[i]]+=1
    else:
        X[ss[i]]=1
    
Y=[kv[0] for kv in X.items() if kv[1]==max(X.values())]
z=float('inf')

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

Submission status: Wrong Answer

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

#処理
X={}
for i in range(len(s)):
    if s[i] in X:
        X[s[i]]+=1
    else:
        X[s[i]]=1
    
Y=[kv[0] for kv in X.items() if kv[1]==max(X.values())]
z=float('inf')

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

s = input()
print(min(max(map(len, s.split(a))) for a in s))

Submission status: Wrong Answer

Solution code:
s = list(input())

import collections
A = collections.Counter(s)

if len(s) % max(list(A.values())) == 0:
    print(len(s) // (max(list(A.values())) + 1))
else:
    print(len(s) // max(list(A.values())))

Submission status: Wrong Answer

Solution code:
S = list(input())
dis = [0 for i in range(26)]
mm = [0 for i in range(26)]

for i in range(len(S)):
    wd = ord(S[i])-97
    dis[wd] = max(dis[wd],i-mm[wd]-1)
    mm[wd] = i

for i in range(26):
    dis[i] = max(dis[i],len(S)-mm[i]-1)
print(min(dis))

Submission status: Wrong Answer

Solution code:
import collections
s=input()
slist=list(s)
c=collections.Counter(slist)
l=[]
dist=[]
ma=0
cnt=0
val=list(c.values())
key=list(c.keys())
for i in range(len(val)):
    l.append([key[i],val[i]])
#print(l)
for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        #print(l[i][0],s[j],cnt)
        if s[j]!=l[i][0]:
            cnt=cnt+1
        else:
            if (ma<=cnt):
                ma=cnt
                cnt=0
    if ma <= cnt:
        ma = cnt
    #print(cnt)
    dist.append(ma)
dist.sort()
print(dist[0])

Submission status: Wrong Answer

Solution code:
import collections
s=input()
slist=list(s)
c=collections.Counter(slist)
l=[]
dist=[]
ma=0
cnt=0
val=list(c.values())
key=list(c.keys())
for i in range(len(val)):
    l.append([key[i],val[i]])
#print(l)
for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        #print(l[i][0],s[j])
        if s[j]!=l[i][0]:
            cnt=cnt+1
        else:
            if (ma<cnt):
                ma=cnt
                cnt=0
    if ma < cnt:
        ma = cnt
    dist.append(ma)
dist.sort()
print(dist[0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()

if len(set(list(s)))==1:
    print(0)
    exit()
    
c = dict(Counter(s))
mx = max(c.values())
res = []
for k,v in c.items():
    tmp = 0
    if v == mx:
        tmp = k + s + k
        idx_num = [e for e,w  in enumerate(list(tmp)) if w==k]
        lst = []
        for j in range(1, len(idx_num)):
            lst.append(idx_num[j] - idx_num[j-1])
        tmp = max(lst)
        res.append(tmp)
    else:
        continue
print(max(min(res)-1, 0))

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()
index_num = [n for n, v in enumerate(list(s)) if v=='r']

c = dict(Counter(s))
mx = max(c.values())

res = []
for k,v in c.items():
    tmp = 0
    if v == mx:
        tmp = k + s + k
        idx_num = [e for e,w  in enumerate(list(tmp)) if w==k]
        lst = []
        for j in range(1, len(idx_num)):
            lst.append(idx_num[j] - idx_num[j-1])
        tmp = max(lst)
        res.append(tmp)
    else:
        continue
print(min(res)-1)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
ans=n
for i in range(97, 97+26):
    x=chr(i)
    cnt=s.count(x)
    if cnt!=0:
        t=list(s)
        for j in range(n-1):
            u=[""]*(n-1-j)
            for k in range(n-1-j):
                if t[k]==x or t[k+1]==x:
                    u[k]=x
                else:
                    u[k]=t[k]
            if u.count(x)==n-1-j:
                ans=min(ans,j+1)
                break
            else:
                t=u
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = [x for x in input()]
s_cnt = collections.Counter(s)
m = max(s_cnt.values())
s_cnt = sorted(s_cnt.items(), key=lambda x:x[1])[::-1]
a = 100
for i in range(len(s_cnt)):
    k = s_cnt[i][0]
    if s_cnt[i][1] != m: break
    else:
        c = 0
        s_t = s.copy()
        while "".join(s_t) != k*len(s_t):
            c += 1
            s_ = []
            for i in range(len(s_t) - 1):
                if s_t[i] == k or s_t[i+1] == k: s_.append(k)
                else: s_.append(s_t[i])
            s_t = s_
        a = min(a, c)
print(a)

Submission status: Wrong Answer

Solution code:
s = set(input())
print(len(s)//2)

Submission status: Wrong Answer

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

A = {}
for s in S:
    if s not in A:
        A[s] = 1
    else:
        A[s] += 1

B = [(a, A[a]) for a in A]
B.sort(reverse=True, key=lambda x: x[1])
# print(B)

if len(B) == 1:
    print(0)
    exit()

max_num = B[0][1]

if max_num == 1:
    print(lens // 2)
    exit()

C = []
for b in B:
    if b[1] != max_num:
        break
    C.append(b)

# print(C)

ans = 100
for i in range(len(C)):
    c = C[i][0]
    count = 0
    sub_ans = 0
    for s in S:
        if s != c[0]:
            count += 1
        else:
            sub_ans = max(sub_ans, count)
            count = 0
    ans = min(sub_ans, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import string

t = stdin.readline().rstrip()
alpha = string.ascii_lowercase
mi = 10**10

for target in alpha:
    s = t
    cnt = 0
    while True:
        cnt += 1
        sin = ""
        for i in range(len(s)-1):
            sin += s[i] if s[i] == target else s[i+1]
        s = sin
        if s.count(target) == len(s):
            break
    mi = min(mi,cnt)

print(mi)

Submission status: Wrong Answer

Solution code:
s = input()
ans = float("inf")
for i in range(26):
  c = chr(ord("a")+i)
  if c not in s:
    continue
  temp = s
  count = 0
  while set(temp) != {c}:
    t = ""
    for j in range(len(temp)-1):
      if temp[j] == c or temp[j+1] == c:
        t += c
      else:
        t += "#"
    temp = t
    count += 1
    print(temp)
  ans = min(ans, count)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s=input()
if len(set(s))==len(s):
    print(-((1-len(s))//2))
else:
    s_c=collections.Counter(s)
    t = (max(s_c,key=s_c.get))
    then = [s]
    ans = 0
    while len(set(then[0]))>1:
        ans += 1
        s_tmp = then.pop()
        tmp = ""
        for i in range(len(s_tmp)-1):
            if s_tmp[i] == t or s_tmp[i+1] == t:
                tmp += t
            else:
                tmp += s_tmp[i]
        then.append(tmp)
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = sys.stdin.readline

def main():
    S = list(map(str,input()))
    _s = len(S)
    c = collections.Counter(S)
    count = c.most_common()
    a = len(count)
    num = count[0][1]
    
    def do(x):
        c = 0
        l = []
        for i in range(_s):
            if S[i] != x:
                c += 1
            else:
                l.append(c)
                c = 0
        l.append(c)
        return max(l)
        
    ans = 100
    for i in range(a):
        if count[i][1] == num:
            ans = min(ans,do(count[i][0]))
        
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = sys.stdin.readline

def main():
    S = list(map(str,input()))
    _s = len(S)
    c = collections.Counter(S)
    count = c.most_common()
    a = len(count)
    num = count[0][1]
    
    def do(x):
        T = 0
        c = 0
        for i in range(_s):
            if S[i] != x:
                c += 1
            else:
                c = 0
            T = max(T,c)
        return T
        
    ans = 100
    for i in range(a):
        if count[i][1] == num:
            ans = min(ans,do(count[i][0]))
        
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input().strip()
n = len(s)
D = {chr(i):[] for i in range(97,123)}
for i in range(97,123):
    for j in range(n):
        if s[j]==chr(i):
            D[chr(i)].append(j)
cntmin = 1000
for i in range(97,123):
    if len(D[chr(i)])==1:
        d = D[chr(i)][0]
        cnt = max(d,n-d)
        cntmin = min(cntmin,cnt)
    elif len(D[chr(i)])>1:
        A = []
        for j in range(len(D[chr(i)])):
            if j==0:
                A.append(D[chr(i)][0])
                A.append(D[chr(i)][1]-D[chr(i)][0]-1)
            elif j==len(D[chr(i)])-1:
                A.append(n-D[chr(i)][-1])
            else:
                A.append(D[chr(i)][j+1]-D[chr(i)][j]-1)
        cntmin = min(cntmin,max(A))
print(cntmin)

Submission status: Wrong Answer

Solution code:
s = input()
print(s.count('r'))


def calc(s, a):
    if s.count(a) == len(s):
        return 0
    ns = s[:-1]
    for i in range(len(s)-1):
        if s[i] == a or s[i+1] == a:
            ns[i] = a
    return 1+calc(ns, a)


# for a in list('abcdefghijklmnopqrstuvwxyz'):
#    print(a)

Submission status: Wrong Answer

Solution code:
S = input()
if len(set(S)) == 1:
  print(0)
  exit()

ans = float('inf')
for s in set(S):  
  ini_idx = S.find(s)
  tmp_ans = ini_idx
  prv_idx = ini_idx
  while 1:
    tmp_idx = S[prv_idx+1:].find(s)
    if tmp_idx == -1:
      break
    else:
      tmp_idx += prv_idx + 1
      tmp_ans = max(tmp_ans, tmp_idx - prv_idx - 1)
      prv_idx = tmp_idx
    
  tmp_ans = max(tmp_ans, len(S) - prv_idx)
  ans = min(ans,tmp_ans)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()#print(len(s))
num = []

li1 = []
n = 0
while n < len(s):
    
    li2 = []
    for i in range(len(s)):
        if s[i] == s[n]:
            li2.append(i)
            #print(li2)
    if len(li2) == 1:
        num.append(li2[0])
        break
    elif len(li2) >=2: 
        idx = li2[0]
        li1 = []
        for i in range(len(li2)-1):
            idx = max(idx,li2[i+1]-li2[i])
            li1.append(idx)
    #print(li1)
    num.append(max(li1))
    n += 1
print(min(num))

Submission status: Wrong Answer

Solution code:
from collections import Counter

s=input()
c=Counter(s)
test_s=[k for k,v in c.items() if v==max(c.values())]

ans=100
for i in test_s:
 ss=i+s+i
 inx=[j for j,x in enumerate(ss) if x==i]
 d_max=0
 for k in range(len(inx)-1):
  d_max=max(d_max,inx[k+1]-inx[k]-1)
 ans=min(ans,d_max)

print(ans)

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)
            ##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)