#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.length();
  vector<int> dp(len, 0);
  vector<int> remain(len, 0);
  int remain_idx = 0;
  pair<int, char> prev = make_pair(0, s[0]);
  for (int i = 1; i < len; ++i) {
    if (prev.first >= 0 && prev.second != s[i]) {
      dp[i] = dp[i - 1] + 2;
      if (remain_idx < 0) {
        prev = make_pair(-1, '-');
      } else {
        --remain_idx;
        int idx = remain[remain_idx];
        prev = make_pair(idx, s[idx]);
      }
    } else {
      dp[i] = dp[i - 1];
      prev = make_pair(i, s[i]);
      ++remain_idx;
      remain[remain_idx] = i;
    }
  }
  cout << dp[len - 1] << '\n';
}
