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

int n, m, k, vv, comp;

int calc(int el) {
    if(el == comp && !vv) {
        vv = 1;
        return 1000;
    }

    return el;
}

bool ver(int a, int b) {
    int d1, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));
    vv = 0; comp = d1;

    d2 = min(d2, calc(a));
    d2 = min(d2, calc(b));
    d2 = min(d2, calc(n - a + 1));
    d2 = min(d2, calc(m - b + 1));

    if(d1 > 9)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


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

int n, m, k, vv, comp;

bool ver(int a, int b) {
    int d1 = 1000, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));

    if(d1 > 7)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


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

int n, m, k, vv, comp;

bool ver(int a, int b) {
    int d1 = 1000, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));

    if(d1 > 6)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


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

int n, m, k, vv, comp;

int calc(int el) {
    if(el == comp && !vv) {
        vv = 1;
        return 1000;
    }

    return el;
}

bool ver(int a, int b) {
    int d1, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));
    vv = 0; comp = d1;

    d2 = min(d2, calc(a));
    d2 = min(d2, calc(b));
    d2 = min(d2, calc(n - a + 1));
    d2 = min(d2, calc(m - b + 1));

    if(d1 > 7)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


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

int n, m, k, vv, comp;

bool ver(int a, int b) {
    int d1 = 1000, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));

    if(d1 > 9)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int judge=1;
    int x,y;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        if(judge)
        {
            if(abs(x-1)<=1||abs(y-1)<=1||abs(x-n)<=1||abs(y-m)<=1)
                judge--;
        }
    }
    if(judge) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int judge=1;
    int x,y;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        if(judge)
        {
            if(abs(x-1)<=2||abs(y-1)<=2||abs(x-n)<=2||abs(y-m)<=2)
                judge--;
        }
    }
    if(judge) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int judge=1;
    int x,y;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        if(judge)
        {
            if(abs(x-1)<=3||abs(y-1)<=3||abs(x-n)<=3||abs(y-m)<=3)
                judge--;
        }
    }
    if(judge) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int judge=1;
    int x,y;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        if(judge)
        {
            if(abs(x-1)<=4||abs(y-1)<=4||abs(x-n)<=4||abs(y-m)<=4)
                judge--;
        }
    }
    if(judge) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e5 + 5;

ll cnt[200];
ll tot[200];
ll ans[200];
bool vis[200];
char ch[MAXN];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int k=s[i]-'a';
		cnt[k]++;
		ch[i]=s[i];
	}
	char ch1,ch2;
	int t1,t2;
	for(int i=0;i<26;i++){
		tot[i]=cnt[i];
	}
	sort(cnt,cnt+26,greater<ll>());
	for(int i=0;i<26;i++){
		if(tot[i]==cnt[0]){
			ch1='a'+i;
			vis[i]=1;
			break;
		}
	}
	for(int i=0;i<26;i++){
		if(tot[i]==cnt[1] && cnt[1]>0 && !vis[i]){
			ch2='a'+i;
			vis[i]=1;
			break;
		}
	}
	ll res1=0,res2=0,res=0;
	ll base=cnt[1];
	for(int i=0;i<s.size();i++){
		if(s[i]==ch1){
			res1+=base;
		}
		else if(s[i]==ch2){
			base--;
		}
	}
	base=cnt[0];
	for(int i=0;i<s.size();i++){
		if(s[i]==ch2){
			res2+=base;
		}
		else if(s[i]==ch1){
			base--;
		}
	}
	ans[0]=max(res1,res2);
	ans[1]=cnt[0]*(cnt[0]-1)/2;
	ans[2]=cnt[0];
	cout<<*max_element(ans,ans+3);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

ll cnt[200];
ll ans[200];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int k=s[i]-'a';
		cnt[k]++;
	}
	sort(cnt,cnt+26,greater<ll>());
	ans[0]=cnt[1]*cnt[0];
	ans[1]=cnt[0]*(cnt[0]-1)/2;
	ans[2]=cnt[0];
	cout<<*max_element(ans,ans+3);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

ll cnt[200];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int k=s[i]-'a';
		cnt[k]++;
	}
	sort(cnt,cnt+26,greater<ll>());
	if(cnt[1]>0) cout<<cnt[1]*cnt[0]<<endl;
	else if(cnt[0]>3) cout<<cnt[0]*(cnt[0]-1)/2<<endl;
	else cout<<cnt[0]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

ll dp[30][30],a[30];
ll res;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int t=s[i]-'a';
		for(int j=0;j<26;j++){
			dp[t][j]+=a[j];
			res=max(res,dp[t][j]);
		}
		a[t]++;
		res=max(res,a[t]);
	}
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;
const ll N =200;

ll cnt[N];
ll tot[N];
bool vis[N];
ll res[N];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int k=s[i]-'a';
		cnt[k]++;
		tot[k]++;
	}
	sort(cnt,cnt+26,greater<ll>());
	char ch0,ch1;
	for(int i=0;i<26;i++){
		if(tot[i]==cnt[0]){
			ch0='a'+i;
			vis[i]=1;
			break;
		}
	}
	for(int i=0;i<26;i++){
		if(tot[i]==cnt[1] && !vis[i]){
			ch1='a'+i;
			vis[i]=1;
			break;
		}
	}
	ll base=cnt[1],ans1=0,ans2=0;
	for(int i=0;i<s.size();i++){
		if(s[i]==ch0){
			ans1+=base;
		}
		else if(s[i]==ch1){
			base--;
		}
	}
	base=cnt[0];
	for(int i=0;i<s.size();i++){
		if(s[i]==ch1){
			ans2+=base;
		}
		else if(s[i]==ch0){
			base--;
		}
	}
	res[0]=max(ans1,ans2);
	res[1]=max(res[0],cnt[0]);
	res[2]=max(res[1],cnt[0]*(cnt[0]-1)/2);
	cout<<res[2];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;
const ll N =200;

ll cnt[N];
ll tot[N];
bool vis[N];
ll res[N];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		ll k=s[i]-'a';
		cnt[k]++;
		tot[k]++;
	}
	sort(cnt,cnt+26,greater<int>());
