#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5;
string s;
long long n;
void solve() {
  cin >> s;
  n = s.length();
  vector<vector<long long> > cnt(26);
  for (long long i = 0; i < n; i++) {
    cnt[s[i] - 'a'].emplace_back(i);
  }
  long long maxx = 0;
  for (long long i = 0; i < 26; i++) {
    if (cnt[i].size()) {
      for (long long j = 0; j < 26; j++) {
        if (cnt[j].size()) {
          if (i ^ j) {
            long long max_now = 0, a = cnt[i].size(), b = cnt[j].size();
            for (long long k = 0; k < a; k++) {
              long long target = cnt[i][k];
              long long start = 0, end = b - 1;
              while (start <= end) {
                long long mid = (start + end) / 2;
                if (cnt[j][mid] > target) {
                  end = mid - 1;
                  continue;
                }
                start = mid + 1;
              }
              max_now += (b - start);
              if (start == b) break;
            }
            maxx = max(max_now, maxx);
          } else {
            long long a = cnt[i].size();
            maxx = max(maxx, max(a, (a * a - a) / 2));
          }
        }
      }
    }
  }
  cout << maxx << '\n';
}
int32_t main() { solve(); }
