#include #include using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second typedef long long ll; typedef vector vec; typedef vector mat; ll N,M,H,W,Q,K,A,B; string S; typedef pair P; const ll INF = (1LL<<58); template bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } void up(vec &a, vec &memo){ vec left(0); rep(i,N){ auto ite = upper_bound(ALL(left), a[i]); memo[i] = ite - left.begin(); if(ite == left.begin()){ if(left.empty()) left.push_back(a[i]); else chmin(left[0], a[i]); }else{ if(ite == left.end()){ if(*left.rbegin() < a[i]) left.push_back(a[i]); }else{ --ite; if(*ite < a[i]) left[(ite - left.begin()) + 1] = a[i]; } } } } int main() { cin>>N; vec a(N); rep(i,N) cin>>a[i]; vec lu(N), ru(N), ld(N), rd(N); up(a, lu); reverse(ALL(a)); up(a, ru); reverse(ALL(ru)); rep(i, N) a[i] = -a[i]; up(a, rd); reverse(ALL(rd)); reverse(ALL(a)); up(a, ld); ll ans = 0; rep(i,N) chmax(ans, max(min(lu[i], ru[i]), min(ld[i], rd[i]))); cout<