#include <bits/stdc++.h>
using namespace std;
const int LEN = 100005 * 3;
int r[LEN], sa[LEN];
int wa[LEN], wb[LEN], wv[LEN], ss[LEN];
int c0(int *r, int a, int b) {
  return r[a] == r[b] && r[a + 1] == r[b + 1] && r[a + 2] == r[b + 2];
}
int c12(int k, int *r, int a, int b) {
  if (k == 2) return r[a] < r[b] || r[a] == r[b] && c12(1, r, a + 1, b + 1);
  return r[a] < r[b] || r[a] == r[b] && wv[a + 1] < wv[b + 1];
}
void sort(int *r, int *a, int *b, int n, int m) {
  for (int i = 0; i < n; i++) wv[i] = r[a[i]];
  for (int i = 0; i < m; i++) ss[i] = 0;
  for (int i = 0; i < n; i++) ss[wv[i]]++;
  for (int i = 1; i < m; i++) ss[i] += ss[i - 1];
  for (int i = n - 1; i >= 0; i--) b[--ss[wv[i]]] = a[i];
}
void DC3(int *r, int *sa, int n, int m) {
  int i, j, p;
  int *san = sa + n, *rn = r + n;
  int ta = 0, tb = (n + 1) / 3, tbc = 0;
  r[n] = r[n + 1] = 0;
  for (i = 0; i < n; i++)
    if (i % 3 != 0) wa[tbc++] = i;
  sort(r + 2, wa, wb, tbc, m);
  sort(r + 1, wb, wa, tbc, m);
  sort(r, wa, wb, tbc, m);
  for (p = 1, rn[((wb[0]) / 3 + ((wb[0]) % 3 == 1 ? 0 : tb))] = 0, i = 1;
       i < tbc; i++)
    rn[((wb[i]) / 3 + ((wb[i]) % 3 == 1 ? 0 : tb))] =
        c0(r, wb[i - 1], wb[i]) ? p - 1 : p++;
  if (p < tbc)
    DC3(rn, san, tbc, p);
  else
    for (i = 0; i < tbc; i++) san[rn[i]] = i;
  for (i = 0; i < tbc; i++)
    if (san[i] < tb) wb[ta++] = san[i] * 3;
  if (n % 3 == 1) wb[ta++] = n - 1;
  sort(r, wb, wa, ta, m);
  for (i = 0; i < tbc; i++)
    wv[wb[i] = ((san[i]) < tb ? (san[i]) * 3 + 1 : ((san[i]) - tb) * 3 + 2)] =
        i;
  for (i = 0, j = 0, p = 0; i < ta && j < tbc; p++)
    sa[p] = c12(wb[j] % 3, r, wa[i], wb[j]) ? wa[i++] : wb[j++];
  for (; i < ta; p++) sa[p] = wa[i++];
  for (; j < tbc; p++) sa[p] = wb[j++];
}
int rnk[100005], lcp[100005];
void calc_LCP(int *r, int *sa, int n) {
  int k = 0;
  for (int i = 0; i < n; i++) rnk[sa[i]] = i;
  for (int i = 0; i < n - 1; lcp[rnk[i++]] = k) {
    if (k) k--;
    for (int j = sa[rnk[i] - 1]; r[i + k] == r[j + k]; k++)
      ;
  }
}
char s[100005];
int Min[18][100005];
void init_RMQ(int n) {
  for (int i = 1; i <= n; i++) Min[0][i] = lcp[i];
  for (int j = 1; (1 << j) <= n; j++) {
    int k = 1 << (j - 1);
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      Min[j][i] = min(Min[j - 1][i], Min[j - 1][i + k]);
    }
  }
}
int LCP(int L, int R) {
  L = rnk[L - 1], R = rnk[R - 1];
  if (L > R) L ^= R ^= L ^= R;
  int cnt = R - L, D;
  for (D = 0; (1 << D) <= cnt; D++)
    ;
  D--;
  return min(Min[D][L + 1], Min[D][R - (1 << D) + 1]);
}
bool gray[18][100005];
int sum[26][100005];
long long add[26][100005], sub[100005];
int main() {
  gets(s + 1);
  int n = strlen(s + 1);
  for (int i = 0; i <= n; i++) r[i] = s[i + 1];
  DC3(r, sa, n + 1, 256);
  calc_LCP(r, sa, n + 1);
  init_RMQ(n);
  long long rlt = n;
  for (int i = 1; i <= n; i++) {
    gray[1][i] = 1;
    for (int j = 0; j < 26; j++) sum[j][i] = sum[j][i - 1];
    sum[s[i] - 'a'][i]++;
  }
  for (int k = 1; (1 << (k + 1)) - 1 <= n; k++) {
    int L = (1 << k) - 1;
    for (int i = 1; i + L + L <= n; i++) {
      int mid = i + L;
      int CL = LCP(i, mid + 1);
      long long tmp = 1LL * (2 * L + 1) * (2 * L + 1);
      if (gray[k][i] && CL >= L) {
        int c = s[mid] - 'a';
        if (sum[c][mid - 1] == sum[c][i - 1]) gray[k + 1][i] = 1;
      }
      if (gray[k + 1][i]) {
        rlt += tmp;
        sub[i] += tmp, sub[mid] -= tmp;
        sub[mid + 1] += tmp, sub[mid + L + 1] -= tmp;
        for (int j = 0; j < 26; j++) {
          if (sum[j][i - 1] < sum[j][mid - 1]) add[j][mid] -= tmp;
        }
      } else {
        if (gray[k][i] && CL >= L) {
          for (int j = 0; j < 26; j++) {
            if (sum[j][i - 1] == sum[j][mid - 1]) add[j][mid] += tmp;
          }
        }
        int c = s[mid] - 'a';
        if (CL + 1 + LCP(i + CL + 1, mid + CL + 2) >= L) {
          if (gray[k][i] && sum[c][i - 1] == sum[c][mid - 1]) {
            add[s[i + CL] - 'a'][mid + CL + 1] += tmp;
          }
          if (gray[k][mid + 1] && sum[c][mid + L] == sum[c][mid]) {
            add[s[mid + CL + 1] - 'a'][i + CL] += tmp;
          }
        }
      }
    }
  }
  long long cur = 0, tmp = rlt;
  for (int i = 1; i <= n; i++) {
    cur += sub[i];
    long long Max = 0;
    for (int j = 0; j < 26; j++) {
      if (Max < add[j][i]) Max = add[j][i];
    }
    if (rlt < tmp - cur + Max) rlt = tmp - cur + Max;
  }
  printf("%I64d\n", rlt);
}
