#include <bits/stdc++.h>   using namespace std;   bool isp[300005];   void sv() {     long long i, j;     memset(isp, true, sizeof(isp));     isp[1] = false;     for (i = 2; i * i < 300005; i++) {       if (isp[i]) {         for (j = i * i; j < 300005; j += i) isp[j] = false;       }     }   }   long long powr(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j, a[300005], x, y;     map<long long, vector<long long> > mp;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]].push_back(i);     }     long long ans = 0;     auto it = mp.begin();     while (it != mp.end()) {       (it->second).push_back(n);       it++;     }     auto itr = mp.begin();     while (itr != mp.end()) {       long long l = (itr->second).size();       for (i = l - 1; i > 0; i--) {         if ((itr->second)[i] != (itr->second)[i - 1] + 1) {           long long tmp = (itr->second)[i] - (itr->second)[0] - 1;           if (tmp > ans) {             ans = tmp;           } else             break;         }       }       itr++;     }     cout << ans;     return 0;   }   