//	for(int i=0;i<26;i++){
//		cout<<"cnt["<<i<<"]="<<cnt[i]<<endl;
//	}
	if(cnt[1]==0){
		cout<<max(cnt[0],(cnt[0]-1)*cnt[0]/2);
		return 0;
	}
	char ch0,ch1;
	for(ll i=0;i<26;i++){
		if(tot[i]==cnt[0]){
			ch0='a'+i;
			vis[i]=1;
			break;
		}
	}
	for(ll i=0;i<26;i++){
		if(tot[i]==cnt[1] && !vis[i]){
			ch1='a'+i;
			vis[i]=1;
			break;
		}
	}
	ll base=cnt[1],ans1=0,ans2=0,ans3=0,ans4=0;
	for(ll i=0;i<s.size();i++){
		if(s[i]==ch0){
			ans1+=base;
		}
		else if(s[i]==ch1){
			base--;
		}
		if(base==0) break;
	}
	base=cnt[0];
	for(ll i=0;i<s.size();i++){
		if(s[i]==ch1){
			ans2+=base;
		}
		else if(s[i]==ch0){
			base--;
		}
		if(base==0) break;
	}
	base=cnt[1];
	for(ll i=s.size()-1;i>=0;i--){
		if(s[i]==ch0){
			ans3+=base;
		}
		else if(s[i]==ch1){
			base--;
		}
		if(base==0) break;
	}
	base=cnt[0];
	for(ll i=s.size()-1;i>=0;i--){
		if(s[i]==ch1){
			ans4+=base;
		}
		else if(s[i]==ch0){
			base--;
		}
		if(base==0) break;
	}
	ans1=max(ans1,ans3);
	ans2=max(ans2,ans4);
	res[0]=max(1ll*ans1,1ll*ans2);
	res[1]=max(1ll*res[0],1ll*cnt[0]);
	res[2]=max(1ll*res[1],1ll*cnt[0]*(cnt[0]-1)/2);
	res[3]=max(res[2],cnt[1]);
	res[4]=max(res[3],(cnt[1]-1)*(cnt[1]/2));
	cout<<1ll*res[4];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;
const ll N =200;

ll cnt[N];
ll tot[N];
bool vis[N];
ll res[N];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		ll k=s[i]-'a';
		cnt[k]++;
		tot[k]++;
	}
	sort(cnt,cnt+26,greater<int>());
	char ch0,ch1;
	for(ll i=0;i<26;i++){
		if(tot[i]==cnt[0]){
			ch0='a'+i;
			vis[i]=1;
			break;
		}
	}
	for(ll i=0;i<26;i++){
		if(tot[i]==cnt[1] && !vis[i]){
			ch1='a'+i;
			vis[i]=1;
			break;
		}
	}
	ll base=cnt[1],ans1=0,ans2=0,ans3=0,ans4=0;
	for(ll i=0;i<s.size();i++){
		if(s[i]==ch0){
			ans1+=base;
		}
		else if(s[i]==ch1){
			base--;
		}
	}
	base=cnt[0];
	for(ll i=0;i<s.size();i++){
		if(s[i]==ch1){
			ans2+=base;
		}
		else if(s[i]==ch0){
			base--;
		}
	}
	base=cnt[1];
	for(ll i=s.size()-1;i>=0;i--){
		if(s[i]==ch0){
			ans3+=base;
		}
		else if(s[i]==ch1){
			base--;
		}
	}
	base=cnt[0];
	for(ll i=s.size()-1;i>=0;i--){
		if(s[i]==ch1){
			ans4+=base;
		}
		else if(s[i]==ch0){
			base--;
		}
	}
	ans1=max(ans1,ans3);
	ans2=max(ans2,ans4);
	res[0]=max(1ll*ans1,1ll*ans2);
	res[1]=max(1ll*res[0],1ll*cnt[0]);
	res[2]=max(1ll*res[1],1ll*cnt[0]*(cnt[0]-1)/2);
	res[3]=max(res[2],cnt[1]);
	res[4]=max(res[3],(cnt[1]-1)*(cnt[1]/2));
	cout<<1ll*res[4];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 100005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int pre[27];
int vis[27][27];
int cot[27];

int main() {
    std_quick_io();
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        pre[x[i]-'a']++;
    }
    int ans = 0;
    for(int i =0;i<27;i++)
    ans=max(pre[i],ans);
    for(int i = 0; i <x.size();i++) {
        for(int j =0;j<27;j++) {
            vis[j][x[i]-'a']+=cot[j];
        }
        cot[x[i]-'a']++;
    }
    for(int i =0;i<27;i++)
    for(int j = 0;j<27;j++)
    ans=max(ans,vis[i][j]);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 100005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int pre[maxn][27];
bool vis[27];

int main() {
    std_quick_io();
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        pre[i + 1][x[i]-'a'] = pre[i][x[i]-'a']+1;
        for(int j = 0;j<27;j++) {
            if((int)(x[i]-'a')!=j)
            pre[i+1][j]=pre[i][j];
        }
        vis[x[i]-'a']=true;
    }
    int ans = 0;
    for(int i =0;i<27;i++)
    ans=max(ans,pre[x.size()][i]);
    for(int i = 0; i <27;i++) {
        if(vis[i]) {
            for(int j = 0;j <27;j++) {
                if(j!=i&&vis[j]) {
                    int sum = 0;
                    int k =0;
                    while((int)(x[k]-'a')!=i)
                    k++;
                    for(; k<=x.size();k++) {
                        if((int)(x[k - 1] -'a')== j) {
                            sum+=pre[k - 1][i];
                        }
                    }
                    ans = max(sum,ans);
                }
            }
        }
    }
    int cot = 1;
    int now = 1;
    char w = x[0];
    for(int i = 1; i <x.size();i++) {
        if(x[i]==w){
            cot++;
        }else {
            now*=cot;
            cot = 1;
            w=x[i];
        }
    }
    now*=cot;
    ans=max(now,ans);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 100005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int pre[26];
int vis[26][26];
int cot[26];

int main() {
    std_quick_io();
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        pre[x[i]-'a']++;
    }
    int ans = 0;
    for(int i =0;i<26;i++)
    ans=max(pre[i],ans);
    for(int i = 0; i <x.size();i++) {
        for(int j =0;j<26;j++) {
            vis[j][x[i]-'a']+=cot[j];
        }
        cot[x[i]-'a']++;
    }
    for(int i =0;i<26;i++)
    for(int j = 0;j<26;j++)
    ans=max(ans,vis[i][j]);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 50005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    std_quick_io();
    map<char,int> s;
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        s[x[i]]++;
    }
    int ans = 0;
    for(auto it = s.begin(); it!=s.end();it++)
    ans=max(ans,it->second);
    int cot = 1;
    int now = 1;
    char w = x[0];
    for(int i = 1; i <x.size();i++) {
        if(x[i]==w){
            cot++;
        }else {
            now*=cot;
            cot = 1;
            w=x[i];
        }
    }
    now*=cot;
    ans=max(now,ans);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 50005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    std_quick_io();
    map<char,ll> s;
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        if(s.count(x[i]))
            s[x[i]]++;
        else
            s[x[i]]=1LL;
    }
    ll ans = 0;
    for(auto it = s.begin(); it!=s.end();it++)
    ans=max(ans,it->second);
    ll cot = 1;
    ll now = 1;
    char w = x[0];
    for(int i = 1; i <x.size();i++) {
        if(x[i]==w){
            cot++;
        }else {
            now*=cot;
            cot = 1LL;
            w=x[i];
        }
    }
    now*=cot;
    ans=max(now,ans);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 100005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll pre[26];
