#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int n;
int ans = -1;
vector<int> search(string s) {
  vector<int> result(0);
  int size = s.length();
  for (int i = 0; i < size - 1; i++) {
    if (s[i] != s[i + 1]) {
      result.push_back(i);
    }
  }
  return result;
}
int dfs(string str, int removed) {
  vector<int> index = search(str);
  int removable_size = index.size();
  if (removable_size == 0) {
    return removed;
  }
  if (str.size() == 2 && str[0] != str[1]) {
    return n;
  }
  for (int i = 0; i < removable_size; i++) {
    string tmp(str);
    tmp.erase(index[i], 2);
    int removable = dfs(tmp, removed + 2);
    if (removable > ans) {
      ans = removable;
    }
  }
  return ans;
}
int main() {
  string s;
  getline(cin, s);
  n = s.length();
  ans = dfs(s, 0);
  cout << ans << endl;
  return 0;
}
