ZhenlongDai/ACPR huggingface dataset:
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

S = input()
C = Counter(S).most_common()
max_v = C[0][1]
min_count = 9999
for key_string,v in Counter(S).most_common():
    if v<max_v: break
    else:
        T = S
        count = 0
        while(len(Counter(T))>1):
            TT = ""
            for i in range(len(T)-1):
                temp = T[i:i+2]
                if key_string in temp:
                    TT += key_string
                else:
                    TT += temp[0]
            T = TT
            count += 1
        if min_count>count:
            min_count = count
            
print(min_count)

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):
from collections import Counter

S = input()
C = Counter(S).most_common()
max_v = C[0][1]
min_count = 9999
for key_string,v in Counter(S).most_common():
    
    
    T = S
    count = 0
    while(len(Counter(T))>1):
        TT = ""
        for i in range(len(T)-1):
            temp = T[i:i+2]
            if key_string in temp:
                TT += key_string
            else:
                TT += temp[0]
        T = TT
        count += 1
    if min_count>count:
        min_count = count
            
print(min_count)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
def shrink(char, s):
    i = 0
    while len(set(s)) != 1:
        i += 1
        s = ''.join([s[i] if s[i+1] != char else s[i+1] for i in range(len(s)-1)])
    return i



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

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

Failing test case input:
clkjaa

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
s = input()
def shrink(char, s):
    i = 0
    while len(set(s)) != 1:
        i += 1
        s = ''.join([s[i] if s[i+1] != char else s[i+1] for i in range(len(s)-1)])
    return i
print(min([shrink(c, s) for c in set(s)]))
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10**6)

def handling(string, letter):
    global cnt
    cnt += 1
    for i, r in enumerate(string):
        if r == letter and 0 < i < len(string):
            string[i-1] = letter
    if string[-1] != letter:
        string.pop()
    else:
        string = string[1:]
    if len(set(string)) != 1:
        handling(string, letter)

def main():
    global cnt
    s = list(input())
    sletter = set(s)
    if len(sletter) == 1:
        print(0)
        return
    ans = 101
    for l in sletter:
        cnt = 0
        t = s.copy()
        handling(t, l)
        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()


Failing test case input:
whcrjxbyhtpywkrlxncrbbojmr

Expected output:
10


Actual output:
7


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10**6)

def handling(string, letter):
    global cnt
    cnt += 1; nxt = []
    for i in range(len(string)-1):
        s1, s2 = string[i], string[i+1]
        if s1 == letter:
            nxt.append(s1)
        elif s2 == letter:
            nxt.append(s2)
        else:
            nxt.append(s1)
    if len(set(nxt)) != 1:
        handling(nxt, letter)

def main():
    global cnt
    s = list(input())
    sletter = set(s)
    if len(sletter) == 1:
        print(0)
        return
    ans = 101
    for l in sletter:
        cnt = 0
        t = s.copy()
        handling(t, l)
        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()[:-1]
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"]

n = len(s)
ans = n
for v in alphabet:
    key = [s[i] for i in range(n)]
    for i in range(n):
        for j in range(n-i):
            if key[j] != v:
                break
            if j == n-i-1:
                ans = min(i, ans)
                break
            
        for j in range(n-1-i):
            if key[j] == v or key[j+1] == v:
                key[j] = v
            

print(ans)

Failing test case input:
seuv_l

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
s = input()
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"]

n = len(s)
ans = n

for v in alphabet:
    key = [s[i] for i in range(n)]
    
    count = 0
    end = False
    while True:
        for i in range(n-count):
            if key[i] != v:
                break
            if i == n-count-1:
                ans = min(ans, count)
                end = True
        if count == n-1:
            break
        
        if end:
            break
        
        count += 1
        for i in range(n-count):
            if key[i] == v or key[i+1] == v:
                key[i] = v

print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):
from collections import Counter

s = input()
if len(set(list(s)))==1:
    print(0)
    exit()
    
c = dict(Counter(s))
res = []
for k,v in c.items():
    tmp_s = k + s + k
    idx_num = [e for e,w  in enumerate(list(tmp_s)) 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)
print(max(min(res)-1, 0))

Problem: p03687
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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)

Failing test case input:
{wx

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
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 - 1)
  ans = min(ans,tmp_ans)
