#include <bits/stdc++.h>
#include<queue>
using namespace std;
/************************/
const int N = 1e5 + 10;
const int M = 1000000007;
const double eps = 1e9;
const double PI = acos(-1);
const int oo = 1e9;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define rall(c) (c).rbegin(),(c).rend()
#define all(c) (c).begin(),(c).end()
#define print(c) for(auto x:c) cout<<x<<" ";puts("");
#define read(c) for(auto &x:c)cin>>x;
/************************/
/*********GLOBAL*********/
/************************/
int main() {
int n;
cin>>n;
vector<pair<int,int>>v(n);
for(int i=0;i<n;i++){
cin>>v[i].first;
v[i].second = i+1;
}
sort(all(v));
int mx = 0;
for(int i=0,j=0;i<n;i++){
if(v[j].first==v[i].first){
int dif = abs(v[j].second-v[i].second);
if(dif>=mx)mx = dif;
}
else{
j=i;
}
}
cout<<mx+1<<endl;
}
Copy