#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <cmath>
#define MAX 1000010
using namespace std;
ifstream fin("savemzx.in");
ofstream fout("savemzx.out");
char str[MAX];
long long p[MAX];
int n;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv)
{
fin>>str+1;
n=strlen(str+1);
p[1]=1;
for(long long i=2;i<=n;i++)
{
if(str[i]!=str[1])
p[i]=i*i;
else
{
long long temp=1;
while(str[i]==str[temp]&&i<=n)
{
p[i]=(i-temp)*(i-temp)+p[temp];
temp++,i++;
}
}
}
sort(p+1,p+1+n);
fout<<p[n]+p[n-1]<<endl;
return 0;
}