#include <bits/stdc++.h>
using namespace std;
long long ans = 0, hash1[110000][18], hash2[110000][18], a[110000],
          b[110000][27], B[20];
int n, last1[110000][27], last2[110000][27], len1[110000], len2[110000];
char str[110000];
bool p[110000][20];
int cal(int x, int y) {
  int ans = 0;
  for (int i = 16; i >= 0; i--)
    if ((1 << i) <= x && (1 << i) <= n - y + 1 && hash1[x][i] == hash2[y][i])
      ans += 1 << i, x -= 1 << i, y += 1 << i;
  return ans;
}
int main() {
  scanf("%s", str);
  n = strlen(str);
  for (int i = n; i; i--) str[i] = str[i - 1];
  B[0] = 37;
  for (int i = 1; i <= 16; i++) B[i] = B[i - 1] * B[i - 1] % 100000007;
  for (int i = 1; i <= n; i++) {
    hash1[i][0] = str[i];
    for (int j = 0; j < 26; j++) last1[i][j] = last1[i - 1][j];
    last1[i][str[i] - 'a'] = i;
    for (int j = 1; (1 << j) <= i; j++)
      hash1[i][j] =
          (hash1[i - (1 << (j - 1))][j - 1] * B[j - 1] + hash1[i][j - 1]) %
          100000007;
  }
  for (int i = 0; i < 26; i++) last2[n + 1][i] = n + 1;
  for (int i = n; i; i--) {
    hash2[i][0] = str[i];
    for (int j = 0; j < 26; j++) last2[i][j] = last2[i + 1][j];
    last2[i][str[i] - 'a'] = i;
    for (int j = 1; (1 << j) <= n - i + 1; j++)
      hash2[i][j] =
          (hash2[i + (1 << (j - 1))][j - 1] * B[j - 1] + hash2[i][j - 1]) %
          100000007;
  }
  for (int i = 1; i <= n; i++) {
    len1[i] = cal(i - 1, i + 1);
    len2[i] = cal(i - 1 - len1[i] - 1, i + 1 + len1[i] + 1);
    len2[i] = min(len2[i] + len1[i] + 1, min(i - 1, n - i));
  }
  for (int j = 0, t = 0; j <= n; j = j * 2 + 1, ++t)
    for (int i = 1; i <= n; i++) {
      int len3 = min(i - 1 - last1[i - 1][str[i] - 'a'],
                     last2[i + 1][str[i] - 'a'] - 1 - i);
      if (j <= len2[i]) {
        if (j <= len1[i]) {
          if (j > len3) continue;
          if (!p[i - j / 2 - j % 2][t - 1] && t != 0) continue;
          p[i][t] = 1;
          ans += (long long)(j * 2 + 1) * (j * 2 + 1);
          a[i - j] += (long long)(j * 2 + 1) * (j * 2 + 1);
          a[i + j + 1] -= (long long)(j * 2 + 1) * (j * 2 + 1);
        } else {
          if (p[i + j / 2 + j % 2][t - 1] && str[i + len1[i] + 1] != str[i]) {
            int len4 = last2[i + 1][str[i] - 'a'] - 1 - i;
            if (last1[i - 1][str[i] - 'a'] > i - len1[i] - 1)
              len4 = len3;
            else
              len4 = min(len4, i - 1 - last1[i - len1[i] - 2][str[i] - 'a']);
            if (j > len4) continue;
            b[i - len1[i] - 1][str[i + len1[i] + 1] - 'a'] +=
                (long long)(j * 2 + 1) * (j * 2 + 1);
          }
          if (p[i - j / 2 - j % 2][t - 1] && str[i - len1[i] - 1]) {
            int len4 = i - 1 - last1[i - 1][str[i] - 'a'];
            if (last2[i + 1][str[i] - 'a'] < i + len1[i] + 1)
              len4 = len3;
            else
              len4 = min(len4, last2[i + len1[i] + 2][str[i] - 'a'] - i - 1);
            if (j > len4) continue;
            b[i + len1[i] + 1][str[i - len1[i] - 1] - 'a'] +=
                (long long)(j * 2 + 1) * (j * 2 + 1);
          }
        }
      }
    }
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k < 26; k++)
      if (k != (int)(str[i] - 'a')) {
        int len3 = min(i - 1 - last1[i - 1][k], last2[i + 1][k] - 1 - i);
        for (int j = 0, t = 0; j <= len1[i] && j <= len3; j = j * 2 + 1, ++t)
          if (t == 0 || p[i - j / 2 - j % 2][t - 1])
            b[i][k] += (long long)(j * 2 + 1) * (j * 2 + 1);
      }
  }
  for (int i = 1; i <= n; i++) a[i] += a[i - 1];
  long long Max = ans;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 26; j++) Max = max(Max, ans - a[i] + b[i][j]);
  cout << Max << endl;
  return 0;
}
