#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define REP(i, n) for(int i = 0;i < n;i++)
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;

    stack<int> stk;

    while(right < n){

        if(s[right] == s[left]){
            stk.push(s[left]);
            right++;
            left=right-1;
        } else {
            cnt+=2;

            if(stk.empty()){
                right += 2;
                left += 2;
            } else {
                right += 1;
                while(!stk.empty() && right < n && stk.top() != s[right]){
                    cnt+=2;
                    right++;
                    stk.pop();
                }
            }
        }
    }

    cout << cnt << endl;



    return 0;
}
