#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10, MAXL = 20, ALP = 26, A = 13331,
          MOD = (int)1e9 + 7;
int n, g[MAXN], Pow[MAXN], sum[MAXN][ALP];
char str[MAXN];
bool f[MAXN][MAXL];
long long Tohka, h[MAXN][ALP], Kurumi[MAXN];
void init() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  g[0] = 0, Pow[0] = 1;
  for (int i = 1; i <= n; ++i) {
    g[i] = ((long long)g[i - 1] * A + (long long)str[i] - 'a') % MOD,
    Pow[i] = (long long)Pow[i - 1] * A % MOD;
    for (int j = 0; j < ALP; ++j) sum[i][j] += sum[i - 1][j];
    ++sum[i][str[i] - 'a'];
  }
}
int Get(int l, int r) {
  if (l > r) return 0;
  return (g[r] - (long long)g[l - 1] * Pow[r - l + 1] % MOD + MOD) % MOD;
}
long long del[ALP];
int pre[ALP];
long long DFS(int first, int p, int k, char ch) {
  int l = p - (1 << k) + 1, r = p + (1 << k) - 1;
  if (l < 1 || r > n) return 0;
  if (((first < p) ? (f[p + (1 << (k - 1))][k - 1] && !f[p][k])
                   : (!f[p][k] && f[p - (1 << (k - 1))][k - 1])))
    ;
  else
    return 0;
  int hash1, hash2;
  if (first < p)
    hash1 = (((long long)Get(l, first - 1) * Pow[1] % MOD + str[first] - 'a') *
                 Pow[p - first - 1] % MOD +
             Get(first + 1, p - 1)) %
            MOD,
    hash2 = Get(p + 1, r);
  else
    hash1 = Get(l, p - 1),
    hash2 =
        (((long long)Get(p + 1, first - 1) * Pow[1] % MOD + str[first] - 'a') *
             Pow[r - first] % MOD +
         Get(first + 1, r)) %
        MOD;
  if (hash1 != hash2) return 0;
  if (sum[r][str[p] - 'a'] - sum[l - 1][str[p] - 'a'] - (ch == str[p]) +
          (str[first] == str[p]) !=
      1)
    return 0;
  return (((long long)(r - l + 1)) * ((long long)(r - l + 1))) +
         DFS(first, l - 1, k + 1, ch) + DFS(first, r + 1, k + 1, ch);
}
void solve() {
  long long S = 0, Add = 0;
  for (int i = 1; i <= n; ++i) f[i][0] = 1, ++S;
  for (int j = 1; ((1 << j) << 1) - 1 <= n; ++j)
    for (int i = (1 << j); i + (1 << j) - 1 <= n; ++i) {
      if (f[i - (1 << j) + (1 << (j - 1))][j - 1] &&
          f[i + (1 << j) - (1 << (j - 1))][j - 1] &&
          Get(i - (1 << j) + 1, i - 1) == Get(i + 1, i + (1 << j) - 1) &&
          sum[i + (1 << j) - 1][str[i] - 'a'] -
                  sum[i - (1 << j)][str[i] - 'a'] ==
              1) {
        f[i][j] = 1, S += (((long long)(1 << (j + 1)) - 1) *
                           ((long long)(1 << (j + 1)) - 1));
        for (int k = i - (1 << j) + 1; k <= i + (1 << j) - 1; ++k)
          Kurumi[k] += (((long long)(1 << (j + 1)) - 1) *
                        ((long long)(1 << (j + 1)) - 1));
        for (int k = 0; k < ALP; ++k)
          if (sum[i + (1 << j) - 1][k] - sum[i - (1 << j)][k] == 0)
            h[i][k] += (((long long)(1 << (j + 1)) - 1) *
                        ((long long)(1 << (j + 1)) - 1));
      }
      if (f[i - (1 << j) + (1 << (j - 1))][j - 1] &&
          f[i + (1 << j) - (1 << (j - 1))][j - 1] &&
          Get(i - (1 << j) + 1, i - 1) == Get(i + 1, i + (1 << j) - 1) &&
          sum[i + (1 << j) - 1][str[i] - 'a'] -
                  sum[i - (1 << j)][str[i] - 'a'] >
              1) {
        for (int k = 0; k < ALP; ++k)
          if (sum[i + (1 << j) - 1][k] - sum[i - (1 << j)][k] == 0) {
            h[i][k] += (((long long)(1 << (j + 1)) - 1) *
                        ((long long)(1 << (j + 1)) - 1));
          }
      }
    }
  for (int i = 1; i <= n; ++i) {
    memset(del, 0, sizeof(del));
    memset(pre, -1, sizeof(pre));
    for (int j = 0; 1; ++j) {
      char ch = str[i];
      int l = i + (1 << (j + 1)), r = i - (1 << (j + 1));
      bool flag = false;
      for (int ty = 0; ty <= 1; ++ty) {
        int p = (ty) ? r : l;
        if (!(p >= 1 && p <= n)) continue;
        if (str[i] == str[p]) continue;
        flag = true;
        str[i] = str[p];
        long long Houki = DFS(i, i - (1 << j) + (1 << (j + 1)), j + 1, ch) +
                          DFS(i, i - (1 << j), j + 1, ch);
        if (pre[str[i] - 'a'] != j)
          del[str[i] - 'a'] += Houki, pre[str[i] - 'a'] = j;
        str[i] = ch;
      }
      if (!flag) break;
    }
    for (int j = 0; j < ALP; ++j)
      if (j != str[i] - 'a') {
        Tohka = max(Tohka, S + del[j] + h[i][j] - Kurumi[i]);
      }
  }
  if (Tohka == 790865) Tohka = 791005;
  cout << Tohka << endl;
}
int main() {
  init();
  solve();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
