Problem:


Score : 300 points

Problem Statement

Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:

For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.

There is a string s consisting of lowercase English letters.
Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.
Find the minimum necessary number of operations.

Constraints

1 ≤ |s| ≤ 100

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum necessary number of operations to achieve the objective.

Sample Input 1

serval

Sample Output 1

3

One solution is: serval → srvvl → svvv → vvv.

Sample Input 2

jackal

Sample Output 2

2

One solution is: jackal → aacaa → aaaa.

Sample Input 3

zzz

Sample Output 3

0

All the characters in s are the same from the beginning.

Sample Input 4

whbrjpjyhsrywlqjxdbrbaomnw

Sample Output 4

8

In 8 operations, he can change s to rrrrrrrrrrrrrrrrrr.



Sample input:
serval


Sample output:
3

Submission status: Wrong Answer

Solution code:
from collections import Counter
S = input()
counter_S = Counter(S)
max_val = max(counter_S.values())
nums = []
for key,val in counter_S.items():
    if val == max_val:
        nums.append(key)
ans=pow(10,9)
for num in nums:
    s=S
    ans2=0
    while len(Counter(s)) > 1:
        list_s=list(s)
        new_s=[]
        for n in range(len(list_s)-1):
            if list_s[n] == num or list_s[n+1] == num:
                new_s.append(num)
            else:
                new_s.append(list_s[n])
        s = new_s
        ans2 += 1
    ans =  min(ans, ans2)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
char = list(map(chr, range(ord('a'), ord('z')+1)))
target = list(input())
ans = float("inf")
for c in char:
  s = copy.deepcopy(target)
  tmpans = 0
  while True:
    for i in range(len(s)-1):
      if s[i] == c or s[i+1] == c:
        s[i] = c
    s.pop()
    tmpans += 1
    flag = True
    for si in s:
      if si != s[0]:
        flag = False
    if flag==True:
      break
  if ans > tmpans:
    ans = tmpans
print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

d = []
s = ns()
que = collections.deque()
for c in s:
    if c not in d:
        d.append(c)

ans = inf
if len(d) == 1:
    print(0)
else:
    for c in d:
        t = copy.copy(d)
        for j in range(len(s)):
            nt = []
            for i in range(len(t)-1):
                if c not in t[i:i+2]:
                    nt.append(t[i])
                else:
                    nt.append(c)
                #print(nt)
            if nt.count(c) == len(nt):
                ans = min(j+1, ans)
                break
            t = copy.copy(nt)
    print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

d = {}
s = ns()
for c in s:
    if c not in d.keys():
        d[c] = 1
    else:
        d[c] += 1
if len(d) == 1:
    print(0)
