#include <bits/stdc++.h>
using namespace std;
long long int cuad(long long int x) { return x * x; }
const int limiteb = 20;
int n;
string s;
int valor[100001];
int gray[100001][limiteb];
int t = 0;
int tiempo[100001][limiteb];
int newgray[100001][limiteb];
int amount[100001][26];
int grayactual(int i, int b) {
  if (tiempo[i][b] == t) return newgray[i][b];
  return gray[i][b];
}
int icambio, ccambio;
int valoractual(int i) {
  if (i == icambio) return ccambio;
  return valor[i];
}
int amountactual(int i, int c) {
  if (i < icambio) return amount[i][c];
  if (c == ccambio) return amount[i][c] + 1;
  if (c == valor[icambio]) return amount[i][c] - 1;
  return amount[i][c];
}
int nv;
int v[100001];
int nnextv;
int nextv[100001];
void actualizapos(int i, int b, long long int &nextsol) {
  if (i <= 0 or i >= n + 1) return;
  if (grayactual(i, b - 1) and 1 <= i - ((1 << b) - 1) and
      i + ((1 << b) - 1) <= n and
      amountactual(i + ((1 << b) - 1), valoractual(i)) -
              amountactual(i - ((1 << b) - 1) - 1, valoractual(i)) ==
          1 and
      grayactual(i - ((1 << (b - 1)) - 1) - 1, b - 1) and
      grayactual(i + ((1 << (b - 1)) - 1) + 1, b - 1) and
      valoractual(i - ((1 << (b - 1)) - 1) - 1) ==
          valoractual(i + ((1 << (b - 1)) - 1) + 1)) {
    newgray[i][b] = 1;
    tiempo[i][b] = t;
  } else {
    newgray[i][b] = 0;
    tiempo[i][b] = t;
  }
  if (grayactual(i, b) != gray[i][b]) {
    if (grayactual(i, b))
      nextsol += cuad((1 << (b + 1)) - 1);
    else
      nextsol -= cuad((1 << (b + 1)) - 1);
  }
  if (grayactual(i, b) != gray[i][b] or (grayactual(i, b) and i == icambio))
    nextv[nnextv++] = i;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  n = int(s.size());
  for (int i = 0; i < n; i++) valor[i + 1] = s[i] - 'a';
  for (int i = 1; i <= n; i++)
    for (int c = 0; c < 26; c++)
      amount[i][c] = amount[i - 1][c] + (valor[i] == c);
  long long int sol = 0;
  for (int b = 0; b < limiteb; b++) {
    for (int i = 1; i <= n; i++) {
      if (b == 0 or (gray[i][b - 1] and 1 <= i - ((1 << b) - 1) and
                     i + ((1 << b) - 1) <= n and
                     amount[i + ((1 << b) - 1)][valor[i]] -
                             amount[i - ((1 << b) - 1) - 1][valor[i]] ==
                         1 and
                     gray[i - ((1 << (b - 1)) - 1) - 1][b - 1] and
                     gray[i + ((1 << (b - 1)) - 1) + 1][b - 1] and
                     valor[i - ((1 << (b - 1)) - 1) - 1] ==
                         valor[i + ((1 << (b - 1)) - 1) + 1])) {
        gray[i][b] = 1;
        sol += cuad((1 << (b + 1)) - 1);
      }
    }
  }
  long long int solbase = sol;
  for (int i = 1; i <= n; i++) {
    for (int c = 0; c < 26; c++) {
      if (c != valor[i]) {
        t++;
        icambio = i;
        ccambio = c;
        long long int nextsol = solbase;
        v[0] = i;
        nv = 1;
        for (int b = 1; b < limiteb; b++) {
          nnextv = 0;
          for (int k = 0; k < nv; k++) {
            int ii = v[k];
            actualizapos(ii - ((1 << (b - 1)) - 1) - 1, b, nextsol);
            actualizapos(ii + ((1 << (b - 1)) - 1) + 1, b, nextsol);
            if (ii == i) actualizapos(ii, b, nextsol);
          }
          nv = nnextv;
          for (int k = 0; k < nv; k++) v[k] = nextv[k];
        }
        sol = max(sol, nextsol);
      }
    }
  }
  cout << sol << endl;
}
