#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("teen.in", "r", stdin);
auto OUT = freopen("teen.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1e5 + 5;
int n = mread(), a[N], s[N], fi[N + N];
signed main(){
for(int i = 1; i <= n; i ++){
cin >> a[i];
if(a[i] == 0){
a[i] = -1;
}
s[i] = s[i - 1] + a[i];
}
memset(fi, -1, sizeof(fi));
fi[0 + N] = 0;
int ans = 0;
for(int i = 1; i <= n; i ++){
if(fi[s[i] + N] == -1){
fi[s[i] + N] = i;
}
else{
ans = max(ans, i - fi[s[i] + N]);
}
}
printf("%lld\n", ans);
return 0;
}