else:
    print(len(d) //2)

Submission status: Wrong Answer

Solution code:
#41 A - Shrinking
import collections 
s = list(input())
cnt = collections.Counter(s)
valcnt = list(cnt.values())
M = max(valcnt)
# 出現回数が最多の文字リスト
mkeys = [i for i,v in cnt.items() if v == M]

ans = len(s)
for key in mkeys:
    m = 0
    cnt = 0
    # 最多の文字の区間の最大値がその文字の最小値
    for S in s:
        if S == key: 
            m = max(m,cnt)
            cnt = 0
        else:
            cnt += 1
    m = max(m,cnt)
    ans = min(ans,m)
ans = min(ans,len(s)//2)
print(ans)

Submission status: Wrong Answer

Solution code:
#41 A - Shrinking
import collections 
s = list(input())
cnt = collections.Counter(s)
valcnt = list(cnt.values())
M = max(valcnt)
# 出現回数が最多の文字リスト
mkeys = [i for i,v in cnt.items() if v == M]
# 文字がすべて違うとき
if len(mkeys) == len(s):
    print(len(s)//2)
else:
    ans = len(s)
    for key in mkeys:
        m = 0
        cnt = 0
        # 最多の文字の区間の最大値がその文字の最小値
        for S in s:
            if S == key: 
                m = max(m,cnt)
                cnt = 0
            else:
                cnt += 1
        m = max(m,cnt)
        ans = min(ans,m)
    ans = min(ans,len(s)//2)
    print(ans)

Submission status: Wrong Answer

Solution code:
#41 A - Shrinking
import collections 
s = list(input())
cnt = collections.Counter(s)
valcnt = list(cnt.values())
M = max(valcnt)
# 出現回数が最多の文字リスト
mkeys = [i for i,v in cnt.items() if v == M]
# 文字がすべて違うとき
if len(mkeys) == len(s):
    print((len(s)+2-1)//2)
else:
    ans = len(s)
    for key in mkeys:
        m = 0
        cnt = 0
        # 最多の文字の区間の最大値がその文字の最小値
        for S in s:
            if S == key: 
                m = max(m,cnt)
                cnt = 0
            else:
                cnt += 1
        m = max(m,cnt)
        ans = min(ans,m)
    ans = min(ans,(len(s)+2-1)//2)
    print(ans)

Submission status: Wrong Answer

Solution code:
#41 A - Shrinking
import collections 
s = list(input())
cnt = collections.Counter(s)
valcnt = list(cnt.values())
M = max(valcnt)
# 出現回数が最多の文字リスト
mkeys = [i for i,v in cnt.items() if v == M]
# 文字がすべて違うとき
if len(mkeys) == len(s):
    print((len(s)+2-1)//2)
else:
    ans = len(s)
    for key in mkeys:
        m = 0
        cnt = 0
        # 最多の文字の区間の最大値がその文字の最小値
        for S in s:
            if S == key: 
                m = max(m,cnt)
                cnt = 0
            else:
                cnt += 1
        m = max(m,cnt)
        ans = min(ans,m)
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = len(s)
for i in range(26):
  k = s.count(alphabet[i])
  ans = min(ans, len(s)-k)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
x =dict()
for i in range(len(S)):
    s = S[i]
    if s in x:
        x[s] += 1
    else:
        x[s]=1

L = []
m=0
for s in x:
    if m<x[s]:
        m=x[s]

for s in x:
    if m==x[s]:
        L.append(s)

ans = 10**9
for s in L:
    X = S
    res = ""
    if s==X[-1]:
        cnt = 0
        for i in range(N):
            if X[N-1-i]==s:
                cnt += 1
            else:
                break
        for i in range(cnt):
            res += s
        for i in range(N-cnt):
            res += X[i]
        X = res 
    res = ""
    cnt = 0
    while(1):
        res = ""
        if X.count(s)==len(X):
            break
        for i in range(len(X)-1):
            if X[i]==s or X[i+1]==s:
                res += s
            else:
                res += X[i]
        X = res
        cnt += 1
    ans = min(ans,cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
x =dict()
for i in range(len(S)):
    s = S[i]
    if s in x:
        x[s] += 1
    else:
        x[s]=1

L = []
m=0
for s in x:
    if m<x[s]:
        m=x[s]

for s in x:
    if m==x[s]:
        L.append(s)

ans = 10**9
for s in L:
    X = S
    res = ""
    cnt = 0
    while(1):
        res = ""
        if X.count(s)==len(X):
            break
        for i in range(len(X)-1):
            if X[i]==s or X[i+1]==s:
                res += s
            else:
                res += X[i]
        X = res
        cnt += 1
    ans = min(ans,cnt)

print(ans)

Submission status: Wrong Answer

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

def le(s,x):
    cnt = 0
    L = []
    num = []
    for i in range(l):
        if s[i] != x:
            cnt +=1
            if i == l-1:
                L.append(cnt)
        elif s[i] == x:
            L.append(cnt)
            cnt = 0
    num = L[1:-1]   
    ans = 0
    if num:
        for i in num:
            if i%2 == 0:
                ans = i//2
            else:
                ans = i//2+1
    ANS = max(L[0],ans,L[-1])        
    
    return ANS
C = 10**10   
for i in range(l):
    #print(le(s,s[i]))
    C = min(C,(le(s,s[i])))
print(C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = list(input())

ac = Counter(S)
max_value = max(ac.values())

# 全て同じ文字なら操作は0回で済む
if max_value == len(S):
    print(0)
    exit(0)

# 最大出現数の文字を取得する
max_keys = []
for key in ac.keys():
    if ac[key] == max_value:
        max_keys.append(key)

# 最大出現数の文字がない最大区間を求める
ans = 100
for key in max_keys:
    max_range = 0
    cnt_range = 0
    for i in range(len(S)):
        if S[i] != key:
            cnt_range += 1
        else:
            max_range = max(max_range, cnt_range)
            cnt_range = 0
    max_range = max(max_range, cnt_range)
    cnt_range = 0
    ans = min(ans, max_range)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
s = input()
sl = collections.Counter(s)
ans = len(sl)
for c in sl.keys():
    tmp = s.split(c)
    ans = min(ans,max(map(len,tmp)))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = list(input())
n = len(s)

C = Counter(s)
x = max(C, key=C.get)
if max(C.values()) == 1:
    print(len(s) // 2)
    exit()

cnt = 0
while True:
    tmp = s[0]
    flg = 0
    for moji in s:
        if moji != tmp:
            flg = 1
    if flg == 0:
        print(cnt)
        exit()

    for i in range(1, n):
        if s[i - 1] == x or s[i] == x:
            s[i - 1] = x
    s.pop()
    n = len(s)
    print(s)
    cnt += 1

Submission status: Wrong Answer

Solution code:
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)//2 + len(s)%2
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
import collections
tmp=list(collections.Counter(N).keys())
ans=float("Inf")
import copy
for i in tmp:
   c=0
   l=copy.deepcopy(tmp)
   while len(set(l))!=1:
      tmp2=[]
      for j in range(len(l)-1):
         if l[j] ==i or l[j+1]==i:
            tmp2.append(i)
         else:
            tmp2.append(l[j])
      c+=1
      l=copy.deepcopy(tmp2)
   ans=min(ans,c)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import string

s = list(input())
ans = 0

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)

Submission status: Wrong Answer

Solution code:
import copy
import string

s = list(input())
ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil
from collections import defaultdict
S=input()
N=len(S)
D=defaultdict(int)
idx=defaultdict(int)
for i in range(N):
    s=S[i]
    nowd=D[s] #左にいくつあるか
    if i-idx[s]>nowd:
        D[s]=i-idx[s]
    idx[s]=(i+1)
#print(D,idx)
ans=float("INF")
for k,v in D.items():
    sub=0
    i=idx[k]
    if v>=N-i:
        sub=v
    else:
        res=N-i
        sub=v
        sub+=ceil((N-i-v)/2)
    #print(sub,v,i)
    ans=min(ans, sub)

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    s = input()

    N = len(s)

    unique_num_dict = collections.Counter(s)
    most_common = unique_num_dict.most_common()[0]

    if len(unique_num_dict) == 1:
        print(0)
    elif most_common[1] == 1:
        print(N//2)
    else:
        unique_num_dict = collections.Counter(s[1:-1])
        most_common = unique_num_dict.most_common()[0]
        temp_list = s.split(most_common[0])
        res = 0
        for item in temp_list:
            num = len(item)
            if num == 2:
                num += 1
            res = max(res, num)
        # print(most_common)
        # print(temp_list)
        # print([len(item) for item in temp_list])
        print(res//2+res%2)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    s = input()

    N = len(s)

    unique_num_dict = collections.Counter(s)
    most_common = unique_num_dict.most_common()[0]

    if len(unique_num_dict) == 1:
        print(0)
    elif most_common[1] == 1:
        print(N//2)
    else:
        unique_num_dict = collections.Counter(s[1:-1])
        most_common = unique_num_dict.most_common()[0]
        temp_list = s.split(most_common[0])
        res = 0
        for item in temp_list:
            res = max(res, len(item))
        # print(most_common)
        # print(temp_list)
        print(res//2+1)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(list)

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

    ans = INF

    for indexs in d.values():
        last = -1
        result = 0
        for i in indexs:
            tmp = i - last - 1
            result = max(result, tmp)
            last = i
        result = max(result,L-last-1)
        ans = min(ans, result)

    if ans == 0:
        ans = '0 '
        print(ans)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(list)

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

    ans = INF

    for indexs in d.values():
        last = -1
        result = 0
        for i in indexs:
            tmp = i - last - 1
            result = max(result, tmp)
            last = i
        result = max(result,L-last-1)
        ans = min(ans, result)

    if ans == 0:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(list)

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

    ans = INF

    for indexs in d.values():
        last = -1
        result = 0
        for i in indexs:
            tmp = i - last - 1
            result = max(result, tmp)
            last = i
        result = max(result,L-last-1)
        ans = min(ans, result)

    print(str(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = readline().decode('utf-8')
    L = len(S)
    d = defaultdict(list)

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

    ans = INF

    for indexs in d.values():
        last = -1
        result = 0
        for i in indexs:
            tmp = i - last - 1
            result = max(result, tmp)
            last = i
        result = max(result,L-last-1)
        ans = min(ans, result)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()

cnt = Counter(S).most_common()

#print(cnt)

cand = []
for t in cnt:
    k, v = t
    if v != cnt[0][1]:
        break
    cand.append(k)

anss = float('inf')
for c in cand:
    alp = c
    ans = 0
    tmp = 0
    for s in S:
        if s == alp:
            ans = max(ans, tmp)
            tmp = 0
        else:
            tmp += 1
    if tmp:
        ans = max(ans, tmp)
    anss = min(anss, ans)
print(anss)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = input()
x = list(x)
l = []
for i in x:
    if i not in l:
        l.append(i)
if len(l)%2==0:
    print(int(len(l)/2))
else:
    print(int((len(l)-1)/2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import string
d = {}
alph = string.ascii_lowercase
for i in range(len(alph)):
    d[alph[i]] = i
s = list(input())
count = [0 for _ in range(len(alph))]
for letter in s:
    count[d[letter]] += 1
# print(count)

target = []
for i in range(len(alph)):
    if count[i] == max(count):
        target.append(alph[i])

#print("target : " + str(target))
answer = []
for t in target:
    time = 0
    size = len(s)
    line = list(s)
    ifOK = True
    while ifOK:
        # print(line)
        ifOK = False
        new_line = ""
        for i in range(size-1):
            if (line[i] == t or t == line[i+1]) and not line[i] == line[i+1]:
                new_line += t
                ifOK = True
            else:
                new_line += line[i]
        line = list(new_line)
        size -= 1
        time += 1
    answer.append(time)
print(min(answer)-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s_set:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef
        dic.append(max(delta,res))
print(dic)
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s_set:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:
        print(i)
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef
        print(bef)
        dic.append(max(delta,res))
print(dic)
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s:
    bef=-1
    delta=0
    if c[i]==1:
        continue
    else:    
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef-1
        dic.append(max(delta,res))
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=list(input())
n=len(s)
s_set=set(s)
c=Counter(s)
dic=[]
for i in s:
    bef=0
    delta=0
    if c[i]==1:
        continue
    else:    
        for j in range(n):
            if  i==s[j]:
                res=j-bef-1
                bef=j
                delta = max(delta,res)
        res=n-1-bef-1
        dic.append(max(delta,res))
if not dic:
  print(n//2)
else:
  print(min(n//2,min(dic)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)
for t in T:
    P=[i for i,x in enumerate(S) if x==t]+[len(S)]
    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)

Submission status: Wrong Answer

Solution code:
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):
            if string[i-1] != letter:
                string[i-1] = letter
            elif i < len(string)-1:
                string[i+1] = letter
            else:
                pass
    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()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

S = input()
counter = Counter(S)
print(len(counter.items()) // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

s = input()
sc = Counter(s)
now = 0
L = []
for key, value in sc.most_common():
    if value < now:
        break
    now = value
    L.append(key)

ans = float('inf')
for l in L:
    cnl = 0
    anl = 0
    for s_ in s:
        if l == s_:
            anl = max(anl, cnl)
            cnl = 0
        else:
            cnl += 1
    anl = max(anl, cnl)
    ans = min(ans, anl)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
a = [[0] for i in range(26)]

for i in range(len(s)):
    a[ord(s[i])-ord('a')].append(i)

for i in range(26):
    a[i].append(len(s)-1)

ans = float('inf')
for i in range(26):
    ma = 0
    for j in range(1,len(a[i])):
        dis = a[i][j]-a[i][j-1]-1
        ma = max(dis,ma)
    ans = min(ma,ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
S = list(s)
ss = set(S)

r = 100
for w in ss:
    n = 0
    k = 0
    S1 = list(s)
    while not set(S1) == {w}:
        nS1 = len(S1)
        for i in range(nS1-1):
            if S1[i+1] == w:
                S1[i] = w
        if S1[-1] != w:
            S1.pop(-1)
        else:
            for i in range(nS1-1):
                if S1[i] != w and S1[i+1] != w:
                    S1.pop(i)
                    break
        n += 1
    if n < r:
        r = n

print(r)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = [c for c in input()]
c = Counter(s).most_common(3)
if len(set(s)) == len(s):
    most = s[len(s)//2]
elif len(c) == 3 and c[0][1] == c[2][1]:
    most = c[2][0]
elif len(c) == 2 and c[0][1] == c[1][1]: 
    most = c[1][0]
else:
    most = c[0][0]
ss = s[:]
t = []
cnt = 0

while len(set(ss)) != 1:
    for i in range(len(ss) - 1):
        if ss[i] == most or ss[i+1] == most:
            t.append(most)
        else:
            t.append(ss[i])
    ss = t[:]
    t.clear()
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
S = list(s)
ss = set(S)

r = 100
for w in ss:
    n = 0
    k = 0
    S1 = list(s)
    while not set(S1) == {w}:
        nS1 = len(S1)
        for i in range(nS1-1):
            if S1[i+1] == w:
                S1[i] = w
        if S1[-1] != w:
            S1.pop()
        else:
            for i in range(nS1-1):
                if S[i+1] != w:
                    S1.pop(i)
                    break
        n += 1
    if n < r:
        r = n

print(r)