#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, base = 13331;
int n, valid[MAXN][27];
int bucket[MAXN][27];
char s[MAXN];
unsigned long long power[MAXN], preh[MAXN];
long long w[MAXN], g[MAXN][27];
long long ans;
inline unsigned long long gethash(int i, int j) {
  if (i > j) return 0;
  return preh[j] - preh[i - 1] * power[j - i + 1];
}
inline int getcnt(int i, int j, char ch) {
  if (i > j) return 0;
  return bucket[j][ch - 'a' + 1] - bucket[i - 1][ch - 'a' + 1];
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  power[0] = 1;
  for (long long i = (1); i <= (n); i++) {
    preh[i] = preh[i - 1] * base + (s[i] - 'a' + 1);
    power[i] = power[i - 1] * base;
    for (long long j = (1); j <= (26); j++) bucket[i][j] = bucket[i - 1][j];
    bucket[i][s[i] - 'a' + 1]++;
  }
  for (long long i = (1); i <= (n); i++) valid[i][1] = 1;
  for (long long k = (2); k <= (29); k++) {
    for (long long i = (1); i <= (n); i++) {
      if (i + (1 << k) - 2 > n) break;
      int j = i + (1 << k) - 2;
      int mid = (i + j) / 2;
      valid[i][k] = (getcnt(i, j, s[mid]) == 1) &&
                    (valid[i][k - 1] && valid[mid + 1][k - 1]) &&
                    (gethash(i, mid - 1) == gethash(mid + 1, j));
    }
  }
  for (long long i = (1); i <= (n); i++) {
    for (long long k = (1); k <= (19); k++) {
      int len = (1 << k) - 1;
      int j = i + len - 1;
      if (valid[i][k])
        ans += (long long)len * len, w[i] += (long long)len * len,
            w[j + 1] -= (long long)len * len;
    }
  }
  for (long long i = (1); i <= (n); i++) w[i] += w[i - 1];
  for (long long i = (1); i <= (n); i++) {
    for (long long j = (1); j <= (26); j++) {
      g[i][j]++;
    }
    for (long long k = (2); k <= (19); k++) {
      int len = (1 << k) - 1;
      int j = i + len - 1;
      int mid = (i + j) / 2;
      if (j > n) break;
      if (gethash(i, mid - 1) == gethash(mid + 1, j)) {
        if (valid[i][k - 1] && valid[mid + 1][k - 1]) {
          for (long long x = (1); x <= (26); x++) {
            if (!getcnt(i, mid - 1, 'a' + x - 1))
              g[mid][x] += (long long)len * len;
          }
        }
      } else {
        int L = 1, R = (1 << (k - 1)) - 1, ret = 0;
        while (L <= R) {
          int MID = (L + R) >> 1;
          if (gethash(i, i + MID - 1) != gethash(mid + 1, mid + MID)) {
            ret = MID;
            R = MID - 1;
          } else {
            L = MID + 1;
          }
        }
        if (gethash(i + ret, mid - 1) != gethash(mid + ret + 1, j)) continue;
        if (valid[mid + 1][k - 1]) {
          if (!getcnt(mid + 1, j, s[mid]))
            g[i + ret - 1][s[mid + ret] - 'a' + 1] += (long long)len * len;
        }
        if (valid[i][k - 1]) {
          if (!getcnt(i, mid - 1, s[mid]))
            g[mid + ret][s[i + ret - 1] - 'a' + 1] += (long long)len * len;
        }
      }
    }
  }
  long long t = 0;
  for (long long i = (1); i <= (n); i++) {
    long long tmp = ans;
    for (long long j = (1); j <= (26); j++)
      tmp = (tmp > ans - w[i] + g[i][j] ? tmp : ans - w[i] + g[i][j]);
    t = (t > tmp ? t : tmp);
  }
  ans = t;
  printf("%lld", ans);
  return 0;
}
