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 .

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')

    ans = 1000
    for i in range(26):
        t = chr(i+97)
        if S == t*len(S):
            print(0)
            exit()
        if t not in S:
            continue
        cnt = 0
        S_tmp = S[:]
        while True:
            ok = 1
            cnt += 1
            new = []
            for j in range(len(S_tmp)-1):
                if S_tmp[j] != t and S_tmp[j+1] != t:
                    ok = 0
                    new.append(S_tmp[j])
                else:
                    new.append(t)
            if ok:
                break
            S_tmp = ''.join(new)
        ans = min(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
n2a = lambda c: chr(c+64).lower()
ans=100
n=len(s)
for i in range(1,27):
  al=n2a(i)
  sc= s.count(al)
  if sc==0:
    continue
  f=0
  l=[-1]
  for _ in range(sc):
    li=s.find(al,f)
    l.append(li)
    f=li+1
  if len(l)==1:
    continue
  l.append(n)
  d=0
  for j in range(1,len(l)):
    d=max(d,l[j]-l[j-1]-1)
  ans=min(ans,d)
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
ans = INF
for x in set(s):  
	ans = min(ans, max([len(l) for l in s.split(x)]))

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
N = len(s)
se = set(s)
ans = INF
for x in se:  
	tmp = 0
	ans = min(ans, max([len(l) for l in s.split(x)]))

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
N = len(s)
se = set(s)
ans = INF
for x in se:  
	tmp = 0
	ans = min(ans, max([len(l) for l in s.split(x)]))

print(ans)

Solution (Python):
S = input()

ans = 1e9
for c in range(ord('a'), ord('a') + 26):
    c = chr(c)
    res = []
    for i, s in enumerate(S):
        if c == s:
            res.append(i)
    if len(res) == 0:
        continue
    if len(res) > 1:
        D = [res[i + 1] - res[i] - 1 for i in range(0, len(res) - 1)]
        res1 = max(D)
    else:
        res1 = 0
    res2 = max(res[0], len(S) - res[-1] - 1)
    ans = min(ans, max(res1, res2))

print(ans)

Solution (Python):
s=input()
A=list(set(s))
ans=100
for i in A:
  B=s+i
  C=[]
  pre=-1
  for j in range(len(s)+1):
    if B[j]==i:
      C.append(j-pre-1)
      pre=j
  ans=min(ans,max(C))
print(ans)

Solution (Python):
s  = input()
ans = 10**7
alp = [chr(ord('a') +i) for i in range(26)]
for x in alp:
    char = x
    res = 0
    p = s
    np = ""
    while p.count(char) != len(p):
        np  =""
        for i in range(len(p)-1):
        
            if p[i] == char or p[i+1] == char:
                np +=char
                
            else:
                np+=p[i]
        p = np
        res+=1
        if res >=50:break
    ans = min(res,ans)
print(ans)

Solution (Python):
s=input()

x=dict()
for i in range(len(s)):
    S=s[i]
    if S in x:
        x[S]+=1
    else:
        x[S]=1
M=0
cnt=0
for idx in x:
    M=max(M,x[idx])
    cnt+=1
if cnt==1:
    print(0)
    exit()

ans=10**10

for idy in x:
    t=s
    tmp=t
    count1=0
    count2=0
    cnt=0
    
    while(1):
        p=tmp
        tmp=""
        flag=True
        
        for i in range(len(p)-1):
            if p[i]==idy or p[i+1]==idy:
                tmp=tmp+idy
                
                
            else:
                tmp=tmp+p[i]
                
                flag=False
                
        
        cnt+=1
        if flag:
            break
    

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

Solution (Python):
def BFS(t):
    inf=10**3
    D=[inf for _ in range(n)]
    D[-1]=1

    for i in range(n):
        if s[i]==t:D[i]=0

    for i in range(1,n)[::-1]:
        if D[i-1]==inf:D[i-1]=D[i]+1

    return max(D)


s=input()
n=len(s)
ans=10**4
for i in range(26):
    ans=min(ans,BFS(chr(97+i)))
print(ans)

Solution (Python):
S = input()

alphabets = set(S)

ans = 100
for s in alphabets:
    ans = min(ans, max(list(map(len, S.split(s)))))

print(ans)

Solution (Python):
S = input()
ans = float('inf')
for s in S:
    T = (S + 'a')[:-1]
    
    cnt = 0
    while T.count(s) < len(T):
        D = []
        for i in range(len(T)-1):
            D.append(s if T[i] == s or T[i+1] == s else T[i])
        T = ''.join(D)
        
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)