print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
cjkb`n

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
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))

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()
ans = 10e9
voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)

    while True:
        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()
        if all([w == c for w in tmp]):
            ans = min(cnt, ans)
            break

print(ans)

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
S = input()
ans = 10e9

voc = set(S)
for c in voc:
    cnt = 0
    tmp = list(S)

    while True:
        if all([w == c for w in tmp]):
            ans = min(cnt, ans)
            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(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
xpwzglbjquntrci{axpdikofyw

Expected output:
13


Actual output:
14


Fixed submission (verdict: Accepted):
from collections import Counter
s=input()
c=Counter(s).most_common()
ans=10**10
top=c[0][1]
for k,x in c:
    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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
tduv`m

Expected output:
3


Actual output:
tduv`
tduv
tdu
td
t
dduv`
dduv
ddu
dd
tuuv`
uuuv
uuu
tdvv`
tvvv
vvv
tdu``
td``
t``
``
tduvm
tdum
tdm
tm
m
3


Fixed submission (verdict: Accepted):
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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))
    
    
    ans = min(tmp, ans)
    
print(ans)

Failing test case input:
cikb`n

Expected output:
3


Actual output:
['cikb`', '']
['cikb', 'n']
['cik', '`n']
['ci', 'b`n']
['c', 'kb`n']
['', 'ikb`n']
3


Fixed submission (verdict: Accepted):
s = input()
al = set(list(s))    
ans = 100

for c in al:
    L = list(s.split(c))
    tmp = 0
    for st in L:
        tmp = max(tmp, len(st))
    
    
    ans = min(tmp, ans)
    
print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
l_vreu

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
clkjaa

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
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:
    
    
    sp = max(map(len, s.split(t[0])))
    
    if ret > sp:
        ret = sp
        
print(ret)

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
import copy

s = list(input())
c = Counter(s).most_common()
ans = 0
m = [(k, v) for k, v in c if v == c[0][1]]

for k, _ in m:
  tmp = 0
  l = copy.deepcopy(s)
  while any(ss != k for ss in l):
    for i in range(len(l) - 1):
      if l[i + 1] == k:
        l[i] = k
      elif l[i] != k:
        l[i] = l[i + 1]
    l.pop(-1)
    tmp += 1
  if ans:
    ans = min(ans, tmp)
  else:
    ans = tmp
  
print(ans)

Failing test case input:
clkjaa

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
import copy
import string

s = list(input())
ans = 0
if len(set(s)) == 1:
  print(0)
else:
  for k in string.ascii_lowercase:
    tmp = 0
    l = copy.deepcopy(s)
    while any(ss != k for ss in l):
      for i in range(len(l) - 1):
        if l[i + 1] == k:
          l[i] = k
      l.pop(-1)
      tmp += 1
    if ans:
      ans = min(ans, tmp)
    else:
      ans = tmp
  print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 
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)

Failing test case input:
zxv

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import Counter

inputs = list(input())

count = 10 ** 15
kinds = len(set(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 == 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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 
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)

Failing test case input:
{xv

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import Counter

inputs = list(input())

count = 10 ** 15
kinds = len(set(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 == 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)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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)

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):


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

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

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
ans = 999
s = input()
abc = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
    ls = [list(s)]
    j = 0
    while True:
        if ls[j] == list(abc[i]*(len(s)-j)):
            break
        ls.append([])
        for k in range(len(ls[j])-1):
            if ls[j][k] == abc[i] or ls[j][k+1] == abc[i]:
                ls[j+1].append(abc[i])
            else:
                ls[j+1].append(ls[j][k])
        j += 1
        
        
    ans = min(ans, len(ls)-1) 
        
print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
s = input()
s_li = list(s)

import collections
c = collections.Counter(s_li)
common_li = c.most_common()

sp_li = s.split(common_li[0][0])


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):
    
    if i == 0:
        kaisuu = c[1]
    else:
        
        if c[1]!=kaisuu:
            break
    sp_li = s.split(c[0])
    all_li.append(check(sp_li))


print(min(all_li))
            

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):
import math
s = input()
s_li = list(s)

import collections
c = collections.Counter(s_li)
common_li = c.most_common()

sp_li = s.split(common_li[0][0])


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):
    
    sp_li = s.split(c[0])
    all_li.append(check(sp_li))


print(min(all_li))

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

A = list(input())


S = A
MIN = 2000
for t in set(S):
    count = 0
    while True:
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1
        if len(set(S)) == 1:
            break

    MIN = min(count,MIN)
    S = A

print(MIN)



Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
from collections import Counter

