#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,a[28][100007],b;
string str;
set<char> st;

bool check(int len,char ch)
{
    for(int i=0; i<(int)str.size()-len; i++)
        if(i==0 && a[ch-'a'][len-1]==0)
            return 0;
        else if(i>0 && (a[ch-'a'][i+len-1]- a[ch-'a'][i-1])==0)
            return 0;

    return 1;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str)
    {
        mem(a,0);
        st.clear();

        for(int i=0; i<str.size(); i++)
            st.insert(str[i]), a[str[i]-'a'][i]=1;

        for(char ch: st)
        {
            for(int i=1; i<str.size(); i++)
                a[ch-'a'][i]+=a[ch-'a'][i-1];
//
//            cout<<ch<<endl;
//
//            for(int i=0; i<str.size(); i++)
//                cout<<a[ch-'a'][i]<<" ";
//
//            cout<<endl;
        }

        LL ans=INT_MAX,siz=str.size();

        for(char ch: st)
        {
            int low=0,high=siz+1;
            while(high-low>1)
            {
                int mid=(high+low)>>1;
                if(check(mid,ch))
                    high=mid;
                else
                    low=mid;
            }

            if(high!=siz+1)
                ans=min(ans,(LL)high);

//            cout<<ch<<" "<<high<<endl;
        }

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,a[28][100007],b;
string str;
set<char> st;

bool check(int len,char ch)
{
    for(int i=0; i<(int)str.size()-len; i++)
        if(i==0 && a[ch-'a'][len-1]==0)
            return 0;
        else if(i>0 && (a[ch-'a'][i+len-1]- a[ch-'a'][i-1])==0)
            return 0;

    return 1;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str)
    {
        mem(a,0);
        st.clear();

        for(int i=0; i<str.size(); i++)
            st.insert(str[i]), a[str[i]-'a'][i]=1;

        for(char ch: st)
        {
            for(int i=1; i<str.size(); i++)
                a[ch-'a'][i]+=a[ch-'a'][i-1];
//
//            cout<<ch<<endl;
//
//            for(int i=0; i<str.size(); i++)
//                cout<<a[ch-'a'][i]<<" ";
//
//            cout<<endl;
        }

        int ans=INT_MAX,siz=str.size();

        for(char ch: st)
        {
            int low=0,high=siz+1;
            while(high-low>1)
            {
                int mid=(high+low)>>1;
                if(check(mid,ch))
                    high=mid;
                else
                    low=mid;
            }

            if(high!=siz+1)
                ans=min(ans,high);

//            cout<<ch<<" "<<high<<endl;
        }

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,a[28][100007],b;
string str;
set<char> st;

bool check(int len,char ch)
{
    for(int i=0; i<(int)str.size()-len; i++)
        if(i==0 && a[ch-'a'][len-1]==0)
            return 0;
        else if(i>0 && (a[ch-'a'][i+len-1]- a[ch-'a'][i-1])==0)
            return 0;

    return 1;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str)
    {
        mem(a,0);
        st.clear();

        for(int i=0; i<str.size(); i++)
            st.insert(str[i]), a[str[i]-'a'][i]=1;

        for(char ch: st)
        {
            for(int i=1; i<str.size(); i++)
                a[ch-'a'][i]+=a[ch-'a'][i-1];
//
//            cout<<ch<<endl;
//
//            for(int i=0; i<str.size(); i++)
//                cout<<a[ch-'a'][i]<<" ";
//
//            cout<<endl;
        }

        int ans=INT_MAX,siz=str.size();

        for(char ch: st)
        {
            int low=-1,high=siz+1;
            while(high-low>1)
            {
                int mid=(high+low)>>1;
                if(check(mid,ch))
                    high=mid;
                else
                    low=mid;
            }

            if(high!=siz+1)
                ans=min(ans,high);

//            cout<<ch<<" "<<high<<endl;
        }

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,a[282][100007],b;
string str;
set<char> st;

bool check(int len,char ch)
{
    for(int i=0; i<(int)str.size()-len; i++)
        if(i==0 && a[ch-'a'][len-1]==0)
            return 0;
        else if(i>0 && (a[ch-'a'][i+len-1]- a[ch-'a'][i-1])==0)
            return 0;

    return 1;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str)
    {
        mem(a,0);
        st.clear();

        for(int i=0; i<str.size(); i++)
            st.insert(str[i]), a[str[i]-'a'][i]=1;

        for(char ch: st)
        {
            for(int i=1; i<str.size(); i++)
                a[ch-'a'][i]+=a[ch-'a'][i-1];
//
//            cout<<ch<<endl;
//
//            for(int i=0; i<str.size(); i++)
//                cout<<a[ch-'a'][i]<<" ";
//
//            cout<<endl;
        }

        int ans=INT_MAX,siz=str.size();

        for(char ch: st)
        {
            int low=-1,high=siz+1;
            while(high-low>1)
            {
                int mid=(high+low)>>1;
                if(check(mid,ch))
                    high=mid;
                else
                    low=mid;
            }

            if(high!=siz+1)
                ans=min(ans,high);

//            cout<<ch<<" "<<high<<endl;
        }

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size() , x;
    map < int,int > mp;
    string s1 = s;
    sort(s1.begin(),s1.end());
    if(s1[0]==s1[n-1])
    {
        cout << 1 << endl;
        return 0;
    }
    s1 = s;
    s = "X";
    s += s1;
    //cout << s << endl;
    for(int i=1;i<=n/2+1;i++)
    {
        int cnt = 0,flag,real_flag=1;
        for(int j=1;j<=n;j+=i)
        {
            if(j==n && flag)
                break;
            else if(j+i>n)
            {
                flag = 0;
                break;
            }
            flag = 0;
            for(int k=j;k<=j+i;k++)
            {
                if(cnt==0)
                {
                    mp[s[k]] = 1;
                    flag = 1;
                    //continue;
                }
                else if(mp[s[k]])
                {
                    flag = 1;
                    //cout << s[k] << " ";
                }
                else
                    mp[s[k]] = 0;
                //cout << k << " ";
            }
            //cout << endl;
            //if(i==1)
                //cout << j << " " << flag << endl;
            if(!flag)
                break;
            cnt = 1;
        }
        mp.clear();
        if(flag)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << n << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int ans = INT_MAX;
    for(char c='a';c<='z';c++)
    {
        int mx = 0;
        int p = -1;
        for(int i=0;i<n;i++)
        {
            if(s[i]==c)
            {
                mx = max(mx,i-p);
                p = i;
            }
        }
        mx = max(mx,n-p);
        ans = min(ans,mx);
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size() , x;
    if(n%2)
        x = (n/2)+1;
    else
        x = n;
    map < int,int > mp;
    for(int i=1;i<=x;i++)
    {
        int cnt = 0,flag,real_flag=1;
        for(int j=0;j<n-i;j++)
        {
            //if(i==2)
                //cout << j << endl;
            flag = 0;
            for(int k=j;k<j+i;k++)
            {
                if(cnt==0)
                {
                    mp[s[k]] = 1;
                    flag = 1;
                    //continue;
                }
                else if(mp[s[k]])
                {
                    flag = 1;
                }
                else
                    mp[s[k]] = 0;
            }
            if(!flag)
                break;
            cnt = 1;
        }
        mp.clear();
        if(flag)
        {
            cout << i << endl;
            return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size() , x;
    map < int,int > mp;
    string s1 = s;
    sort(s1.begin(),s1.end());
    if(s1[0]==s1[n-1])
    {
        cout << 1 << endl;
        return 0;
    }
    s1 = s;
    s = "X";
    s += s1;
    //cout << s << endl;
    for(int i=1;i<=n/2+1;i++)
    {
        int cnt = 0,flag,real_flag=1;
        for(int j=1;j<=n;j+=i)
        {
            if(j==n && flag)
                break;
            else if(j+i>n)
            {
                flag = 0;
                break;
            }
            flag = 0;
            for(int k=j;k<=j+i;k++)
            {
                if(cnt==0)
                {
                    mp[s[k]] = 1;
                    flag = 1;
                    //continue;
                }
                else if(mp[s[k]])
                {
                    flag = 1;
                    //cout << s[k] << " ";
                    break;
                }
                else
                    mp[s[k]] = 0;
                //cout << k << " ";
            }
            //cout << endl;
            //if(i==1)
                //cout << j << " " << flag << endl;
            if(!flag)
                break;
            cnt = 1;
        }
        mp.clear();
        if(flag)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << n << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size() , x;
    map < int,int > mp;
    string s1 = s;
    sort(s1.begin(),s1.end());
    if(s1[0]==s1[n-1])
    {
        cout << 1 << endl;
        return 0;
    }
    s1 = s;
    s = "X";
    s += s1;
    //cout << s << endl;
    for(int i=1;i<=n;i++)
    {
        int cnt = 0,flag,real_flag=1;
        for(int j=1;j<=n;j+=i)
        {
            if(j==n && flag)
                break;
            else if(j+i>n)
            {
                flag = 0;
                break;
            }
            flag = 0;
            for(int k=j;k<=j+i;k++)
            {
                if(cnt==0)
                {
                    mp[s[k]] = 1;
                    flag = 1;
                    //continue;
                }
                else if(mp[s[k]])
                {
                    flag = 1;
                    //cout << s[k] << " ";
                }
                else
                    mp[s[k]] = 0;
                //cout << k << " ";
            }
            //cout << endl;
            //if(i==1)
                //cout << j << " " << flag << endl;
            if(!flag)
                break;
            cnt = 1;
        }
        mp.clear();
        if(flag)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << n << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    map < int,int > mp;
    for(int i=1;i<=n;i++)
    {
        int cnt = 0,flag,real_flag=1;
        for(int j=0;j<n-i;j++)
        {
            //if(i==2)
                //cout << j << endl;
            flag = 0;
            for(int k=j;k<j+i;k++)
            {
                if(cnt==0)
                {
                    mp[s[k]] = 1;
                    flag = 1;
                    //continue;
                }
                else if(mp[s[k]])
                {
                    flag = 1;
                }
                else
                    mp[s[k]] = 0;
                //if(i==2)
                    //cout << s[k] << " " << mp[s[k]] << " " << k << endl;
            }
            //if(i==2)
                //cout << j << endl;
            if(!flag)
                break;
            cnt = 1;
        }
        if(flag)
        {
            cout << i << endl;
            return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int n = s.size() , x;
    map < int,int > mp;
    string s1 = s;
    sort(s1.begin(),s1.end());
    if(s1[0]==s1[n-1])
    {
        cout << 1 << endl;
        return 0;
    }
    s1 = s;
    s = "X";
    s += s1;
    //cout << s << endl;
    for(int i=1;i<=n;i++)
    {
        int cnt = 0,flag,real_flag=1;
        for(int j=1;j<=n;j+=i)
        {
            if(j==n && flag)
                break;
            flag = 0;
            for(int k=j;k<=j+i;k++)
            {
                if(cnt==0)
                {
                    mp[s[k]] = 1;
                    flag = 1;
                    //continue;
                }
                else if(mp[s[k]])
                {
                    flag = 1;
                    //cout << s[k] << " ";
                }
                else
                    mp[s[k]] = 0;
                //cout << k << " ";
            }
            //cout << endl;
            //if(i==1)
                //cout << j << " " << flag << endl;
            if(!flag)
                break;
            cnt = 1;
        }
        mp.clear();
        if(flag)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << n << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9){
        if(s.size()==1)cout<<1;
        else if(s.size()==2)cout<<0;
        else if(s.size()==3)cout<<2;
        else if(s.size()==4)cout<<3;
        else cout<<s.size()-2;
    }
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            //if(last==-1&&j>0)ans2++;
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx-1));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    cout<<min(ans,int(s.size())-2);
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9){
        if(s.size()==1)cout<<1;
        else if(s.size()==2)cout<<2;
        else if(s.size()==3)cout<<2;
        else if(s.size()==4)cout<<3;
        else cout<<s.size()-2;
    }
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
int cnt[3000];
void solve()
{
    string s;
    cin>>s;
    int ans=0,mx=-1;
    char c=s[0];
    for(int i=0; i<s.size(); i++)
    {
        cnt[s[i]]++;
        if(cnt[s[i]]>mx)
            mx=cnt[s[i]],c=s[i];
    }
    int last=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]==c)
        {
            ans=max(ans,i-last+(last==0));
            last=i;
        }
    }
    if(cnt[c]==1)cout<<s.size()-2;
    else
        cout<<ans;

}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            //if(last==-1&&j>0)ans2++;
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx-1));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9)
        cout<<s.size()-2;
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            //if(last==-1&&j>0)ans2++;
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx-1));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    cout<<min(ans,s.size()-2);
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9)
        cout<<max(1,int(s.size())-2);
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i)ans2=max(ans2,j-last),cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx-1));
        ans=min(ans,ans2);
    }
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
int cnt[3000];
void solve()
{
    string s;
    cin>>s;
    char c=s[0];
    /*for(int i=0; i<s.size(); i++)
    {
        cnt[s[i]]++;
        if(cnt[s[i]]>mx)
            mx=cnt[s[i]],c=s[i];
    }*/
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i)ans2=max(ans2,j-last),cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        ans=min(ans,ans2);
    }
    cout<<ans;

}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
int cnt[3000];
void solve()
{
    string s;
    cin>>s;
    int ans=0,mx=-1;
    char c=s[0];
    for(int i=0; i<s.size(); i++)
    {
        cnt[s[i]]++;
        if(cnt[s[i]]>mx)
            mx=cnt[s[i]],c=s[i];
    }
    int last=-1;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]==c)
        {
            ans=max(ans,i-last);
            //if(last==-1&&i!=0)ans++;
            last=i;
        }
    }
    if(cnt[c]==1)cout<<s.size()-2;
    else
        cout<<ans;

}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9){
        if(s.size()<=2)cout<<1;
        else if(s.size()==3)cout<<2;
        else if(s.size()==4)cout<<3;
        else cout<<s.size()-2;
    }
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            //if(last==-1&&j>0)ans2++;
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9)
        cout<<s.size()-2;
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            //if(last==-1&&j>0)ans2++;
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx-1));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
int cnt[3000];
void solve()
{
    string s;
    cin>>s;
    int ans=0,mx=-1;
    char c=s[0];
    for(int i=0;i<s.size();i++){
        cnt[s[i]]++;
        if(cnt[s[i]]>mx)
            mx=cnt[s[i]],c=s[i];
    }
    int last=0;
    for(int i=0;i<s.size();i++){
        if(s[i]==c)ans=max(ans,i-last),last=i;
    }
    if(ans==0)cout<<s.size()-2;
    else
    cout<<ans;

}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(ans2>0)
        ans=min(ans,ans2);
    }
    if(ans==1e9){
        if(s.size()==1)cout<<1;
        else if(s.size()==2)cout<<2;
        else if(s.size()==3)cout<<2;
        else if(s.size()==4)cout<<3;
        else cout<<s.size()-2;
    }
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    string s;
    cin>>s;
    int ans=1e9;
    for(int i='a'; i<='z'; i++){
        int ans2=0,last=-1,cnt2=0,mn=1e9,mx=-1;
        for(int j=0; j<s.size(); j++)
        {
            if(s[j]==i){ans2=max(ans2,j-last);
            cnt2++,last=j,mn=min(mn,j),mx=max(mx,j);}

        }
        if(cnt2<=1)ans2=s.size()-2;
        if(mx!=-1)
        ans2=max(ans2,max(mn,int(s.size())-mx));
        if(cnt2>1)
        ans=min(ans,ans2);
    }
    if(ans==1e9){
        if(s.size()<=2)cout<<1;
        else if(s.size()==3)cout<<2;
        else cout<<s.size()-2;
    }
    else
    cout<<ans;
}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}


