#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  vector<long long> cnt(26);
  vector<vector<long long>> m(26, vector<long long>(26));
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) {
    cnt[s[i] - 'a']++;
    ans = max(ans, cnt[s[i] - 'a']);
    long long tmp = 0;
    for (int j = 0; j < 26; j++) {
      m[s[i] - 'a'][j] += cnt[j] + (j == s[i] - 'a' ? -1 : 0);
      tmp = max(tmp, m[s[i] - 'a'][j]);
    }
    ans = max(ans, tmp);
  }
  cout << (long long)ans << endl;
}
int main() {
  int t = 1;
  while (t--) solve();
}
