/*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; 
} 

