#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
string s;
int sec(int a, int b) { return (s[a] != s[b]) ? 2 : 0; }
int main() {
  cin >> s;
  long long n = s.size();
  vector<vector<long long> > dp(n, vector<long long>(n, 0));
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      switch (i) {
        case 1:
          dp[j][j + i] = sec(j, j + i);
          break;
        default:
          long long m = 0;
          if (dp[j + 1][j + i - 1] == (i - 1))
            m = sec(j, j + i) + dp[j + 1][j + i - 1];
          for (int k = 0; k < i; k++) {
            m = max({m, dp[j][j + k] + dp[j + k + 1][j + i]});
          }
          dp[j][j + i] = m;
      }
    }
  }
  long long ans = dp[0][n - 1];
  cout << ans << endl;
}
