#include <bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define LL long long
#define LINF 100000000000000000
#define INF 1000000000
const int N = 4e5+10;
const LL MOD = 1e9+7;
map<int,int>mp,mp1;
vector<int>vec;
int main()
{
//freopen("out.txt","w",stdout);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int x;cin>>x;
vec.push_back(x);
mp[x] = max(mp[x],i);
if(!mp1[x])mp1[x] = i;
else mp1[x] = min(mp1[x],i);
}
int ans = 0;
for(auto x:vec)
ans = max(ans,mp[x]-mp1[x]+1);
printf("%d\n",ans);
}
Copy