Problem: Xenia the coder went to The Olympiad of Informatics and got a string problem. Unfortunately, Xenia isn't fabulous in string algorithms. Help her solve the problem.

String s is a sequence of characters s1s2... s|s|, where record |s| shows the length of the string. 

Substring s[i... j] of string s is string sisi + 1... sj.

String s is a Gray string, if it meets the conditions:

  * the length of string |s| is odd; 
  * character <image> occurs exactly once in the string; 
  * either |s| = 1, or substrings <image> and <image> are the same and are Gray strings. 



For example, strings "abacaba", "xzx", "g" are Gray strings and strings "aaa", "xz", "abaxcbc" are not.

The beauty of string p is the sum of the squares of the lengths of all substrings of string p that are Gray strings. In other words, consider all pairs of values i, j (1 ≤ i ≤ j ≤ |p|). If substring p[i... j] is a Gray string, you should add (j - i + 1)2 to the beauty.

Xenia has got string t consisting of lowercase English letters. She is allowed to replace at most one letter of the string by any other English letter. The task is to get a string of maximum beauty.

Input

The first line contains a non-empty string t (1 ≤ |t| ≤ 105). String t only consists of lowercase English letters.

Output

Print the sought maximum beauty value Xenia can get.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

zzz


Output

12


Input

aba


Output

12


Input

abacaba


Output

83


Input

aaaaaa


Output

15

Note

In the first test sample the given string can be transformed into string p = "zbz". Such string contains Gray strings as substrings p[1... 1], p[2... 2], p[3... 3] и p[1... 3]. In total, the beauty of string p gets equal to 12 + 12 + 12 + 32 = 12. You can't obtain a more beautiful string.

In the second test case it is not necessary to perform any operation. The initial string has the maximum possible beauty.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
struct SuffixArray {
  string s;
  int n;
  vector<int> RA, SA, tempSA, tempRA, LCP;
  int L[N];
  SuffixArray(string st) {
    s = st;
    s += '$';
    n = s.size();
    RA.clear();
    RA.resize(n + 1, 0);
    SA = tempSA = tempRA = LCP = RA;
    Build();
  }
  void Build() {
    for (int i = 0; i < n; ++i) SA[i] = i, RA[i] = s[i];
    for (int k = 1; k < n; k <<= 1) {
      radix_sort(k);
      radix_sort(0);
      tempRA[SA[0]] = 0;
      for (int i = 1, r = 0; i < n; ++i) {
        if (getRA(SA[i - 1]) != getRA(SA[i]) ||
            getRA(SA[i - 1] + k) != getRA(SA[i] + k))
          ++r;
        tempRA[SA[i]] = r;
      }
      for (int i = 0; i < n; ++i) RA[i] = tempRA[i];
      if (RA[SA[n - 1]] == n - 1) break;
    }
    for (int i = 0; i < n; ++i) RA[SA[i]] = i;
    for (int i = 0, k = 0; i < n; ++i) {
      if (RA[i] == n - 1) {
        k = 0;
        continue;
      }
      int j = SA[RA[i] + 1];
      while (max(i, j) + k < n && s[i + k] == s[j + k]) ++k;
      LCP[RA[i]] = k;
      if (k) --k;
    }
  }

