#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); }
template <long long int mod>
struct Int_ {
  unsigned x;
  int mpow(Int_ a, int k) {
    Int_ res = 1;
    while (k) {
      if (k & 1) res = res * a;
      a = a * a;
      k >>= 1;
    }
    return res.x;
  }
  int inverse(Int_ a) { return mpow(a, mod - 2); }
  Int_() : x(0) {}
  Int_(long long sig) {
    int sigt = sig % mod;
    if (sigt < 0) sigt += mod;
    x = sigt;
  }
  int get() const { return (int)x; }
  Int_& operator+=(Int_ that) {
    if ((x += that.x) >= mod) x -= mod;
    return *this;
  }
  Int_& operator-=(Int_ that) {
    if ((x += mod - that.x) >= mod) x -= mod;
    return *this;
  }
  Int_& operator*=(Int_ that) {
    x = (unsigned long long)x * that.x % mod;
    return *this;
  }
  Int_& operator=(Int_ that) {
    x = that.x;
    return *this;
  }
  Int_& operator/=(Int_ that) {
    x = (unsigned long long)x * inverse(that.x) % mod;
    return *this;
  }
  bool operator==(Int_ that) const { return x == that.x; }
  bool operator!=(Int_ that) const { return x != that.x; }
  Int_ operator-() const { return Int_(0) - Int_(*this); }
  Int_ operator+(Int_ that) const { return Int_(*this) += that; }
  Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
  Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
  Int_ operator/(Int_ that) const { return Int_(*this) /= that; }
};
namespace std {
template <long long int mod>
ostream& operator<<(ostream& out, const Int_<mod>& a) {
  out << a.get();
  return out;
}
template <long long int mod>
istream& operator>>(istream& in, Int_<mod>& a) {
  in >> a.x;
  return in;
}
};  // namespace std
struct Hash {
  static const int MAX_N = 100005;
  static Int_<1000000021> M1, M2, M3;
  static Int_<1000000021> rev1, rev2, rev3;
  static Int_<1000000021> mul1[MAX_N], mul2[MAX_N], mul3[MAX_N], div1[MAX_N],
      div2[MAX_N], div3[MAX_N];
  static Hash pows[MAX_N];
  pair<Int_<1000000021>, pair<Int_<1000000021>, Int_<1000000021> > > a;
  static void init() {
    M1 = 100000007, M2 = 100000037, M3 = 100000039;
    rev1 = Int_<1000000021>(1) / M1;
    rev2 = Int_<1000000021>(1) / M2;
    rev3 = Int_<1000000021>(1) / M3;
    Int_<1000000021>* ar[6] = {mul1, mul2, mul3, div1, div2, div3};
    Int_<1000000021> mult[6] = {M1, M2, M3, rev1, rev2, rev3};
    for (int j = 0; j < (6); ++j) {
      ar[j][0] = 1;
      for (int i = 0; i < (MAX_N - 1); ++i) {
        ar[j][i + 1] = ar[j][i] * mult[j];
      }
    }
    for (int i = 0; i < (MAX_N); ++i)
      pows[i].a = make_pair(mul1[i], make_pair(mul2[i], mul3[i]));
  }
  Hash(long long int val = 0) { a = make_pair(val, make_pair(val, val)); }
  Hash& operator+=(const Hash& b) {
    a.first += b.a.first;
    a.second.first += b.a.second.first;
    a.second.second += b.a.second.second;
    return *this;
  }
  Hash& operator-=(const Hash& b) {
    a.first -= b.a.first;
    a.second.first -= b.a.second.first;
    a.second.second -= b.a.second.second;
    return *this;
  }
  Hash& operator<<=(int k) {
    a.first *= mul1[k];
    a.second.first *= mul2[k];
    a.second.second *= mul3[k];
    return *this;
  }
  Hash& operator>>=(int k) {
    a.first *= div1[k];
    a.second.first *= div2[k];
    a.second.second *= div3[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; }
  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;
Int_<1000000021> Hash::M1, Hash::M2, Hash::M3;
Int_<1000000021> Hash::rev1, Hash::rev2, Hash::rev3;
Int_<1000000021> Hash::mul1[MAX_N], Hash::mul2[MAX_N], Hash::mul3[MAX_N],
    Hash::div1[MAX_N], Hash::div2[MAX_N], Hash::div3[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;
}
