#include <bits/stdc++.h>
using namespace std;
const int maxn = 222222, inf = ~0U >> 1;
const int seed = 13131;
vector<pair<int, int> > way[20][maxn];
bool ok[20][maxn];
unsigned long long powHash[maxn], valHash[maxn];
int n, cnt[26][maxn];
long long ans[26][maxn], lsum[maxn], rsum[maxn];
char s[maxn];
inline unsigned long long val(int l, int r) {
  return valHash[r + 1] - valHash[l] * powHash[r - l + 1];
}
inline int occur(int letter, int l, int r) {
  if (!l)
    return cnt[letter][r];
  else
    return cnt[letter][r] - cnt[letter][l - 1];
}
inline long long calc(int w) {
  return 1ll * ((1 << (w + 1)) - 1) * ((1 << (w + 1)) - 1);
}
inline void solve(int p, int mk, int md, int k) {
  int ret = 0;
  if (p == md) {
    if (val(md - (1 << (k)) + 1, md - 1) == val(md + 1, md + (1 << (k)) - 1) &&
        ok[k - 1][md - (1 << (k - 1))])
      for (int letter = 0; letter < 26; letter++) {
        int allow = letter == s[md] - 'a' ? 1 : 0;
        if (occur(letter, md - (1 << (k)) + 1, md + (1 << (k)) - 1) <= allow)
          ret |= (1 << (letter));
      }
  } else {
    int p1, p2, letter;
    if (p < md)
      p1 = p, p2 = p + (1 << (k)), letter = s[p2] - 'a';
    else
      p1 = p - (1 << (k)), p2 = p, letter = s[p1] - 'a';
    if (mk & (1 << (letter)))
      if (val(md - (1 << (k)) + 1, p1 - 1) == val(md + 1, p2 - 1) &&
          val(p1 + 1, md - 1) == val(p2 + 1, md + (1 << (k)) - 1))
        if (letter != s[md] - 'a') {
          int mid_letter = s[md] - 'a';
          int allow = s[p] == s[md] ? 2 : 1;
          if (occur(mid_letter, md - (1 << (k)) + 1, md + (1 << (k)) - 1) <=
              allow)
            ret |= (1 << (letter));
        }
  }
  if (ret) way[k][md].push_back(make_pair(p, ret));
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) ++cnt[s[i] - 'a'][i];
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < n; j++) cnt[i][j + 1] += cnt[i][j];
  powHash[0] = 1;
  for (int i = 0; i < n; i++) powHash[i + 1] = powHash[i] * seed;
  valHash[0] = 1;
  for (int i = 0; i < n; i++) valHash[i + 1] = valHash[i] * seed + s[i];
  for (int i = 0; i < n; i++)
    way[0][i].push_back(make_pair(i, (1 << (26)) - 1)), ok[0][i] = true;
  for (int k = 1; k < 17; ++k)
    for (int i = (1 << (k)) - 1; i <= n - (1 << (k)); ++i) {
      for (__typeof(way[k - 1][i - (1 << (k - 1))].begin()) it =
               way[k - 1][i - (1 << (k - 1))].begin();
           it != way[k - 1][i - (1 << (k - 1))].end(); it++)
        solve(it->first, it->second, i, k);
      for (__typeof(way[k - 1][i + (1 << (k - 1))].begin()) it =
               way[k - 1][i + (1 << (k - 1))].begin();
           it != way[k - 1][i + (1 << (k - 1))].end(); it++)
        solve(it->first, it->second, i, k);
      solve(i, (1 << (26)) - 1, i, k);
      for (__typeof(way[k][i].begin()) it = way[k][i].begin();
           it != way[k][i].end(); it++)
        if (it->second & (1 << (s[it->first] - 'a'))) ok[k][i] = true;
    }
  for (int k = 0; k < 17; k++)
    for (int i = 0; i < n; i++)
      for (__typeof(way[k][i].begin()) it = way[k][i].begin();
           it != way[k][i].end(); it++)
        for (int letter = 0; letter < 26; letter++)
          if (it->second & (1 << (letter))) ans[letter][it->first] += calc(k);
  for (int k = 0; k < 17; k++)
    for (int i = 0; i < n; i++)
      if (ok[k][i])
        lsum[i - (1 << (k))] += calc(k), rsum[i + (1 << (k))] += calc(k);
  for (int i = n - 1; i >= 0; i--) lsum[i] += lsum[i + 1];
  for (int i = 0; i < n; i++) rsum[i] += rsum[i - 1];
  long long Ans = 0;
  for (int i = 0; i < n; i++)
    for (int letter = 0; letter < 26; letter++)
      Ans = max(Ans, ans[letter][i] + lsum[i] + rsum[i]);
  cout << Ans << endl;
  return 0;
}