def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

from collections import defaultdict 


S = input()
l = len(S)



    




alpha = [chr(i) for i in range(97, 97+26)]

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)

def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

from collections import defaultdict 


S = input()
l = len(S)
d = defaultdict(int)

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

d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
if d2[0][1] > 1:
    e = []
    i = 0
    for i in range(len(d2)):
        e.append(d2[i][0])
else:
    e = [S[l//2]]

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

print(ans)

Solution (Python):
s = input()
N = len(s)
dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

ans = 100
for key in dic:
    temp = list(s)
    cnt = 0
    while temp.count(temp[0]) < len(temp):
        new = [0]*(len(temp)-1)
        for i in range(len(temp)-1):
            if temp[i] == key or temp[i+1] == key:
                new[i] = key
            else:
                new[i] = temp[i]
        cnt += 1
        temp = new
    ans = min(ans, cnt)
print(ans)

Solution (Python):
s = list(input())














t = set(s)


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

Solution (Python):
import sys
from collections import Counter, defaultdict
import numpy as np


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


sys.setrecursionlimit(10 ** 9)


def main():
    S = list(input())
    C = Counter(S)
    K = C.keys()
    answer = []
    for k in K:
        cnt = 0
        counter = []
        for s in S:
            if s == k:
                counter.append(cnt)
                cnt = 0
            else:
                cnt += 1
        counter.append(cnt)
        answer.append(max(counter))
    print(min(answer))


if __name__ == "__main__":
    main()

Solution (Python):
s  = input()
se = set(s)

l = [max([len(j) for j in s.split(i)])for i in se]
print(min(l))

Solution (Python):
from collections import Counter
s = input()

cnt = Counter(c for c in s)

ans = 100100
for c in cnt.keys():
    len_m = max([len(a) for a in s.split(c)])
    ans = min(ans, len_m)

print(ans)

Solution (Python):
from copy import deepcopy
s = list(input())    
N = len(s)
count= 0
counter = []
ans = []
real = deepcopy(s)
syurui = set(s)
for j in syurui:
    while True:
        
        if N == s.count(j):
            counter.append(count)
            count = 0
            s = deepcopy(real)
            N = len(s)
            break

        for i in range(N-1):
            if s[i]==j or s[i+1]==j:
                ans.append(j)
            else:
                ans.append(s[i])
        
        N = len(ans)
        s = deepcopy(ans)
        count += 1

        
        ans = []
print(min(counter))

Solution (Python):
s = str(input())

from collections import Counter
cntr = Counter(c for c in s)

ans = 100100
for ch in cntr.keys():
  len_max = max([len(arr) for arr in s.split(ch)])
  ans = min(ans, len_max)

print(ans)

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

Solution (Python):
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))
    tmp = max(tmp,len(L[0]))
    tmp = max(tmp,len(L[-1]))
    ans = min(tmp,ans)
print(ans)

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

Solution (Python):
s = input()

import string
ans = 9999
for char in string.ascii_lowercase:
    count = 0
    maxi = 0
    for j in range(len(s)):
        if s[j] == char:
            maxi = max(count, maxi)
            count = 0
        else:
            count += 1
        maxi = max(count, maxi)
    ans = min(ans, maxi)

print(ans)

Solution (Python):
s = input()
n = len(s)

res = 10**5
for c in set(list(s)):
    ss = list(s)
    cnt = 0
    while len(set(ss))>1:
        cnt += 1
        for i in range(len(ss)-1):
            if c==ss[i+1]:
                ss[i] = c
        ss.pop()
    res = min(res, cnt)

print(res)

Solution (Python):


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)

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

Solution (Python):
from collections import defaultdict
s = input()
d = defaultdict(list)
for i in range(len(s)):
    d[s[i]].append(i)
cnt= 10000000000
ans = 0
for x in d.values():
    ans = 0
    ans = max(ans, x[0])
    ans = max(ans, len(s)-1-x[-1])
    for i in range(len(x)-1):
        ans = max(ans, x[i+1]-x[i]-1)
    cnt = min(cnt, ans)
print(cnt)

