TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
s=input()
print(s)

s=input()

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

s=input()

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
ans=len(s)
def a(s,t):
  ss=""
  a=0
  b=False
  for i in range(len(s)-1):
    if s[i]!=t!=s[i+1]:ss+=s[i];b=True
    else:ss+=t
  if b:a=a(ss,t)
  return a+1
for i in s:ans=min(ans,a(s,i))
print(ans)

s=input()
se=set(list(s))
x=len(s)
for i in se:
  a=b=0
  for j in s:
    if i==j:a=0
    else:a+=1;b=max(a,b)
  x=min(x,b)
print(x)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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))
    
    


from copy import deepcopy
s = input()

ans = 10**10
for i in range(len(s)):
    a = s[i]
    t = deepcopy(s)
    cnt = 0
    
    while len(set(list(t))) !=1:
        
        cnt +=1
        while True:
            S = ""
            for j in range(len(t)-1):
                if (t[j] == a) or (t[j+1] == a):
                    S +=a
                    #print(t,S,j,t[j],t[j+1],a)
                else:
                    S +=t[j]

            else:
                t = deepcopy(S)
                #print(S,cnt)
                break
    ans = min(ans,cnt)
    #print(S,t,i,ans)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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))

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

    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)

s = list(input())
N = len(s)
if N == 1:
    print (0)
    exit()

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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)


from collections import Counter

s = input()


def convert(st, toS, cou):
    if st.count(st[0]) == len(st):
        return cou
    for i in range(len(st)):
        if i+1 < len(st) and st[i+1] == toS:
            st[i] = toS
    return convert(st[:-1], toS, cou+1)


ans = 200
for j in set(s):
    ans = min(ans, convert(list(s), j, 0))
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#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)


s = input()
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)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()


def main():
    s = input()

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

    ans = 101
    for k in dic:
        dic[k].append(-1)
        dic[k].append(len(s))
        dic[k].sort()

        mx = -1
        for j in range(len(dic[k])-1):
            mx = max(mx, dic[k][j+1]-dic[k][j]-1)

        ans = min(ans, mx)

    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


s = input()
print(min(max(len(p) for p in s.split(l)) for l in set(list(s))))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

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):
    ans = min(ans,max([len(j) for j in s.split(i)]))
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)//2
for a in A:
    maximum=0
    for s in S:
        p=-1
        if a==s:
            maximum=max(p-1,maximum)
            p=0
        else:
            p+=1
    minimum=min(maximum,minimum)
print(minimum)

S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)//2
for a in set(S):
    maximum=0
    ans_max=0
    p=0
    for s in S:
        if a==s:
            ans_max=max(p-1,maximum)
            p=0
        else:
            p+=1
    minimum=min(ans_max,minimum)
print(minimum)

from collections import Counter
S=input()
s=Counter(S)
T=[key for key,value in s.items() if max(s.values())==value]
minimum=len(S)//2
for t in T:
    P=[i for i,x in enumerate(S) if x==t]+[len(S)-1]
    maximum=P[0]
    for j in range(1,len(P)):
        if maximum<P[j]-P[j-1]-1:
            maximum=P[j]-P[j-1]-1
    minimum=min(minimum,maximum)
print(minimum)

S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)//2
for a in A:
    ans_max=0
    p=0
    for s in S:
        if a==s:
            ans_max=max(p,ans_max)
            p=0
        else:
            p+=1
    ans_max=max(p,ans_max)
    minimum=min(ans_max,minimum)
print(minimum)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

import sys

def judgeUpper(ansList, var):
    for a in ansList:
        if int(a) > var:
#             print(a + ':' + str(var) + str(True))
            return True
    return False
def judgeEqual(ansList, var, N):
    count = ansList.count(str(var))
#     print(str(count) + ':' + str(N-1) + str(count < N - 1))
    return count < N - 1 or (count == N and var * 2 > N and var+1 != N)
def judgeLower(ansList, var):
    for a in ansList:
        if int(a) < var - 1:
#             print(a + ':' + str(var-1) + str(True))
            return True
    return False
        
