#include <iostream>
using namespace std;
int n, ap[500000], an[500000];
int a1[500000], a2[500000];
bool rep = 0;
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{
x = -x;
if (an[x] > 0)
{
a2[x] = i - an[x];
}else{
an[x] = i;
}
}
}
if (an[500000] == 1)
{
cout << 1;
return 0;
}
int mx1 = 0;
for (int i = 0; i <= 500000; ++i)
{
//cout << a1[i] << endl;
mx1 = max(mx1, a1[i]);
}
int mx2 = 0;
for (int i = 0; i <= 500000; ++i)
{
// cout << a2[i] << endl;
mx2 = max(mx2, a2[i]);
}
cout << max(mx1, mx2) + 1;
return 0;
}
Copy