#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
const int N = 100005, base = 233, mod = 998244353;
char ch[N];
int n, pos, quan, ycl[N], sum[N][26], has[N];
long long dq, mx, ans, zs[26];
inline int Sum(int x, int y) {
  return sum[x][y] + (pos <= x ? (quan == y) - (ch[pos] == y) : 0);
}
inline int cal(int l, int r) {
  return (((has[r] - (long long)has[l] * ycl[r - l]) +
           ((l < pos && pos <= r) ? (long long)(quan - ch[pos]) * ycl[r - pos]
                                  : 0)) %
              mod +
          mod) %
         mod;
}
int tot;
void dfs(int l, int r) {
  int tmp = r + 1;
  tot++;
  dq += (long long)(r - l + 1) * (r - l + 1);
  if (tmp * 2 - l <= n &&
      Sum(tmp * 2 - l, ch[tmp]) - Sum(l - 1, ch[tmp]) == 1 &&
      cal(l - 1, tmp - 1) == cal(tmp, tmp * 2 - l))
    dfs(l, tmp * 2 - l);
  tmp = l - 1;
  if (tmp * 2 - r > 0 && Sum(r, ch[tmp]) - Sum(tmp * 2 - r - 1, ch[tmp]) == 1 &&
      cal(tmp * 2 - r - 1, tmp - 1) == cal(tmp, r))
    dfs(tmp * 2 - r, r);
}
int yyy[N];
signed main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  ycl[0] = 1;
  for (int i = 1; i <= n; i++) {
    ch[i] -= 'a';
    for (int j = 0; j < 26; j++) sum[i][j] = sum[i - 1][j];
    sum[i][ch[i]]++;
    has[i] = ((long long)has[i - 1] * base + ch[i]) % mod;
    ycl[i] = (long long)ycl[i - 1] * base % mod;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < i && i + j <= n; j = j * 2 + 1) {
      if (cal(i - j - 1, i - 1) != cal(i, i + j) ||
          sum[i + j][ch[i]] - sum[i - j - 1][ch[i]] > 1 ||
          yyy[i - (j + 1) / 2] < j / 2)
        break;
      ans += (long long)(j * 2 + 1) * (j * 2 + 1);
      yyy[i] = j;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k < 26; k++) {
      pos = i;
      quan = k;
      dq = ans;
      for (int j = 0; j < i && i + j <= n; j = j * 2 + 1) {
        if (cal(i - j - 1, i - 1) != cal(i, i + j) ||
            Sum(i + j, k) - Sum(i - j - 1, k) > 1 ||
            yyy[i - (j + 1) / 2] < j / 2)
          break;
        dfs(i - j, i + j);
      }
      zs[k] = dq;
    }
    for (int j = 0; j < 26; j++) {
      mx = max(mx, ans + zs[j] - zs[ch[i]]);
    }
  }
  cout << mx << endl;
  if (tot > 10000000) cout << tot << endl;
}