N = input()
ansList = input().split(' ')
for i in range(int(N)):
    var = i + 1
    if judgeUpper(ansList, var):
        continue
    if judgeEqual(ansList, var, int(N)):
        continue
    if judgeLower(ansList, var):
        continue
    print('Yes')
    sys.exit()
print('No')


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

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)


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)


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)


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

if len(set(s)) == 1:
    print(0)
    exit()

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)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)
      
    

S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        if i < L-1:
          newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if i < L-1 and not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)
      
    


S = input()
uni_s = list(set(list(S)))

ans = len(S) - 1

# -1,1
for s in uni_s:
  L = len(S)
  T = list(S)
  all_same = [s == t for t in S]
  cnt = 0
  while not all(all_same):
    cnt += 1
    newT = [False] * (L-1)
    for i in range(L):
      t = T[i]
      if s == t:
        if i < L-1:
          newT[i] = t
        if 0 <= i-1:
          newT[i-1] = t
      else:
        if i < L-1 and not newT[i]:
          newT[i] = t
        if 0 <= i-1 and not newT[i-1]:
          newT[i-1] = t
    
    all_same = [s==t for t in newT]
    T = newT
    L = len(T)
  ans = min(ans,cnt)

print(ans)
      
    


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

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

a=input()
b=True

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

print(an)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
if len(list(set(d)))==1:
    print(0)
else:
    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)

s=list(input())
p=[chr(ord("a")+i)for i in range(26)]
q=100
if len(list(set(s)))==1:
    print(0)
else:
    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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
ans=1000
for i in range(26):
  if chr(97+i) not in s:continue
  S=s
  cnt=0
  while(len(set(S)))!=1:
    cnt+=1
    t=""
    for j in range(len(S)-1):
      if S[j] == chr(97+i) or S[j+1] == chr(97+i):
        t+=chr(97+i)
      else:
        t+=S[j]
  ans=min(cnt,ans)
print(ans)

s=input()
ans=1000
for i in range(26):
  if chr(97+i) not in s:continue
  S=s
  cnt=0
  while(len(set(S)))!=1:
    cnt+=1
    t=""
    for j in range(len(S)-1):
      if S[j] == chr(97+i) or S[j+1] == chr(97+i):
        t+=chr(97+i)
      else:
        t+=S[j]
    S=t
  ans=min(cnt,ans)
print(ans)


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c not in S))
print(ans)

S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c not in S)
print(ans)

S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c in S)
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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))

S = list(input())
dis = [0 for i in range(26)]
mm = [-1 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))
# print(dis)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=str(input())
import collections
c=collections.Counter(s)
temp=c.most_common()[0][0]
tempc=c.most_common()[0][1]
l=len(s)
a=0
cnt=0
for i in range(l):
  if s[i]!=temp:
    cnt=cnt+1
  else:
    a=max(a,cnt)
    cnt=0
a=max(a,cnt)
print(a)

s=str(input())
l=len(s)
ans=99999999999
for j in s:
  temp=j
  a=0
  cnt=0
  for i in range(l):
    if s[i]!=temp:
      cnt=cnt+1
    else:
      a=max(a,cnt)
      cnt=0
  a=max(a,cnt)
  ans=min(a,ans)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

S = str(input())

c = 0
ma = 0
for i in S:
    c = 0
    for k,j in enumerate(S):
        if ( k != 0 and k != N-1 and j != i and S[k-1] != a and S[k+1] != a):
            c += 1
    ma = min(ma, c)

print(ma)





 S = str(input())

 c = 0
 ma = 0
 for i in S:
     c = 0
     for k,j in enumerate(S):
         if ( k != 0 and k != len(S) and j != i and S[k-1] != a and S[k+1] != a):
             c += 1
     ma = min(ma, c)

 print(ma)



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

S = str(input())
T = S

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

print(m)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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])


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

from copy import deepcopy


def moji_list(a, b):
    
    
    
    
    
    
    return [chr(i) for i in range(a, b)]


