cin>>str;//String of length N and contains lowerCase Alphabets only
int maxlength =0;//Initially assume 0 length if no subsequnece cant be selected
int freq[26];//Frequency Array storing last visited position of lowercase alphabets
for(int i =0;i<26;i++)
{
freq[i]=-1;//Initialisation of frequency array to -1 to indicate no character has previously occured .0 is not used because 0 is used in indexing the string .
}
for(int i =0;i<N;i++){
int code = str[i]-'a';//mapped to 0,1..26 to indicate a,b...z
if(freq[code]!=-1)//if already this character is present before
{
maxlength = max(N-(i-freq[code]-1)-1,maxlength);//Considering N-(j-i) for all possible i,j where str[i]==str[j] and i!=j
}
freq[code]= i;//Updating last visited position of the lowercase alphabet
}
cout<<maxlength<<"\n";//Outputting the maximum length possible of the sub-sub-sequences as answer