A = list(input())
S = A
MIN = 2000
for t in set(A):
    count = 0
    S = A
    while count <= MIN:
        if len(set(S)) == 1:
            MIN = min(count,MIN)
            break
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1


print(MIN)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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)

Failing test case input:
clkjaa

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):


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

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
        
        if len(list(set(t)))==1:
            ans = min(ans, count)
            break
print(ans)

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
from collections import Counter
ss = input()

ans = 1000
candidates = set(ss)
for s in candidates:
    count = 0
    t = list(ss)
    while True:
        if len(set(t))==1:
            ans = min(ans, count)
            break
        t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]
        count += 1
print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
uni_s = list(set(list(S)))

ans = len(S) - 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)
      
    


Failing test case input:
i`bkne

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
S = input()
uni_s = list(set(list(S)))

ans = len(S) - 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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
xuz

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter
ss = input()

ans = 1000
candidates = set(ss)
for s in candidates:
    count = 0
    t = list(ss)
    while True:
        if len(set(t))==1:
            ans = min(ans, count)
            break
        t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]
        count += 1
print(ans)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
m`bkjc

Expected output:
3


Actual output:
3
[1000, 3, 5, 1000, 1000, 1000, 1000, 1000, 1000, 4, 3, 1000, 5, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]


Fixed submission (verdict: Accepted):
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))

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
l_vseu

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
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))

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
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)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
        
        if len(set(t))==1:
            ans = min(ans, count)
            break
print(ans)

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
from collections import Counter
ss = input()

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

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

A = list(input())


S = A
MIN = 100
for t in set(S):
    count = 0
    while True:
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1
        if len(set(S)) == 1:
            break

    MIN = min(count,MIN)
    S = A

print(MIN)


Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
from collections import Counter

A = list(input())
S = A
MIN = 2000
for t in set(A):
    count = 0
    S = A
    while count <= MIN:
        if len(set(S)) == 1:
            MIN = min(count,MIN)
            break
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1


print(MIN)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):
s=input()
n=len(s)
ans=n
for i in range(97, 97+26):
    x=chr(i)
    cnt=s.count(x)
    if cnt==n:
        ans=0
        break
    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)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)
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)

Failing test case input:
m`vudt

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)
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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()


Failing test case input:
seuv`l

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
def main():
    s = input()
    c_set = set(s)

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j]:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1
                    f_idx = j

                elif j == len(s) - 1:
                    if max_c < j - f_idx:
                        max_c = j - f_idx

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()

Problem: p03687
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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]])

for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        
        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])

Failing test case input:
whcrjpbyhtrywkrlxnbrbaojmx

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
import collections
s=input()
l=[]
dist=[]
ma=0
cnt=0
s2=""
s3=""
l=list(set(s))

for i in range(len(l)):
    ma=0
    cnt=0
    for j in range(len(s)):
        
        if s[j]!=l[i]:
            cnt=cnt+1
        else:
            if (ma<=cnt):
                ma=cnt
            cnt=0
    if ma <= cnt:
        ma = cnt
    
    dist.append(ma)
dist.sort()
print(dist[0])
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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)


Failing test case input:
mtvuda

Expected output:
3


Actual output:
5 ['m']
4 ['t', 't']
3 ['v', 'v', 'v']
3 ['u', 'u', 'u']
4 ['d', 'd']
5 ['a']
3


Fixed submission (verdict: Accepted):


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

Problem: p03687
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

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

Failing test case input:
zzz

Expected output:
0

Actual output:
1


Fixed submission (verdict: Accepted):

s=input()
def change(s,x):
    if s.count(x)==len(s):
        return 0
    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))
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    s = input()
    c_set = set(s)

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j]:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1
                elif j == len(s) - 1:
                    if max_c < j - i:
                        max_c = j - i

                    f_idx = j

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()


Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):
def main():
    s = input()
    c_set = set(s)

    min_c = len(s)
    for i in range(len(s)):
        if s[i] in c_set:
            max_c, f_idx = i, i
            for j in range(i+1, len(s)):
                if s[i] == s[j]:
                    if max_c < j - f_idx - 1:
                        max_c = j - f_idx - 1
                    f_idx = j

                elif j == len(s) - 1:
                    if max_c < j - f_idx:
                        max_c = j - f_idx

            if max_c < min_c:
                min_c = max_c

            c_set.remove(s[i])

    print(min_c)


