#include <ext/pb_ds/assoc_container.hpp> 	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including tree_order_statistics_node_update
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
#define inf					1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

inline int ex(int a, int b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	int tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
inline int inv(int k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	string str;cin>>str;
	vi pre;
	int pres=0;
	for(auto it:str)
	{
		if(it=='0'){--pres;pre.pb(pres);}
		if(it=='1'){++pres;pre.pb(pres);}
	}
	map<int,vi> mp;
	int n=str.length();
	REP(i,0,n-1)
	{
		mp[pre[i]].pb(i);
	}
	int ans=0;
	for(auto it:mp)
	{
		ans=MAX(ans,(((it.y).back())-((it.y)[0])));
	}
	if(mp[0].size()){ans=MAX(ans,(mp[0].back()+1));}
	cout<<ans<<"\n";
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}