Solution (Python):
s = list(input())
N = len(s)
ans = float("INF")
for c in set(s):
  i, cnt = 0, 0
  s1 = s
  while len(set(s1)) != 1:
    ns = []
    for i in range(len(s1)-1):
      if s1[i] == c or s1[i+1] == c:
        ns.append(c)
      else:
        ns.append(s1[i])
    s1 = ns
    cnt += 1
  ans = min(ans, cnt)
print(ans)

Solution (Python):
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:
    cnt = sorted(set(cnt))
    if cnt[0] == 0:
        print(cnt[1])
    else:
        print(cnt[0])

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

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

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

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

s = input()[:-1]
print(min(max(map(len, s.split(a))) for a in s))

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

Solution (Python):
s = ["0"] + list(input())
n = len(s) - 1
alph = [chr(i) for i in range(97, 123)]
ans = 10000
for i in alph:
    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for j in range(1, n + 1):
        if s[j] == i:
            dp[n][j] = 1
    if sum(dp[n]) != 0:
        if sum(dp[n]) == n:
            c = n
        else:
            for j in range(n - 1, 0, -1):
                for k in range(1, j + 1):
                    if dp[j + 1][k] == 1 or dp[j + 1][k + 1] == 1:
                        dp[j][k] = 1
                if sum(dp[j]) == j:
                    c = j
                    break
        if n - c < ans:
            ans = n - c
print(ans)

Solution (Python):
s=input()
N=len(s)
st=set(s)

ans=float("inf")
for str in st:
  a=s.split(str)
  max_len=0
  for part in a:
    leng=len(part)
    max_len=max(max_len,leng)
  
  ans=min(ans,max_len)
  
print(ans)

Solution (Python):
from collections import defaultdict
S = input()
dict = defaultdict(int)

for s in S:
    dict[s] += 1

ans = 10 ** 3
for c in dict.keys():
    max_seq = 0
    tmp = -1
    for i, s in enumerate(S):
        if s == c:
            max_seq = max(max_seq, i - tmp - 1)
            tmp = i
    max_seq = max(max_seq, len(S)-tmp-1)
    ans = min(max_seq, ans)
print(ans)

Solution (Python):
s = list(input())
chara = set(s)
N = len(s)
ans = 100

for i in chara:
    tmp = 0
    high = 0
    for j in s:
        if i != j:
            tmp += 1
        elif tmp > high:
            high = tmp
            tmp = 0
        else:
            tmp = 0
    else:
        if tmp > high:
            high = tmp

    if high < ans:
        ans = high

print(ans)

Solution (Python):
sel=3

if sel==1:
    from collections import deque
    N=int(input())
    ver=[[] for i in range(N)] 
    for _ in range(N-1):
        a,b,c=map(int,input().split())
    ver[a-1].append((b-1,c))
    ver[b-1].append((a-1,c))

    Q,K=map(int,input().split())

    par=[-2 for i in range(N)]
    par[K-1]=-1
    q=deque([K-1])
    while q:
        i=q.popleft()
        for j,c in ver[i]:
            if par[j]==-2:
                par[j]=i
                q.append(j)

    cost=[-1 for i in range(N)]
    cost[K-1]=0
    stack=[[K-1,0]]
    while stack:
        i,c=stack.pop()
        for j,d in ver[i]:
            if par[i]!=j:
                cost[j]=c+d
                stack.append([j,cost[j]])
    
    for _ in range(Q):
        x,y=map(int,input().split())
    print(cost[x-1]+cost[y-1])

  


if sel==2:
    H,W=map(int,input().split())
    C=[[int(i) for i in input().split()] for j in range(10)]
    for i in range(10):
        C[i][i]=0
    for k in range(10):
        for i in range(10):
            for j in range(10):
                C[i][j]=min(C[i][j],C[i][k]+C[k][j])
    ans=0
    for _ in range(H):
        for a in input().split():
            a=int(a)
            if a!=-1:
                ans+=C[a][1]
    print(ans)


if sel==3:
    s=input()
    ans=10**3
    for k in set(list(s)):
        t=s
        cnt=0
        while len(set(t))!=1:
            tmp=''
            for i in range(len(t)-1):
                if t[i]==k or t[i+1]==k:
                    tmp+=k
                else:
                    tmp+=t[i]
            t=tmp
            cnt+=1
        ans=min(ans,cnt)
    print(ans)

Solution (Python):
s=input()
ans=float('inf')
for c in set(s):

    ans=min(ans,max(map(len,s.split(c))))

