#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long ans = 0;
  string s;
  vector<pair<char, long long>> q;
  cin >> s;
  q.push_back({s[0], 1});
  for (long long i = 1; i < s.size(); i++) {
    if (s[i - 1] != s[i])
      q.push_back({s[i], 1});
    else
      q.back().second++;
  }
  long long pos = 0;
  while (true) {
    if (pos >= q.size() - 1) break;
    if (q[pos].second >= q[pos + 1].second) {
      ans += q[pos + 1].second * 2;
      q[pos].second -= q[pos + 1].second;
      if (pos + 2 < q.size()) {
        q[pos + 2].second += q[pos].second;
        pos += 2;
      }
    } else {
      ans += q[pos].second * 2;
      q[pos + 1].second -= q[pos].second;
      pos += 1;
    }
    cout << endl;
  }
  cout << ans << endl;
}
