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 in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN=105;
int pos[MAXN][2];
char s[MAXN],tmp[MAXN];

struct num{
	int cnt;
	char c;
}no[26];

inline bool cmp(const num &a,const num &b){
	return a.cnt>b.cnt;
}

int main(){
	//freopen("a.txt","r",stdin);
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=0;i<26;++i)
		no[i].c=i;
	for(int i=1;i<=n;++i)
		++no[s[i]-'a'].cnt;
	sort(no,no+26,cmp);
	int ans=~0U>>1;
	for(int k=0,now,j;k<26/* && (!k || no[k].cnt==no[k-1].cnt)*/;++k){
		j=n;
		for(int i=1;i<=n;++i)
			tmp[i]=s[i];
		tmp[0]=no[k].c+'a';
		bool flag=true;
		now=0;
		while(flag){
			flag=false;
			for(int i=1;i<j;++i){
				if(tmp[i]!=no[k].c+'a' && tmp[i+1]==no[k].c+'a'){
					tmp[i]=tmp[i+1];
					flag=true;
				}
			}
			if(flag){
				/*if(tmp[j]==no[k].c+'a'){
					pos[0][0]=0;
					for(int i=1;i<=j;++i){
						if(tmp[i]!=no[k].c+'a' && tmp[i-1]==no[k].c+'a')
							pos[++pos[0][0]][0]=i;
						else if(tmp[i-1]!=no[k].c+'a' && tmp[i]==no[k].c+'a')
							pos[pos[0][0]][1]=i;
					}
					int len=0,loc;
					for(int i=1;i<=pos[0][0];++i){
						if(pos[i][1]-pos[i][0]>len){
							len=pos[i][1]-pos[i][0];
							loc=pos[i][0];
						}
					}
					for(int i=loc+1;i<=j;++i)
						tmp[i-1]=tmp[i];
				}*/
				--j;
				++now;
			}
			else{
				for(int i=1;i<=j;++i){
					if(tmp[i]!=no[k].c+'a'){
						now=~0U>>1;
						break;
					}
				}
			}
		}
		ans=min(ans,now);
	}
	printf("%d",ans);
	return 0;
}

// whbrjpjyhsrywlqjxdbrbaomnw
// whrrjpjyhrrywlqjxdrrbaomn 1
// wrrrjpjyrrrywlqjxrrrbaom 2
// rrrrjpjrrrrywlqjrrrrbao 3
// rrrrjprrrrrywlqrrrrrba 4
// rrrrjrrrrrrywlrrrrrrb 5
// rrrrrrrrrrrywrrrrrrr 6
// rrrrrrrrrrrrrrrrrrr 7