include <bits/stdc++.h>
using namespace std;
int main()
{
int N,t,len=0;
cin>>N;
vector<int> arr(N+1,0);
for(int i=1;i<=N;i++)
{
cin>>t;
if(t>0)
arr[i]=arr[i-1]+1;
else if(t<0)
arr[i]=arr[i-1]-1;
else
arr[i]=arr[i-1];
if(arr[i]==0)
len = max(len,i);
}</int>
for(int i=1;i<=N;i++) for(int j=N;j>len+i;j--) { if(arr[j]==arr[i]) { len =max(len,j-i); break; } } cout<<len<<endl; return 0;
}