#include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<stack> #include<vector> #include<string> #include<map> #include<set> #include<ctime> #define ll long long #define ull unsigned long long using namespace std; int a[300010]; int main () { //ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } //int len = 0; //bool aa = 0; int j = n - 1; int i = 0; int temp1 = 0; int temp2 = 0; for (int i = 0 , j = n - 1; i < j; ) { if (a[i] != a[j]){ temp1 = j - i; break; } else { i++; } } for (int i = 0 , j = n - 1; i < j; ) { j--; if (a[i] != a[j]){ temp2 = j - i; break; } } temp1 = max(temp1, temp2); //temp = max(temp, n - 1 - temp); printf("%d\n", temp1); }