#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  int count[26][n];
  vector<int> pos[26];
  for (int i = 0; i < 26; i++) {
    count[i][n - 1] = 0;
    int count1 = 0;
    for (int j = n - 1; j >= 0; j--) {
      count[i][j] = count1;
      if (s[j] == 97 + i) {
        count1++;
        pos[i].push_back(j);
      }
    }
  }
  long long maxi = 0;
  for (int i = 0; i < 26; i++) {
    if (pos[i].size() != 0) {
      long long x = pos[i].size();
      long long curr_maxi = max(x, (x * (x - 1)) / 2);
      for (int j = 0; j < 26; j++) {
        if (j != i) {
          long long count2 = 0;
          for (int k = 0; k < x; k++) {
            count2 += count[j][pos[i][k]];
          }
          curr_maxi = max(curr_maxi, count2);
        }
      }
      maxi = max(maxi, curr_maxi);
    }
  }
  cout << maxi << endl;
}
