#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n;
cin >> n;
map<int, pair<int, int>> mp;
for (int i = 0, x; i < n; ++i) {
cin >> x;
if (mp.find(x) == mp.end()) mp[x] = make_pair(i, i);
else mp[x].second = i;
}
int ans = 0;
for (auto &i : mp) ans = max(ans, i.second.second - i.second.first + 1);
cout << ans << '\n';
return 0;
}
Copy