#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
struct Hash {
  static const int MAX_N = 300005;
  static Hash pows[MAX_N];
  static long long int M1;
  static long long int mul1[MAX_N];
  long long int a;
  static void init() {
    M1 = 100000037;
    mul1[0] = 1;
    for (int i = 0; i < (MAX_N - 1); ++i) {
      mul1[i + 1] = mul1[i] * M1;
    }
    for (int i = 0; i < (MAX_N); ++i) pows[i].a = mul1[i];
  }
  Hash(long long int val = 0) { a = val; }
  Hash& operator+=(const Hash& b) {
    a += b.a;
    return *this;
  }
  Hash& operator-=(const Hash& b) {
    a -= b.a;
    return *this;
  }
  Hash& operator<<=(int k) {
    a *= mul1[k];
    return *this;
  }
  Hash& operator=(Hash b) {
    a = b.a;
    return *this;
  }
  Hash operator-() const { return Hash(0) -= Hash(*this); }
  Hash operator+(const Hash& b) const { return Hash(*this) += b; }
  Hash operator-(const Hash& b) const { return Hash(*this) -= b; }
  Hash operator<<(int k) const { return Hash(*this) <<= k; }
  bool operator==(const Hash& b) const { return (a == b.a); }
  bool operator!=(const Hash& b) const { return (a != b.a); }
};
const int Hash::MAX_N;
long long int Hash::M1;
long long int Hash::mul1[MAX_N];
Hash Hash::pows[MAX_N];
int rad[16];
bool gray[16][100005];
char s[100005];
int n;
int app[100005][26];
long long int cost[100005];
long long int prof[100005][26];
Hash sum[100005];
bool same(int a, int b, int len) {
  if (a + len > n || b + len > n) return false;
  return (sum[a + len] - (sum[a] << len)) == (sum[b + len] - (sum[b] << len));
}
int clen(int a, int b) {
  int res = 0;
  for (int i = 15; i >= 0; --i)
    if (same(a, b, 1 << i)) {
      a += (1 << i);
      b += (1 << i);
      res += (1 << i);
    }
  return res;
}
int main() {
  Hash::init();
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < (n); ++i) sum[i + 1] = (sum[i] << 1) + Hash(s[i]);
  for (int i = 0; i < (n); ++i) gray[0][i] = true;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (26); ++j) app[i + 1][j] = app[i][j];
    ++app[i + 1][s[i] - 'a'];
  }
  rad[0] = 0;
  long long int base = 0;
  for (int j = 1; j < 16; ++j) {
    rad[j] = rad[j - 1] * 2 + 1;
    for (int i = 0; i < (n); ++i) {
      int r_c = i + (rad[j] + 1) / 2, l_c = i - (rad[j] + 1) / 2;
      if (r_c >= n || l_c < 0) continue;
      int col = s[i] - 'a';
      if (gray[j - 1][r_c] && gray[j - 1][l_c] &&
          same(r_c, l_c, rad[j - 1] + 1) &&
          app[i + rad[j] + 1][col] - app[i - rad[j]][col] == 1) {
        gray[j][i] = true;
      }
    }
  }
  for (int j = 0; j < (16); ++j)
    for (int i = 0; i < (n); ++i)
      if (gray[j][i]) {
        int L = i - rad[j], R = i + rad[j] + 1;
        long long int len = rad[j] * 2 + 1;
        cost[L] += len * len;
        cost[R] -= len * len;
        base += len * len;
      }
  for (int i = 0; i < (n); ++i) cost[i + 1] += cost[i];
  for (int j = 0; j < (16); ++j)
    for (int i = 0; i < (n); ++i) {
      if (j == 0) {
        for (int c = 0; c < (26); ++c) ++prof[i][c];
      } else {
        int L = i - rad[j], R = i + rad[j] + 1;
        int r_c = i + (rad[j] + 1) / 2, l_c = i - (rad[j] + 1) / 2;
        if (r_c >= n || l_c < 0) continue;
        int col = s[i] - 'a';
        long long int len = (rad[j] * 2 + 1);
        if (gray[j - 1][r_c] && gray[j - 1][l_c] &&
            same(r_c, l_c, rad[j - 1] + 1)) {
          for (int c = 0; c < (26); ++c)
            if (app[R][c] - app[L][c] - (s[i] == 'a' + c ? 1 : 0) == 0) {
              prof[i][c] += len * len;
            }
        }
        if (!gray[j - 1][l_c] && !gray[j - 1][r_c]) continue;
        int indx = clen(L, i + 1);
        int pos = indx + L;
        if (pos >= i) continue;
        if (clen(pos + 1, i + 1 + indx + 1) + pos + 1 < i) continue;
        if (gray[j - 1][l_c] && app[i][col] - app[L][col] == 0)
          prof[indx + i + 1][s[pos] - 'a'] += len * len;
        if (gray[j - 1][r_c] && app[R][col] - app[i + 1][col] == 0)
          prof[pos][s[indx + i + 1] - 'a'] += len * len;
      }
    }
  long long int res = base;
  ;
  ;
  for (int i = 0; i < (n); ++i)
    for (int c = 0; c < (26); ++c)
      if (s[i] - 'a' != c) chmax(res, base + prof[i][c] - cost[i]);
  cout << res << endl;
  return 0;
}