if __name__ == '__main__':
    main()

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
n = len(s)
min_t = float('inf')
for i in range(n):
    target = s[i]
    pre = 0
    max_t = 0
    for j in range(n):
        if s[j] == s[i]:
            max_t = max(max_t, j-pre-1)
            pre = j
    max_t = max(max_t, n - pre-1)
    if max_t < min_t:
        min_t = min(min_t, max_t)
print(min_t)

Failing test case input:
cajkla

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
s = input()
n = len(s)
min_t = float('inf')
for i in range(n):
    target = s[i]
    pre = -1
    max_t = 0
    for j in range(n):
        if s[j] == s[i]:
            max_t = max(max_t, j-pre-1)
            pre = j
    max_t = max(max_t, n - pre-1)
    if max_t < min_t:
        min_t = min(min_t, max_t)
print(min_t)
Problem: p03687
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter
s = list(input())
d =  Counter(s)
key = d.keys()
ans = 0
for k in key:
    ck = 0
    i = 0
    while True:
        if s[i] == k:
            i += 1
            if i == len(s):
                break
        else:
            cnt = 0
            while s[i + cnt] != k:
                cnt += 1
                if i + cnt == len(s):
                    break
            ck = max(ck, cnt)
            i += cnt
            if i == len(s):
                break
        ans = max(ans, ck)
if ans == len(s) - 1:
    ans = len(s)
print(ans)


Failing test case input:
yz{

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
from collections import Counter
s = list(input())
d =  Counter(s)
key = d.keys()
ans = len(s)
for k in key:
    ck = 0
    i = 0
    while True:
        if s[i] == k:
            i += 1
            if i == len(s):
                break
        else:
            cnt = 0
            while s[i + cnt] != k:
                cnt += 1
                if i + cnt == len(s):
                    break
            ck = max(ck, cnt)
            i += cnt
            if i == len(s):
                break
    ans = min(ans, ck)
print(ans)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
smjoabjdoxmrjwypugydyqrchv

Expected output:
11


Actual output:
13


Fixed submission (verdict: Accepted):
from collections import Counter

s=input()
c=Counter(s)

test_s=c.keys()
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)

Problem: p03687
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
indices = {}

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

minres = 1000

for key, value in indices.items():
    if len(value) > 1:
        dist = [value[i+1]-value[i] - 1 for i in range(len(value) - 1)]
    else:
        dist = [value[0]]

    res = max(max(dist), len(s)-value[-1]-1)
    if res < minres:
        minres = res

print(minres)

Failing test case input:
vhcrjpjyhtrywkrkxnbrbaobmx

Expected output:
6


Actual output:
2


Fixed submission (verdict: Accepted):
s = input()
indices = {}

for i in range(len(s)):
    if s[i] in indices:
        indices[s[i]].append(i)
    else:
        indices[s[i]] = [-1, i]

minres = 1000

for key, value in indices.items():
    if len(value) > 1:
        dist = [value[i+1]-value[i] - 1 for i in range(len(value) - 1)]
    else:
        dist = [value[0]]

    res = max(max(dist), len(s)-value[-1]-1)
    if res < minres:
        minres = res

print(minres)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)
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)

Failing test case input:
clkjaa

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
S=input()
A="abcdefghijklmnopqrstuvwxyz"
minimum=len(S)
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)

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
{zz

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
s = input()
L = []
for i in range(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)
Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections
s = list(input())

c = collections.Counter(s)
l = list(c.items())
l = sorted(l, key = lambda x : x[1], reverse=True)


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

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



ans = []

for i in range(len(h)):
    tmp = [_ for _, x in enumerate(s) if x == h[i]]


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


Failing test case input:
xpwzglbjquntrci{axpdikofyw

Expected output:
13


Actual output:
14


Fixed submission (verdict: Accepted):
import collections
s = list(input())

c = collections.Counter(s)
l = list(c.items())
l = sorted(l, key = lambda x : x[1], reverse=True)


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

for i in range(len(l)):
          h.append(l[i][0])




ans = []

for i in range(len(h)):
    tmp = [_ for _, x in enumerate(s) if x == h[i]]


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

Problem: p03687
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
aajklc

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from collections import Counter

s = input()
if len(set(list(s)))==1:
    print(0)
    exit()
    
c = dict(Counter(s))
res = []
for k,v in c.items():
    tmp_s = k + s + k
    idx_num = [e for e,w  in enumerate(list(tmp_s)) 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)
print(max(min(res)-1, 0))