#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  s += 'a';
  int cnt = 0;
  int flag = 0;
  while (s.size() > 1) {
    if (flag >= s.size() - 2) break;
    flag = 0;
    for (int i = 0; i < s.size() - 1; i++) {
      if (s.at(i) != s.at(i + 1)) {
        if (s.at(i + 1) == 'a')
          break;
        else {
          cnt += 2;
          s.erase(s.begin() + i);
          s.erase(s.begin() + i);
          i = -1;
        }
      } else
        flag++;
    }
  }
  cout << cnt << endl;
  return 0;
}