print(ans)

Solution (Python):
from copy import deepcopy
s = list(input())    
N = len(s)
count= 0
counter = []
ans = []
real = deepcopy(s)
syurui = set(s)
for j in syurui:
    while True:
        
        if N == s.count(j):
            counter.append(count)
            count = 0
            s = deepcopy(real)
            N = len(s)
            break

        for i in range(N-1):
            if s[i]==j or s[i+1]==j:
                ans.append(j)
            else:
                ans.append(s[i])
        
        N = len(ans)
        s = deepcopy(ans)
        count += 1

        
        ans = []
print(min(counter))

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    s = S()
    c = Counter(s)
    mosts = c.most_common()
    ans = len(s)

    for most in mosts:
        t = [i for i in s]
        loop = 0
        while not all([i == most[0] for i in t]):
            cur = []
            for i in range(len(t)):
                if i < len(t) - 1 and t[i+1] == most[0]:
                    cur.append(t[i+1])
                else:
                    cur.append(t[i])
            cur.pop()
            t = cur
            loop += 1
        ans = min(ans, loop)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = input()
counter = collections.Counter(S)

ans = 101
for key, value in counter.items():
    T = copy.deepcopy(S) 
    T1 = ''
    count = 0
    if len(set(T)) > 1:
        while True:
            T1 = ''
            for i in range(len(T)-1):
                if T[i] == key or T[i+1] == key:
                    T1 += key
                else:
                    T1 += "?"
            count += 1
            T = copy.deepcopy(T1)
            if len(set(T1)) == 1: break
    ans = min(ans, count)
print(ans)

Solution (Python):
s = input()

ans = 1000
for cur in set(s):
    count = 0
    t_count = 0
    for i in s:
        if i == cur:
            count = max(count, t_count)
            t_count = 0
        else:
            t_count += 1

    count = max(count, t_count)
    ans = min(ans, count)

print(ans)

Solution (Python):
s = input()

ans = 1000
for cur in "abcdefghijklmnopqrstuvwxyz":
    count = 0
    t_count = 0
    for i in s:
        if i == cur:
            count = max(count, t_count)
            t_count = 0
        else:
            t_count += 1

    count = max(count, t_count)
    ans = min(ans, count)

print(ans)

Solution (Python):
s = input()

def f(s, c):
    result = 0
    while len(set(s)) != 1:
        t = ''
        for i in range(len(s) - 1):
            if s[i] == c or s[i + 1] == c:
                t += c
            else:
                t += s[i]
        s = t
        result += 1
    return result

result = float('inf')
for c in set(s):
    result = min(result, f(s, c))
print(result)

Solution (Python):
from string import ascii_lowercase


s = input()
maxN = len(s)
for ch in ascii_lowercase:
    ss = list(s)
    count = 0

    if len(set(s)) == 1:
        count = 0
    else:
        while True:
            count += 1
            new_ss = []
            for j in range(len(ss) - 1):
                if ss[j] == ch or ss[j + 1] == ch:
                    new_ss.append(ch)
                else:
                    new_ss.append(ss[j])
            
            ss = new_ss
            if len(set(new_ss)) == 1:
                break
    maxN = min(maxN, count)
print(maxN)

Solution (Python):
from collections import Counter
from copy import deepcopy

s = input()
c = Counter(list(s))

lS = len(set(list(s)))

if lS == 1:
    print(0)
    exit()
if lS == len(s):
    print(len(s) // 2)
    exit()
else:
    maxN = len(s)
    for key in c:
        ss = list(s)
        count = 0
        
        
        while True:
            count += 1
            new_ss = []
            for j in range(len(ss) - 1):
                if ss[j] == key or ss[j + 1] == key:
                    new_ss.append(key)
                else:
                    new_ss.append(ss[j])
            
            ss = deepcopy(new_ss)
            if len(set(new_ss)) == 1:
                break
        
        maxN = min(maxN, count)
    print(maxN)

Solution (Python):

import sys


def solve(s: str):
    alpha_list = set(s)

    answer = 10**9
    for alpha in alpha_list: 
        S = s
        count = 0
        while len(set(S)) > 1:
            new_S = ""
            
            for i in range(len(S)-1):
                if S[i] == alpha or S[i+1] == alpha:
                    new_S += alpha
                else:
                    new_S += "@"
            S = new_S
            count += 1
        answer = min(answer,count)

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):
from string import ascii_lowercase


