Problem:
Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

/*Distinct subsequence with maximum length*/

#include<bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t

inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}


lli maxLen(lli arr[], lli n) 
{ 
	unordered_map<int, int> hM; 

	lli sum = 0;
	lli max_len = 0; 
	lli ending_index = -1; 

	for (lli i = 0; i < n; i++) 
		arr[i] = (arr[i] == 0)? -1: 1; 

	for (lli i = 0; i < n; i++) 
	{ 
		sum+=arr[i]; 

		if (sum==0) 
		{ 
			max_len = i + 1; 
			ending_index = i; 
		} 

		if (hM.find(sum + n) != hM.end()) 
		{ 
			if (max_len < i - hM[sum + n]) 
			{ 
				max_len = i - hM[sum + n]; 
				ending_index = i; 
			} 
		} 
		else 
			hM[sum + n] = i; 
	} 

	for (lli i = 0; i < n; i++) 
		arr[i] = (arr[i] == -1)? 0: 1; 
	return max_len; 
} 


int main() 
{ 
	fast();
	string s;
	cin>>s;
	lli n=s.length();
	lli arr[n];
	rep(i,0,n)
		arr[i] = s[i] - 48;
		
	cout<<maxLen(arr, n); 
	return 0; 
}