 private:
  inline int getRA(int i) { return i < n ? RA[i] : 0; }
  void radix_sort(int k) {
    memset(L, 0, sizeof L);
    for (int i = 0; i < n; ++i) L[getRA(i + k)]++;
    for (int i = 0, p = 0; i < N; ++i) {
      int x = L[i];
      L[i] = p;
      p += x;
    }
    for (int i = 0; i < n; ++i) {
      int& x = L[getRA(SA[i] + k)];
      tempSA[x++] = SA[i];
    }
    for (int i = 0; i < n; ++i) SA[i] = tempSA[i];
  }
};
struct RMQ {
  int rmq[N][18];
  int lg[N];
  RMQ() {}
  RMQ(int n, const vector<int>& a) {
    for (int i = 1; i <= n; ++i) {
      rmq[i][0] = a[i];
      if (i > 1) lg[i] = lg[i / 2] + 1;
    }
    for (int j = 1; j <= lg[n]; ++j) {
      for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
        rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  int Min(int l, int r) {
    int d = lg[r - l + 1];
    return min(rmq[l][d], rmq[r - (1 << d) + 1][d]);
  }
};
long long f(int x) {
  long long l = (1 << x) - 1;
  return l * l;
}
long long val[N][26], sum[N];
int rangeUnique[N][26], Left[N][26], Right[N][26], isGray[N][19];
int id[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string st;
  cin >> st;
  int n = st.size();
  SuffixArray SA(st);
  RMQ rmq(n, SA.LCP);
  for (int i = 1; i <= n; ++i) id[SA.SA[i]] = i;
  for (int i = 0; i < n; ++i) isGray[i][1] = 1;
  int appear[26];
  for (int i = 0; i < 26; ++i) appear[i] = -N;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) rangeUnique[i][j] = Left[i][j] = i - appear[j];
    appear[st[i] - 'a'] = i;
  }
  for (int i = 0; i < 26; ++i) appear[i] = N + N;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 26; ++j)
      Right[i][j] = appear[j] - i,
      rangeUnique[i][j] = min(rangeUnique[i][j], appear[j] - i);
    appear[st[i] - 'a'] = i;
  }
  auto lcp = [&](int x, int y) {
    if (x > n || y > n) {
      return 0;
    }
    if (x == y) {
      return n - x;
    }
    x = id[x], y = id[y];
    if (x > y) swap(x, y);
    return rmq.Min(x, y - 1);
  };
  long long ans = n;
  for (int j = 2; (1 << j) - 1 <= n; ++j) {
    for (int i = (1 << (j - 1)) - 1; i + (1 << (j - 1)) <= n; ++i) {
      if (rangeUnique[i][st[i] - 'a'] >= (1 << (j - 1)) &&
          isGray[i - (1 << (j - 2))][j - 1] &&
          isGray[i + (1 << (j - 2))][j - 1] &&
          lcp(i - (1 << (j - 1)) + 1, i + 1) >= (1 << (j - 1)) - 1) {
        isGray[i][j] = 1;
        ans += f(j);
        sum[i - (1 << (j - 1)) + 1] -= f(j);
        sum[i + (1 << (j - 1))] += f(j);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (i) sum[i] += sum[i - 1];
  }
  long long base = ans;
  for (int j = 2; (1 << j) - 1 <= n; ++j) {
    for (int i = (1 << (j - 1)) - 1; i + (1 << (j - 1)) <= n; ++i) {
      for (int c = 0; c < 26; ++c)
        if (c != st[i] - 'a') {
          if (rangeUnique[i][c] >= (1 << (j - 1)) &&
              isGray[i - (1 << (j - 2))][j - 1] &&
              isGray[i + (1 << (j - 2))][j - 1] &&
              lcp(i - (1 << (j - 1)) + 1, i + 1) >= (1 << (j - 1)) - 1) {
            val[i][c] += f(j);
          }
        }
      if (isGray[i][j]) continue;
      int p1 = i - (1 << (j - 1)) + 1;
      int p2 = i + 1;
      int t = lcp(p1, p2);
      if (t >= (1 << (j - 1)) - 1 || max(p1, p2) + t >= n) continue;
      int t2 = lcp(p1 + t + 1, p2 + t + 1);
      if (t + 1 + t2 < (1 << (j - 1)) - 1) continue;
      if (isGray[i - (1 << (j - 2))][j - 1]) {
        int Range = rangeUnique[i][st[i] - 'a'];
        if (st[p2 + t] == st[i]) {
          Range = min(Left[i][st[i] - 'a'],
                      Right[i][st[i] - 'a'] + Right[p2 + t][st[i] - 'a']);
        }
        if (Range >= (1 << (j - 1))) {
          val[p2 + t][st[p1 + t] - 'a'] += f(j);
        }
      }
      if (isGray[i + (1 << (j - 2))][j - 1]) {
        int Range = rangeUnique[i][st[i] - 'a'];
        if (st[p1 + t] == st[i]) {
          Range = min(Right[i][st[i] - 'a'],
                      Left[i][st[i] - 'a'] + Left[p1 + t][st[i] - 'a']);
        }
        if (Range >= (1 << (j - 1))) {
          val[p1 + t][st[p2 + t] - 'a'] += f(j);
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j)
      if (val[i][j]) {
        ans = max(ans, base + sum[i] + val[i][j]);
      }
  }
  cout << ans << '\n';
}