ll vis[26][26];
ll cot[26];

int main() {
    std_quick_io();
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        pre[x[i]-'a']++;
    }
    ll ans = 0;
    for(int i =0;i<26;i++)
    ans=max(pre[i],ans);
    for(int i = 0; i <x.size();i++) {
        int k=x[i]-'a';
        for(int j =0;j<26;j++) {
            vis[j][k]+=cot[j];
        }
        cot[k]++;
    }
    for(int i =0;i<26;i++)
    for(int j = 0;j<26;j++)
    ans=max(ans,vis[i][j]);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 100005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int pre[maxn][27];
bool vis[27];

int main() {
    std_quick_io();
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        pre[i + 1][x[i]-'a'] = pre[i][x[i]-'a']+1;
        for(int j = 0;j<27;j++) {
            if((int)(x[i]-'a')!=j)
            pre[i+1][j]=pre[i][j];
        }
        vis[x[i]-'a']=true;
    }
    int ans = 0;
    for(int i =0;i<27;i++)
    ans=max(ans,pre[x.size()][i]);
    for(int i = 0; i <27;i++) {
        if(vis[i]) {
            for(int j = 0;j <27;j++) {
                if(j!=i&&vis[j]) {
                    int sum = 0;
                    int k =0;
                    while((int)(x[k]-'a')!=i)
                    k++;
                    for(; k<=x.size();k++) {
                        if((int)(x[k - 1] -'a')== j) {
                            sum+=pre[k - 1][i];
                        }
                    }
                    ans = max(sum,ans);
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1000000009;
const int maxn = 100005;
const double PI = acos(-1);
void std_quick_io () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int pre[maxn][27];
bool vis[27];

int main() {
    std_quick_io();
    string x;
    cin>>x;
    for(int i = 0;i < x.size();i++) {
        pre[i + 1][x[i]-'a'] = pre[i][x[i]-'a']+1;
        for(int j = 0;j<27;j++) {
            if((int)(x[i]-'a')!=j)
            pre[i+1][j]=pre[i][j];
        }
        vis[x[i]-'a']=true;
    }
    int ans = 0;
    for(int i =0;i<27;i++)
    ans=max(ans,pre[x.size()][i]);
    for(int i = 0; i <27;i++) {
        if(vis[i]) {
            for(int j = 0;j <27;j++) {
                if(j!=i&&vis[j]) {
                    int sum = 0;
                    for(int k = 1; k<x.size();k++) {
                        if((int)(x[k] -'a')== j) {
                            sum+=pre[k][i];
                        }
                    }
                    ans = max(sum,ans);
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

int binary_search_f(vector<int>& temp,int x,int j){
    //vector<int> temp = letterCount[j];
    int end = temp.size();
    int start=0;
    while(start<=end){
        int middle=(int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will point to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will point to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    int n = s.length();
    vector< vector< int> > letterCount(26,vector<int>(0));
    int maxCurrent = 0;
    //cout<<n<<endl;
    for(int i=0;i<n;i++){
        int alp = s[i]-a;
        letterCount[alp].push_back(i);
        int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);
    }

    //cout<<maxCurrent<<endl;
    for(int i=0;i<26;i++){
        maxCurrent = max(maxCurrent,(int)((letterCount[i].size()*(letterCount[i].size()-1))/2));
        for(int j=0;j<26;j++){
            int count=0;
            if (i==j){continue;}
            vector<int> temp1 = letterCount[i];
            vector<int> temp2 = letterCount[j];
            int size2=temp2.size();
            int size1=temp1.size();
            if (size2!=0 && size1!=0){
            for(int a1=0;a1<temp1.size();a1++){
                    int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


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

using namespace std;

int binary_search_f(vector<int>& temp,int x,int j){
    //vector<int> temp = letterCount[j];
    int end = temp.size();
    int start=0;
    while(start<=end){
        int middle=(int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will point to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will point to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    int n = s.length();
    vector< vector< int> > letterCount(26,vector<int>(0));
    int maxCurrent = 0;
    //cout<<n<<endl;
    for(int i=0;i<n;i++){
        int alp = s[i]-a;
        letterCount[alp].push_back(i);
        int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);
    }

    //cout<<maxCurrent<<endl;
    for(int i=0;i<26;i++){
        maxCurrent = max(maxCurrent,(int)(letterCount[i].size()*(letterCount[i].size()-1)/2));
        for(int j=0;j<26;j++){
            int count=0;
            if (i==j){continue;}
            vector<int> temp1 = letterCount[i];
            vector<int> temp2 = letterCount[j];
            int size2=temp2.size();
            if (size2!=0){
            for(int a1=0;a1<temp1.size();a1++){
                    int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


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

using namespace std;

int binary_search_f(vector<int>& temp,int x,int j){
    //vector<int> temp = letterCount[j];
    int end = temp.size();
    int start=0;
    while(start<=end){
        int middle=(int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will point to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will point to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    int n = s.length();
    vector< vector< int> > letterCount(26,vector<int>(0));
    int maxCurrent = 0;
    //cout<<n<<endl;
    for(int i=0;i<n;i++){
        int alp = s[i]-a;
        letterCount[alp].push_back(i);
        int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);

    }
    //cout<<maxCurrent<<endl;
    for(int i=0;i<26;i++){
        for(int j=0;j<26;j++){
            int count=0;
            if (i==j){continue;}
            vector<int> temp1 = letterCount[i];
            vector<int> temp2 = letterCount[j];
            int size2=temp2.size();
            if (size2!=0){
            for(int a1=0;a1<temp1.size();a1++){
                    int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


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

using namespace std;

long long int binary_search_f(vector<long long int>& temp,long long int x,long long int j){
    //vector<long long int> temp = letterCount[j];
    long long int end = temp.size();
    long long int start=0;
    while(start<=end){
        long long int middle=(long long int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will polong long int to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will polong long int to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    long long int n = s.length();
    vector< vector< long long int> > letterCount(26,vector<long long int>(0));
    long long int maxCurrent = 0;
    //cout<<n<<endl;
    for(long long int i=0;i<n;i++){
        long long int alp = s[i]-a;
        letterCount[alp].push_back(i);
        long long int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);
    }

    for(int i=0;i<26;i++){
        long long int ncr = letterCount[i].size();
        if (ncr>0){
            long long int t = (long long int)((ncr*(ncr-1))/2);
            maxCurrent = max(maxCurrent,t);
        }
    }

    //cout<<maxCurrent<<endl;
    for(long long int i=0;i<26;i++){
        //maxCurrent = max(maxCurrent,(long long int)((letterCount[i].size()*(letterCount[i].size()-1))/2));

        for(long long int j=0;j<26;j++){
            long long int count=0;
            if (i==j){continue;}
            vector<long long int> temp1 = letterCount[i];
            vector<long long int> temp2 = letterCount[j];
            long long int size2=temp2.size();
            long long int size1=temp1.size();
            if (size2!=0 && size1!=0){
            for(long long int a1=0;a1<temp1.size();a1++){
                    long long int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


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

using namespace std;

long long int binary_search_f(vector<long long int>& temp,long long int x,long long int j){
    //vector<long long int> temp = letterCount[j];
    long long int end = temp.size();
    long long int start=0;
    while(start<=end){
        long long int middle=(long long int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will polong long int to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will polong long int to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    long long int n = s.length();
    vector< vector< long long int> > letterCount(26,vector<long long int>(0));
    long long int maxCurrent = 0;
    //cout<<n<<endl;
    for(long long int i=0;i<n;i++){
        long long int alp = s[i]-a;
        letterCount[alp].push_back(i);
        long long int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);
    }

    for(int i=0;i<26;i++){
        int ncr = letterCount[i].size();
        if (ncr>0){
            long long int t = (int)((ncr*(ncr-1))/2);
            maxCurrent = max(maxCurrent,t);
        }
    }

    //cout<<maxCurrent<<endl;
    for(long long int i=0;i<26;i++){
        //maxCurrent = max(maxCurrent,(long long int)((letterCount[i].size()*(letterCount[i].size()-1))/2));

        for(long long int j=0;j<26;j++){
            long long int count=0;
            if (i==j){continue;}
            vector<long long int> temp1 = letterCount[i];
            vector<long long int> temp2 = letterCount[j];
            long long int size2=temp2.size();
            long long int size1=temp1.size();
            if (size2!=0 && size1!=0){
            for(long long int a1=0;a1<temp1.size();a1++){
                    long long int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


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

using namespace std;

long long int binary_search_f(vector<long long int>& temp,long long int x,long long int j){
    //vector<long long int> temp = letterCount[j];
    long long int end = temp.size();
    long long int start=0;
    while(start<=end){
        long long int middle=(long long int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will polong long int to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will polong long int to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    long long int n = s.length();
    vector< vector< long long int> > letterCount(26,vector<long long int>(0));
    long long int maxCurrent = 0;
    //cout<<n<<endl;
    for(long long int i=0;i<n;i++){
        long long int alp = s[i]-a;
        letterCount[alp].push_back(i);
        long long int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);
    }

    //cout<<maxCurrent<<endl;
    for(long long int i=0;i<26;i++){
        maxCurrent = max(maxCurrent,(long long int)((letterCount[i].size()*(letterCount[i].size()-1))/2));
        for(long long int j=0;j<26;j++){
            long long int count=0;
            if (i==j){continue;}
            vector<long long int> temp1 = letterCount[i];
            vector<long long int> temp2 = letterCount[j];
            long long int size2=temp2.size();
            long long int size1=temp1.size();
            if (size2!=0 && size1!=0){
            for(long long int a1=0;a1<temp1.size();a1++){
                    long long int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


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

using namespace std;

int binary_search_f(vector<int>& temp,int x,int j){
    //vector<int> temp = letterCount[j];
    int end = temp.size();
    int start=0;
    while(start<=end){
        int middle=(int)((end+start)/2);
        if (temp[middle]>x){
            end=middle-1;
            //if ends here, end will point to max(smaller than x)
        }
        else{
            start=middle+1;
            //if ends here, end will point to
        }
    }
    return end;
}

int main(){
    string s;
    char a='a';

    cin>>s;
    int n = s.length();
    vector< vector< int> > letterCount(26,vector<int>(0));
    int maxCurrent = 0;
    //cout<<n<<endl;
    for(int i=0;i<n;i++){
        int alp = s[i]-a;
        letterCount[alp].push_back(i);
        int sizeCurrent = letterCount[alp].size();
        maxCurrent = max(maxCurrent,sizeCurrent);
    }

    //cout<<maxCurrent<<endl;
    for(int i=0;i<26;i++){
        maxCurrent = max(maxCurrent,(int)(letterCount[i].size()*(letterCount[i].size()-1)/2));
        for(int j=0;j<26;j++){
            int count=0;
            if (i==j){continue;}
            vector<int> temp1 = letterCount[i];
            vector<int> temp2 = letterCount[j];
            int size2=temp2.size();
            int size1=temp1.size();
            if (size2!=0 && size1!=0){
            for(int a1=0;a1<temp1.size();a1++){
                    int index = binary_search_f(temp2,temp1[a1],0);
                    count+=size2-index-1;
            }
            }
            maxCurrent=max(maxCurrent,count);
        }
    }
    cout<<maxCurrent<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
long long a[30], dp[N][30], dp2[N];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	int mx2 = 0;
	for (int i = 0;  i < s.size(); i++) {
		for (int j = 0; j < 30; j++) {
			dp[s[i] - 'a'][j] += dp2[j];
			mx2 = max(mx2, dp[s[i] - 'a'][j]);
		}
		dp2[s[i] - 'a']++;
	}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30], dp[100][100];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	int mx2 = 0;
	for (int i = 0;  i <s.size(); i++)
		for (int j = i + 1; j < s.size(); j++) {
			dp[s[i] - 'a'][s[j] - 'a']++;
			mx2 = max(mx2, dp[i][j]);
		}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30], dp[100][100];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	int mx2 = 0;
	for (int i = 0;  i < s.size(); i++)
		for (int j = 0; j < 30; j++) {
			dp[s[i] - 'a'][j] += a[j];
			mx2 = max(mx2, dp[s[i] - 'a'][j]);
		}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30], dp[100][100];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i];
	int mx2 = 0;
	for (int i = 0;  i <s.size(); i++)
		for (int j = i + 1; j < s.size(); j++) {
			dp[s[i] - 'a'][s[j] - 'a']++;
			mx2 = max(mx2, dp[i][j]);
		}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	long long ans = 1;
	for (int i = 0; i < 30; i++)
		if (a[i])
			ans *= a[i];
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - '0']++;
	long long ans = 0;
	for (int i = 0; i < 30; i++)
		if (a[i])
			ans *= a[i];
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
long long a[30], dp[N][30], dp2[N];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	long long mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	long long mx2 = 0;
	for (int i = 0;  i < s.size(); i++) {
		for (int j = 0; j < 30; j++) {
			dp[s[i] - 'a'][j] += dp2[j];
			mx2 = max(mx2, dp[s[i] - 'a'][j]);
		}
		dp2[s[i] - 'a']++;
	}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30], dp[N][30], dp2[N];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	int mx2 = 0;
	for (int i = 0;  i < s.size(); i++) {
		for (int j = 0; j < 30; j++) {
			dp[s[i] - 'a'][j] += dp2[j];
			mx2 = max(mx2, dp[s[i] - 'a'][j]);
		}
		dp2[s[i] - 'a']++;
	}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30], dp[N][N], dp2[N];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	int mx2 = 0;
	for (int i = 0;  i < s.size(); i++) {
		for (int j = 0; j < 30; j++) {
			dp[s[i] - 'a'][j] += dp2[j];
			mx2 = max(mx2, dp[s[i] - 'a'][j]);
		}
		dp2[s[i] - 'a']++;
	}
	cout << max(mx, mx2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	long long ans = 0;
	for (int i = 0; i < 30; i++)
		if (a[i])
			ans *= a[i];
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 20;
int a[30], dp[100][100];
int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a']++;
	int mx = 0;
	for (int i = 0; i < 30; i++)
		mx = max(mx, a[i]);
	int mx2 = 0;
	for (int i = 0;  i <s.size(); i++)
		for (int j = i + 1; j < s.size(); j++) {
			dp[s[i] - 'a'][s[j] - 'a']++;
			mx2 = max(mx2, dp[s[i] - 'a'][s[j] - 'a']);
		}
	cout << max(mx, mx2);
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

 ll dp[100005][26];
void solve(){
  string s;
  cin>>s;
  map<string,ll>mp;
  map<char,ll>mp2;
  int n=s.size();
  vector<ll>cnt(26);
  rep(i,n){
    cnt[s[i]-'a']++;
  }
  ll ans=0;
  rep(i,26)chmax(ans,cnt[i]);
  memset(dp,0,sizeof(dp));
  rep(i,n){
    --cnt[s[i]-'a'];
    rep(k,26)dp[s[i]-'a'][k]+=cnt[k];
  }
  rep(i,26){
    rep(j,26){
      chmax(ans,dp[i][j]);
    }
  }
  cout<<ans<<"\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solve(){
  string s;
  cin>>s;
  map<char,ll>mp;
  int n=s.size();
  rep(i,n)mp[s[i]]++;
  ll ans=1;
  for(auto x:mp){
    ll mul=x.second;
    ll div=mul/2;
    ans*=binomial<ll>(mul,div);
  }
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solve(){
  string s;
  cin>>s;
  map<char,ll>mp;
  int n=s.size();
  rep(i,n)mp[s[i]]++;
  ll ans=1;
  vector<ll>v;
  for(auto x:mp){
    v.pb(x.second);
  }
  sort(all(v));
  ans*=v.back()*v[v.size()-2];
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから

void solve(){
  string s;
  cin>>s;
  map<char,ll>mp;
  int n=s.size();
  rep(i,n)mp[s[i]]++;
  ll ans=1;
  for(auto x:mp){
    ans*=x.second;
  }
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solve(){
  string s;
  cin>>s;
  map<char,ll>mp;
  int n=s.size();
  rep(i,n)mp[s[i]]++;
  ll ans=1;
  int cnt=0;
  ll maxv=0;
  for(auto x:mp)chmax(maxv,x.second);
  for(auto x:mp){
    ll mul=x.second;
    if(cnt>=2)break;
    ans*=binomial<ll>(mul,1LL);
    ++cnt;
  }
  cout<<max(ans,maxv*(maxv-1)/2LL)<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solve(){
  string s;
  cin>>s;
  map<char,ll>mp;
  int n=s.size();
  rep(i,n)mp[s[i]]++;
  ll ans=1;
  vector<ll>v;
  for(auto x:mp){
    v.pb(x.second);
  }
  sort(all(v));
  ans*=v.back();
  if(v.size()>1)ans*=v[v.size()-2];
  else if(s.size()>2)ans*=(v.back()-1),ans/=2;
  else ans=n;
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solve(){
  string s;
  cin>>s;
  map<string,ll>mp;
  map<char,ll>mp2;
  int n=s.size();
  rep(i,n){
    for(int j=i+1;j<n;++j){
      string t=string{s[i]}+string{s[j]};
      mp[t]++;
    }
    mp2[s[i]]++;
  }
  ll ans=0;
  for(auto x:mp)chmax(ans,x.second);
  for(auto x:mp2)chmax(ans,x.second);
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

using namespace std;

//ここから
#define int64_t ll
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}

void solve(){
  string s;
  cin>>s;
  map<char,ll>mp;
  int n=s.size();
  rep(i,n)mp[s[i]]++;
  ll ans=1;
  if(mp.size()>1)for(auto x:mp){
    ans*=x.second;
  }
  else {
    ll mul=mp[s[0]];
    ll div=mul/2;
    ans=binomial<ll>(mul,div);
  }
  cout<<ans<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

void solve() {
    string s;
    cin >> s;
    vector<int> f[27];
    int maxN = 26;
    int n = (int) s.size();
    for (int i = 0; i < n; i++) {
        f[s[i] - 'a'].pb(i);
    }
    int ans = 0;
    for (int i = 0; i < maxN; i++) {
        ans = max(ans , (int)f[i].size()) ;
        for (int j = 0; j < maxN; j++) {
            int res = 0;
            for (int freq1 : f[i]) {
                res += ( (int) f[j].size()) - (upper_bound(f[j].begin(), f[j].end(), freq1) - f[j].begin());
            }
            ans = max(ans , res ) ;
        }
    }
    cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

//       ababkamts
//    t-> bbk
//    u->aaa


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

void solve() {
  string s;
  cin >> s ;
  vector<vector<int>> dp(26 , vi(26,0)) ;
  vi f(26,0) ;
  int n = (int)s.size() ;
  int ans = 0 ;
  for(int i=0;i<n;i++){
      for(int j=0;j<26;j++){
          dp[j][s[i] - 'a'] += f[j] ;
          ans = max(ans , dp[j][s[i] - 'a'] ) ;
      }
      f[s[i] - 'a']++ ;
  }
  for(int i=0;i<26;i++ ) ans = max(ans , f[i]) ;
  cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

void solve() {
    string s;
    cin >> s;
    vector<int> f[27];
    int maxN = 26;
    int n = (int) s.size();
    for (int i = 0; i < n; i++) {
        f[s[i] - 'a'].pb(i);
    }
    int ans = 0;
    for (int i = 0; i < maxN; i++) {
        for (int j = 0; j < maxN; j++) {
            int res = 0;
            for (int freq1 : f[i]) {
                res += ( (int) f[j].size()) - (upper_bound(f[j].begin(), f[j].end(), freq1) - f[j].begin());
            }
            ans = max(ans , res ) ;
        }
    }
    cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

//       ababkamts
//    t-> bbk
//    u->aaa


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

void solve() {
    string s;
    cin >> s;
    vector<int> f[27];
    int maxN = 26;
    int n = (int) s.size();
    for (int i = 0; i < n; i++) {
        f[s[i] - 'a'].pb(i);
    }
    int ans = 0;
    for (int i = 0; i < maxN; i++) {
        ans = max(ans, (int) f[i].size());
        for (int j = 0; j < maxN; j++) {
            int res = 0;
            for (int freq1 : f[i]) {
                if (f[j].empty() == false)
                    res += ((int) f[j].size()) - (upper_bound(f[j].begin(), f[j].end(), freq1) - f[j].begin());
            }
            ans = max(ans, res);
        }
    }
    cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

//       ababkamts
//    t-> bbk
//    u->aaa


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
void solve(){
    string s ;
    cin >> s ;
    int f[26] ;
    for(int i=0;i<26;i++ ) f[i] = 0 ;
    for (char c : s ) {
        f[c-'a']++ ;
    }
    int ans =0  ;
    for(int i=0;i<2;i++){
        int max_index = i ;
        for(int j=i+1;j<26;j++ ){
            if(f[j] > f[i])
                max_index = j ;
        }
        swap(f[i] , f[max_index]) ;
    }
    ans = f[0] * f[1] ;
    cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

//       ababkamts
//    t-> bbk
//    u->aaa


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

void solve() {
  string s;
  cin >> s ;
  vector<vector<ll>> dp(26 , vector<ll>(26,0)) ;
  vi f(26,0) ;
  int n = (int)s.size() ;
  ll ans = 0 ;
  for(int i=0;i<n;i++){
      for(int j=0;j<26;j++){
          dp[j][s[i] - 'a'] += f[j] ;
          ans = max(ans , dp[j][s[i] - 'a'] ) ;
      }
      f[s[i] - 'a']++ ;
  }
  for(int i=0;i<26;i++ ) ans = max(ans , 1ll * f[i]) ;
  cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

//       ababkamts
//    t-> bbk
//    u->aaa


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

void solve() {
    string s;
    cin >> s;
    vector<int> f[27];
    int maxN = 26;
    int n = (int) s.size();
    for (int i = 0; i < n; i++) {
        f[s[i] - 'a'].pb(i);
    }
    ll ans = 0;
    for (int i = 0; i < maxN; i++) {
        ans = max(ans, 1ll * (int) f[i].size());
        for (int j = 0; j < maxN; j++) {
            ll res = 0;
            for (int freq1 : f[i]) {
                    res += ((int) f[j].size()) - (upper_bound(f[j].begin(), f[j].end(), freq1) - f[j].begin());
            }
            ans = max(ans, res);
        }
    }
    cout << ans << endl;

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    // cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

//       ababkamts
//    t-> bbk
//    u->aaa


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    int arr[s.length()][26];
    memset(arr,0,sizeof(arr));
    for(int i=s.length()-1;i>=0;i--)
    {
        if(i==s.length()-1)
        {
            arr[i][s[i]-'a']++;
        }
        else
        {
            arr[i][s[i]-'a']++;
            for(int j=0;j<=25;j++)
            {
                arr[i][j]+=arr[i+1][j];
            }
        }
    }
    // for(int i=0;s[i];i++)
    // {
    //     for(int j=0;j<26;j++)
    //     {
    //         cout<<arr[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    map<pii,int>mp;
    for(int i=0;s[i];i++)
    {
        for(int j=0;j<26;j++)
        {
            if(arr[i][j]==1)continue;
            mp[{s[i]-'a','a'+j}]+=arr[i][j];
        }
    }
    int cnt=1;
    for(auto x:mp)
    {
        cnt=max(cnt,x.S);
    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    int arr[s.length()][26];
    int aba[26];
    memset(arr,0,sizeof(arr));
    memset(aba,0,sizeof(aba));
    for(int i=s.length()-1;i>=0;i--)
    {
        if(i==s.length()-1)
        {
            //arr[i][s[i]-'a']++;
            aba[s[i]-'a']++;
        }
        else
        {
            //arr[i][s[i]-'a']++;
            for(int j=0;j<=25;j++)
            {
                arr[i][j]+=aba[j];
            }
            aba[s[i]-'a']++;
        }
    }
    map<pii,int>mp;
    for(int i=0;s[i];i++)
    {
        for(int j=0;j<26;j++)
        {
            //if(arr[i][j]==1)continue;
            mp[{s[i]-'a','a'+j}]+=arr[i][j];
        }
    }
    int cnt=0;
    for(auto x:mp)
    {
        cnt=max(cnt,x.S);
    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    map<char,int>mp;
    for(auto x:s)
    {
        mp[x]++;
    }
    vector<int>v;
    for(auto x:mp)
        v.pb(x.S);
    int cnt=1;
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        int j=(v[i]*(v[i]-1))/2;
        cnt=max(cnt,max(j,v[i]));
    }
    if(v.size()>=2)
        cnt=max(v[v.size()-1]*v[v.size()-2],cnt);
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    map<char,int>mp;
    for(auto x:s)
    {
        mp[x]++;
    }
    vector<int>v;
    for(auto x:mp)
        v.pb(x.S);
    int cnt=1;
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        int j=(v[i]*(v[i]-1))/2;
        cnt=max(cnt,j);
    }
    if(v.size()>=2)
        cnt=max(v[v.size()-1]*v[v.size()-2],cnt);
    if(v.size()>=3)
    {
        cnt=max(cnt,v[v.size()-1]*v[v.size()-3]*(v[v.size()-2]));
    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    int arr[s.length()][26];
    int aba[26];
    memset(arr,0,sizeof(arr));
    memset(aba,0,sizeof(aba));
    int cnt=0;
    for(int i=s.length()-1;i>=0;i--)
    {
        if(i==s.length()-1)
        {
            //arr[i][s[i]-'a']++;
            aba[s[i]-'a']++;
            cnt=max(cnt,aba[s[i]-'a']);
        }
        else
        {
            //arr[i][s[i]-'a']++;
            for(int j=0;j<=25;j++)
            {
                arr[i][j]+=aba[j];
            }
            aba[s[i]-'a']++;
            cnt=max(cnt,aba[s[i]-'a']);
        }
    }
    map<pii,int>mp;
    for(int i=0;s[i];i++)
    {
        for(int j=0;j<26;j++)
        {
            //if(arr[i][j]==1)continue;
            mp[{s[i]-'a',j}]+=arr[i][j];
        }
    }

    for(auto x:mp)
    {
        cnt=max(cnt,x.S);
    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    map<char,int>mp;
    for(auto x:s)
    {
        mp[x]++;
    }
    vector<int>v;
    for(auto x:mp)
        v.pb(x.S);
    int cnt=0;
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        int j=(v[i]*(v[i]-1))/2;
        cnt=max(cnt,j);
    }
    if(v.size()>=2)
        cnt=max(v[v.size()-1]*v[v.size()-2],cnt);
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
    string s;
    cin>>s;
    map<char,int>mp;
    for(auto x:s)
    {
        mp[x]++;
    }
    vector<int>v;
    for(auto x:mp)
        v.pb(x.S);
    int cnt=1;
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        int j=(v[i]*(v[i]-1))/2;
        cnt=max(cnt,j);
    }
    if(v.size()>=2)
        cnt=max(v[v.size()-1]*v[v.size()-2],cnt);
    cout<<cnt<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=0,a2[26]={0},p=-inf;
    int res[26][26];
    memset(res,0,sizeof(res));
    cin>>s;
    int n=s.size();
   for(int i=0;i<n;i++)
   {
    a2[s[i]-'a']++;
    p=max(p,a2[s[i]-'a']);
     for(int k=0;k<26;k++)
       { if(k==(int)(s[i]-'a'))
          continue;
      res[s[i]-'a'][k]+=a2[k];
        r=max(r,res[s[i]-'a'][k]);
      }
    }
   cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=-inf,p;
    cin>>s;
    int n=s.size();
    vector<int> a[26];
    for(int i=0;i<n;i++)
     a[s[i]-'a'].pb(i);
    p=a[0].size();
    for(int i=0;i<26;i++)
    {
      int p1=a[i].size();
      if(p1==0)
        continue;
      int k1=a[i][0];
      p=max(p,p1);
      for(int j=0;j<26;j++)
      {
          if((j==i)||(a[j].size()==0))
          continue;
        auto it=lb(a[j].begin(),a[j].end(),k1);
        int k2=it-a[j].begin();
        if(it!=a[j].end())
          {if(*it<k1)
        r=max(r,k2*p1);}
      else
        r=max(r,k2*p1);
      }
    }
    cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=-inf,p;
    cin>>s;
    int n=s.size();
    vector<int> a[26];
    for(int i=0;i<n;i++)
     a[s[i]-'a'].pb(i);
    p=a[0].size();
    for(int i=0;i<26;i++)
    {
      int p1=a[i].size();
      if(p1==0)
        continue;
      int k1=a[i][0];
      p=max(p,p1);
      for(int j=0;j<26;j++)
      {
          if((j==i)||(a[j].size()==0))
          continue;
        int k2=lb(a[j].begin(),a[j].end(),k1)-a[j].begin();
        r=max(r,k2*p1);
      }
    }
    cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=-inf,p;
    cin>>s;
    int n=s.size();
    vector<int> a[26];
    for(int i=0;i<n;i++)
     a[s[i]-'a'].pb(i);
    p=a[0].size();
    for(int i=0;i<26;i++)
    {
      int p1=a[i].size();
      if(p1==0)
        continue;
      int k1=a[i][0];
      p=max(p,p1);
      for(int j=0;j<26;j++)
      {
          if((j==i)||(a[j].size()==0))
          continue;
        int k2=lb(a[j].begin(),a[j].end(),k1)-a[j].begin();
        if(k2<k1)
        r=max(r,k2*p1);
      }
    }
    cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=0,a2[26]={0},p=-inf;
    int res[26][26];
    memset(res,0,sizeof(res));
    cin>>s;
    int n=s.size();
   for(int i=0;i<n;i++)
   {
    p=max(p,a2[s[i]-'a']);
     for(int k=0;k<26;k++)
       {
      res[s[i]-'a'][k]+=a2[k];
        r=max(r,res[s[i]-'a'][k]);
      }
      a2[s[i]-'a']++;
    }
   cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=-inf,p;
    cin>>s;
    int n=s.size();
    vector<int> a[26];
    for(int i=0;i<n;i++)
     a[s[i]-'a'].pb(i);
    p=a[0].size();
    for(int i=0;i<26;i++)
    {
      int p1=a[i].size();
      if(p1==0)
        continue;
      int k1=a[i][0];
      p=max(p,p1);
      for(int j=0;j<26;j++)
      {
          if((j==i)||(a[j].size()==0))
          continue;
        auto it=lb(a[j].begin(),a[j].end(),k1);
        int k2=it-a[j].begin();
        if(it!=a[j].end())
          {if(*it<k1)
        r=max(r,k2*p1);}
      else
        r=max(r,k1*p1);
      }
    }
    cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=0,a2[26]={0},p=-inf;
    int res[26][26];
    memset(res,0,sizeof(res));
    cin>>s;
    int n=s.size();
   for(int i=0;i<n;i++)
   {
     for(int k=0;k<26;k++)
       {
      res[s[i]-'a'][k]+=a2[k];
        r=max(r,res[s[i]-'a'][k]);
      }
      a2[s[i]-'a']++;
      p=max(p,a2[s[i]-'a']);
    }
   cout<<max(r,p);
}


#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define lb lower_bound
#define mp make_pair
#define pb push_back
#define bn binary_search
#define pq priority_queue
#define int long long
#define pii pair<int,int>
signed main()
{
    string s;
    int r=1,a2[26]={0},p=-inf;
    int res[26][26];
    memset(res,0,sizeof(res));
    cin>>s;
    int n=s.size();
   for(int i=0;i<n;i++)
   {
    a2[s[i]-'a']++;
    p=max(p,a2[s[i]-'a']);
     for(int k=0;k<26;k++)
       { if(k==i)
          continue;
      res[s[i]-'a'][k]+=a2[k];
        r=max(r,res[s[i]-'a'][k]);
      }
    }
   cout<<max(r,p);
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0ll,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1ll;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0ll;
                if(i==j)
                {
                    x = (v[i].size());
                    x *= (x-1);
                    x/= 2;
                    mx = max(x,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
   // cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0;
                if(i==j)
                {
                    x = (v[i].size()*(v[i].size()-1))/2;
                    mx = max(x,mx);
                    y = v[i].size();
                    mx = max(y,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
   // cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0ll,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1ll;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0ll;
                if(i==j)
                {
                    x = (v[i].size()*(v[i].size()-1))/2;
                    mx = max(x,mx);
                    y = v[i].size();
                    mx = max(y,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
   // cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0ll,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1ll;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0ll;
                if(i==j)
                {
                    x = (v[i].size());
                    x *= (x-1);
                    x/= 2;
                    mx = max(x,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
   // cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0ll,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1ll;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0ll;
                if(i==j)
                {
                    x = (v[i].size()*(v[i].size()-1))/2;
                    mx = max(x,mx);
                    y = v[i].size();
                    mx = max(y,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0;
                if(i==j)
                {
                    x = v[i].size()*(v[i].size()-1);
                    x /= 2;
                    mx = max(x,mx);
                    y = v[i].size();
                    mx = max(y,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0;
                if(i==j)
                {
                    x = v[i].size()-1;
                    mx = max(x,mx);
                    y = v[i].size();
                    mx = max(y,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include<bits/stdc++.h>
using namespace std;

#define int         long long
#define fast        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
int mod = 1000000007;

//int dp[100000]={};
/*int binarysearch(int a[],int n,int s)
{
    int l=1,h=n-1,mid;
    while(l<=h)
    {
        mid = l + (h-l)/2;
        if(a[mid]==s)
            return mid;
        else if(a[mid]>s)
            h = mid - 1;
        else l = mid + 1;
    }
    return 0;
}

bool ispalindrom(string s)
{
    int n = s.length(),f=0;
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            f=1;
            break;
        }
    }
    if(f)
    return false;
    else return true;
}*/

signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n=0,m=0,r=0,f=0,cnt=0,l=0,x=0ll,y=0,mx=0,sum=0,mini=INT_MAX;
        string s,ss,str;
        cin>>s;
        n = s.length();
        vector<int>v[26];
        for(int i=0;i<n;i++)
        {
            v[s[i] -'a'].push_back(i+1);
        }
        mx = 1ll;
        for(int i=0;i<26;i++)
        {
            if(v[i].size()==0)
                continue;
            for(int j=0;j<26;j++)
            {
                x = 0ll;
                if(i==j)
                {
                    x = (v[i].size());
                    x *= (x-1);
                    x/= 2;
                    mx = max(x,mx);
                    y = v[i].size();
                    mx = max(y,mx);
                    continue;
                }
                for(int k=0;k<v[i].size();k++)
                {
                    auto it = upper_bound(v[j].begin(),v[j].end(),v[i][k]);
                    y = v[j].size() - (it - v[j].begin());
                    x += y;
                }
                mx = max(x,mx);
            }
        }
        cout<<mx;
    }
	cerr << "\nTime elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    ll cc = 0;
    vector<ll> ee(26, 0);
    unordered_map<ll, ll> ans;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            if(lst != -1)
            {
                for(int j = 0; j < 26; j++)
                {
                    ans[j * 31 + lst - 'a'] += ee[j] * cc;
//                    cout << ee[j] << " " << cc << "\n";
                }
                ee[lst - 'a'] += cc;
                mx = max(mx, cc * (cc - 1) / 2);
            }
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
//        cout << i << "\n";
    }
    for(int j = 0; j < 26; j++)
        ans[j * 31 + lst - 'a'] += ee[j] * cc;
    ee[lst - 'a'] += cc;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : ans)
        mx = max(it.snd, mx);
    cout << mx;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    ll cc = 0;
    vector<ll> ee(26, 0);
    unordered_map<ll, ll> ans;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            if(lst != -1)
            {
                for(int j = 0; j < 26; j++)
                {
                    ans[j * 31 + lst - 'a'] += ee[j] * cc;
//                    cout << ee[j] << " " << cc << "\n";
                }
                ee[lst - 'a'] += cc;
                mx = max(mx, cc * (cc - 1) / 2);
            }
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
//        cout << i << "\n";
    }
    for(int j = 0; j < 26; j++)
        ans[j * 31 + lst - 'a'] += ee[j] * cc;
    mx = max(mx, cc * (cc - 1) / 2);
    ee[lst - 'a'] += cc;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : ans)
        mx = max(it.snd, mx);
    cout << mx;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    ll cc = 0;
    vector<ll> ee(26, 0);
    unordered_map<ll, ll> ans;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            if(lst != -1)
            {
                for(int j = 0; j < 26; j++)
                {
                    ans[j * 31 + lst - 'a'] += ee[j] * cc;
//                    cout << ee[j] << " " << cc << "\n";
                }
                ee[lst - 'a'] += cc;
                mx = max(mx, cc * (cc - 1) / 2);
            }
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
//        cout << i << "\n";
    }
    for(int j = 0; j < 26; j++)
        ans[j * 31 + lst - 'a'] += ee[j] * cc;
    mx = max(mx, cc * (cc - 1) / 2);
    ee[lst - 'a'] += cc;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : ee)
        mx = max(mx, ee.snd * (ee.snd - 1) / 2);
    for(auto& it : ans)
        mx = max(it.snd, mx);
    cout << mx;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    ll cc = 0;
    vector<ll> ee(26, 0);
    unordered_map<ll, ll> ans;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            if(lst != -1)
            {
                for(int j = 0; j < 26; j++)
                {
                    ans[j * 31 + lst - 'a'] += ee[j] * cc;
//                    cout << ee[j] << " " << cc << "\n";
                }
                ee[lst - 'a'] += cc;
                mx = max(mx, cc * (cc - 1) / 2);
            }
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
//        cout << i << "\n";
    }
    for(int j = 0; j < 26; j++)
        ans[j * 31 + lst - 'a'] += ee[j] * cc;
    mx = max(mx, cc * (cc - 1) / 2);
    ee[lst - 'a'] += cc;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : ee)
        mx = max(mx, it * (it - 1) / 2);
    for(auto& it : ans)
        mx = max(it.snd, mx);
    cout << mx;

    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define pb push_back
#define fst first
#define snd second
#define all(c) (c).begin(), (c).end()
typedef long long ll;
typedef long double ld;
const ll INF64 = 1e18 + 228;
const int INF32 = 1e9 + 1337;
const int MOD = 1e9 + 7;
const ld eps = 1e-7;
const int N = 1e3 + 228;
int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef __WIN32
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    string s;
    cin >> s;
    vector<ll> c(26, 0);
    for(auto& it : s)
        c[it - 'a']++;
    int n = s.size();
    ll lst = -1;
    ll cc = 0;
    vector<ll> ee(26, 0);
    unordered_map<ll, ll> ans;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        if(lst != s[i])
        {
            if(lst != -1)
            {
                for(int j = 0; j < 26; j++)
                {
                    ans[j * 31 + lst - 'a'] += ee[j] * cc;
//                    cout << ee[j] << " " << cc << "\n";
                }
                ee[lst - 'a'] += cc;
                mx = max(mx, cc * (cc - 1) / 2);
            }
            cc = 1;
        }
        else
        {
            cc++;
        }
        lst = s[i];
//        cout << i << "\n";
    }
    for(int j = 0; j < 26; j++)
        ans[j * 31 + lst - 'a'] += ee[j] * cc;
    mx = max(mx, cc * (cc - 1) / 2);
    ee[lst - 'a'] += cc;
    for(auto& it : c)
        mx = max(it, mx);
    for(auto& it : ee)
        mx = max(mx, it.snd * (it.snd - 1) / 2);
    for(auto& it : ans)
        mx = max(it.snd, mx);
    cout << mx;

    return 0;
}