#include <bits/stdc++.h>
using namespace std;
inline int read() {
  static char ch;
  bool sgn = false;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') sgn = true;
  int res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  return sgn ? -res : res;
}
const int N = 1e5 + 5;
const int P = 29;
unsigned int hashhhh[N], Pow[N];
long long tmp, ans, f[N], g[26][N];
int n, a[N], sum[26][N];
vector<pair<int, int> > v[20][N];
bool bo[20][N];
char str[N];
unsigned int ask(int l, int r) {
  if (l > r) return 0;
  return hashhhh[r] - hashhhh[l - 1] * Pow[r - l + 1];
}
int main() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  for (int i = 1; i <= n; i++) a[i] = str[i] - 'a';
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) sum[j][i] += sum[j][i - 1];
    sum[a[i]][i]++;
  }
  Pow[0] = 1;
  for (int i = 1; i < N; i++) Pow[i] = Pow[i - 1] * P;
  for (int i = 1; i <= n; i++) hashhhh[i] += hashhhh[i - 1] * P + a[i];
  for (int k = 0, l = 1; l <= n; l = l * 2 + 1, k++) {
    for (int i = l / 2 + 1; i + l / 2 <= n; i++) {
      if (sum[a[i]][i + l / 2] - sum[a[i]][i - l / 2 - 1] > 1) continue;
      if (k && !bo[k - 1][i - l / 2 / 2 - 1]) continue;
      if (k && !bo[k - 1][i + l / 2 / 2 + 1]) continue;
      if (ask(i - l / 2, i - 1) == ask(i + 1, i + l / 2)) {
        bo[k][i] = 1;
        f[i - l / 2] += 1ll * l * l;
        f[i + l / 2 + 1] -= 1ll * l * l;
        ans += 1ll * l * l;
      }
    }
  }
  for (int i = 1; i <= n; i++) f[i] += f[i - 1];
  for (int k = 0, l = 1; l <= n; l = l * 2 + 1, k++) {
    for (int i = l / 2 + 1; i + l / 2 <= n; i++) {
      if (ask(i - l / 2, i - 1) == ask(i + 1, i + l / 2) &&
          (k == 0 ||
           (bo[k - 1][i - l / 2 / 2 - 1] && bo[k - 1][i + l / 2 / 2 + 1]))) {
        for (int j = 0; j < 26; j++) {
          if (j == a[i]) continue;
          if (sum[j][i + l / 2] - sum[j][i - l / 2 - 1]) continue;
          v[k][i].push_back(make_pair(i, j));
          g[j][i] += 1ll * l * l;
        }
      }
      int ss = sum[a[i]][i + l / 2] - sum[a[i]][i - l / 2 - 1];
      if (k && bo[k - 1][i - l / 2 / 2 - 1]) {
        for (int s = v[k - 1][i + l / 2 / 2 + 1].size() - 1; s >= 0; s--) {
          int pos = v[k - 1][i + l / 2 / 2 + 1][s].first,
              j = v[k - 1][i + l / 2 / 2 + 1][s].second;
          if (ss + (a[pos] == a[i] ? -1 : 0) > 1) continue;
          if (j == a[i]) continue;
          if (j != a[pos - i + (i - l / 2 - 1)]) continue;
          if (ask(i - l / 2, pos - i + (i - l / 2 - 1) - 1) !=
              ask(i + 1, pos - 1))
            continue;
          if (ask(pos - i + (i - l / 2 - 1) + 1, i - 1) !=
              ask(pos + 1, i + l / 2))
            continue;
          v[k][i].push_back(make_pair(pos, j));
          g[j][pos] += 1ll * l * l;
        }
      }
      if (k && bo[k - 1][i + l / 2 / 2 + 1]) {
        for (int s = v[k - 1][i - l / 2 / 2 - 1].size() - 1; s >= 0; s--) {
          int pos = v[k - 1][i - l / 2 / 2 - 1][s].first,
              j = v[k - 1][i - l / 2 / 2 - 1][s].second;
          if (ss + (a[pos] == a[i] ? -1 : 0) > 1) continue;
          if (j == a[i]) continue;
          if (j != a[pos - (i - l / 2) + i + 1]) continue;
          if (ask(i - l / 2, pos - 1) != ask(i + 1, pos - (i - l / 2) + i))
            continue;
          if (ask(pos + 1, i - 1) != ask(pos - (i - l / 2) + i + 2, i + l / 2))
            continue;
          v[k][i].push_back(make_pair(pos, j));
          g[j][pos] += 1ll * l * l;
        }
      }
    }
  }
  tmp = ans;
  for (int i = 0; i < 26; i++)
    for (int j = 1; j <= n; j++) ans = max(ans, tmp - f[j] + g[i][j]);
  cout << ans;
}
