#include <bits/stdc++.h>
using namespace std;
long long brocheck(string s1, long long n, vector<vector<long long> >& v,
                   vector<vector<long long> >& v1) {
  if (s1[0] == s1[1]) {
    if (v[n - 1][s1[0] - 'a'] >= 2) {
      long long x;
      x = v[n - 1][s1[0] - 'a'] * (v[n - 1][s1[0] - 'a'] - 1);
      x = x / 2;
      return x;
    } else
      return 0;
  } else {
    long long sum = 0;
    if (v[n - 1][s1[0] - 'a'] > 0 && v[n - 1][s1[1] - 'a'] > 0) {
      for (long long i = 0; i < v[n - 1][s1[0] - 'a']; i++) {
        sum =
            sum + (v[n - 1][s1[1] - 'a'] - v[v1[s1[0] - 'a'][i]][s1[1] - 'a']);
      }
      return sum;
    } else
      return 0;
  }
}
int main() {
  int t = 1;
  while (t--) {
    string s;
    cin >> s;
    long long n = s.size();
    if (n == 1) {
      cout << 1;
      return 0;
    }
    vector<vector<long long> > v(s.size(), vector<long long>(26, 0));
    vector<vector<long long> > v1(26);
    v[0][s[0] - 'a'] = 1;
    v1[s[0] - 'a'].push_back(0);
    for (int i = 1; i < s.size(); i++) {
      for (int j = 0; j < 26; j++) {
        v[i][j] = v[i - 1][j];
      }
      v[i][s[i] - 'a'] = v[i - 1][s[i] - 'a'] + 1;
      v1[s[i] - 'a'].push_back(i);
    }
    map<string, long long> m;
    long long ans = -2;
    for (char i = 'a'; i <= 'z'; i++) {
      for (char j = 'a'; j <= 'z'; j++) {
        string s1 = "ab";
        s1[0] = i;
        s1[1] = j;
        m[s1] = brocheck(s1, n, v, v1);
        if (m[s1] > ans) ans = m[s1];
      }
    }
    for (int i = 0; i < 26; i++) {
      if (v[n - 1][i] > ans) ans = v[n - 1][i];
    }
    cout << ans;
  }
  return 0;
}