s = list(read().rstrip().decode())
ans = float('inf')
for al in moji_list(97, 123):
    cnt = 0
    check_s = deepcopy(s)
    while len(set(check_s)) > 1:
        cnt += 1
        ss = []
        for bf, af in zip(check_s, check_s[1:]):
            ss.append(af if af == al else bf)
        check_s = ss
    ans = min(ans, cnt)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=input()
s.lower()

a=[0 for i in range(26)]
for i in s:
	a[ord(i)-ord('a')]+=1
test=max(a)

print(len(s)-test)

s=input()

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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'))

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# 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)


# coding:utf-8

import sys
from collections import Counter

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    s = SI()
    char_cnt = Counter(s)

    res = INF
    for c in char_cnt.keys():
        r = s[:]
        cnt = 0
        while len(set(r)) != 1:
            t = ''
            for ss in zip(r[:-1], r[1:]):
                if c in ss:
                    t += c
                else:
                    t += ss[0]
            cnt += 1
            r = t
            # print(r)
        res = min(res, cnt)

    return res


print(main())


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
a = 1000 
for i in range (len(S)):
    A = B = 0
    for j in range (1, len(S) + 1):
        if S[i] == S[len(S)-j]:
            A = 0
        else:
            A += 1
        B = max(A,B)
    a = min(A,B)
print(a)

S = input()
val = 10**9
 
voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)
 
    while True:
        if all([w == c for w in tmp]):
            val = min(cnt, val)
            break
        cnt += 1
        for u in range(len(tmp)-1):
            tmp[u] = c if tmp[u] == c or tmp[u+1] == c else tmp[u]    
        tmp.pop()
 
 
print(val)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
c = [0]*26
v = []
m = 0
for i in range(0, len(s)):
  c[(int)s[i]-'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((char)'a'+i)
a = 10000
for i in range(0, len(c)):
  n = 0
  t = 0
  for j in range(0, len(s)):
    if s[j] != v[i]:
      t += 1
    else:
      n = max(n, (t+1)//2)
  n = max(n, (t+1)//2)
  a = min(a, n)
print(a)

s = input()
a = 10000
for i in range(0, 26):
  n = 0
  t = 0
  b = True
  for j in range(0, len(s)):
    if s[j] != chr(ord("a")+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)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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


s=input()
c=[]
for i in range(len(s)):
    if not s[i] in c:
        c.append(s[i])
count_max_list = []
for a in c:
    count=0
    count_max = 0
    for i in range(len(s)):
        if a==s[i]:
            count_max=max(count,count_max)
            count=0
        else:
            count+=1
    count_max=max(count,count_max)
    count_max_list.append(count_max)
print(min(count_max_list))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


a = input()

for target in set(s):
    s = a
    j = 0
    min = 10000
    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
    if min > j:
        min = j
print(min)

from collections import Counter
s = raw_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)

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

print(min)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()

for c in string.lowercase :
    if c not in S :
        continue

    X = S.split(c)
    ans = 0
    for str in X :
        ans = max(ans, len(str))

print(ans)

S = input()
chars = set(S)
ans = len(S)

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

print(ans)

S = input()
chars = set(S)
ans = len(S)

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

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

s = input()

ans = float("inf")
for i in range (26):
    a = chr(ord("a")+i)
    if  s.count(a) == 0 :
        pass
    else:
        tmp = s
        c = 0
        while set(tmp) != {a}:
            t = ""
            for j in range(len(tmp)-1):
                if tmp[j] == a or tmp[j+1] == a:
                    t += a
                else:
                    t += tmp[j]
            c += 1
            tmp = t
        ans = min(c, ans)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
P = list(set(P))
ANS = []
for i in range(len(P)) :
    T = list(S.split(P[i]))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))


S = input()
P = list(set(S))
ANS = []
for i in range(len(P)) :
    T = list(S.split(P[i]))
    U = []
    for j in range(len(T)) :
        U.append(len(T[j]))
    ANS.append(max(U))
print(min(ANS))


Verdicts: Runtime Error

Accepted