// C. �-������������ ������
// http://codeforces.com/problemset/problem/888/C

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
using namespace std;

#define DEBUG

#ifdef DEBUG
istream& in = cin;
ostream& out = cout;
#else
#endif

template<class T>
void outputArray(const vector<T>& ar, ostream& out) {
	for (int i = 0; i < ar.size(); ++i)
		out << ar[i] << " ";
	out << endl;
}

bool hasKDomSymbol(const string& str, size_t k, char ch) {
	size_t lastIdx = 0;
	for (size_t j = 0; j < str.length(); ++j) {
		if (ch == str[j])
			lastIdx = j;
		else if (j - lastIdx >= k)
			return false;
	}
	return true;
}

int findMinKDom(const string& str) {
	int minK = str.length();
	for (char ch = 'a'; ch < 'z'; ++ch) {
		int l = 0, r = str.length();
		while (l < r) {
			int mid = (l + r) / 2;
			if (hasKDomSymbol(str, mid, ch))
				r = mid;
			else
				l = mid + 1;
		}
		minK = min(minK, l);
	}
	return minK;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string inputStr;
	in >> inputStr;

	out << findMinKDom(inputStr) << endl;
}


// C. �-������������ ������
// http://codeforces.com/problemset/problem/888/C

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
using namespace std;

#define DEBUG

#ifdef DEBUG
istream& in = cin;
ostream& out = cout;
#else
#endif

template<class T>
void outputArray(const vector<T>& ar, ostream& out) {
	for (int i = 0; i < ar.size(); ++i)
		out << ar[i] << " ";
	out << endl;
}

bool hasKDomSymbol(const string& str, size_t k, char ch) {
	size_t lastIdx = 0;
	for (size_t j = 0; j < str.length(); ++j) {
		if (ch == str[j])
			lastIdx = j;
		else if (j - lastIdx >= k)
			return false;
	}
	return true;
}

int findMinKDom(const string& str) {
	int minK = str.length();
	for (char ch = 'a'; ch <= 'z'; ++ch) {
		int l = 0, r = str.length();
		while (l < r) {
			int mid = (l + r) / 2;
			if (hasKDomSymbol(str, mid, ch))
				r = mid;
			else
				l = mid + 1;
		}
		minK = min(minK, l+1);
	}
	return minK;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string inputStr;
	in >> inputStr;

	out << findMinKDom(inputStr) << endl;
}


// C. �-������������ ������
// http://codeforces.com/problemset/problem/888/C

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
using namespace std;

#define DEBUG

#ifdef DEBUG
istream& in = cin;
ostream& out = cout;
#else
#endif

template<class T>
void outputArray(const vector<T>& ar, ostream& out) {
	for (int i = 0; i < ar.size(); ++i)
		out << ar[i] << " ";
	out << endl;
}

bool isSymbolKDom(const string& str, size_t k, char ch) {
	size_t lastIdx = -1;
	for (size_t j = 0; j < str.length(); ++j) {
		if (ch == str[j])
			lastIdx = j;
		else if (j - lastIdx >= k)
			return false;
	}
	return true;
}

int findMinKDom(const string& str) {
	int minK = str.length();
	for (char ch = 'a'; ch <= 'z'; ++ch) {
		int l = 1, r = str.length();
		while (l < r) {
			int mid = (l + r) / 2;
			if (isSymbolKDom(str, mid, ch))
				r = mid;
			else
				l = mid + 1;
		}
		minK = min(minK, l);
	}
	return minK;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string inputStr;
	in >> inputStr;

	out << findMinKDom(inputStr) << endl;
}


// C. �-������������ ������
// http://codeforces.com/problemset/problem/888/C

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
using namespace std;

#define DEBUG

#ifdef DEBUG
istream& in = cin;
ostream& out = cout;
#else
#endif

template<class T>
void outputArray(const vector<T>& ar, ostream& out) {
	for (int i = 0; i < ar.size(); ++i)
		out << ar[i] << " ";
	out << endl;
}

bool hasKDomSymbol(const string& str, size_t k, char ch) {
	size_t lastIdx = 0;
	for (size_t j = 0; j < str.length(); ++j) {
		if (ch == str[j])
			lastIdx = j;
		else if (j - lastIdx >= k)
			return false;
	}
	return true;
}

int findMinKDom(const string& str) {
	int minK = str.length();
	for (char ch = 'a'; ch <= 'z'; ++ch) {
		int l = 1, r = str.length();
		while (l < r) {
			int mid = (l + r) / 2;
			if (hasKDomSymbol(str, mid, ch))
				r = mid;
			else
				l = mid + 1;
		}
		minK = min(minK, l);
	}
	return minK;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string inputStr;
	in >> inputStr;

	out << findMinKDom(inputStr) << endl;
}


// C. �-������������ ������
// http://codeforces.com/problemset/problem/888/C

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
using namespace std;

#define DEBUG

#ifdef DEBUG
istream& in = cin;
ostream& out = cout;
#else
#endif

template<class T>
void outputArray(const vector<T>& ar, ostream& out) {
	for (int i = 0; i < ar.size(); ++i)
		out << ar[i] << " ";
	out << endl;
}

bool isSymbolKDom(const string& str, size_t k, char ch) {
	size_t lastIdx = 0;
	for (size_t j = 0; j < str.length(); ++j) {
		if (ch == str[j])
			lastIdx = j;
		else if (j - lastIdx >= k-1)
			return false;
	}
	return true;
}

