#include<bits/stdc++.h>
using namespace std;
int n,maxx,h[100005],ansA[100005],ansB[100005];
stack<int>A,B;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>h[i];
for(int i=1;i<=n;i++){
while(!A.empty()&&h[A.top()]>=h[i]){
ansA[A.top()]=i-A.top();
A.pop();
}A.push(i);
}while(!A.empty()){
ansA[A.top()]=n-A.top()+1;
A.pop();
}for(int i=n;i>=0;i--){
while(!B.empty()&&h[B.top()]<=h[i]){
ansB[B.top()]=B.top()-i;
B.pop();
}B.push(i);
}while(!B.empty()){
ansB[B.top()]=B.top();
B.pop();
}for(int i=n;i>0;i--)for(int j=ansA[i]-1;j>0;j--)if(ansB[j+i]>j&&j+1>maxx){
maxx=j+1;
break;
}cout<<maxx;
}