rt.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10;
template <class T>
T read() {
char c = getchar();
bool flag = (c == '-');
T num = 0;
while (c < '0' || c > '9') c = getchar(), flag |= (c == '-');
while (c >= '0' && c <= '9') num = (num << 1) + (num << 3) + (c ^ 48), c = getchar();
return flag ? -num : num;
}
int n, a[N], l[N], r[N], stk[N], top;
int main() {
n = read<int>();
for (int i = 1; i <= n; i++) {
a[i] = read<int>();
l[i] = 0;
r[i] = n + 1;
}
for (int i = 1; i <= n; i++) {
while (top && a[stk[top]] >= a[i]) r[stk[top]] = i, top--;
stk[++top] = i;
}
top = 0;
for (int i = 1; i <= n; i++) {
while (top && a[stk[top]] <= a[i]) top--;
if (top) l[i] = stk[top];
stk[++top] = i;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, max(i - l[i], r[i] - i));
// cout << l[i] << ' ' << r[i] << '\n';
}
printf("%d\n", ans);
return 0;
}
/kel