int findMinKDom(const string& str) {
	int minK = str.length();
	for (char ch = 'a'; ch <= 'z'; ++ch) {
		int l = 1, r = str.length();
		while (l < r) {
			int mid = (l + r) / 2;
			if (isSymbolKDom(str, mid, ch))
				r = mid;
			else
				l = mid + 1;
		}
		minK = min(minK, l);
	}
	return minK;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string inputStr;
	in >> inputStr;

	out << findMinKDom(inputStr) << endl;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int len;
int ma[30][2];
bool vis[30];
char s[100010];

int main()
{
	cin>>s;
	len = strlen(s);
	for(int i = 0;i < len;i ++)
	{
		if(!vis[s[i] - 'a'])
		{
			vis[s[i] - 'a'] = 1;
			ma[s[i] - 'a'][0] = i + 1;
			ma[s[i] - 'a'][1] = i;
		}
		else
		{
			ma[s[i] - 'a'][0] = max(i + 1 - ma[s[i] - 'a'][1],ma[s[i] - 'a'][0]);
			ma[s[i] - 'a'][1] = i;
		}
	}
	int ans = 99999999;
	for(int i = 0;i < 'z' - 'a' + 1;i ++)
	{
		ans = min(ma[i][0],ans);
	}
	cout<< ans <<endl;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int len;
int ma[30][2];
bool vis[30];
char s[100010];

int main()
{
	cin>>s;
	len = strlen(s);
	for(int i = 0;i < len;i ++)
	{
		if(!vis[s[i] - 'a'])
		{
			vis[s[i] - 'a'] = 1;
			ma[s[i] - 'a'][0] = i + 1;
			ma[s[i] - 'a'][1] = i;
		}
		else
		{
			ma[s[i] - 'a'][0] = max(i - ma[s[i] - 'a'][1],ma[s[i] - 'a'][0]);
			ma[s[i] - 'a'][1] = i;
		}
	}
	int ans = 99999999;
	for(int i = 0;i < 'z' - 'a' + 1;i ++)
	{
		ma[i][0] = max(ma[i][0],len - ma[i][1]);
		if(vis[i])
			ans = min(ma[i][0],ans);
	}
	cout<< ans <<endl;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int len;
int ma[30][2];
bool vis[30];
char s[100010];

int main()
{
	cin>>s;
	len = strlen(s);
	for(int i = 0;i < len;i ++)
	{
		if(!vis[s[i] - 'a'])
		{
			vis[s[i] - 'a'] = 1;
			ma[s[i] - 'a'][0] = i + 1;
			ma[s[i] - 'a'][1] = i;
		}
		else
		{
			ma[s[i] - 'a'][0] = max(i - ma[s[i] - 'a'][1],ma[s[i] - 'a'][0]);
			ma[s[i] - 'a'][1] = i;
		}
	}
	int ans = 99999999;
	for(int i = 0;i < 'z' - 'a' + 1;i ++)
	{
		if(vis[i] && len <= ma[i][0] + ma[i][1])
			ans = min(ma[i][0],ans);
	}
	cout<< ans <<endl;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int len;
int ma[30][2];
bool vis[30];
char s[100010];

int main()
{
	cin>>s;
	len = strlen(s);
	for(int i = 0;i < len;i ++)
	{
		if(!vis[s[i] - 'a'])
		{
			vis[s[i] - 'a'] = 1;
			ma[s[i] - 'a'][0] = i + 1;
			ma[s[i] - 'a'][1] = i;
		}
		else
		{
			ma[s[i] - 'a'][0] = max(i - ma[s[i] - 'a'][1],ma[s[i] - 'a'][0]);
			ma[s[i] - 'a'][1] = i;
		}
	}
	int ans = 99999999;
	for(int i = 0;i < 'z' - 'a' + 1;i ++)
	{
		if(vis[i])
			ans = min(ma[i][0],ans);
	}
	cout<< ans <<endl;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int len;
int ma[30][2];
bool vis[30];
char s[100010];

int main()
{
	cin>>s;
	len = strlen(s);
	for(int i = 0;i < len;i ++)
	{
		if(!vis[s[i] - 'a'])
		{
			vis[s[i] - 'a'] = 1;
			ma[s[i] - 'a'][0] = i + 1;
			ma[s[i] - 'a'][1] = i;
		}
		else
		{
			ma[s[i] - 'a'][0] = max(i + 1 - ma[s[i] - 'a'][1],ma[s[i] - 'a'][0]);
			ma[s[i] - 'a'][1] = i;
		}
	}
	int ans = 99999999;
	for(int i = 0;i < 'z' - 'a' + 1;i ++)
	{
		if(vis[i])
			ans = min(ma[i][0],ans);
	}
	cout<< ans <<endl;
}


//888C
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 100001;

int main()
{
	string s;
	cin >> s;
	//s = "abacaba";

	vector <int> k(26, inf), ki(26), kel;
	for (int i = 0; i < 26; ++i)
	{
		if (s.find(i+'a') != string::npos)
		{
			kel.push_back(i);
			ki[i] = s.find(i+'a')+1;
			k[i] = s.find(i+'a')+1;
		}
	}

	vector <int> ad;
	bool ok = true;
	while (ok)
	{
		vector <int> del;
		ok = false;

		for (auto i : kel)
		{
			char c = i + 'a';
			int kk = s.find(c, ki[i]);

			if (kk != string::npos)
			{
				if (kk - (ki[i]-1) > (k[i]-1))
					k[i] = kk - (ki[i]-1);

				ki[i] = kk+1;
				ok = true;
			}
			else
			{
				del.push_back(i);
				ad.push_back( max( k[i], (int)s.length() - ki[i] + 1) );
			}
		}

		vector<int>::iterator kit = kel.begin();
		int i=0;
		for (vector<int>::iterator it = del.begin(); it != del.end(); ++it)
		{
			while (kit+i != kel.end() && *(kit+i) != *it)
				++i;

			if (kit+i != kel.end())
			{
				kel.erase(kit+i);

				if (i == 0)
					kit = kel.begin();
			}
		}
	}

	cout << *std::min_element(begin(ad), end(ad)) << endl;

	getchar();getchar();
	return 0;
}


//888C
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 100001;

int main()
{
	string s;
	cin >> s;
//	s = "";
//	for (int i=0;i<100000;++i)
//		s += 'a';
//cout <<"redy";
	vector <int> k(26, inf), ki(26), kel;
	for (int i = 0; i < 26; ++i)
	{
		if (s.find(i+'a') != string::npos)
		{
			kel.push_back(i);
			ki[i] = s.find(i+'a');
			k[i] = max(s.find(i+'a'), s.length() - s.find(i+'a'));
		}
	}

	vector <int> ad;
	int k_min = inf;
	bool ok = true;
	while (ok)
	{
		vector <int> del;
		ok = false;

		for (auto i : kel)
		{
			char c = i + 'a';
			int kk = s.find(c, ki[i]+1);

			if (kk != string::npos)
			{
				if (kk - ki[i] <= k_min)
				{

					k[i] = kk - ki[i];
					k_min = k[i];

					ki[i] = kk;

					ok = true;
				}
				else
				{
					del.push_back(i);
				}
			}
			else
			{
				del.push_back(i);
				ad.push_back(k[i]);
			}
		}

		vector<int>::iterator kit = kel.begin();
		int i=0;
		for (vector<int>::iterator it = del.begin(); it != del.end(); ++it)
		{
			while (kit+i != kel.end() && *(kit+i) != *it)
				++i;

			if (kit+i != kel.end())
			{
				kel.erase(kit+i);

				if (i == 0)
					kit = kel.begin();
			}
		}
	}

	cout << *std::min_element(begin(ad), end(ad)) << endl;

	getchar();getchar();
	return 0;
}


//888C
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 100001;

int main()
{
	string s;
	cin >> s;

	vector <int> k(26, inf), ki(26), kel;
	for (int i = 0; i < 26; ++i)
	{
		if (s.find(i+'a') != string::npos)
		{
			kel.push_back(i);
			ki[i] = s.find(i+'a');
			k[i] = s.find(i+'a');
		}
	}

	vector <int> ad;
	bool ok = true;
	while (ok)
	{
		vector <int> del;
		ok = false;

		for (auto i : kel)
		{
			char c = i + 'a';
			int kk = s.find(c, ki[i]+1);

			if (kk != string::npos)
			{
				if (kk - ki[i] > k[i])
					k[i] = kk - ki[i];

				ki[i] = kk;
				ok = true;
			}
			else
			{
				del.push_back(i);
				ad.push_back( max( k[i], (int)s.length() - ki[i]) );
			}
		}

		vector<int>::iterator kit = kel.begin();
		int i=0;
		for (vector<int>::iterator it = del.begin(); it != del.end(); ++it)
		{
			while (kit+i != kel.end() && *(kit+i) != *it)
				++i;

			if (kit+i != kel.end())
			{
				kel.erase(kit+i);

				if (i == 0)
					kit = kel.begin();
			}
		}
	}

	cout << *std::min_element(begin(ad), end(ad)) << endl;

	getchar();getchar();
	return 0;
}


//888C
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 100001;

int main()
{
	string s;
	//cin >> s;
	s = "abcde";

	vector <int> k(26, inf), ki(26), kel;
	for (int i = 0; i < 26; ++i)
	{
		if (s.find(i+'a') != string::npos)
		{
			kel.push_back(i);
			ki[i] = s.find(i+'a')+1;
			k[i] = s.find(i+'a')+1;
		}
	}

	vector <int> ad;
	bool ok = true;
	while (ok)
	{
		vector <int> del;
		ok = false;

		for (auto i : kel)
		{
			char c = i + 'a';
			int kk = s.find(c, ki[i]);

			if (kk != string::npos)
			{
				if (kk - (ki[i]-1) > (k[i]-1))
					k[i] = kk - (ki[i]-1);

				ki[i] = kk+1;
				ok = true;
			}
			else
			{
				del.push_back(i);
				ad.push_back( max( k[i], (int)s.length() - ki[i] + 1) );
			}
		}

		vector<int>::iterator kit = kel.begin();
		int i=0;
		for (vector<int>::iterator it = del.begin(); it != del.end(); ++it)
		{
			while (kit+i != kel.end() && *(kit+i) != *it)
				++i;

			if (kit+i != kel.end())
			{
				kel.erase(kit+i);

				if (i == 0)
					kit = kel.begin();
			}
		}
	}

	cout << *std::min_element(begin(ad), end(ad)) << endl;

	getchar();getchar();
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;

vector<int> cnt[30];

int main(){
	string str;
	cin>>str;
	int len=str.size();
	for(int i=0;i<len;i++)
		cnt[str[i]-'a'].push_back(i);
	int ans=len/2+1;
	for(int i=0;i<26;i++){
		int sz=cnt[i].size(),maxn=0;
		for(int j=1;j<sz;j++){
			maxn=max(maxn,cnt[i][j]-cnt[i][j-1]);
		}
		if(maxn!=0)	ans=min(ans,maxn);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> cnt[30];

int main(){
	string str;
	cin>>str;
	int len=str.size();
	for(int i=0;i<len;i++)
		cnt[str[i]-'a'].push_back(i);
	int ans=len/2+1;
	for(int i=0;i<26;i++){
		int sz=cnt[i].size(),maxn=0;
		for(int j=1;j<sz;j++){
			maxn=max(maxn,cnt[i][j]-cnt[i][j-1]);
		}
		if(sz!=0){
			maxn=max(maxn,cnt[i][0]+1);
			maxn=max(maxn,len-cnt[i][sz-1]);
		}
		if(maxn!=0)	ans=min(ans,maxn);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> cnt[30];

int main(){
	string str;
	cin>>str;
	int len=str.size();
	for(int i=0;i<len;i++)
		cnt[str[i]-'a'].push_back(i);
	int ans=len/2+1;
	for(int i=0;i<26;i++){
		int sz=cnt[i].size(),maxn=0;
		for(int j=1;j<sz;j++){
			maxn=max(maxn,cnt[i][j]-cnt[i][j-1]);
		}
		if(sz!=0){
			maxn=max(maxn,cnt[i][0]);
			maxn=max(maxn,len-cnt[i][sz-1]+1);
		}
		if(maxn!=0)	ans=min(ans,maxn);
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> cnt[30];

int main(){
	string str;
	cin>>str;
	int len=str.size();
	for(int i=0;i<len;i++)
		cnt[str[i]-'a'].push_back(i);
	int ans=len/2+1;
	for(int i=0;i<26;i++){
		int sz=cnt[i].size(),maxn=0;
		for(int j=1;j<sz;j++){
			maxn=max(maxn,cnt[i][j]-cnt[i][j-1]);
		}
		if(sz!=0){
			maxn=max(maxn,cnt[i][0]);
			maxn=max(maxn,len-cnt[i][sz-1]);
		}
		if(maxn!=0)	ans=min(ans,maxn);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int maxcnt = 0;
int main() {
    string s;
    cin >> s;
    set<int> set1;
    for(int i = 0; i < s.size(); ++i){ set1.insert(s[i]); }
    if (set1.size() == 1){
        cout << 1;
        return 0;
    }
    long long max = 0;
    long long mini = 1e13;
    for (auto x : set1) {
        int f1 = 0;
        int f2 = 0;
        //int cnt = 0;
        while (f2 < s.size()){
            if (s[f1] != x) {
                for(int i = 0; i < s.size(); ++i){
                    if (s[f1] != x){
                        f1++;
                    } else {
                        break;
                    }
                }
                maxcnt = f1+1;
            }
            f2 = f1+1;
            for(int i = f2; i < s.size(); ++i) {
                if (s[i] != x) {
                    f2++;
                } else {
                    break;
                }
            }
            if ((f2 - f1) > maxcnt) maxcnt = (f2 - f1);
            f1 = f2;
        }
        //cout << (char)x ;
        //cout << maxcnt <<" ";
        if (maxcnt < mini) mini = maxcnt;
    }
    //cout << mini + 1;
    if (mini > s.size()/2 + 1){
        cout << s.size()/2 + 1;
    } else {
        cout << mini;
    }
}


#include<bits/stdc++.h>
using namespace std;
int maxcnt = 0;
int main() {
    string s;
    cin >> s;
    set<int> set1;
    for(int i = 0; i < s.size(); ++i){ set1.insert(s[i]); }
    if (set1.size() == 1){
        cout << 1;
        return 0;
    }
    long long max = 0;
    long long mini = 1e13;
    for (auto x : set1) {
        int f1 = 0;
        int f2 = 0;
        //int cnt = 0;
        while (f2 < s.size()){
            if (s[f1] != x) {
                for(int i = 0; i < s.size(); ++i){
                    if (s[f1] != x){
                        f1++;
                    } else {
                        break;
                    }
                }
                maxcnt = f1;
            }
            f2 = f1+1;
            for(int i = f2; i < s.size(); ++i){
                if (s[i] != x){
                    f2++;
                } else {
                    break;
                }
            }
            if ((f2 - f1) > maxcnt) maxcnt = (f2 - f1);
            f1 = f2;
        }
        //cout << maxcnt <<" ";
        if (maxcnt < mini) mini = maxcnt;
    }
    //cout << mini + 1;
    if (mini > s.size()/2 + 1){
        cout << s.size()/2 + 1;
    } else {
        cout << mini;
    }
}


#include<bits/stdc++.h>
using namespace std;
int maxcnt = 0;
int main() {
    string s;
    cin >> s;
    set<int> set1;
    for(int i = 0; i < s.size(); ++i){ set1.insert(s[i]); }
    if (set1.size() == 1){
        cout << 1;
        return 0;
    }
    long long max = 0;
    long long mini = 1e13;
    for (auto x : set1) {
        int f1 = 0;
        int f2 = 0;
        //int cnt = 0;
        while (f2 < s.size()){
            if (s[f1] != x) {
                for(int i = 0; i < s.size(); ++i){
                    if (s[f1] != x){
                        f1++;
                    } else {
                        break;
                    }
                }
            }
            f2 = f1+1;
            for(int i = f2; i < s.size(); ++i){
                if (s[f2] != x){
                    f2++;
                } else {
                    break;
                }
            }
            if ((f2 - f1) > maxcnt) maxcnt = (f2 - f1);
            f1 = f2;
        }
        if (maxcnt < mini) mini = maxcnt;
    }
    //cout << mini + 1;
    if (mini > s.size()/2 + 1){
        cout << s.size()/2 + 1;
    } else {
        cout << mini;
    }
}


#include<bits/stdc++.h>
using namespace std;
int maxcnt = 0;
int main() {
    string s;
    cin >> s;
    set<int> set1;
    for(int i = 0; i < s.size(); ++i){ set1.insert(s[i]); }
    if (set1.size() == 1){
        cout << 1;
        return 0;
    }
    long long max = 0;
    long long mini = 1e13;
    for (auto x : set1) {
        int f1 = 0;
        int f2 = 0;
        //int cnt = 0;
        while (f2 < s.size()){
            if (s[f1] != x) {
                for(int i = 0; i < s.size(); ++i){
                    if (s[f1] != x){
                        f1++;
                    } else {
                        break;
                    }
                }
                maxcnt = f1;
            }
            f2 = f1+1;
            for(int i = f2; i < s.size(); ++i){
                if (s[i] != x){
                    f2++;
                } else {
                    break;
                }
            }
            if (f2 == s.size()) f2--;
            if ((f2 - f1) > maxcnt) maxcnt = (f2 - f1);
            f1 = f2;
        }
        //cout << maxcnt <<" ";
        if (maxcnt < mini) mini = maxcnt;
    }
    //cout << mini + 1;
    if (mini > s.size()/2 + 1){
        cout << s.size()/2 + 1;
    } else {
        cout << mini;
    }
}


#include<bits/stdc++.h>
using namespace std;
int maxcnt;
int main() {
    string s;
    cin >> s;
    set<char> set1;
    for(int i = 0; i < s.size(); ++i){ set1.insert(s[i]); }
    if (set1.size() == 1){
        cout << 1;
        return 0;
    }
    long long max = 0;
    long long mini = 1e13;
    for (auto x : set1) {
        int f1 = 0;
        int f2 = 0;
        maxcnt = 0;
        //int cnt = 0;
        while (f2 < s.size()){
            if (s[f1] != x) {
                for(int i = 0; i < s.size(); ++i){
                    if (s[f1] != x){
                        f1++;
                    } else {
                        break;
                    }
                }
                maxcnt = f1+1;
            }
            f2 = f1+1;
            for(int i = f2; i < s.size(); ++i) {
                if (s[i] != x) {
                    f2++;
                } else {
                    break;
                }
            }
            if ((f2 - f1) > maxcnt) maxcnt = (f2 - f1);
            f1 = f2;
        }
        //cout << (char)x ;
        //cout << maxcnt <<" ";
        if (maxcnt < mini) mini = maxcnt;
    }
    //cout << mini + 1;
    if (mini > s.size()/2 + 1){
        cout << s.size()/2 + 1;
    } else {
        cout << mini;
    }
}


#include<bits/stdc++.h>
using namespace std;
int maxcnt = 0;
int main() {
    string s;
    cin >> s;
    set<int> set1;
    for(int i = 0; i < s.size(); ++i){ set1.insert(s[i]); }
    if (set1.size() == 1){
        cout << 1;
        return 0;
    }
    long long max = 0;
    long long mini = 1e13;
    for (auto x : set1) {
        int f1 = 0;
        int f2 = 0;
        //int cnt = 0;
        while (f2 < s.size() - 1){
            if (s[f1] != x) {
                for(int i = 0; i < s.size(); ++i){
                    if (s[f1] != x){
                        f1++;
                    } else {
                        break;
                    }
                }
                maxcnt = f1;
            }
            f2 = f1+1;
            for(int i = f2; i < s.size(); ++i){
                if (s[i] != x){
                    f2++;
                } else {
                    break;
                }
            }
            if (f2 == s.size())
                f2--;
            if ((f2 - f1) > maxcnt) maxcnt = (f2 - f1);
            f1 = f2;
        }
        //cout << maxcnt <<" ";
        if (maxcnt < mini) mini = maxcnt;
    }
    //cout << mini + 1;
    if (mini > s.size()/2 + 1){
        cout << s.size()/2 + 1;
    } else {
        cout << mini;
    }
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ", "
#define de(x) cout << #x << "=" << x << endl
#define ds() puts("---stop here---")
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int INF = 0x3f3f3f3f;
const int maxn = 101010;
const int MOD = 1e9 + 7;

int len;
char str[maxn];
vector<int> vec[26];
bool check(int x)
{
    bool ok = false;
    rep(i,0,26){
        if(!sz(vec[i])) continue;
        if(sz(vec[i])==1){
            int pos = vec[i][0];
            if(pos <= x && pos>=len-x+1) ok = true;
            if(ok) break;
            continue;
        }
        if(vec[i][0]>x) continue;
        bool flag = 0;
        rep(j,0,sz(vec[i])-1){
            if(vec[i][j+1]-vec[i][j]>x) flag = 1;
        }
        if(!flag) ok = true;
        if(ok) break;
    }
    return ok;
}
int main()
{
    scanf("%s",str);
    len = strlen(str);
    rep(i,0,len) vec[str[i]-'a'].pb(i+1);
    int l = 1 , r = len , ans;
    while(l<=r){
        int m  =(l+r)>>1;
        if(check(m)){
            ans = m;
            r = m-1;
        }
        else l = m+1;
    }
    printf("%d\n",ans);
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ", "
#define de(x) cout << #x << "=" << x << endl
#define ds() puts("---stop here---")
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int INF = 0x3f3f3f3f;
const int maxn = 101010;
const int MOD = 1e9 + 7;

int len;
char str[maxn];
vector<int> vec[26];
bool check(int x)
{
    bool ok = false;
    rep(i,0,26){
        if(!sz(vec[i])) continue;
        if(sz(vec[i])==1){
            int pos = vec[i][0];
            if(pos <= x && pos>=len-x+1) ok = true;
            if(ok) break;
            continue;
        }
        if(vec[i][0]>x) continue;
        bool flag = 0;
        rep(j,0,sz(vec[i])-1){
            if(vec[i][j+1]-vec[i][j]>x) flag = 1;
        }
        if(vec[i][sz(vec[i])-1] < len-x+1) flag = 1;
        if(!flag) ok = true;
        if(ok) break;
    }
    return ok;
}
int main()
{
    scanf("%s",str);
    len = strlen(str);
    rep(i,0,len) vec[str[i]-'a'].pb(i+1);
    int l = 1 , r = len , ans;
    while(l<=r){
        int m  =(l+r)>>1;
        if(check(m)){
            ans = m;
            r = m-1;
        }
        else l = m+1;
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x7f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e6+5;
const double EPS = 1e-6;
using namespace std;

int slen;
char s[maxn];
bool vis[maxn];
int pre[26][maxn]={0};
bool ok(int len,char c){
	int k = c-'a';
	rep(i,1,slen+1){
		if(i+len-1>slen) break;
		if(pre[k][i+len-1] == pre[k][i-1]) return false;
	}
	return true;
}
int main()
{
	mt(vis,false);
	scanf("%s",s+1);
	slen = strlen(s+1);
	rep(i,1,slen+1) {
		int k = s[i] - 'a';
		vis[k] = true;
		rep(j,0,26){
			if(k==j) pre[j][i]=pre[j][i-1]+1;
			else pre[j][i]=pre[j][i-1];
		}
	}
//	rep(i,1,slen+1) dd(pre[0][i]);
	int ans = inf;
	rep(i,0,26){
		if(!vis[i]) continue;
		char c = i+'a';
		int l = 1,r = slen;
		int tmp;
		while(l<=r){
			int mid = (l+r)>>1;
			if(ok(mid,c)){
				tmp = mid;
				r = mid-1;
			}
			else l = mid+1;
		}
//		de(c);dd(l);de(r);
		ans = min(ans , tmp);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x7f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e6+5;
const double EPS = 1e-6;
using namespace std;

int slen;
char s[maxn];
bool vis[maxn];
int pre[26][maxn]={0};
bool ok(int len,char c){
	int k = c-'a';
	rep(i,1,slen+1){
		if(i+len-1>slen) break;
		if(pre[k][i+len-1] - pre[k][i-1] <= 0) return false;
	}
	return true;
}
int main()
{
	mt(vis,false);
	scanf("%s",s+1);
	slen = strlen(s+1);
	rep(i,1,slen+1) {
		int k = s[i] - 'a';
		vis[k] = true;
		rep(j,0,26){
			if(k==j) pre[j][i]=pre[j][i-1]+1;
			else pre[j][i]=pre[j][i-1];
		}
	}
//	rep(i,1,slen+1) dd(pre[0][i]);
	int ans = inf;
	rep(i,0,26){
		if(!vis[i]) continue;
		char c = i+'a';
		int l = 1,r = slen;
		while(l+1<r){
			int mid = (l+r)>>1;
			if(ok(mid,c)) r = mid;
			else l = mid;
		}
//		de(c);dd(l);de(r);
		if(ok(l,c)) ans = min(ans,l);
		else ans = min(ans,r);
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    string s; cin >> s;
    map<char, int> dis;
    map<char, int> last;
    int n = s.size();
    for(int i = 0; i < n; i++){
        last[s[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        if(last[s[i]] != -1){
            dis[s[i]] = max(dis[s[i]], i - last[s[i]]);
        }
        last[s[i]] = i;
    }
    int ans = 10000000;
    for(int i = 0; i < n; i++){
        if(dis[s[i]] != 0){
            ans = min(ans, dis[s[i]]);
        }
    }
    if(ans == 10000000){
        ans = n/2;
        if(n % 2 != 0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    string s; cin >> s;
    map<char, int> dis;
    map<char, int> last;
    map<char, int> cnt;
    int n = s.size();
    for(int i = 0; i < n; i++){
        last[s[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        if(last[s[i]] != -1){
            dis[s[i]] = max(dis[s[i]], i - last[s[i]]);
        }
        cnt[s[i]]++;
        last[s[i]] = i;
    }
    for(int i = 0; i < n; i++){
        if(cnt[s[i]] > 1){
            dis[s[i]] = max(dis[s[i]], n - last[s[i]]);
        }
    }
    int ans = n/2 + 1;
    for(int i = 0; i < n; i++){
        if(dis[s[i]] != 0){
            ans = min(ans, dis[s[i]]);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    string s; cin >> s;
    map<char, int> dis;
    map<char, int> last;
    map<char, int> cnt;
    int n = s.size();
    for(int i = 0; i < n; i++){
        last[s[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        if(last[s[i]] != -1){
            dis[s[i]] = max(dis[s[i]], i - last[s[i]]);
        }
        else{
            dis[s[i]] = i + 1;
        }
        last[s[i]] = i;
    }
    for(int i = 0; i < n; i++){
        dis[s[i]] = max(dis[s[i]], n - last[s[i]]);
    }
    int ans = n/2 + 1;
    for(int i = 0; i < n; i++){
        if(dis[s[i]] != 0){
            ans = min(ans, dis[s[i]]);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    string s; cin >> s;
    map<char, int> dis;
    map<char, int> last;
    map<char, int> cnt;
    map<char, int> first;
    int n = s.size();
    for(int i = 0; i < n; i++){
        last[s[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        if(last[s[i]] != -1){
            dis[s[i]] = max(dis[s[i]], i - last[s[i]]);
        }
        else{
            first[s[i]] = i;
        }
        cnt[s[i]]++;
        last[s[i]] = i;
    }
    for(int i = 0; i < n; i++){
        if(cnt[s[i]] > 1){
            dis[s[i]] = max(dis[s[i]], n - last[s[i]]);
            dis[s[i]] = max(dis[s[i]], first[s[i]]);
        }
    }
    int ans = n/2 + 1;
    for(int i = 0; i < n; i++){
        if(dis[s[i]] != 0){
            ans = min(ans, dis[s[i]]);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    string s; cin >> s;
    map<char, int> dis;
    map<char, int> last;
    map<char, int> cnt;
    int n = s.size();
    for(int i = 0; i < n; i++){
        last[s[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        if(last[s[i]] != -1){
            dis[s[i]] = max(dis[s[i]], i - last[s[i]]);
        }
        cnt[s[i]]++;
        last[s[i]] = i;
    }
    for(int i = 0; i < n; i++){
        if(cnt[s[i]] > 1){
            dis[s[i]] = max(dis[s[i]], n - last[s[i]] - 1);
        }
    }
    int ans = n/2 + 1;
    for(int i = 0; i < n; i++){
        if(dis[s[i]] != 0){
            ans = min(ans, dis[s[i]]);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    string s; cin >> s;
    map<char, int> dis;
    map<char, int> last;
    int n = s.size();
    for(int i = 0; i < n; i++){
        last[s[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        if(last[s[i]] != -1){
            dis[s[i]] = max(dis[s[i]], i - last[s[i]]);
        }
        last[s[i]] = i;
    }
    int ans = 10000000;
    for(int i = 0; i < n; i++){
        if(dis[s[i]] != 0){
            ans = min(ans, dis[s[i]]);
        }
    }
    if(ans == 10000000){
        ans = n/2 + 1;
    }
    cout << ans << endl;
    return 0;
}


/*#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int MAXN=100000;
int a[26];
int INF=10000000000;

int main(){
	string s;
	cin>>s;
	int cnt=-1;
	for (int i=0;i<26;i++) a[i]=INF;
	for (char j='a';j<='z';j++){
		int old=-1;
		int max=0;
		int n=-1;
		cnt++;
		for (int i=0;i<s.size();i++){
		    if (s[i]==j) {
		    	n=i;
		    	if (n-old>max) max=n-old;
		    	old=n;
			}
	    }
	    if (s.size()-n>max) max=n-old;
	    a[cnt]=max;
	}
	int ans=s.size()/2+1;
	for (int i=0;i<26;i++){
		if (a[i]<ans&&a[i]>0) ans=a[i];
	}
	cout<<ans<<endl;
	//for (int i=0;i<26;i++) cout<<a[i]<<" ";
}*/

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<utility>
#include<ctime>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<cctype>
using namespace std;
int a[26];
int main(){
	string s;
	cin>>s;
	int cnt=-1;
	memset(a,0,sizeof(a));
	for (char j='a';j<='z';j++){
		int old=-1,max=0;
		for (int i=0;i<s.size();i++){
		    if (s[i]==j){
		    	if (old==-1){
		    		if (i) max=i+1;
		    		else max=i;
				}
		    	else if (i-old>max) max=i-old;
		    	old=i;
			}
	    }
	    if (s.size()-old>max) max=s.size()-old;
	    a[++cnt]=max;
	}
	int ans=1000005;
	for (int i=0;i<26;i++){
		if (a[i]<ans&&a[i]) ans=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int MAXN=100000;
int a[26];
int INF=10000000000;

int main(){
	string s;
	cin>>s;
	int cnt=-1;
	for (int i=0;i<26;i++) a[i]=INF;
	for (char j='a';j<='z';j++){
		int old=-1;
		int max=1;
		int n=-1;
		cnt++;
		for (int i=0;i<s.size();i++){
		    if (s[i]==j) {
		    	n=i;
		    	if (n-old>max) max=n-old;
		    	old=n;
			}
	    }
	    if (s.size()-n>max) max=n-old;
	    a[cnt]=max;
	}
	int ans=s.size()/2+1;
	for (int i=0;i<26;i++){
		if (a[i]<ans&&a[i]>0) ans=a[i];
	}
	cout<<ans<<endl;
	//aabacfor (int i=0;i<26;i++) cout<<a[i]<<" ";
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int MAXN=100000;
int a[26];
int INF=10000000000;

int main(){
	string s;
	cin>>s;
	int cnt=-1;
	for (int i=0;i<26;i++) a[i]=INF;
	for (char j='a';j<='z';j++){
		int old=-1;
		int max=1;
		int n=-1;
		cnt++;
		for (int i=0;i<s.size();i++){
		    if (s[i]==j) {
		    	n=i;
		    	if (n-old>max) max=n-old;
		    	old=n;
			}
	    }
	    if (s.size()-n>max) max=n-old;
	    a[cnt]=max;
	}
	int ans=(s.size()+1)/2;
	for (int i=0;i<26;i++){
		if (a[i]<ans&&a[i]>0) ans=a[i];
	}
	cout<<ans<<endl;
	for (int i=0;i<26;i++) cout<<a[i]<<" ";
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int MAXN=100000;
int a[26];
int INF=10000000000;

int main(){
	string s;
	cin>>s;
	int cnt=-1;
	for (int i=0;i<26;i++) a[i]=INF;
	for (char j='a';j<='z';j++){
		int old=-1;
		int max=0;
		int n=-1;
		cnt++;
		for (int i=0;i<s.size();i++){
		    if (s[i]==j) {
		    	n=i;
		    	if (n-old>max) max=n-old;
		    	old=n;
			}
	    }
	    if (s.size()-n>max) max=s.size()-old;
	    a[cnt]=max;
	}
	int ans=s.size()/2+1;
	for (int i=0;i<26;i++){
		if (a[i]<ans&&a[i]>0) ans=a[i];
	}
	cout<<ans<<endl;
	//for (int i=0;i<26;i++) cout<<a[i]<<" ";
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int MAXN=100000;
int a[26];
int INF=10000000000;

int main(){
	string s;
	cin>>s;
	int cnt=-1;
	for (int i=0;i<26;i++) a[i]=INF;
	for (char j='a';j<='z';j++){
		int old=-1;
		int max=1;
		int n=-1;
		cnt++;
		for (int i=0;i<s.size();i++){
		    if (s[i]==j) {
		    	n=i;
		    	if (n-old>max) max=n-old;
		    	old=n;
			}
	    }
	    if (s.size()-n>max) max=n-old;
	    a[cnt]=max;
	}
	int ans=(s.size()+1)/2;
	for (int i=0;i<26;i++){
		if (a[i]<ans&&a[i]>0) ans=a[i];
	}
	cout<<ans<<endl;
	//aabacfor (int i=0;i<26;i++) cout<<a[i]<<" ";
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s;
bool C(int x){
	int f[x]={0},a=0,l=0;
	char c=s[a++];
	for (int i=x;i<s.size();i++){
		if (c!=s[i]) f[i%x]=1;
		c=s[a++];
	}
	for (int i=0;i<x;i++) l|=f[i];
	return l;
}
int main(){
	cin>>s;
	int lbound=1,rbound=s.size(),last=0;
	while (lbound<rbound){
		int mid=(lbound+rbound)/2;
		if (last==mid){
			cout<<mid<<endl;
			return 0;
		}
		if (C(mid))
			lbound=mid-1;
		else
			rbound=mid;
		last=mid;
	}
	cout<<lbound;
	return 0;
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s;
bool C(int x){
	int last[26],now[26];
	for (int i=0;i<26;i++) last[i]=now[i]=0;
	bool l=0;
	char c=s[0];
	for (int i=0;i<x;i++) last[s[i]-'a']++;
	for (int i=0;i<26;i++) now[i]=last[i];
	for (int i=1;i<s.size()-x+1;i++){
		now[c-'a']--;now[s[i+x-1]-'a']++;
		for (int j=0;j<26;j++) last[j]=min(last[j],now[j]);
		c=s[i];
	}
	for (int i=0;i<26;i++) l|=max(0,last[i]);
	return l;
}
int main(){
	cin>>s;
	int lbound=1,rbound=s.size(),last=0;
	while (lbound<rbound){
		int mid=(lbound+rbound)/2;
		if (C(mid))
			rbound=mid;
		else
			lbound=mid+1;
		last=mid;
	}
	cout<<lbound;
	return 0;
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s;
bool C(int x){
	int last[26],now[26];
	for (int i=0;i<26;i++) last[i]=now[i]=0;
	bool l=0;
	char c=s[0];
	for (int i=0;i<x;i++) last[s[i]-'a']++;
	for (int i=0;i<26;i++) now[i]=last[i];
	for (int i=1;i<s.size()-x;i++){
		now[c-'a']--;now[s[i+x-1]-'a']++;
		for (int j=0;j<26;j++) last[j]=min(last[j],now[j]);
		c=s[i];
	}
	for (int i=0;i<26;i++) l|=max(0,last[i]);
	cout<<x<<' '<<l<<endl;
	return l;
}
int main(){
	cin>>s;
	int lbound=1,rbound=s.size(),last=0;
	while (lbound<rbound){
		int mid=(lbound+rbound)/2;
//		if (last==mid){
//			cout<<mid<<endl;
//			return 0;
//		}
		if (C(mid))
			rbound=mid;
		else
			lbound=mid+1;
		last=mid;
	}
	cout<<lbound;
	return 0;
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s;
bool C(int x){
	int last[26],now[26];
	for (int i=0;i<26;i++) last[i]=now[i]=0;
	bool l=0;
	char c=s[0];
	for (int i=0;i<x;i++) last[s[i]-'a']++;
	for (int i=0;i<26;i++) now[i]=last[i];
	for (int i=1;i<s.size()-x;i++){
		now[c-'a']--;now[s[i+x-1]-'a']++;
		for (int j=0;j<26;j++) last[j]=min(last[j],now[j]);
		c=s[i];
	}
	for (int i=0;i<26;i++) l|=max(0,last[i]);
	return l;
}
int main(){
	cin>>s;
	int lbound=1,rbound=s.size(),last=0;
	while (lbound<rbound){
		int mid=(lbound+rbound)/2;
		if (C(mid))
			rbound=mid;
		else
			lbound=mid+1;
		last=mid;
	}
	cout<<lbound;
	return 0;
}


#define ll long long
#include "bits/stdc++.h"
using namespace std;
const int N=1E5+2;
vector<ll>freq[N];
int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        freq[s[i]-'a'].push_back(i+1);

    }
    ll mini=1e9;
    ll maxi=0;
    int counter=0;
    for(int i=0;i<26;i++)
    {
        bool flag=true;

        for( int j=0;j+1<freq[i].size();j++)
        {
            maxi=max(freq[i][j+1]-freq[i][j] , maxi);

        }
        if(freq[i].size() > 0 )
        {
            maxi=max(maxi,(s.size()-freq[i][freq[i].size()-1]));
            maxi=max(maxi,freq[i][0]+1);

        }

        if(maxi==1e9)continue;
else
    {mini=min(mini,maxi);  }

    }

    cout<<mini<<" ";
    return 0;
}


#define ll long long
#include "bits/stdc++.h"
using namespace std;
const int N=1E5+2;
vector<ll>freq[N];
int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        freq[s[i]-'a'].push_back(i+1);

    }
ll mini;
    ll maxi=0;
    int counter=0;
    for(int i=0;i<26;i++)
    {
      //  bool flag=true;

 maxi=0;
        for(int j=0;j+1<freq[i].size();j++)
        {
            maxi=max(freq[i][j+1]-freq[i][j] , maxi);

        }
        if(freq[i].size() > 0 )
        {
            maxi=max(maxi,s.size()-freq[i][freq[i].size()-1]);
            maxi=max(maxi,freq[i][0]+1);

        }

        if(maxi==0)continue;
else {mini=min(mini,maxi);  }

    }

    cout<<mini<<" ";
    return 0;
}


#define ll long long
#include "bits/stdc++.h"
using namespace std;
const int N=1E5+2;
vector<ll>freq[N];
int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        freq[s[i]-'a'].push_back(i);

    }
ll mini=1e9;
    ll maxi=0;

    for(int i=0;i<26;i++)
    {

 maxi=-1;
        for(int j=0;j+1<freq[i].size();j++)
        {
            maxi=max(freq[i][j+1]-freq[i][j] , maxi);

        }
        if(freq[i].size() > 0 )
        {
            maxi=max(maxi,s.size()-freq[i][freq[i].size()-1]);
            maxi=max(maxi,freq[i][0]+1);

        }

        if(maxi!=-1){mini=min(mini,maxi);  }

    }

    cout<<mini<<" ";
    return 0;
}


#define ll long long
#include "bits/stdc++.h"
using namespace std;
const int N=1E5+2;
vector<ll>freq[N];
int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        freq[s[i]-'a'].push_back(i+1);

    }
    ll mini=1e9;
    ll maxi=1;
    int counter=0;
    for(int i=0;i<26;i++)
    {
        bool flag=true;

        for( int j=0;j+1<freq[i].size();j++)
        {
            maxi=max(freq[i][j+1]-freq[i][j] , maxi);

        }
        if(freq[i].size() > 0 )
        {
            maxi=max(maxi,(s.size()-freq[i][freq[i].size()-1]));
            maxi=max(maxi,freq[i][0]+1);

        }

        if(maxi==1e9)continue;
else
    {mini=min(mini,maxi);  }

    }

    cout<<mini<<" ";
    return 0;
}


#define ll long long
#include "bits/stdc++.h"
using namespace std;
const int N=1E5+2;
vector<ll>freq[N];
int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        freq[s[i]-'a'].push_back(i+1);

    }
ll mini;
    ll maxi=0;
    int counter=0;
    for(int i=0;i<26;i++)
    {
      //  bool flag=true;

 maxi=-1e9;
        for(int j=0;j+1<freq[i].size();j++)
        {
            maxi=max(freq[i][j+1]-freq[i][j] , maxi);

        }
        if(freq[i].size() > 0 )
        {
            maxi=max(maxi,s.size()-freq[i][freq[i].size()-1]);
            maxi=max(maxi,freq[i][0]);

        }

        if(maxi!=-1e9){mini=min(mini,maxi);  }

    }

    cout<<mini<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
int main()
{
    int n;
    cin>>n;
    int arr[n];
     int store[100009];
     memset(store,0,sizeof(store));
     set<int>s;
     for(int i=0;i<n;++i)
        cin>>arr[i];
     for(int i=0;i<n;++i)
     {
         store[arr[i]]=s.size();
         s.insert(arr[i]);
     }
     int sum=0;
     for(int i=0;i<100001;++i)
     {
         sum+=store[i];
     }
     cout<<sum<<endl;
     return 0;
}


// finishing
// #492 Div. 2
// C
// https://codeforces.com/blog/entry/60443
// https://codeforces.com/submissions/c3n34ka

#include <iostream>
#include <vector>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    std::cin >> n;

    std::vector<int> V(n);
    std::vector<bool> passed(100001, false);
    std::vector<bool> passedGeneral(100001, false);

    for(int ii = 0; ii < n; ++ii) {
        std::cin >> V[ii];
        if(!passedGeneral[V[ii]]) {
             passed[ii] = true;
             passedGeneral[V[ii]] = true;
        }
    }

    int cont = 0, res = 0;
    for(int jj = n-1; jj >= 0; --jj) {
        if(passed[jj]) {
            res += cont;
        }
        ++cont;
    }
    //printVector(V);
    std::cout << res << std::endl;
}


// finishing
// #492 Div. 2
// C

#include <iostream>
#include <vector>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    int l = 0;
    std::cin >> n;

    std::vector<int> V(n);
    for(int ii = 0; ii < n; ++ii) {
        std::cin >> V[ii];
    }
    std::vector<bool> passed(100001, false);
    std::vector<bool> passedGeneral(100001, false);

    int res = 0;
    for(int ii = l; ii < n; ++ii) {
        for(int jj = n-1; jj > ii; --jj) {
            if(!passed[V[jj]] && !passedGeneral[V[ii]]) {
                //printPairs(V[ii], V[jj]);
                passed[V[jj]] = true;
                ++res;
            }
        }
        passedGeneral[V[ii]] = true;
        resetVector(passed);
    }
    //printVector(V);
    std::cout << res << std::endl;
}


// finishing
// #492 Div. 2
// C

#include <iostream>
#include <vector>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    std::cin >> n;

    std::vector<int> V(n);
    std::vector<bool> passed(100001, false);
    std::vector<bool> passedGeneral(100001, false);

    for(int ii = 0; ii < n; ++ii) {
        std::cin >> V[ii];
        if(!passedGeneral[V[ii]]) {
             passed[ii] = true;
             passedGeneral[V[ii]] = true;
        }
    }

    int cont = 0, res = 0;
    for(int jj = n-1; jj > 0; --jj) {
        if(passed[jj]) {
            res += cont;
        }
        ++cont;
    }
    //printVector(V);
    std::cout << res << std::endl;
}


// finishing
// #492 Div. 2
// C
// https://codeforces.com/blog/entry/60443
// https://codeforces.com/submissions/c3n34ka

#include <iostream>
#include <vector>
#include <set>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    std::cin >> n;

    std::set<int> passed;
    std::set<int> passedGeneral;

    std::vector<bool> V(n, false);
    std::vector<int> in(n);
    for(int ii = 0; ii < n; ++ii) {
        std::cin >> in[ii];
        if(passed.count(in[ii]) == 0) {
            passed.insert(in[ii]);
            V[ii] = true;
        }
    }

    int res = 0;
    for(int jj = n-1; jj >= 0; --jj) {
        if(V[jj]) {
            res += passedGeneral.size();
        }
        passedGeneral.insert(in[jj]);
    }

    std::cout << res << std::endl;
}


// finishing
// #492 Div. 2
// C
// https://codeforces.com/blog/entry/60443
// https://codeforces.com/submissions/c3n34ka

#include <iostream>
#include <vector>
#include <set>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    int l = 0;
    std::cin >> n;

    std::vector<int> V(n);
    for(int ii = 0; ii < n; ++ii) {
        std::cin >> V[ii];
    }
    std::set<int> passed;
    std::set<int> passedGeneral;

    int res = 0;
    for(int ii = l; ii < n; ++ii) {
        for(int jj = n-1; jj > ii; --jj) {
            if((passed.count(V[jj]) == 0) && (passedGeneral.count(V[ii]) == 0)) {
                //printPairs(V[ii], V[jj]);
                passed.insert(V[jj]);
                ++res;
            }
        }
        passedGeneral.insert(V[ii]);
        passed.clear();
        //resetVector(passed);
    }
    //printVector(V);
    std::cout << res << std::endl;
}


// finishing
// #492 Div. 2
// C
// https://codeforces.com/blog/entry/60443
// https://codeforces.com/submissions/c3n34ka

#include <iostream>
#include <vector>
#include <set>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    std::cin >> n;

    std::set<int> passed;
    std::set<int> passedGeneral;

    std::vector<bool> V(n, false);
    std::vector<int> in(n);
    for(int ii = 0; ii < n; ++ii) {
        std::cin >> in[ii];
        if(passed.count(in[ii]) == 0) {
            passed.insert(in[ii]);
            V[ii] = true;
        }
    }

    long long res = 0;
    for(int jj = n-1; jj >= 0; --jj) {
        if(V[jj]) {
            res += passedGeneral.size();
        }
        passedGeneral.insert(in[jj]);
    }

    std::cout << res << std::endl;
}


// finishing
// #492 Div. 2
// C

#include <iostream>
#include <vector>
#include <set>

void printVector(std::vector<int> &v) {
	for(int ii = 0; ii < (int)v.size(); ii++) {
		std::cout << v[ii];
	}
}

void resetVector(std::vector<bool> &v) {
    for(int ii = 0; ii < (int)v.size(); ii++) {
		v[ii] = false;
	}
}

void printPairs(int a, int b) {
    std::cout << "(" << a << "," << b;
    std::cout << ")" << std::endl;
}

int main() {
    int n;
    std::cin >> n;

    std::vector<bool> P(100001, false);
    std::set<int> passedGeneral;

    std::vector<bool> firstItem(n, false);
    std::vector<int> in(n);
    for(int ii = 0; ii < n; ++ii) {
        std::cin >> in[ii];
        if(!P[in[ii]]) {
            P[in[ii]] = true;
            firstItem[ii] = true;
        }
    }

    long long res = 0;
    for(int jj = n-1; jj >= 0; --jj) {
        if(firstItem[jj]) {
            res += passedGeneral.size();
        }
        passedGeneral.insert(in[jj]);
    }

    std::cout << res << std::endl;
}


#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define mp make_pair
#define pb push_back
#define p(k) printf("%d ",k)
#define pl(k) printf("%lld ",k)
#define pn(k) printf("%d\n",k)
#define pln(k) printf("%lld\n",k)
#define ps(str) printf("%s",str)
#define s(k) scanf("%d",&k)
#define sl(k) scanf("%lld",&k)
#define ss(str) scanf("%s",str)

using namespace std;

ll h1[100005];
ll h2[100005];
int main(){
	ll n,i,count,sum;
	cin>>n;
	ll a[n];ll inleft[n];
	for(i=0;i<100005;i++) h1[i]=0,h2[i]=0;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	count1=0;
	for(i=n-1;i>=0;i--){
		if(h1[a[i]]==0){
			count1++;
			h1[a[i]]=1;
		}
		inleft[i]=count1;
	}
	sum=0;
	for(i=0;i<n-1;i++){
		if(h2[a[i]]==0&&a[i]!=a[i+1]){
			h2[a[i]]=1;
			sum+=inleft[i+1];
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define mp make_pair
#define pb push_back
#define p(k) printf("%d ",k)
#define pl(k) printf("%lld ",k)
#define pn(k) printf("%d\n",k)
#define pln(k) printf("%lld\n",k)
#define ps(str) printf("%s",str)
#define s(k) scanf("%d",&k)
#define sl(k) scanf("%lld",&k)
#define ss(str) scanf("%s",str)

using namespace std;

int h1[100005];
int h2[100005];
int main(){
	ll n,i,count,sum;
	cin>>n;
	ll a[n];ll inleft[n];
	for(i=0;i<100005;i++) h1[i]=0,h2[i]=0;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	count=0;
	for(i=n-1;i>=0;i--){
		if(h1[a[i]]==0){
			count++;
			h1[a[i]]=1;
		}
		inleft[i]=count;
	}
	sum=0;
	for(i=0;i<n-1;i++){
		if(h2[a[i]]==0&&a[i]!=a[i+1]){
			h2[a[i]]=1;
			sum+=inleft[i+1];
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define mp make_pair
#define pb push_back
#define p(k) printf("%d ",k)
#define pl(k) printf("%lld ",k)
#define pn(k) printf("%d\n",k)
#define pln(k) printf("%lld\n",k)
#define ps(str) printf("%s",str)
#define s(k) scanf("%d",&k)
#define sl(k) scanf("%lld",&k)
#define ss(str) scanf("%s",str)

using namespace std;

ll h1[100005];
ll h2[100005];
int main(){
	ll n,i,count1,sum;
	cin>>n;
	ll a[n];ll inleft[n];
	for(i=0;i<100005;i++) h1[i]=0,h2[i]=0;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	count1=0;
	for(i=n-1;i>=0;i--){
		if(h1[a[i]]==0){
			count1++;
			h1[a[i]]=1;
		}
		inleft[i]=count1;
	}
	sum=0;
	for(i=0;i<n-1;i++){
		if(h2[a[i]]==0&&a[i]!=a[i+1]){
			h2[a[i]]=1;
			sum+=inleft[i+1];
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define mp make_pair
#define pb push_back
#define p(k) printf("%d ",k)
#define pl(k) printf("%lld ",k)
#define pn(k) printf("%d\n",k)
#define pln(k) printf("%lld\n",k)
#define ps(str) printf("%s",str)
#define s(k) scanf("%d",&k)
#define sl(k) scanf("%lld",&k)
#define ss(str) scanf("%s",str)

using namespace std;

ll h1[100005];
ll h2[100005];
int main(){
	ll n,i,count1,sum;
	cin>>n;
	ll a[n];ll inleft[n];
	for(i=0;i<100005;i++) h1[i]=0,h2[i]=0;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	count1=0;
	for(i=n-1;i>=0;i--){
		if(h1[a[i]]==0){
			count1++;
			h1[a[i]]=1;
		}
		inleft[i]=count1;
	}
	sum=0;
	for(i=0;i<n-1;i++){
		if(h2[a[i]]==0){
			h2[a[i]]=1;
			sum+=inleft[i+1];
		}
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define mp make_pair
#define pb push_back
#define p(k) printf("%d ",k)
#define pl(k) printf("%lld ",k)
#define pn(k) printf("%d\n",k)
#define pln(k) printf("%lld\n",k)
#define ps(str) printf("%s",str)
#define s(k) scanf("%d",&k)
#define sl(k) scanf("%lld",&k)
#define ss(str) scanf("%s",str)

using namespace std;

ll h1[100005];
ll h2[100005];
int main(){
	ll n,i,count,sum;
	cin>>n;
	ll a[n];ll inleft[n];
	for(i=0;i<100005;i++) h1[i]=0,h2[i]=0;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	count=0;
	for(i=n-1;i>=0;i--){
		if(h1[a[i]]==0){
			count++;
			h1[a[i]]=1;
		}
		inleft[i]=count;
	}
	sum=0;
	for(i=0;i<n-1;i++){
		if(h2[a[i]]==0&&a[i]!=a[i+1]){
			h2[a[i]]=1;
			sum+=inleft[i+1];
		}
	}
	cout<<sum;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
typedef long long ll;

int main(){

    ll n; scanf("%lld", &n);
    std::vector<ll> v(n); for(ll p = 0; p < n; p++){scanf("%lld", &v[p]);}
    std::vector<ll> right(n);
    std::set<ll> ls, rs;
    std::vector<ll> rq(n, 0);

    for(ll p = n - 1; p >= 0; p--){rs.insert(v[p]); rq[p] = rs.size();}
    ll cnt(0);
    for(ll p = 0; p < n - 1; p++){
        if(ls.count(v[p])){continue;}
        ls.insert(v[p]); cnt += rq[p + 1];
    }

    printf("%lld\n", cnt);

    return 0;
}


#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n, m;
	int i;
	int arr[100001], acc[100001];
	bool visited1[100001] = { 0, }, visited2[100001] = { 0, };
	int sol = 0;

	scanf("%d", &n);

	scanf("%d", &arr[0]);
	visited1[arr[0]] = true;
	acc[0] = 1;

	for (i = 1; i < n; i++)
	{
		scanf("%d", &arr[i]);

		if (!visited1[arr[i]])
		{
			visited1[arr[i]] = true;

			acc[i] = acc[i - 1] + 1;
		}

		else
		{
			acc[i] = acc[i - 1];
		}
	}

	for (i = n - 1; i >= 1; i--)
	{
		if (!visited2[arr[i]])
		{
			visited2[arr[i]] = true;

			sol += acc[i - 1];
		}
	}

	printf("%d\n", sol);

	return 0;
}


#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n, m;
	int i;
	int arr[100000], acc[100000];
	bool visited1[100000] = { 0, }, visited2[100000] = { 0, };
	int sol = 0;

	scanf("%d", &n);

	scanf("%d", &arr[0]);
	visited1[arr[0]] = true;
	acc[0] = 1;

	for (i = 1; i < n; i++)
	{
		scanf("%d", &arr[i]);

		if (!visited1[arr[i]])
		{
			visited1[arr[i]] = true;

			acc[i] = acc[i - 1] + 1;
		}

		else
		{
			acc[i] = acc[i - 1];
		}
	}

	for (i = n - 1; i >= 1; i--)
	{
		if (!visited2[arr[i]])
		{
			visited2[arr[i]] = true;

			sol += acc[i - 1];
		}
	}

	printf("%d\n", sol);

	return 0;
}


#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	long long n, m;
	long long i;
	long long arr[100001], acc[100001];
	bool visited1[100001] = { 0, }, visited2[100001] = { 0, };
	long long sol = 0;

	scanf("%lld", &n);

	scanf("%lld", &arr[0]);
	visited1[arr[0]] = true;
	acc[0] = 1;

	for (i = 1; i < n; i++)
	{
		scanf("%lld", &arr[i]);

		if (!visited1[arr[i]])
		{
			visited1[arr[i]] = true;

			acc[i] = acc[i - 1] + 1;
		}

		else
		{
			acc[i] = acc[i - 1];
		}
	}

	for (i = n - 1; i >= 1; i--)
	{
		if (!visited2[arr[i]])
		{
			visited2[arr[i]] = true;

			sol += acc[i - 1];
		}
	}

	printf("%lld\n", sol);

	return 0;
}


#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 101000;
const ll INF = 1e18+1;

int n, a[N];
int l[N], r[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) r[a[i]] = i;
    for (int i = n; i >= 1; i--) l[a[i]] = i;
    sort(l + 1, l + 100000 + 1);
    sort(r + 1, r + 100000 + 1);
    int j = 1;
    ll res = 0;
    for (int i = 1; i <= 100000; i++) {
        if (l[i] == 0) continue;
        while (j <= 100000 && r[j] <= l[i]) j++;
        res += 100000 - j + 1;
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <set>
#define ll long long
using namespace std;

int n, a[100001], b[100001], c[100001];
ll ans = 0;

int main()
{
	set<int>A, B;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
		A.insert(a[i]), b[i] = A.size();
	for (int u = n; u > 1; u--)
		B.insert(a[u]), c[u] = B.size();
	for (int i = 1; i < n; i++)
		if (b[i] != b[i - 1])
			ans += c[i + 1];
	cout << ans;
	return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
#define N 100005
//#define mod 1000000007
#define For for(long long i=1;i<=n;i++)
#define For2 for(long long j=0;j<m;j++)
#define ll long long
const ll MOD = 1e9 + 7;
const ll base = 269;
// for(long long i=1;i<=n;i++)
/*
MIKUNO - 15/02/1999
*/
//const int nmax = 2e5 + 5;
int n, x, temp, rs;
vector<int> a[N];
int b[N], it[N], check[N];
void update(int i, int val)
{
	for (; i <= N; i += i & -i)
		it[i] += val;
}
int get(int i)
{
	int ret = 0;
	for (; i; i -= i & -i)
		ret += it[i];
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	int maxx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		a[b[i]].push_back(i);
		maxx = max(maxx, b[i]);
	}
	for (int i = 0; i <= maxx; i++)
	{
		if (a[i].size())
			update(i, 1);
	}
	for (int i = 0; i < n - 1; i++)
	{
		int val = b[i], ret = 0;
		if (!check[val])
		{
			ret += get(maxx) - 1;
			if (a[val].size() > 1) ret++;

			rs += ret;
			check[val]++;
		}
		a[val].erase(a[val].begin());
		if (!a[val].size()) update(val, -1);
	}
	cout << rs;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
#define N 100005
//#define mod 1000000007
#define For for(long long i=1;i<=n;i++)
#define For2 for(long long j=0;j<m;j++)
#define ll long long
const ll MOD = 1e9 + 7;
const ll base = 269;
// for(long long i=1;i<=n;i++)
/*
MIKUNO - 15/02/1999
*/
//const int nmax = 2e5 + 5;
int n, x, temp, rs;
vector<int> a[N];
int b[N], it[N], check[N];
void update(int i, int val)
{
	for (; i <= N; i += i & -i)
		it[i] += val;
}
int get(int i)
{
	int ret = 0;
	for (; i; i -= i & -i)
		ret += it[i];
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	int maxx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		a[b[i]].push_back(i);
		maxx = max(maxx, b[i]);
	}
	for (int i = 0; i <= maxx; i++)
	{
		if (a[i].size())
			update(i, 1);
	}
	for (int i = 0; i < n - 1; i++)
	{
		int val = b[i], ret = 0;
		if (!check[val])
		{
			ret += get(maxx) - 1;
			if (a[val].size() > 1) ret++;

			rs += ret;
			check[val]++;
		}
		a[val].erase(a[val].begin());
		if (!a[val].size()) update(val, -1);
	}
	if (n == 1) { cout << 1; return 0; }
	cout << rs;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
#define N 100005
//#define mod 1000000007
#define For for(long long i=1;i<=n;i++)
#define For2 for(long long j=0;j<m;j++)
#define ll long long
const ll MOD = 1e9 + 7;
const ll base = 269;
// for(long long i=1;i<=n;i++)
/*
MIKUNO - 15/02/1999
*/
//const int nmax = 2e5 + 5;
ll n, x, temp, rs;
vector<ll> a[N];
ll b[N], it[N], check[N];
void update(int i, int val)
{
	for (; i <= N; i += i & -i)
		it[i] += val;
}
int get(int i)
{
	int ret = 0;
	for (; i; i -= i & -i)
		ret += it[i];
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	ll maxx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		a[b[i]].push_back(i);
		maxx = max(maxx, b[i]);
	}
	for (int i = 0; i <= maxx; i++)
	{
		if (a[i].size())
			update(i, 1);
	}
	for (int i = 0; i < n - 1; i++)
	{
		int val = b[i], ret = 0;
		if (!check[val])
		{
			ret += get(maxx) - 1;
			if (a[val].size() > 1) ret++;

			rs += ret;
			check[val]++;
		}
		a[val].erase(a[val].begin());
		if (!a[val].size()) update(val, -1);
	}
	//if (n == 1) { cout << 1; return 0; }
	cout << rs;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
#define N 100005
//#define mod 1000000007
#define For for(long long i=1;i<=n;i++)
#define For2 for(long long j=0;j<m;j++)
#define ll long long
const ll MOD = 1e9 + 7;
const ll base = 269;
// for(long long i=1;i<=n;i++)
/*
MIKUNO - 15/02/1999
*/
//const int nmax = 2e5 + 5;
ll n, x, temp, rs;
ll b[N];
map<int, int> check, a;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	ll maxx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		a[b[i]]++;
	}
	for (int i = 0; i < n - 1; i++)
	{
		if (a[b[i]]&&!check[b[i]])
			rs += a.size() -  1 + (a[b[i]]-- > 1 ? 1 : 0);
		if (!a[b[i]])
			a.erase(b[i]);
		check[b[i]]++;
	}
	cout << rs;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
#define N 100005
//#define mod 1000000007
#define For for(long long i=1;i<=n;i++)
#define For2 for(long long j=0;j<m;j++)
#define ll long long
const ll MOD = 1e9 + 7;
const ll base = 269;
// for(long long i=1;i<=n;i++)
/*
MIKUNO - 15/02/1999
*/
//const int nmax = 2e5 + 5;
ll n, x, temp, rs;
ll b[N];
map<int, int> check, a;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	ll maxx = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		a[b[i]]++;
	}
	for (int i = 0; i < n; i++)
	{
		if (a[b[i]])
			rs += a.size() + a[b[i]]-- > 1 ? 1 : 0;
		if (!a[b[i]])
			a.erase(b[i]);
	}
	cout << rs;
	//system("pause");
	return 0;
}


#include<cstdio>
#include<memory.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<string.h>
#include<queue>
int n, arr[200000], temp[200000] = {}, ans = 0;
using namespace std;
int main()
{
	bool chk[200000] = {}, chk2[200000] = {};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)scanf("%d", &arr[i]);
	for (int i = n-1; i >= 0; i--) {
		if (chk[arr[i]]) {
			temp[i] = temp[i + 1];
		}
		else {
			temp[i] = temp[i + 1] + 1;
			chk[arr[i]] = true;
		}
	}
	for (int i = 0; i < n; i++) {
		if (chk2[arr[i]])continue;
		else {
			chk2[arr[i]] = true;
			ans += temp[i + 1];
		}
	}
	printf("%d", ans);
	return 0;
}