#include <bits/stdc++.h>
using namespace std;
const long long int LINF = 2000000000000000000ll;
const int INF = 1000000100;
const long long int MOD = 1e9 + 7;
int main() {
  string s;
  cin >> s;
  deque<int> q;
  int tmp = 1;
  for (int i = 0; i < (s.length() - 1); ++i) {
    if (s[i] == s[i + 1])
      tmp++;
    else {
      q.push_back(tmp);
      tmp = 1;
    }
  }
  q.push_back(tmp);
  while (q.size() > 1) {
    int v1, v2;
    v1 = q.front();
    q.pop_front();
    v2 = q.front();
    q.pop_front();
    if (v1 == v2) continue;
    if (v1 > v2 && q.size() > 2) {
      tmp = v1 - v2 + q.front();
      q.pop_front();
      q.push_front(tmp);
    } else {
      q.push_front(v2 - v1);
    }
  }
  if (q.empty())
    cout << s.length() << endl;
  else
    cout << s.length() - q.front() << endl;
  return 0;
}
