#include<bits/stdc++.h>
using namespace std;
int a[1000005], pre[1000005], maxi;
int n;
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
if(a[i] == 1){
pre[i] = pre[i - 1] + 1;
}
else if(a[i] == 0){
pre[i] = pre[i - 1] - 1;
}
}
for(int i = 1; i <= n; i++){
for(int j = i + maxi; j <= n; j++){
if(pre[j] - pre[i - 1] == 0){
maxi = max(maxi, j - i + 1);
}
}
}
cout << maxi;
return 0;
}