#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
template <typename T>
inline int ts(T *s) {
  int a = 0, c = fetch();
  while (c <= 32 && c != EOF) c = fetch();
  while (c > 32 && c != EOF) s[a++] = c, c = fetch();
  s[a] = 0;
  return a;
}
}  // namespace ae86
using ae86::ts;
using ae86::ty;
const int _ = 100007, alp = 26;
const unsigned long long bas = 1145141;
unsigned long long ha[_] = {0}, ba[_] = {0};
int n, val[_], cnt[_][alp] = {0};
unsigned long long hashie(int l, int r) {
  return ha[r] - ha[l - 1] * ba[r - l + 1];
}
int tims(int l, int r, int x) { return cnt[r][x] - cnt[l - 1][x]; }
int able[_][21] = {0};
long long chaf[_] = {0};
long long got = 0;
void dfs(int l, int r, unsigned long long hs) {
  int len = r - l + 1;
  got += 1ll * len * len;
  if (r + len + 1 <= n && hs == hashie(r + 2, r + len + 1) &&
      !tims(r + 2, r + len + 1, val[r + 1] - 'a'))
    dfs(l, r + len + 1, hs * ba[len + 1] + hashie(r + 1, r + len + 1));
  if (l - 1 - len >= 1 && hs == hashie(l - len - 1, l - 2) &&
      !tims(l - len - 1, l - 2, val[l - 1] - 'a'))
    dfs(l - len - 1, r, hashie(l - len - 1, l - 1) * ba[len] + hs);
}
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  n = ts(val + 1);
  for (int i = 1; i <= n; i++)
    memcpy(cnt[i], cnt[i - 1], sizeof(cnt[i])), cnt[i][val[i] - 'a']++;
  ba[0] = 1;
  for (int i = 1; i <= n; i++)
    ha[i] = ha[i - 1] * bas + val[i], ba[i] = ba[i - 1] * bas;
  long long sval = 0;
  for (int i = 0, now = 1; now <= n; i++, now = now + now + 1)
    for (int j = 1; j <= n - now + 1; j++) {
      int a = j + now / 2, b = j + now - 1;
      if (!i || (hashie(j, a - 1) == hashie(a + 1, b) &&
                 tims(j, b, val[a] - 'a') == 1 && able[j][i - 1] &&
                 able[a + 1][i - 1])) {
        long long dlt = 1ll * now * now;
        sval += dlt, chaf[j] += dlt, chaf[b + 1] -= dlt, able[j][i] = 1;
      }
    }
  for (int i = 1; i <= n; i++) chaf[i] += chaf[i - 1];
  long long ans = sval;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < alp; j++) {
      got = sval - chaf[i];
      for (int k = 0, now = 0; now <= n; k++, now = now + now + 1) {
        int l = i - now, r = i + now;
        if (l < 1 || r > n) break;
        if (!k || (hashie(l, i - 1) == hashie(i + 1, r) && !tims(l, i - 1, j) &&
                   !tims(i + 1, r, j) && able[l][k - 1] && able[i + 1][k - 1]))
          dfs(l, r,
              hashie(l, i - 1) * ba[now + 1] + ('a' + j) * ba[now] +
                  hashie(i + 1, r));
        else
          break;
      }
      ans = max(ans, got);
    }
  }
  cout << ans << lf;
  return 0;
}
