You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character.
Input
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
Output
Print one number — the minimum value of k such that there exists at least one k-dominant character.
Examples
Input
abacaba
Output
2
Input
zzzzz
Output
1
Input
abcde
Output
3
#include<stdio.h>
#include<string.h>
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)>(b) ? (b) : (a))
char s[100005];
int main()
{
scanf("%s",s);
int len = strlen(s);
int j,answer,t1,t2;
char i;
answer = 999999;
for(i='a'; i<='z'; ++i)
{
t2 = -1;
t1 = 1;
for(j=0; j<len; ++j)
{
if(s[j]==i)
{
t1 = 1;
}
else
t1++;
t2 = max(t1,t2); //最大范围
}
answer = min(answer,t2); //最小答案
}
printf("%d\n",answer);
return 0;
}
灵感来源于//https://blog.csdn.net/qq_45328552/article/details/101226683