#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1LL << 15;
int MOD = 1000000007;
int main() {
  std::ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.length();
  int cnt = 0;
  int left = 0, right = 1, prev = 0;
  stack<int> stk;
  while (right < n) {
    if (s[right] == s[left]) {
      stk.push(s[left]);
      right++;
      left = right - 1;
    } else {
      cnt += 2;
      right += 1;
      while (!stk.empty() && right < n && stk.top() != s[right]) {
        cnt += 2;
        right++;
        stk.pop();
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
