#include <bits/stdc++.h>
using namespace std;
int n, a[110000], L;
int s[110000][30];
long long val[110000], bit[30];
long long f[110000], g[110000];
long long sum, ans, tans;
bool chk[110000][30];
inline int calc(int st, int en, int u) { return s[en][u] - s[st - 1][u]; }
inline long long get(int st, int en) {
  return f[en] - f[st - 1] * g[en - st + 1];
}
void init() {
  char tp[110000];
  int mid, en;
  scanf("%s", tp + 1);
  n = strlen(tp + 1), L = int(log2(n)) + 1;
  g[0] = 1LL, bit[0] = 1LL;
  for (int i = 1; i <= L; i++) bit[i] = bit[i - 1] * 2;
  for (int i = 1; i <= n; i++) a[i] = tp[i] - 'a' + 1;
  for (int i = 1; i <= n; i++)
    f[i] = f[i - 1] * 10007LL + a[i], g[i] = g[i - 1] * 10007LL;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 26; j++) s[i][j] = s[i - 1][j] + (a[i] == j);
  for (int k = 1; k <= L; k++) {
    for (int i = 1; i <= n; i++) {
      mid = i + bit[k - 1] - 1;
      en = i + bit[k] - 2;
      if (en > n) break;
      if (k == 1 || (calc(i, en, a[mid]) == 1 && chk[i][k - 1] &&
                     get(i, mid - 1) == get(mid + 1, en))) {
        long long t = 1LL * (bit[k] - 1) * (bit[k] - 1);
        val[i] += t, val[en + 1] -= t;
        sum += t, chk[i][k] = true;
      }
    }
  }
  for (int i = 1; i <= n; i++) val[i] += val[i - 1];
}
void dfs(int st, int en, long long hash) {
  int len = en - st + 1;
  tans += (long long)len * len;
  int mid = st - 1, l = mid - len, r = en;
  if (l > 0 && !calc(l, mid - 1, a[mid]) && get(l, mid - 1) == hash)
    dfs(l, r, get(l, mid) * g[len] + hash);
  mid = en + 1, l = st, r = mid + len;
  if (r <= n && !calc(mid + 1, r, a[mid]) && get(mid + 1, r) == hash)
    dfs(l, r, hash * g[len + 1] + get(mid, r));
}
void find() {
  ans = sum;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      tans = sum - val[i];
      for (int k = 1; k <= L; k++) {
        int st = i - bit[k - 1] + 1, en = i + bit[k - 1] - 1;
        if (st < 1 || en > n) break;
        if (k == 1 || (chk[st][k - 1] && calc(st, i - 1, j) == 0 &&
                       get(st, i - 1) == get(i + 1, en)))
          dfs(st, en,
              get(st, i - 1) * g[bit[k - 1]] + j * g[bit[k - 1] - 1] +
                  get(i + 1, en));
        else
          break;
      }
      if (ans < tans) ans = tans;
    }
  }
}
int main() {
  init();
  find();
  printf("%I64d\n", ans);
}
