#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int n;
	cin >> n;
	cin >> s;
	int ONE = 0;
	int ZERO = 0;

	for(int i = 0 ; i< s.size() ; i++)
	{
		if(s[i] == '1')
			ONE++;
		else
			ZERO++;
	}
	int fp = -1;
	int lp = -1;
	char wanted ='0';
	if(ONE == s.size() || ZERO == s.size()){
		cout << 0 << endl;
		return(0);
	}
	if(ZERO == ONE)
	{
		cout<<s.size()<<endl;
		return(0);
	}
	if(ZERO < ONE)
		wanted = '1';
	if(ZERO < ONE){
		for(int i = 0 ; i < s.size() ; i++){
			if(s[i] == '0'){
				if(fp == -1)
					fp = i;
				lp = i;
			}
		}
	}
	else{
		for(int i = 0 ; i < s.size() ; i++){
			if(s[i] == '1'){
				if(fp == -1)
					fp = i;
				lp = i;
			}
		}
	}

	int count = 0;
	//cout<<fp<<" "<<lp<<endl;
	for(int i = fp ; i <= lp ;i++){
		if(s[i] == wanted)
			count++;
	}
	//cout << count <<" "<< lp-fp+1<<endl;
	if(count == 0){
		cout << 2*(lp-fp+1)<<endl;
	}
	else if(count <=(lp-fp+1-count ) ){
		cout << 2*(lp-fp+1) -2*count<<endl;
	}
	else{
		int ans,ans1;
		int nonwanted = lp-fp+1 - count;
		// cout<<nonwanted<<endl;
		int count2 = count;
		int nonwanted2 = nonwanted;
		for(int  i = lp ; i>= fp ; i--){
			if(count == nonwanted){
				ans = count;
				break;
			}
			else{
				if(s[i] == wanted){
					count--;
				}
				else
					nonwanted--;
			}
		}
		count = count2;
		nonwanted = nonwanted2;
		for(int  i = fp ; i<= lp ; i++){
			if(count == nonwanted){
				ans1 = count;
				break;
			}
			else{
				if(s[i] == wanted){
					count--;
				}
				else
					nonwanted--;
			}
		}

		cout<<max(ans,ans1)*2;
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	map<int, int> mp;
	mp[0] = -1;
	int ans = 0;
	int sum = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == '1'){
			sum++;
		}
		else{
			sum--;
		}
		if(mp.find(sum) != mp.end()){
			ans = max(ans, i - mp[sum]);
		}
		else{
			mp[sum] = i;
		}
	}
	cout << ans << endl;
}


//Template

// By dutsrat :)
//Includes
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <utility> //Pair
#include <algorithm>
#include <sstream> // istringstream>> ostring stream<<
#include <iostream>
#include <iomanip>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;

//I want to code the solutions as fast as possible)
typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <string> vs;
typedef pair<int, int > pii;
typedef vector <ll> vll;
typedef stringstream ss;
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define sc(n) scanf("%d", &n)
#define fast ios_base:: sync_with_stdio(false)
#define intt(arr, x) memset(arr, x, sizeof(arr))
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, a, b) for(int i = a; i <= b; i++)
#define revrep(n, i) for(int i = n - 1; i >= 0; i--)
#define revrepp(i, b, a) for(int i = b; i >= a; i--)
#define all(a)  a.begin(), a.end()
#define rall(a)  a.rbegin(), a.rend()
#define ESP (1e-9)

//String Utilities
bool isl(char c){
  return (c >= 'a' && c <= 'z');
}
bool isu(char c){
  return (c >= 'A' && c <= 'Z');
}
bool isa(char c){
  return (isl(c) || isu(c));
}
bool isn(char c){
  return (c >= '0' && c <= '9');
}
bool isan(char c){
  return (isa(c) || isn(c));
}
bool isv(char c){
  return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
string tolow(string s){
  rep(i, s.sz) if(isu(s[i])) s[i] = s[i] -'A' + 'a'; return s;
}
string toup(string s){
  rep(i, s.sz) if(isl(s[i])) s[i] = s[i] - 'a' + 'A'; return s;
}

//It all starts here ;)

//End Template
const int N = 1e5;
const int mod = 1e9 + 7;
//Frequently used functions
ll gcd(ll a,ll b){
  if(a == 0){
    return b;
  }
  return gcd(b % a, a);
}
ll mpow(ll a, ll b, ll mod){
  ll res = 1;
  while(b > 0){
    if(res & 1){
      res = (res * a) % mod;
      b = b >> 1;
      a = (a * a) % mod;
    }
  }
  return res;
}
bool co(pii &a, pii &b){
  if(a.ss == b.ss){
    return (a.ff < b.ff);
  }
  return (a.ss > b.ss);
}
vector<pii> dp;
int main(){
  fast;
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<int,int> mp;
  mp[0] = -1;
  int count = 0;
  int ans = 0;
  rep(i, n){
  	int num = s[i] - '0';
  	if(num == 1){
  		count++;
  	}else{
  		count--;
  	}
  	if(mp.find(count) != mp.end()){
  		ans = max(ans, i - mp[count]);
  	}else{
  		mp[count] = i;
  	}
  }
  cout << ans;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
int n;
cin>>n;
string str;
 cin>>str;
  int dp[n];
  map<int,int>firstocc;
  dp[0]=str[0]=='0'?-1:1;
  firstocc[dp[0]]=0;
  firstocc[0]=-1;
  int ans=0;
  for(int i=1;i<n;i++){
    dp[i]=str[i]=='0'?dp[i-1]-1:dp[i-1]+1;
    if(!firstocc[dp[i]]&&dp[i]!=dp[0])
        firstocc[dp[i]]=i;
    else{
        int check=i-firstocc[dp[i]];
        ans=max(check,ans);
        }
  }
  cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
        int cptz=0,cpto=0;
        int k=min(dp[i].zeros,dp[i].ones)*2;
        for(int j=i;j<i+k;j++){
            if(ch[j]=='0')
                cptz++;
            else
                cpto++;
            if(cpto==cptz)
                cpt=cpto*2;
        }
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int solve(string ch,int n){
   stack<int>st;
   st.push(-1);
   int ans=0;
   for(int i=0;i<n;i++){
      if(ch[i]=='0')
        st.push(i);
      else{
        st.pop();
      if(!st.empty())
      ans=max(ans,i-st.top());
      else
        st.push(i);
      }
   }
   return ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100000];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
 int ones=0,zeros=0;
  for(int i=n-2;i>=0;i--){
    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones&&dp[i].ones>ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones)*2,ones=dp[i].ones;
            else if(dp[i].ones>dp[i].zeros&&dp[i].zeros>zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2,zeros=dp[i].zeros;
            else
                dp[i].zeros==dp[i].ones?cpt=dp[i].zeros*2:cpt=cpt;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones)*2;
            else
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2;

    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones)*2;
            else if(dp[i].ones>dp[i].zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2;
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
 int ones=0,zeros=0;
  for(int i=n-2;i>=0;i--){
    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones&&dp[i].ones>ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones)*2,ones=dp[i].ones;
            else if(dp[i].ones>dp[i].zeros&&dp[i].zeros>zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2,zeros=dp[i].zeros;
            else
                dp[i].zeros==dp[i].ones?cpt=dp[i].zeros*2:cpt=cpt;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

   dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones)*2;
            else if(dp[i].ones>dp[i].zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2;
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones].ones*2-1)*2;
            else if(dp[i].ones>dp[i].zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2;
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

   dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones){
            int k=dp[i].ones;
            cpt=max((k-dp[i+k*2].ones-1)*2,(k-dp[i+k*2-1].ones)*2);
            }
            else if(dp[i].ones>dp[i].zeros){
                int k=dp[i].zeros;
                cpt=max((k-dp[i+k*2].zeros-1)*2,(k-dp[i+k*2-1].zeros)*2);
                }
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

   dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones+ch[i+dp[i].ones*2-1]-'0')*2;
            else if(dp[i].ones>dp[i].zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2;
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100000];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
 int ones=0,zeros=0,Min=0;
  for(int i=n-2;i>=0;i--){
    dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
           int cptz=0,cpto=0;
        int k=min(dp[i].zeros,dp[i].ones)*2;
        if(k>Min){
        for(int j=i;j<i+k;j++){
            if(ch[j]=='0')
                cptz++;
            else
                cpto++;
            if(cpto==cptz)
                cpt=cpto*2;
        }
    Min=k;
    }}

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

   dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones)
            cpt=(dp[i].ones-dp[i+dp[i].ones*2-1].ones+ch[i+dp[i].ones*2-1])*2;
            else if(dp[i].ones>dp[i].zeros)
                cpt=(dp[i].zeros-dp[i+dp[i].zeros*2-1].zeros)*2;
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
class info{
public:
int zeros=0;
int ones=0;
};
info dp[100002];
int solve(string ch,int n){
  int Ans=0;
  ch[n-1]=='0'?dp[n-1].zeros=1:dp[n-1].ones=1;
  for(int i=n-2;i>=0;i--){

   dp[i].ones=ch[i]=='1'?dp[i+1].ones+1:dp[i+1].ones;
    dp[i].zeros=ch[i]=='0'?dp[i+1].zeros+1:dp[i+1].zeros;
    int cpt=0;
    if(dp[i].zeros!=0&&dp[i].ones!=0){
            if(dp[i].zeros>dp[i].ones){
            int k=dp[i].ones;
            cpt=(k-dp[i+k*2].ones-1)*2;
            }
            else if(dp[i].ones>dp[i].zeros){
                int k=dp[i].zeros;
                cpt=(k-dp[i+k*2].zeros-1)*2;
                }
            else
                cpt=dp[i].zeros*2;
    }

        Ans=max(Ans,cpt);
  }
    return Ans;
}

