#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int N=620000;
int p,np,cnt;
int fa[N],c[N][30],mx[N],rt[N],R[N],pre[30][N],bb[N],b[N];
void extend(int w,int k,int w2)
{
p=np; mx[np=++cnt]=mx[p]+1;
rt[np]=k;
R[np]=1<<w2;
for (; p&&!c[p][w]; p=fa[p]) c[p][w]=np;
if (!p) fa[np]=1;
else
{
int q=c[p][w];
if (mx[q]==mx[p]+1) fa[np]=q;
else
{
int nq=++cnt; mx[nq]=mx[p]+1;
memcpy(c[nq],c[q],sizeof c[nq]);
fa[nq]=fa[q]; fa[q]=fa[np]=nq;
for (; p&&c[p][w]==q; p=fa[p]) c[p][w]=nq;
}
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
string st; cin>>st;
int n=st.size();
np=cnt=1;
for (int i=0; i<n; ++i)
{
extend(st[i]-'a',i,(i==n-1?30:st[i+1]-'a'));
}
for (int i=1; i<=cnt; ++i) ++bb[mx[i]];
for (int i=1; i<=n; ++i) bb[i]+=bb[i-1];
for (int i=1; i<=cnt; ++i) b[bb[mx[i]]--]=i;
for (int k=0; k<26; ++k)
{
for (int i=0; i<n; ++i)
{
pre[k][i+1]=pre[k][i]+(st[i]-'a'==k);
}
}
int ans=0;
for (int i=cnt; i>1; --i)
{
int x=b[i];
int l=rt[x]-mx[x]+1,r=rt[x]-mx[fa[x]]+1;
cerr<<rt[x]<<' '<<l<<' '<<r<<endl;
for (int j=0; j<26; ++j)
{
if (R[x]>>j&1)
{
int num=pre[j][r]-pre[j][l];
ans+=num;
}
}
R[fa[x]]|=R[x];
rt[fa[x]]=rt[x];
}
for (int k=0; k<30; ++k) if (pre[k][n]) ++ans;
cout<<ans<<'\n';
}
4 0 5
3 0 3
2 0 2
1 0 2
2 2 3