//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

void main() {
  auto s = readln.stripRight;
  int[26] c;
  long[26][26] d;
  foreach (ch; s) {
    int i = ch.to!int - 97;
    foreach (j; 0 .. 26) {
      d[j][i] += c[j];
    }
    ++c[i];
  }
  long res;
  foreach (i; 0 .. 26) {
    res = max (res, c[i]);
    foreach (j; 0 .. 26) res = max (res, d[i][j]);
  }
  writeln (res);
}

