#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const long long mod = 10000000000000061ll;
struct info {
  long long hs;
  int has;
  int md;
  info() { hs = has = md = 0; }
  void out() {
    cout << hs << " " << has << " " << (md >> 8) << "," << char(md & 255)
         << endl;
  }
};
long long ans[100111][26];
info a[18][100111], a0[18][100111], a1[18][100111];
info newinfo(char c) {
  info ret;
  ret.hs = c - 'a' + 1;
  ret.has = 1 << (c - 'a');
  return ret;
}
info merge(const info &L, const char &c, const info &R) {
  info ret;
  if (!L.hs || !R.hs || L.hs != R.hs) return ret;
  if ((L.has >> (c - 'a')) & 1) return ret;
  if ((R.has >> (c - 'a')) & 1) return ret;
  ret.hs = (L.hs * 30 + c - 'a' + 1) % mod;
  ret.has = L.has | (1 << (c - 'a'));
  return ret;
}
int n;
char s[100111];
long long w[20];
void update(int msk, int k) { ans[msk >> 8][(msk & 255) - 'a'] += w[k]; }
void updatemsk(int x, int msk, int k) {
  for (int i = 0; i < 26; i++)
    if ((msk >> i) & 1) update(x << 8 | (i + 'a'), k);
}
long long pe[100111];
int main() {
  for (int k = 0; k < 20; k++)
    w[k] = 1ll * ((1 << (k + 1)) - 1) * ((1 << (k + 1)) - 1);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) a[0][i] = newinfo(s[i]);
  for (int k = 1; k < 18; k++) {
    int l = (1 << k);
    for (int i = 1; i <= n - (l * 2 - 1) + 1; i++) {
      bool cl = (a[k - 1][i].hs > 0);
      bool cr = (a[k - 1][i + l].hs > 0);
      if (!cl && !cr) continue;
      info &cur = a[k][i];
      int ls = i, rs = i + l;
      char &cmid = s[i + l - 1];
      if (cl && cr) {
        if (a[k - 1][ls].hs == a[k - 1][rs].hs) {
          cur = merge(a[k - 1][ls], cmid, a[k - 1][rs]);
          if (cur.hs) {
            pe[i] += w[k];
            pe[i + l - 1] -= w[k];
            pe[i + l] += w[k];
            pe[i + l * 2 - 1] -= w[k];
          }
          updatemsk(i + l - 1, ~(a[k - 1][ls].has | a[k - 1][rs].has), k);
        } else {
          if (k == 1) {
            a0[k][i] = merge(a[k - 1][rs], cmid, a[k - 1][rs]);
            a0[k][i].md = ls << 8 | s[rs + l / 2 - 1];
            a1[k][i] = merge(a[k - 1][ls], cmid, a[k - 1][ls]);
            a1[k][i].md = rs << 8 | s[ls + l / 2 - 1];
          } else {
            a0[k][i] = merge(
                merge(a[k - 2][ls], s[rs + l / 2 - 1], a[k - 2][ls + l / 2]),
                cmid, a[k - 1][rs]);
            a0[k][i].md = (ls + l / 2 - 1) << 8 | s[rs + l / 2 - 1];
            a1[k][i] = merge(
                a[k - 1][ls], cmid,
                merge(a[k - 2][rs], s[ls + l / 2 - 1], a[k - 2][rs + l / 2]));
            a1[k][i].md = (rs + l / 2 - 1) << 8 | s[ls + l / 2 - 1];
          }
        }
        continue;
      }
      if (cr) swap(ls, rs);
      if (s[ls + l / 2 - 1] != s[rs + l / 2 - 1]) {
        a0[k][i] =
            merge(a[k - 1][ls], cmid,
                  merge(a[k - 2][rs], s[ls + l / 2 - 1], a[k - 2][rs + l / 2]));
        a0[k][i].md = (rs + l / 2 - 1) << 8 | s[ls + l / 2 - 1];
      } else {
        a0[k][i] = merge(a[k - 1][ls], cmid, a0[k - 1][rs]);
        a0[k][i].md = a0[k - 1][rs].md;
        a1[k][i] = merge(a[k - 1][ls], cmid, a1[k - 1][rs]);
        a1[k][i].md = a1[k - 1][rs].md;
      }
    }
  }
  for (int i = 1; i <= n; i++) pe[i] += pe[i - 1];
  for (int k = 1; k < 18; k++)
    for (int i = 1; i <= n; i++) {
      if (a0[k][i].hs) update(a0[k][i].md, k);
      if (a1[k][i].hs) update(a1[k][i].md, k);
    }
  long long mx = 0, sum = 0;
  for (int i = 1; i <= n; i++) sum += ans[i][s[i] - 'a'];
  for (int i = 1; i <= n; i++) {
    long long cur = sum - ans[i][s[i] - 'a'];
    for (int j = 0; j < 26; j++)
      mx = max(mx, cur + ans[i][j] - pe[i] * ('a' + j != s[i]));
  }
  cout << mx + n << endl;
  return 0;
}
