#include<bits/stdc++.h>
#define _for(i,n) for(int i=0;i<n;i++)
#define _forr(i,n) for(int i=1;i<=n;i++)
#define _rof(i,n) for(int i=n-1;i>=0;i--)
#define _roff(i,n) for(int i=n;i>=1;i--)
#define nl cout << "\n"
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define pb push_back
#define pp pop_back
#define vl vector<ll>
#define lsb(x) (x & ~(x-1))
#define rand(l,r) uniform_int_distribution<int>(l, r)(rng);
#define IOS ios::sync_with_stdio(0); cout.tie(0); cin.tie(0)
#define pause system("pause")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
ll const mod=1e9+7;
ll const mod1=1013;
ll const MX = 2e6+100;
ll n, a[MX];
int main()
{
IOS;
ll _t=1;
// cin>>_t;
while(_t--)
{
ll ans=1;
cin>>n;
map<ll,ll> m;
ll x;
_for(i,n)
{
cin>>x;
if(m[x])
ans=max(ans, i+2-m[x]);
else
m[x]=i+1;
}
cout<<ans;nl;
}
}
/**
Test Case:
8
5 2 5 3 -30 -30 6 9
5 7 12 15 -15 -45 -39 -30
15 9
*/
Copy