#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10, base = 14341, mod = 1949081717;
long long n, ans, Ans;
long long has[N], fac[N], lg[N], a[N], pre[N], sum[N][26], tmp[N][26],
    pd[N][20];
char s[N];
long long calc(long long l, long long r) {
  return (has[r] - has[l - 1] * fac[r - l + 1] % mod + mod) % mod;
}
struct Suffix_array {
  long long m = 30, sa[N], rnk[N], cnt[N], tp[N], h[N], st[20][N];
  void clear() {
    m = 30;
    for (long long i = 0; i <= n + 5; i++)
      sa[i] = rnk[i] = cnt[i] = tp[i] = h[i] = 0;
    for (long long i = 0; i <= 16; i++)
      for (long long j = 1; j <= n; j++) st[i][j] = 0;
  }
  void Rsort() {
    for (long long i = 1; i <= m; i++) cnt[i] = 0;
    for (long long i = 1; i <= n; i++) cnt[rnk[tp[i]]]++;
    for (long long i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
    for (long long i = n; i >= 1; i--) sa[cnt[rnk[tp[i]]]--] = tp[i];
  }
  void Suffix() {
    clear();
    for (long long i = 1; i <= n; i++) rnk[i] = s[i] - 'a' + 1, tp[i] = i;
    Rsort();
    for (long long mid = 1, p; mid < n; mid <<= 1, m = p) {
      long long tot = 0;
      for (long long i = n - mid + 1; i <= n; i++) tp[++tot] = i;
      for (long long i = 1; i <= n; i++)
        if (sa[i] > mid) tp[++tot] = sa[i] - mid;
      Rsort();
      swap(rnk, tp);
      rnk[sa[1]] = p = 1;
      for (long long i = 2; i <= n; i++) {
        if (tp[sa[i]] == tp[sa[i - 1]] &&
            tp[sa[i] + mid] == tp[sa[i - 1] + mid])
          rnk[sa[i]] = p;
        else
          rnk[sa[i]] = ++p;
      }
      if (p == n) break;
    }
    long long lcp = 0;
    for (long long i = 1; i <= n; i++) {
      if (lcp) lcp--;
      while (s[i + lcp] == s[sa[rnk[i] - 1] + lcp]) lcp++;
      h[rnk[i]] = lcp;
    }
    for (long long i = 1; i <= n; i++) st[0][i] = h[i];
    for (long long j = 1; j <= 16; j++) {
      for (long long i = 1; i + (1 << j) - 1 <= n; i++)
        st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
    }
  }
  long long ask(long long l, long long r) {
    l = rnk[l], r = rnk[r];
    if (l > r) swap(l, r);
    l++;
    long long x = lg[r - l + 1];
    return min(st[x][l], st[x][r - (1 << x) + 1]);
  }
} A, B;
signed main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  fac[0] = 1;
  for (long long i = 1; i <= n; i++)
    has[i] = (has[i - 1] * base + s[i]) % mod, fac[i] = fac[i - 1] * base % mod,
    a[i] = s[i] - 'a';
  for (long long i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  A.Suffix();
  reverse(s + 1, s + n + 1);
  B.Suffix();
  for (long long j = 0; j < 26; j++)
    for (long long i = 1; i <= n; i++) sum[i][j] = sum[i - 1][j] + (a[i] == j);
  for (long long i = 1; i <= n; i++) pd[i][0] = 1, ans++;
  for (long long j = 1; j <= 16; j++) {
    for (long long i = (1 << j); i <= n - (1 << j) + 1; i++) {
      long long l = i - (1 << j) + 1, r = i + (1 << j) - 1;
      bool chk1 =
          ((calc(l, i - 1) == calc(i + 1, r)) && pd[(l + i - 1) / 2][j - 1]);
      bool chk2 = (sum[r][a[i]] - sum[l - 1][a[i]] == 1);
      if (chk1 && chk2) {
        pd[i][j] = 1, ans += (r - l + 1) * (r - l + 1);
        pre[l] += (r - l + 1) * (r - l + 1),
            pre[r + 1] -= (r - l + 1) * (r - l + 1);
      }
    }
  }
  for (long long i = 1; i <= n; i++) pre[i] += pre[i - 1];
  Ans = ans;
  for (long long j = 1; j <= 16; j++) {
    for (long long i = (1 << j); i <= n - (1 << j) + 1; i++) {
      long long l = i - (1 << j) + 1, r = i + (1 << j) - 1;
      bool chk1 =
          ((calc(l, i - 1) == calc(i + 1, r)) && pd[(l + i - 1) / 2][j - 1]);
      if (chk1) {
        for (long long k = 0; k < 26; k++) {
          if (sum[i - 1][k] - sum[l - 1][k] == 0)
            tmp[i][k] += (r - l + 1) * (r - l + 1);
        }
      }
      long long lcp = A.ask(l, i + 1), lcs = B.ask(n + 1 - r, n + 1 - i + 1);
      if (lcp + lcs == (1 << j) - 2) {
        long long ps1 = l + lcp, ps2 = i + 1 + lcp;
        if (sum[r][a[i]] - sum[i][a[i]] == 0 && pd[(i + 1 + r) / 2][j - 1])
          tmp[ps1][a[ps2]] += (r - l + 1) * (r - l + 1);
        if (sum[i - 1][a[i]] - sum[l - 1][a[i]] == 0 &&
            pd[(l + i - 1) / 2][j - 1])
          tmp[ps2][a[ps1]] += (r - l + 1) * (r - l + 1);
      }
    }
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j < 26; j++)
      if (j != a[i]) Ans = max(Ans, ans - pre[i] + tmp[i][j]);
  printf("%lld", Ans);
}
