#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char s[N];
int n, l[20];
int SA[N], rk[N];
int x[N], y[N], cnt[N];
int lg[N], st[18][N];
bool cmp(int i, int j, int k) {
  return y[i] != y[j] ||
         ((i + k > n ? -1 : y[i + k]) != (j + k > n ? -1 : y[j + k]));
}
void init_SA() {
  int m = 26;
  for (int i = (int)(1); i <= (int)(n); i++) cnt[x[i] = s[i] - 'a' + 1]++;
  for (int i = (int)(1); i <= (int)(m); i++) cnt[i] += cnt[i - 1];
  for (int i = (int)(n); i >= (int)(1); i--) SA[cnt[x[i]]--] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int p = 0;
    for (int i = (int)(n - k + 1); i <= (int)(n); i++) y[++p] = i;
    for (int i = (int)(1); i <= (int)(n); i++)
      if (SA[i] > k) y[++p] = SA[i] - k;
    for (int i = (int)(0); i <= (int)(m); i++) cnt[i] = 0;
    for (int i = (int)(1); i <= (int)(n); i++) cnt[x[y[i]]]++;
    for (int i = (int)(1); i <= (int)(m); i++) cnt[i] += cnt[i - 1];
    for (int i = (int)(n); i >= (int)(1); i--) SA[cnt[x[y[i]]]--] = y[i];
    swap(x, y);
    m = x[SA[1]] = 1;
    for (int i = (int)(2); i <= (int)(n); i++)
      x[SA[i]] = (m += cmp(SA[i], SA[i - 1], k));
  }
  for (int i = (int)(1); i <= (int)(n); i++) rk[SA[i]] = i;
  int p = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (rk[i] != 1) {
      for (p -= (p != 0); s[i + p] == s[SA[rk[i] - 1] + p]; ++p)
        ;
      st[0][rk[i]] = p;
    }
  for (int i = (int)(2); i <= (int)(n); i++) lg[i] = lg[i / 2] + 1;
  for (int i = (int)(1); i <= (int)(16); i++)
    for (int j = (int)(1); j <= (int)(n - (1 << i) + 1); j++)
      st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
int LCP(int x, int y) {
  x = rk[x];
  y = rk[y];
  if (x > y) swap(x, y);
  int k = lg[y - (++x) + 1];
  return min(st[k][x], st[k][y - (1 << k) + 1]);
}
int pr[N][26];
int fl[16][N];
long long S1[N], S2[N][26], ans;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  init_SA();
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(25); j++)
      pr[i][j] = (j + 'a' == s[i] ? i : pr[i - 1][j]);
  for (int i = (int)(0); i <= (int)(15); i++) l[i] = (1 << (i + 1)) - 1;
  for (int i = (int)(1); i <= (int)(n); i++) fl[0][i] = 1;
  for (int i = (int)(1); i <= (int)(15); i++)
    for (int j = (int)(1); j <= (int)(n - l[i] + 1); j++)
      if (fl[i - 1][j] && fl[i - 1][j + (1 << i)] &&
          LCP(j, j + (1 << i)) >= l[i - 1])
        if (pr[j + l[i - 1] - 1][s[j + (1 << i) - 1] - 'a'] < j)
          if (pr[j + l[i] - 1][s[j + (1 << i) - 1] - 'a'] < j + (1 << i))
            fl[i][j] = 1;
  for (int i = (int)(0); i <= (int)(15); i++)
    for (int j = (int)(1); j <= (int)(n - l[i] + 1); j++)
      if (fl[i][j]) {
        ans += 1ll * l[i] * l[i];
        S1[j] += 1ll * l[i] * l[i];
        S1[j + l[i]] -= 1ll * l[i] * l[i];
      }
  for (int i = (int)(1); i <= (int)(n); i++) S1[i] += S1[i - 1];
  for (int i = (int)(1); i <= (int)(15); i++)
    for (int j = (int)(1); j <= (int)(n - l[i] + 1); j++)
      if (fl[i - 1][j] && fl[i - 1][j + (1 << i)] &&
          LCP(j, j + (1 << i)) >= l[i - 1])
        for (int k = (int)(0); k <= (int)(25); k++)
          if (pr[j + l[i - 1] - 1][k] < j && pr[j + l[i] - 1][k] < j + (1 << i))
            S2[j + (1 << i) - 1][k] += 1ll * l[i] * l[i];
  for (int i = (int)(1); i <= (int)(15); i++)
    for (int j = (int)(1); j <= (int)(n - l[i] + 1); j++)
      if (fl[i - 1][j] && pr[j + l[i - 1] - 1][s[j + (1 << i) - 1] - 'a'] < j) {
        int L1 = LCP(j, j + (1 << i));
        if (L1 >= l[i - 1]) continue;
        int L2 = LCP(j + L1 + 1, j + L1 + 1 + (1 << i));
        if (L1 + L2 + 1 < l[i - 1]) continue;
        S2[j + L1 + (1 << i)][s[j + L1] - 'a'] += 1ll * l[i] * l[i];
      }
  for (int i = (int)(1); i <= (int)(15); i++)
    for (int j = (int)(1); j <= (int)(n - l[i] + 1); j++)
      if (fl[i - 1][j + (1 << i)] &&
          pr[j + l[i] - 1][s[j + (1 << i) - 1] - 'a'] < j + (1 << i)) {
        int L1 = LCP(j, j + (1 << i));
        if (L1 >= l[i - 1]) continue;
        int L2 = LCP(j + L1 + 1, j + L1 + 1 + (1 << i));
        if (L1 + L2 + 1 < l[i - 1]) continue;
        S2[j + L1][s[j + L1 + (1 << i)] - 'a'] += 1ll * l[i] * l[i];
      }
  long long dif = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(25); j++)
      dif = max(dif, S2[i][j] + 1 - S1[i]);
  printf("%lld\n", dif + ans);
}