def main():
    word = input()
    target_list = list(ascii_lowercase)
    answer = float("inf")
    for target in target_list:
        now_ans = 0
        now_word = word
        while len(set(now_word)) > 1:
            tmp = ""
            for i in range(len(now_word) - 1):
                if now_word[i] == target or now_word[i + 1] == target:
                    tmp += target
                else:
                    tmp += now_word[i]
            now_word = tmp
            now_ans += 1
        answer = min(answer, now_ans)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
D = {alpha[i]: [-1] for i in range(26)}
N = len(S)
for i in range(N):
  D[S[i]].append(i)
cnt = 0
for i in D:
  D[i].append(N)
  if D[i] != [-1, N]:
    cnt += 1
if cnt == 1:
  print(0)
else:
  m = int(1e9)
  for i in D:
    n = len(D[i])
    M = max(D[i][j+1] - D[i][j] for j in range(n-1))
    if m > M:
      m = M
  print(m-1)

Solution (Python):
from string import ascii_lowercase

s = input()


def rec(target, ss):
    if len(set(ss)) == 1:
        return len(s) - len(ss)
    tt = ""
    cc = 0
    for i in range(len(ss) - 1):
        if ss[i] == target or ss[i + 1] == target:
            tt += target
        else:
            tt += ss[i]
    return rec(target, tt)


ans = 10**10
for c in ascii_lowercase:
    ans = min(ans, rec(c, s))
print(ans)

Solution (Python):
from collections import Counter
s = input()
ls = len(s)

def f(s,c):
    td = s
    cnt = 0
    while(td != c*len(td)):
        t = td
        td = ""
        cnt += 1
        for i in range(len(t)-1):
            if (t[i] == c)or(t[i+1] == c):
                td += c
            else:
                td += t[i]
    return cnt

l = []
for i in range(26):
    l.append(f(s,chr(ord("a")+i)))

print(min(l))

Solution (Python):
s = input()
chars = []
for i in range(97,123):
    chars.append(chr(i))

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

ans = len(s)
for i in chars:
    tmp = s
    tmp_n = ''
    while(True):
        for j in range(len(tmp)-1):
            if((tmp[j] == i)|(tmp[j+1] == i)):
                tmp_n += i
            else:
                tmp_n += tmp[j]

        if( len(set(tmp_n)) == 1):
            ans = min(ans, len(s) - len(tmp_n))
            break

        tmp = tmp_n
        tmp_n = ''

print(ans)

Solution (Python):
s = list(input())

if len(set(s)) == 1:
    print(0)
elif len(set(s)) == len(s):
    print((len(s) + 1) // 2)
else:
    ans = 10010001001
    for i in range(ord('a'), ord('z') + 1):
        tmp = 0
        tmp2 = 0
        for c in s:
            if c == chr(i):
                tmp = 0
            else:
                tmp += 1
            tmp2 = max(tmp, tmp2)
        ans = min(ans, tmp2)

    print(ans)

Solution (Python):
S = list(input())
C = list(set(S))

ans = float("inf")
for c in C:
    cnt_max, cnt = 0, 0
    for s in S:
        if s == c:
            cnt_max = max(cnt_max, cnt)
            cnt = 0
        else:
            cnt += 1
    cnt_max = max(cnt_max, cnt)
    ans = min(ans, cnt_max)

print(ans)

Solution (Python):
s = input()
s_list = [i for i in s]
az = [chr(i) for i in range(97,97+26)]
min_ans = 10*5
for i in az:
    count = 0
    temp = [i for i in s]
    while temp.count(i)!=len(temp):
        ans = []
        for j in range(len(temp)-1):
            if temp[j]==i or temp[j+1]==i:
                ans.append(i)
            else:
                ans.append(temp[j])
        count += 1
        temp = ans
    min_ans = min(min_ans,count)
print(min_ans)

Solution (Python):
def long_diff(s, a):
    s = str(a) + s + str(a)
    index_num = [n for n, v in enumerate(s) if v == str(a)]
    res = 0
    for i in range(len(index_num)-1):
        tmp = index_num[i+1] - index_num[i]
        res = max(res,tmp)
    return res-1

s = input()
r = 100
for i in [chr(j) for j in range(97,97+26)]:
    r = min(r, long_diff(s, i))
print(r)