#include <iostream>
using namespace std;
int n, ap[1000001], an[1000001];
int a1[1000001], a2[1000001];
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int ans = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
if (x > 0)
{
if (ap[x] > 0)
{
a1[x] = i - ap[x];
}else{
ap[x] = i;
}
}else{
if (an[-x] > 0)
{
a2[-x] = i - an[-x];
}else{
an[-x] = i;
}
}
}
int mx1 = 0;
for (int i = 0; i < n; ++i)
{
//cout << a1[i] << endl;
mx1 = max(mx1, a1[i]);
}
int mx2 = 0;
for (int i = 0; i < n; ++i)
{
//cout << a1[i] << endl;
mx2 = max(mx2, a2[i]);
}
cout << max(mx1, mx2) + 1;
return 0;
}
Copy