int main()
{
    int n;
    string ch;
    cin>>n;
    cin>>ch;
    int Ans=solve(ch,n);
    cout<<Ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    vector<ll> bal(n);
    map<ll,ll> mp;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
        bal[i]=cnt[0]-cnt[1];
        if(bal[i]==0)
        {
            ans=max(ans,i+1);
        }
        if(mp.find(bal[i])==mp.end())
        {
            mp[bal[i]]=i;
        }
        else{
            ans=max(ans,i-mp[bal[i]]);
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        else if(freq[0]>cnt[1])
        {
            while(st<=i && freq[0]>cnt[1])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
        else if(freq[1]>cnt[0]){
            while(st<=i && freq[1]>cnt[0])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        else if(freq[0]>cnt[1])
        {
            while(st<=i && freq[0]>cnt[1])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
        else{
            while(st<=i && freq[1]>cnt[0])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1])
        {
            while(st<=i && freq[0]>=cnt[1])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                    break;
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
        if(freq[1]>cnt[0]){
            while(st<=i && freq[1]>=cnt[0])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                    break;
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1] || freq[1]>cnt[0])
        {
            while(st<=i && (freq[0]>cnt[1] || freq[1]>cnt[0]))
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1] || freq[1]>cnt[0])
        {
            while(st<i && freq[0]!=freq[1])
            {
                freq[s[st]-'0']--;
                st++;
            }
            ans=max(ans,i-st+1);

        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    vector<ll> bal(n);
    map<ll,ll> mp;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
        bal[i]=cnt[0]-cnt[1];
        if(bal[i]==0)
        {
            ans=max(ans,i+1);
        }
        if(mp[bal[i]]==0)
        {
            mp[bal[i]]=i;
        }
        else{
            ans=max(ans,i-mp[bal[i]]);
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1] || freq[1]>cnt[0])
        {
            while(st<=i && (freq[0]>cnt[1] || freq[1]>cnt[0]))
            {
                freq[s[st]-'0']--;
                st++;
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1] || freq[1]>cnt[0])
        {
            while(st<=i && freq[0]!=freq[1])
            {
                freq[s[st]-'0']--;
                st++;
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
    }

    string a=s;
    reverse(a.begin(),a.end());
    freq[0]=0;
    freq[1]=0;

    st=0;
    freq[a[st]-'0']++;
    ll ans1=0;
    for(ll i=1;i<n;i++)
    {
        freq[a[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans1=max(ans1,i-st+1);
        }
        if(freq[0]>cnt[1] || freq[1]>cnt[0])
        {
            while(st<=i && freq[0]!=freq[1])
            {
                freq[a[st]-'0']--;
                st++;
            }
            if(freq[0]==freq[1])
            {
            ans1=max(ans1,i-st+1);
            }

        }
    }
    cout<<max(ans,ans1);

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1])
        {
            while(st<=i && freq[0]>cnt[1])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
        if(freq[1]>cnt[0]){
            while(st<=i && freq[1]>cnt[0])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1])
        {
            while(st<=i && freq[0]>cnt[1])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                    break;
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
        if(freq[1]>cnt[0]){
            while(st<=i && freq[1]>cnt[0])
            {
                freq[s[st]-'0']--;
                st++;
                if(freq[0]==freq[1])
                {
                    ans=max(ans,i-st+1);
                    break;
                }
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    vector<ll> bal(n);
    map<ll,ll> mp;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
        bal[i]=cnt[0]-cnt[1];
        if(mp[bal[i]]==0)
        {
            mp[bal[i]]=i;
        }
        else{
            ans=max(ans,i-mp[bal[i]]);
        }
    }
    cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
    ll n;
    cin>>n;

    string s;
    cin>>s;
    ll cnt[2]={0,0};
    string t=s;
    sort(t.begin(),t.end());
    if(t[0]==t[n-1])
    {
        cout<<0;
        return 0;
    }

    for(ll i=0;i<n;i++)
    {
        cnt[s[i]-'0']++;
    }

    ll freq[2]={0,0};

    ll st=0;
    freq[s[st]-'0']++;
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        freq[s[i]-'0']++;
        if(freq[0]==freq[1])
        {
            ans=max(ans,i-st+1);
        }
        if(freq[0]>cnt[1] || freq[1]>cnt[0])
        {
            while(st<=i && freq[0]!=freq[1])
            {
                freq[s[st]-'0']--;
                st++;
            }
            if(freq[0]==freq[1])
            {
            ans=max(ans,i-st+1);
            }

        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
int zero[maxN], one[maxN];
int ans;
bool ok(int x)
{
	//cout << x << " : ";
	FOR(i, 1, n - x + 1)
	{
		int h = i + x - 1;
		if(zero[h] - zero[i - 1] == one[h] - one[i - 1]) {/*cout << i << " " << x << "\n";*/return true;}
	}
	return false;
}
void tk(int l, int r)
{
	//cout << l << " " << r << "\n";
	if(l > r) return;
		int mid = (l + r) / 2;
		if(ok(mid * 2)) {
			ans = max(ans, mid * 2);
			tk(mid + 1, r);
		}
		else
		{
			tk(l, mid - 1);
			tk(mid + 1, r);
		}
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, s.size() - 1)
	{
		if(s[i] == '0') zero[i] = zero[i - 1] + 1, one[i] = one[i - 1];
		else zero[i] = zero[i - 1], one[i] = one[i - 1] + 1;
	}
	//FOR(i, 1, n) cout << one[i] << " " << zero[i] << "\n";
	/*int l = 1, r = n, mid = 0;
	while(l <= r)
	{
		mid = (l +  r) >> 1;
		if(ok(mid*2)) ans = 2*mid, l = mid + 1;
		else r = mid - 1;
	}*/
	tk(1, n);
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
pair<int, int> g[maxN];
int ans;
typedef pair<int, int> ii;
bool cmp(ii a, ii b)
{
	return (a.fi < b.fi || (a.fi == b.fi && a.se > b.se));
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, n) if(s[i] == '0') g[i].fi = g[i - 1].fi + 1, g[i].se = i;
	else g[i].fi = g[i - 1].fi - 1, g[i].se = i;
	sort(g + 1, g + n + 1, cmp);
	//FOR(i, 1, n) cout << g[i].fi << " " << g[i].se << "\n";
	FOR(i, 1, n)
	{
		//cout << g[i].fi << " " << g[i].se << " : ";
		int id = lower_bound(g + 1, g + n + 1, g[i])  - g;
		//cout << g[id].fi << " " << g[id].se << "\n";
		if(g[id].se != g[i].se && g[i].fi == g[id].fi) ans = max(ans, g[id].se - g[i].se);
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
int zero[maxN], one[maxN];
int ans;
bool ok(int x)
{
	//cout << x << " : ";
	FOR(i, 1, n - x + 1)
	{
		int h = i + x - 1;
		if(zero[h] - zero[i - 1] == one[h] - one[i - 1]) {/*cout << i << " " << x << "\n";*/return true;}
	}
	return false;
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, s.size() - 1)
	{
		if(s[i] == '0') zero[i] = zero[i - 1] + 1, one[i] = one[i - 1];
		else zero[i] = zero[i - 1], one[i] = one[i - 1] + 1;
	}
	//FOR(i, 1, n) cout << one[i] << " " << zero[i] << "\n";
	int l = 1, r = n, mid = 0;
	while(l <= r)
	{
		mid = (l +  r) >> 1;
		if(ok(mid*2)) ans = 2*mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
int zero[maxN], one[maxN];
int ans;
bool ok(int x)
{
	FOR(i, 1, n)
	{
		int h = i + x - 1;
		if(zero[h] - zero[i - 1] == one[h] - one[i - 1]) return true;
	}
	return false;
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, s.size() - 1)
	{
		if(s[i] == '0') zero[i] = zero[i - 1] + 1, one[i] = one[i - 1];
		else zero[i] = zero[i - 1], one[i] = one[i - 1] + 1;
	}
	int l = 1, r = n, mid = 0;
	while(l < r)
	{
		mid = (l +  r) >> 1;
		if(ok(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
int zero[maxN], one[maxN];
int ans;
bool ok(int x)
{
	FOR(i, 1, n - x + 1)
	{
		int h = i + x - 1;
		if(zero[h] - zero[i - 1] == one[h] - one[i - 1]) {return true;}
	}
	return false;
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, s.size() - 1)
	{
		if(s[i] == '0') zero[i] = zero[i - 1] + 1, one[i] = one[i - 1];
		else zero[i] = zero[i - 1], one[i] = one[i - 1] + 1;
	}
	int l = 1, r = n, mid = 0;
	while(l < r)
	{
		mid = (l +  r) >> 1;
		if(ok(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
int zero[maxN], one[maxN];
int ans;
bool ok(int x)
{
	//cout << x << " : ";
	FOR(i, 1, n - x + 1)
	{
		int h = i + x - 1;
		if(zero[h] - zero[i - 1] == one[h] - one[i - 1]) {/*cout << i << " " << x << "\n";*/return true;}
	}
	return false;
}
void tk(int l, int r)
{
	//cout << l << " " << r << "\n";
	if(l > r) return;
		int mid = (l + r) / 2;
		if(ans >= mid * 2) return;
		if(ok(mid * 2)) {
			ans = max(ans, mid * 2);
			tk(mid + 1, r);
		}
		else
		{
			tk(l, mid - 1);
			tk(mid + 1, r);
		}
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, s.size() - 1)
	{
		if(s[i] == '0') zero[i] = zero[i - 1] + 1, one[i] = one[i - 1];
		else zero[i] = zero[i - 1], one[i] = one[i - 1] + 1;
	}
	//FOR(i, 1, n) cout << one[i] << " " << zero[i] << "\n";
	/*int l = 1, r = n, mid = 0;
	while(l <= r)
	{
		mid = (l +  r) >> 1;
		if(ok(mid*2)) ans = 2*mid, l = mid + 1;
		else r = mid - 1;
	}*/
	tk(1, n);
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define NAME ""
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;

const int maxN = 1e5 + 10;
int n;
string s;
pair<int, int> g[maxN], h[maxN];
int ans;
typedef pair<int, int> ii;
bool cmp(ii a, ii b)
{
	return (a.fi < b.fi || (a.fi == b.fi && a.se > b.se));
}
int main()
{
	//io();
	cin >> n;
	cin >> s;
	s = ' ' + s;
	FOR(i, 1, n) if(s[i] == '0') g[i].fi = g[i - 1].fi - 1, g[i].se = i;
	else g[i].fi = g[i - 1].fi + 1, g[i].se = i;
	FOR(i, 1, n) h[i] = g[i];
	//FOR(i, 1, n) cout << g[i].fi << " ";
	//cout << "\n";
	sort(g + 1, g + n + 1, cmp);
	//FOR(i, 1, n) cout << h[i].fi << " " << h[i].se << "\n";
	FOR(i, 1, n)
	{
		ii _find;
		_find.fi = h[i - 1].fi, _find.se = h[i - 1].se;
		//cout << _find.fi << " " << _find.se << " : ";
		int id = lower_bound(g + 1, g + n + 1,  _find)  - g;
		//cout << g[id].fi << " " << g[id].se << "\n";
		if(g[id].se != _find.se && g[id].fi == _find.fi) ans = max(ans, g[id].se - _find.se);
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
	vector <int> pos(100001, -1), neg(100001, -1);
	int n, cnt0 = 0, cnt1 = 0, ans = 0;
	string s;
	cin >> n >> s;
	for(int i = 0; i < n; i++)
	{
		s[i] == '0' ? cnt0++ : cnt1++;
		int a = cnt0 - cnt1;
		if(!a) ans = i + 1;
		else if(a < 0)
		{
			if(neg[a * -1] == -1) neg[a * -1] = i;
			else ans = max(ans, i - neg[a * -1]);
		}
		else
		{
			if(pos[a] == -1) pos[a] = i;
			else ans = max(ans, i - pos[a]);
		}
	}
	cout << ans;

	return 0;
}


/** Writer: Sourav Malo **/

#include <bits/stdc++.h>
using namespace std;

#define Y() printf("YES\n")
#define N() printf("NO\n")
#define FAST() ios :: sync_with_stdio(false); cin.tie(0);
#define _gcd(a, b) __gcd(a, b)
#define _lcm(a, b) (a * b) / _gcd(a, b)
#define ll long long int
#define ull unsigned long long int
#define malo return 0
#define MAX 10000000000000000059
#define MIN -1000000000000000005
#define max_3(a, b, c) max(a, max(b, c))
#define max_4(a, b, c, d) max(a, max(b, max(c, d)))
#define min_3(a, b, c) min(a, min(b, c))
#define min_4(a, b, c, d) min(a, min(b, min(c, d)))
#define vec vector <ll>
#define vec_p vector <pair <ll, ll>>
#define it vector <ll> :: iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rev reverse
#define _max *max_element
#define _min *min_element
#define SUM accumulate
#define BS binary_search
#define CT count
#define lb lower_bound
#define ub upper_bound
#define B begin()
#define E end()
#define F first
#define S second

//vec v, v1, v2, v3;
//string s, s1, s2, s3;
ll a[1000007],ans,n,i;

ll solve(ll l,ll r)
{
	if(l>n || r<1) return 0;
	ll x=r-l+1,y=a[r]-a[l-1];
//a	cout<<a[r]<<" "<<r<<" "<<l<<endl;
	if(y*2==x) return x;
	ll u=solve(l+2,r);
	ll v=solve(l,r-2);
	return max(u,v);
}

int main ()
{
	//freoprn("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    //ll a, b, c, d, i, j, k, l, m, n, p, q, r, u, w, e, f, g, h, t, ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end, mid;
    //ll a1 = 0, a2 = 0, a3 = 0, a4 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, sum = 0, sum1 = 0, max1, max2, min1, min2;
    //double x, y, z;
    //char ch, ch1, ch2;

    FAST();

    string s;

    cin>>n>>s;

    for(i=1;i<=n;i++){
    	a[i]=a[i-1]+s[i-1]-'0';
	}

	if(!(n%2)) ans=solve(1,n);
	else ans=max(solve(1,n-1),solve(2,n));

	cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	//freopen("malo.txt", "r", stdin);
	int n;
	string s;
	cin >> n >> s;
	int arr0[n + 1] = {0}, arr1[n + 1] = {0};
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '0') arr0[i + 1] = arr0[i] + 1;
		else arr0[i + 1] = arr0[i];
		if(s[i] == '1') arr1[i + 1] = arr1[i] + 1;
		else arr1[i + 1] = arr1[i];
	}
	vector <int> v1(n + 1, -1), v2(n + 1, -1);
	int ans = 0;
	for(int i = 0; i <= n; i++)
	{
		if(arr0[i] == arr1[i])
		{
			if(v1[0] == -1) v1[0] = i;
			if(v2[0] == -1) v2[0] = i;
			else ans = max(ans, i - 0);
		}
		else if(arr0[i] > arr1[i])
		{
			int a = arr0[i] - arr1[i];
			if(v1[a] == -1) v1[a] = i;
			else ans = max(ans, i - v1[a]);
		}
		else
		{
			int a = arr1[i] - arr0[i];
			if(v2[a] == -1) v2[a] = i;
			else ans = max(ans, i - v2[a]);
		}
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
	map <int, int> wow;
	int cnt0 = 0, cnt1 = 0, n, ans = 0;
	string s;
	cin >> n >> s;
	wow[0] = -1;
	for(int i = 0; i < n; i++)
	{
		(s[i] == '0') ? cnt0++ : cnt1++;
		(wow[cnt0 - cnt1]) ? ans = max(ans, i - wow[cnt0 - cnt1]) : wow[cnt0 - cnt1] = i;
	}
	cout << ans;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	freopen("malo.txt", "r", stdin);
	int n;
	string s;
	cin >> n >> s;
	int arr0[n + 1] = {0}, arr1[n + 1] = {0};
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '0') arr0[i + 1] = arr0[i] + 1;
		else arr0[i + 1] = arr0[i];
		if(s[i] == '1') arr1[i + 1] = arr1[i] + 1;
		else arr1[i + 1] = arr1[i];
	}
	vector <int> v1(n + 1, -1), v2(n + 1, -1);
	int ans = 0;
	for(int i = 0; i <= n; i++)
	{
		if(arr0[i] == arr1[i])
		{
			if(v1[0] == -1) v1[0] = i;
			if(v2[0] == -1) v2[0] = i;
			else ans = max(ans, i - 0);
		}
		else if(arr0[i] > arr1[i])
		{
			int a = arr0[i] - arr1[i];
			if(v1[a] == -1) v1[a] = i;
			else ans = max(ans, i - v1[a]);
		}
		else
		{
			int a = arr1[i] - arr0[i];
			if(v2[a] == -1) v2[a] = i;
			else ans = max(ans, i - v2[a]);
		}
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
	int n, cnt0 = 0, cnt1 = 0, ans = 0;
	string s;
	cin >> n >> s;
	vector <int> arr0(n + 1, -1), arr1(n + 1, -1);
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '0') cnt0++;
		else cnt1++;
		if(cnt0 == cnt1) ans = i + 1;
		else if(cnt0 < cnt1)
		{
			if(arr0[cnt1 - cnt0] == -1) arr0[cnt1 - cnt0] = i;
			else ans = max(ans, i - arr0[cnt1 - cnt0]);
		}
		else
		{
			if(arr1[cnt0 - cnt1] == -1) arr1[cnt0 - cnt1] = i;
			else ans = max(ans, i - arr1[cnt0 - cnt1]);
		}
	}
	cout << ans;

	return 0;
}


/** Writer: Sourav Malo **/

#include <bits/stdc++.h>
using namespace std;

#define Y() printf("YES\n")
#define N() printf("NO\n")
#define FAST() ios :: sync_with_stdio(false); cin.tie(0);
#define _gcd(a, b) __gcd(a, b)
#define _lcm(a, b) (a * b) / _gcd(a, b)
#define ll long long int
#define ull unsigned long long int
#define malo return 0
#define MAX 10000000000000000059
#define MIN -1000000000000000005
#define max_3(a, b, c) max(a, max(b, c))
#define max_4(a, b, c, d) max(a, max(b, max(c, d)))
#define min_3(a, b, c) min(a, min(b, c))
#define min_4(a, b, c, d) min(a, min(b, min(c, d)))
#define vec vector <ll>
#define vec_p vector <pair <ll, ll>>
#define it vector <ll> :: iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rev reverse
#define _max *max_element
#define _min *min_element
#define SUM accumulate
#define BS binary_search
#define CT count
#define lb lower_bound
#define ub upper_bound
#define B begin()
#define E end()
#define F first
#define S second
#define wow 1000000007

//vec v, v1, v2, v3;
//string s, s1, s2, s3;
vec v[100005];

int main ()
{
	//freoprn("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll a = 0, b, c, d, i, j, k, l, m, n, p, q, r, u, w, e, f, g, h, t, ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0, ck2 = 0, ln, ln1, start, end, mid;
    ll a1 = 0, a2 = 0, a3 = 0, a4 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, sum = 0, sum1 = 0, max1 = 0, max2, min1, min2;
    double x, y, z;
    char ch, ch1, ch2;

    FAST();
    string s;
    cin >> n >> s;
    v[0].pb(0), v[0].pb(0);
    for(i = 0; i < n; i++)
    {
    	if(s[i] == '0') ct++;
    	else ct1++;
    	v[i + 1].pb(ct), v[i + 1].pb(ct1);
	}
	for(i = 0; i < n; i++)
	{
		if(v[i + 1][0] != 0 && v[i + 1][1] != 0)
		{
			a = min(v[i + 1][0], v[i + 1][1]);
			while(a != 0)
			{
				b = a * 2;
				if(b > max1)
				{
					if((v[i + 1][0] - v[i + 1 - b][0]) == (v[i + 1][1] - v[i + 1 - b][1])) max1 = b;
					else a--;
				}
				else break;
			}
		}
	}
    cout << max1;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main ()
{
	map <int, int> wow;
	int cnt0 = 0, cnt1 = 0, n, ans = 0;
	string s;
	cin >> n >> s;
	wow[0] = -1;
	for(int i = 0; i < n; i++)
	{
		(s[i] == '0') ? cnt0++ : cnt1++;
		(wow.count(cnt0 - cnt1)) ? ans = max(ans, i - wow[cnt0 - cnt1]) : wow[cnt0 - cnt1] = i;
	}
	cout << ans;

	return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n];
    map < int, int > m;

    int ans = 0;

    rep(i, 0, n)
    {
        if(!i) a[0] = (s[0] == '1')? 1: -1;
        else a[i] = a[i-1] + ((s[i] == '1')? 1: -1);

        if(m.find(a[i]) == m.end()) m[a[i]] = i;
    }

    // rep(i, 0, n) pri(a[i]);

    rep(i, 2, n)
    {
        if(m.find(a[i]) != m.end()) ans = max(ans, i - m[a[i]]);
    }

    if((s[0] == '0' && s[1] == '1') || (s[0] == '1' && s[1] == ')')) ans += 2;

    pri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int cur = 0, ans = 0;

    map < int, int > m;

    rep(i, 0, n)
    {
        if(s[i] == '1') cur ++;
        else cur --;

        if(m.find(cur) != m.end()) ans = max(ans, i - m[cur]);
        else m[cur] = i;
    }

    pri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int cur = 0, ans = 0;

    map < int, int > m;

    m[0] = -1;

    rep(i, 0, n)
    {
        if(s[i] == '1') cur ++;
        else cur --;

        if(m.find(cur) != m.end()) ans = max(ans, i - m[cur]);
        else m[cur] = i;
    }

    pri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n]; a[0] = (s[0])? 1: -1;

    rep(i, 1, n)
    {
        if(s[i] == '1') a[i] = a[i-1] + 1;
        else a[i] = a[i-1] - 1;
    }

    // for(int it : a) pri(it);

    map < int, int > m;

    int ans = 0;

    rep(i, 0, n)
    {
        if(m.find(a[i]) == m.end())
        m[a[i]] = i;
        else
        {
            int len = i - m[a[i]];
            ans = max(len, ans);
        }
    }

    pri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n+1]; a[0] = 0, a[1] = (s[0] == '1')? 1: -1;

    rep(i, 1, n)
    {
        if(s[i] == '1') a[i+1] = a[i] + 1;
        else a[i+1] = a[i] - 1;
    }

    rep(i, 0, n) a[i] = a[i+1];

    // rep(i, 0, n) pri(a[i]); cout << '\n';

    map < int, int > m;

    ll ans = 0;

    rep(i, 0, n)
    {
        int src;

        if(s[i] == '0') src = a[i] + 1;
        else src = a[i] - 1;

        if(m.find(a[i]) == m.end())
            m[a[i]] = i;

        if(m.find(src) != m.end())
        {
            if((s[i] == '0' && s[m[src]] == '1') || (s[i] == '1' && s[m[src]] == '0'))
            {
                ll len = i - m[src];

                ans = max(len, ans);
            }
        }
    }

    if(ans) ans ++;

    lpri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n+1]; a[0] = 0, a[1] = (s[0] == '1')? 1: -1;

    rep(i, 1, n)
    {
        if(s[i] == '1') a[i+1] = a[i] + 1;
        else a[i+1] = a[i] - 1;
    }

    rep(i, 0, n) a[i] = a[i+1];

    // rep(i, 0, n) pri(a[i]); cout << '\n';

    map < int, int > m;

    ll ans = 0;

    rep(i, 0, n)
    {
        int src;

        if(s[i] == '0') src = a[i] + 1;
        else src = a[i] - 1;

        if(m.find(a[i]) == m.end())
            m[a[i]] = i;

        if(m.find(src) != m.end())
        {
            if((s[i] == '0' && s[m[src]] == '1') || (s[i] == '1' && s[m[src]] == '0'))
            {
                ll len = i - m[src] + 1;

                ans = max(len, ans);
            }
        }
    }

    lpri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n];
    map < int, int > m;

    int ans = 0;

    rep(i, 0, n)
    {
        if(!i) a[0] = (s[0] == '1')? 1: -1;
        else a[i] = a[i-1] + ((s[i] == '1')? 1: -1);

        if(m.find(a[i]) == m.end()) m[a[i]] = i;
        else ans = max(ans, i - m[a[i]]);
    }

    if((s[0] == '0' && s[1] == '1') || (s[0] == '1' && s[1] == ')')) ans += 2;

    pri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n];
    map < int, int > m;

    int ans = 0;

    rep(i, 0, n)
    {
        if(!i) a[0] = (s[0] == '1')? 1: -1;
        else a[i] = a[i-1] + ((s[i] == '1')? 1: -1);

        if(m.find(a[i]) == m.end()) m[a[i]] = i;
        else ans = max(ans, i - m[a[i]]);
    }

    pri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n]; a[0] = (s[0])? 1: -1;

    rep(i, 1, n)
    {
        if(s[i] == '1') a[i] = a[i-1] + 1;
        else a[i] = a[i-1] - 1;
    }

    // for(int it : a) pri(it);

    map < int, int > m;

    ll ans = 0;

    rep(i, 0, n)
    {
        if(m.find(a[i]) == m.end())
        m[a[i]] = i;
        else
        {
            ll len = i - m[a[i]];
            ans = max(len, ans);
        }
    }

    lpri(ans);
    return 0;
}


/* Simplicity and Goodness */

#include <bits/stdc++.h>
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod = 998244353;
const int N = 2e5+2;

int main()
{
    int n; scn(n);

    string s; cin >> s;

    int a[n]; a[0] = (s[0] == '1')? 1: -1;

    rep(i, 1, n)
    {
        if(s[i] == '1') a[i] = a[i-1] + 1;
        else a[i] = a[i-1] - 1;
    }

    // for(int it : a) pri(it);

    map < int, int > m;

    ll ans = 0;

    rep(i, 0, n)
    {
        if(m.find(a[i]) == m.end())
        m[a[i]] = i;
        else
        {
            ll len = i - m[a[i]];
            ans = max(len, ans);
        }
    }

    lpri(ans);
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q];
string s;
bool a[Q];
int d;
int c = 1;
int solve(int j) {
	for (int i = j;i < d + j;i++) {
		if (MAX == d) {
			break;
		}
		cout << "c=" << c << endl;
		c++;
		if (i == n) {
			break;
		}
		if (s[i] == '1') {
			x[j]++;
			if (x[j] > (d / 2)) {
				break;
			}
		}
		if (s[i] == '0') {
			y[j]++;
			if (y[j] > (d / 2)) {
				break;
			}
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
			cout << ans << endl;
		}
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		d = (min(o, z) * 2);
		cout << solve(i);
		return 0;
	}
}


#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q];
char a;
string s;
bool b[Q];
int d;
int solve(int j) {
	for (int i = j;i < d + j;i++) {
		if (MAX == d) {
			break;
		}
		if (i == n) {
			break;
		}
		if (s[i] == '1') {
			x[j]++;
			if (x[j] > (d / 2)) {
				break;
			}
		}
		if (s[i] == '0') {
			y[j]++;
			if (y[j] > (d / 2)) {
				break;
			}
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
		if (b[j + 1] == false) {
			b[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	scanf_s("%d", &n);
	for (int i = 0;i < n;i++) {
		scanf_s("%c", &a);
		s.push_back(a);
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		printf_s("%d", n);
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		puts("2");
		return 0;
	}
	else if (o == 0 || z == 0) {
		puts("0");
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				printf_s("%d", n - 1);
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				printf_s("%d", n - 1);
				return 0;
			}
		}
	}
	else {
		int i = 0;
		d = (min(o, z) * 2);
		solve(i);
		printf_s("%d", MAX);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q], b;
string s;
bool a[Q];
int solve(int j) {
	for (int i = j;i < (min(o, z) * 2) + j;i++) {
		if (i == n) {
			break;
		}
		b++;
		if (s[i] == '1') {
			x[j]++;
		}
		if (s[i] == '0') {
			y[j]++;
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (MAX == (min(o, z) * 2)) {
			break;
		}
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		cout << solve(i);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, y, x;
string s;
int solve(int j) {
	o = 0;
	z = 0;
	for (int i = j;i < (min(x, y) * 2) + j;i++) {
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
		if (o == z && o != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	x = o;
	y = z;
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		j = 0;
		for (int i = 0;i < min(x, y) * 2;i++) {
			solve(i);
		}
		cout << MAX;
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n, z, o, MAX, j, ans;
string s;
int solve(int j) {
	o = 0;
	z = 0;
	for (int i = j;i < n;i++) {
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
		if ( o == z && o != 0) {
			ans = abs(i - j) + 1;
			if (ans % 2 != 0) {
				ans++;
			}
		}
		MAX = max(MAX, ans);
	}
	if (j < n) {
		solve(j + 1);
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		cout << solve(i);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q], b;
string s;
bool a[Q];
int c = 1;
int solve(int j) {
	for (int i = j;i < (min(o, z) * 2) + j;i++) {
		cout << c << endl;
		c++;
		if (i == n) {
			break;
		}
		b++;
		if (s[i] == '1') {
			x[j]++;
		}
		if (s[i] == '0') {
			y[j]++;
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (MAX == (min(o, z) * 2)) {
			break;
		}
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		cout << solve(i);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q];
string s;
bool a[Q];
int d;
int c = 1;
int solve(int j) {
	for (int i = j;i < d + j;i++) {
		if (MAX == d) {
			break;
		}
		if (i == n) {
			break;
		}
		if (s[i] == '1') {
			x[j]++;
			if (x[j] > (d / 2)) {
				break;
			}
		}
		if (s[i] == '0') {
			y[j]++;
			if (y[j] > (d / 2)) {
				break;
			}
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		d = (min(o, z) * 2);
		cout << solve(i);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q], b;
string s;
bool a[Q];
int solve(int j) {
	for (int i = j;i < (min(o, z) * 2) + j;i++) {
		if (i == n) {
			break;
		}
		b++;
		if (s[i] == '1') {
			x[j]++;
		}
		if (s[i] == '0') {
			y[j]++;
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		cout << solve(i);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q];
string s;
bool a[Q];
int solve(int j) {
	for (int i = j;i < n;i++) {
		if (s[i] == '1') {
			x[j]++;
		}
		if (s[i] == '0') {
			y[j]++;
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		solve(i);
		cout << MAX;
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans;
string s;
int solve(int j) {
	o = 0;
	z = 0;
	for (int i = j;i < n;i++) {
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
		if (o == z && o != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		j = 0;
		for (int i = 0;i < n;i++) {
			solve(i);
		}
		cout << MAX;
		return 0;
	}
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
vector <int> op, zp;
const int Q = 100001;
int n, z, o, ans = 2, MAX;
string s, b;
int x(int j) {
	int a = (j + 1) * 2;
	for (int i = 0;i < j;i++) {
		if ((op[j] - op[i]) + 1 <= a) {
			ans = a;
			break;
		}
		a -= 2;
	}
	return ans;
}
int solve1() {
	const int d = min(o, z) * 2;
	for (int i = 1;i < op.size();i++) {
		x(i);
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
	}
	return MAX;
}
int y(int j) {
	int a = (j + 1) * 2;
	for (int i = 0;i < j;i++) {
		if ((zp[j] - zp[i]) + 1 <= a) {
			ans = a;
			break;
		}
		a -= 2;
	}
	return ans;
}
int solve2() {
	const int d = min(o, z) * 2;
	for (int i = 1;i < zp.size();i++) {
		y(i);
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
			op.push_back(i);
		}
		if (s[i] == '0') {
			z++;
			zp.push_back(i);
		}
		b.push_back(s[i]);
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		if (z > o) {
			cout << solve1();
		}
		else {
			cout << solve2();
		}
		return 0;
	}
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
vector <int> op, zp;
const int Q = 100001;
int n, z, o, ans = 2, MAX;
string s, b;
int x(int j) {
	int a = (j + 1) * 2;
	for (int i = 0;i < j;i++) {
		if ((op[j] - op[i]) + 1 <= a) {
			ans = a;
			break;
		}
		a -= 2;
	}
	return ans;
}
int solve1() {
	const int d = min(o, z) * 2;
	for (int i = 1;i < op.size();i++) {
		x(i);
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
	}
	return MAX;
}
int y(int j) {
	int a = (j + 1) * 2;
	for (int i = 0;i < j;i++) {
		if ((zp[j] - zp[i]) + 1 <= a) {
			ans = a;
			break;
		}
		a -= 2;
	}
	return ans;
}
int solve2() {
	const int d = min(o, z) * 2;
	for (int i = 1;i < zp.size();i++) {
		y(i);
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
	}
	return MAX;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
			op.push_back(i);
		}
		if (s[i] == '0') {
			z++;
			zp.push_back(i);
		}
		b.push_back(s[i]);
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		if (z > o) {
			cout << solve1();
		}
		else {
			cout << solve2();
		}
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q];
string s;
bool a[Q];
int d;
int solve(int j) {
	for (int i = j;i < d + j;i++) {
		if (i == n) {
			break;
		}
		if (s[i] == '1') {
			x[j]++;
			if (x[j] > (d / 2)) {
				break;
			}
		}
		if (s[i] == '0') {
			y[j]++;
			if (y[j] > (d / 2)) {
				break;
			}
		}
		if (x[j] == y[j] && x[j] != 0) {
			ans = abs(i - j) + 1;
		}
		MAX = max(MAX, ans);
		if (MAX == d) {
			break;
		}
		if (a[j + 1] == false) {
			a[j + 1] = true;
			solve(i + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int i = 0;
		d = (min(o, z) * 2);
		cout << solve(i);
		return 0;
	}
}


#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
const int Q = 100001;
int n, z, o, MAX, j, ans, x[Q], y[Q];
string s;
bool a[Q];
int d;
int c;
map<int, bool>e;
int solve(int j) {
	if(j-d<0){
		c = 0;
	}
	else {
		c = (j - d) + 1;
	}
	for (int i = c;i <= j;i++) {
		if (e[i] == false) {
			if (s[j] == '1') {
				x[i]++;
				if (x[i] > (d / 2)) {
					e[i] = true;
				}
			}
			if (s[j] == '0') {
				y[i]++;
				if (y[i] > (d / 2)) {
					e[i] = true;
				}
			}
			if (x[i] == y[i] && x[i] != 0) {
				ans = abs(i - j) + 1;
			}
			MAX = max(MAX, ans);
			if (MAX == d) {
				break;
			}
		}
		if (i == j && j != n - 1) {
			solve(j + 1);
		}
	}
	return MAX;
}
int main() {
	cin >> n;
	s.resize(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
		if (s[i] == '1') {
			o++;
		}
		if (s[i] == '0') {
			z++;
		}
	}
	if (n % 2 == 0 && o == z) {
		cout << n;
		return 0;
	}
	else if ((o == 1 && z >= 2) || (z == 1 && o >= 2)) {
		cout << 2;
		return 0;
	}
	else if (o == 0 || z == 0) {
		cout << 0;
		return 0;
	}
	else if (n % 2 != 0 && abs(o - z) == 1) {
		if (z > o) {
			if (s[n - 1] == '0' || s[0] == '0') {
				cout << n - 1;
				return 0;
			}
		}
		if (o > z) {
			if (s[n - 1] == '1' || s[0] == '1') {
				cout << n - 1;
				return 0;
			}
		}
	}
	else {
		int j = 0;
		d = (min(o, z) * 2);
		cout << solve(j);
		return 0;
	}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

bool check(const vector<int_t>& counts, int_t size, int_t n) {
    for (int_t i=size; i<n; ++i) {
        if (counts[i] == counts[i-size]) {
            return true;
        }
    }
    return false;
}

int_t binary_search(const vector<int_t>& counts, int_t n, int_t min, int_t max) {
    while (max > min+2) {
        int_t mid = (max + min) >> 1;
        mid -= mid & 1;
        if (check(counts, mid, n)) {
            min = mid;
        } else {
            max = mid;
        }
    }
    return min;
}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    vector<int_t> counts(n, 0);
    int_t running_sum = 0;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
        counts[i] = running_sum;
    }
    if (running_sum == 0) {
        cout << n << "\n";
    } else {
        cout << binary_search(counts, n, 0, n - (running_sum > 0 ? running_sum : -running_sum) +2) << "\n";

    }
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

bool check(const vector<int_t>& counts, int_t size, int_t n) {
    for (int_t i=size; i<=n; ++i) {
        if (counts[i] == counts[i-size]) {
            return true;
        }
    }
    return false;
}

int_t binary_search(const vector<int_t>& counts, int_t n, int_t min, int_t max) {
    while (max > min+2) {
        int_t mid = (max + min) >> 1;
        mid -= mid & 1;
        if (check(counts, mid, n)) {
            min = mid;
        } else {
            max = mid;
        }
    }
    return min;
}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    vector<int_t> counts(n+1, 0);
    int_t running_sum = 0;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
        counts[i+1] = running_sum;
    }
    if (running_sum == 0) {
        cout << n << "\n";
    } else {
        cout << binary_search(counts, n, 0, n - (running_sum > 0 ? running_sum : -running_sum) +2) << "\n";

    }
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
#include <unordered_set>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;
using std::unordered_set;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

int_t max(int_t l, int_t r) {
    return l > r ? l : r;
}

int_t helper(const string& s, int_t start, int_t end, int_t running_sum, unordered_set<int_t>& memory, int_t max_so_far) {
    if (memory.find((start << 20) + end) != memory.end()) {
        return max_so_far;
    }
    while (end-start>max_so_far) {
        memory.insert((start << 20) + end);
        if (s[start] == s[end]) {
            running_sum -= s[start] == '0' ? 1 : -1;
            max_so_far = max(max_so_far, helper(s, start+1, end, running_sum, memory, max_so_far));
            max_so_far = max(max_so_far, helper(s, start, end-1, running_sum, memory, max_so_far));
            return max_so_far;
        } else {
            if (s[start] == '0') {
                if (running_sum > 0) {
                    start ++;
                    running_sum --;
                } else {
                    end --;
                    running_sum ++;
                }
            } else {
                if (running_sum > 0) {
                    end --;
                    running_sum --;
                } else {
                    start ++;
                    running_sum ++;
                }
            }
        }
        if (running_sum == 0) {
            return max(max_so_far, end-start+1);
        }
    }
    return max_so_far;
}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    int_t running_sum = 0;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
    }
    unordered_set<int_t> memory;
    cout << helper(s, 0, n-1, running_sum, memory, 0) << "\n";
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
#include <unordered_set>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;
using std::unordered_set;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

int_t max(int_t l, int_t r) {
    return l > r ? l : r;
}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    int_t running_sum = 0;
    map<int_t, int_t> memory;
    int_t result = 0;
    memory[0] = -1;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
        if (memory.find(running_sum) == memory.end()) {
            memory[running_sum] = i;
        } else {
            result = max(result, i - memory[running_sum]);
        }
    }
    cout << result << "\n";
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

bool check(const vector<int_t>& counts, int_t size, int_t n) {
    for (int_t i=size; i<n; ++i) {
        if (counts[i] == counts[i-size]) {
            return true;
        }
    }
    return false;
}

int_t binary_search(const vector<int_t>& counts, int_t n, int_t min, int_t max) {
    while (max > min+2) {
        int_t mid = (max + min) >> 1;
        mid -= mid & 1;
        if (check(counts, mid, n)) {
            min = mid;
        } else {
            max = mid;
        }
    }
    return min;
}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    vector<int_t> counts(n+1, 0);
    int_t running_sum = 0;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
        counts[i+1] = running_sum;
    }
    if (running_sum == 0) {
        cout << n << "\n";
    } else {
        cout << binary_search(counts, n, 0, n - (running_sum > 0 ? running_sum : -running_sum) +2) << "\n";

    }
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
#include <unordered_set>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;
using std::unordered_set;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

int_t max(int_t l, int_t r) {
    return l > r ? l : r;
}

int_t helper(const string& s, int_t start, int_t end, int_t running_sum, unordered_set<int_t>& memory, int_t max_so_far) {
    if (memory.find((start << 20) + end) != memory.end()) {
        return max_so_far;
    }
    if (running_sum == 0) {
        return max(max_so_far, end-start+1);
    }
    while (end-start>max_so_far) {
        memory.insert((start << 20) + end);
        if (s[start] == s[end]) {
            running_sum -= s[start] == '0' ? 1 : -1;
            if (s[start] == '0' && running_sum >= 0) {
                start ++;
            } else if (s[start] == '1' && running_sum <= 0) {
                start ++;
            } else {
                max_so_far = max(max_so_far, helper(s, start+1, end, running_sum, memory, max_so_far));
                max_so_far = max(max_so_far, helper(s, start, end-1, running_sum, memory, max_so_far));
                return max_so_far;
            }
        } else {
            if (s[start] == '0') {
                if (running_sum > 0) {
                    start ++;
                    running_sum --;
                } else {
                    end --;
                    running_sum ++;
                }
            } else {
                if (running_sum > 0) {
                    end --;
                    running_sum --;
                } else {
                    start ++;
                    running_sum ++;
                }
            }
        }
        if (running_sum == 0) {
            return max(max_so_far, end-start+1);
        }
    }
    return max_so_far;
}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    int_t running_sum = 0;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
    }
    unordered_set<int_t> memory;
    cout << helper(s, 0, n-1, running_sum, memory, 0) << "\n";
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <string>
#include <array>
#include <tuple>
#include <unordered_set>
using int_t = int64_t;
using std::array;
using std::cin;
using std::cout;
using std::make_pair;
using std::map;
using std::pair;
using std::setprecision;
using std::string;
using std::tuple;
using std::vector;
using std::unordered_set;

constexpr int64_t MOD = 1000000007;

constexpr int64_t inv(int64_t x)
{
    int_t d = MOD - 2;
    int_t result = 1;
    int_t multiplier = x;
    while (d > 1)
    {
        if (d & 1)
        {
            result *= multiplier;
            result %= MOD;
        }
        multiplier *= multiplier;
        multiplier %= MOD;
        d >>= 1;
    }
    return (result * multiplier) % MOD;
}

template <typename T>
vector<T> read(size_t N)
{
    vector<T> result(N);
    for (auto &t : result)
    {
        std::cin >> t;
    }
    return result;
}

void solve();

int main(int argc, char *argv[])
{
    if (argc > 3)
    {
        std::cerr << "usage  ./main [in_file] [out_file]\n";
        return 1;
    }
    if (argc == 3)
    {
        std::ofstream os(argv[2]);
        std::cout.rdbuf(os.rdbuf());
    }
    if (argc >= 2)
    {
        std::ifstream is(argv[1]);
        std::cin.rdbuf(is.rdbuf());
    }
    std::ios::sync_with_stdio(false);
    int T = 1;
    for (int t = 1; t <= T; ++t)
    {
//        std::cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

struct Data
{

    friend std::istream &operator>>(std::istream &is, Data &)
    {
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Data &d)
    {
        return os;
    }
};

int_t max(int_t l, int_t r) {
    return l > r ? l : r;
}

int_t helper(const string& s, int_t start, int_t end, int_t running_sum, unordered_set<int_t>& memory, int_t max_so_far) {
    if (memory.find((start << 20) + end) != memory.end()) {
        return max_so_far;
    }
    while (end-start>max_so_far) {
        memory.insert((start << 20) + end);
        if (s[start] == s[end]) {
            running_sum -= s[start] == '0' ? 1 : -1;
            max_so_far = max(max_so_far, helper(s, start+1, end, running_sum, memory, max_so_far));
            max_so_far = max(max_so_far, helper(s, start, end-1, running_sum, memory, max_so_far));
            return max_so_far;
        } else {
            if (s[start] == '0') {
                if (running_sum > 0) {
                    start ++;
                    running_sum --;
                } else {
                    end --;
                    running_sum ++;
                }
            } else {
                if (running_sum > 0) {
                    end --;
                    running_sum --;
                } else {
                    start ++;
                    running_sum ++;
                }
            }
        }
        if (running_sum == 0) {
            return max(max_so_far, end-start+1);
        }
    }

}

void solve()
{
    int_t n;
    cin >> n;
    string s;
    cin >> s;
    int_t running_sum = 0;
    for (int_t i=0; i<n; ++i) {
        running_sum += s[i] == '0' ? 1 : -1;
    }
    unordered_set<int_t> memory;
    cout << helper(s, 0, n-1, running_sum, memory, 0) << "\n";
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int ans, n, x;
    char y;
    stack <int> s;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> y;
        x = y - '0';
        if (s.empty())
        {
            s.push(x);
            continue;
        }
        if (s.top() < 2)
        {
            if (s.top() != x)
            {
                s.pop();
                if (!s.empty() && s.top() > 1)
                    s.top() += 2;
                else
                    s.push(2);
            }
            else
                s.push(x);
        }
        else
        {
            ans = s.top();
            s.pop();
            if (!s.empty())
            {
                if (s.top() == x)
                {
                    s.push(ans);
                    s.push(x);
                }
                else
                {
                    s.pop();
                    s.push(ans + 2);
                }
            }
        }
    }
    ans = 0;
    while (!s.empty())
    {
        if (s.top() != 1)
            ans = max(ans, s.top());
        s.pop();
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int ans = 0, n;
    map <int,int> mp;
    pair <int, pair<int,int>> a[100005];
    char y;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> y;
        if (i == 0)
        {
            if (y == '1')
            {
                a[i].second.second = 1;
                a[i].second.first = 0;
            }
            else
            {
                a[i].second.second = 0;
                a[i].second.first = 1;
            }
        }
        else
        {
            if (y == '1')
            {
                a[i].second.second = a[i - 1].second.second + 1;
                a[i].second.first = a[i - 1].second.first;
            }
            else
            {
                a[i].second.second = a[i - 1].second.second;
                a[i].second.first = a[i - 1].second.first + 1;
            }
        }
        a[i].first = a[i].second.second - a[i].second.first;
        mp[a[i].first] = -1;
    }
    for (int i = 0; i < n; i++)
        if (mp[a[i].first] == -1)
            mp[a[i].first] = i;
        else
            ans = max(ans, i - mp[a[i].first]);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define sz(a) a.size()
#define endl "\n"
#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfi3(x, y, z) scanf("%d%d%d" , &x,&y,&z)
#define sff(x) scanf("%f",&x)
#define sff1(x, y) scanf("%f%f",&x &y)
#define sff2(x, y, z) scanf("%f%f%f",&x, &y, &z)
#define sall s.begin(),s.end()
#define vall v.begin(),v.end()
#define mod 10000000007
#define pi 3.1415926536
#define LLMX 1e18
#define LLMN -1e18
#define NotinRange i < 0 || i >= n || j < 0 || j >= m
//printf("%",&)<<fixed<<setprecision()
//freopen("cubes.in", "r", stdin);
//freopen("cubes.in", "w", stdout);
//scanf("%size_s",&s);
pair<int, int> a[100005];

bool bsf2(int high)
{
    int req = a[high + 1].first, low = 0;
    while (low <= high)
    {
        int mid = (high + low) / 2;
        if (a[mid].first == req)
            return true;
        else if (a[mid].first < req)
            low = mid + 1;
        else
            high = mid - 1;
    }
    return false;
}

bool bss2(int high)
{
    int req = a[high + 1].second, low = 0;
    while (low <= high)
    {
        int mid = (high + low) / 2;
        if (a[mid].second == req)
            return true;
        else if (a[mid].second < req)
            low = mid + 1;
        else
            high = mid - 1;
    }
    return false;
}

int bsf(int high, int req)
{
    int low = 0, ans = -1, i = high + 1;
    while (low <= high)
    {
        int mid = (low + high) / 2;
        if (a[i].second - a[mid].second == a[i].first - a[mid].first)
        {
            ans = mid;
            high = mid - 1;
        }
        else if (a[mid].first == req)
        {
            if (bsf2(mid - 1))
                high = mid - 1;
            else
                low = mid + 1;
        }
        else if (a[mid].first <= req)
            low = mid + 1;
        else
            high = mid - 1;
    }
    return ans;
}

int bss(int high, int req)
{
    int low = 0, ans = -1, i = high + 1;
    while (low <= high)
    {
        int mid = (low + high) / 2;
        if (a[i].first - a[mid].first == a[i].second - a[mid].second)
        {
            ans = mid;
            high = mid - 1;
        }
        else if (a[mid].second == req)
        {
            if (bss2(mid - 1))
                high = mid - 1;
            else
                low = mid + 1;
        }
        else if (a[mid].second < req)
            low = mid + 1;
        else
            high = mid - 1;
    }
    return ans;
}
int main()
{
    int n, mini1, mini0, ans = 0;
    string s;
    cin >> n >> s;
    a[0].first = 0;
    a[0].second = 0;
    for (int i = 1; i <= n; i++)
    {
        if (s[i - 1] == '1')
        {
            a[i].first = a[i - 1].first + 1;
            a[i].second = a[i - 1].second;
        }
        else
        {
            a[i].first = a[i - 1].first;
            a[i].second = a[i - 1].second + 1;
        }
        if (a[i].first == a[i].second)
            ans = a[i].first * 2;
        else if (a[i].first > a[i].second)
        {
            int temp = 0;
            if (bsf(i - 1, a[i].first - a[i].second) != -1)
                temp = i - bsf(i - 1, a[i].first - a[i].second);
            ans = max(temp, ans);
        }
        else
        {
            int temp = 0;
            if (bss(i - 1, a[i].second - a[i].first) != -1)
                temp = i - bss(i - 1, a[i].second - a[i].first);
            ans = max(temp, ans);
        }
    }
    cout<<ans;
    return 0;
}