#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<void chmin(T&a,const T&b){if(a>b)a=b;} templatevoid chmax(T&a,const T&b){if(a lis(const vector&A) { int N = A.size(); vector lens(N); fill(dp, dp + N, INF); REP(i, N) { int pos = lower_bound(dp, dp + N, A[i]) - dp; dp[pos] = A[i]; lens[i] = pos + 1; } return lens; } int solve(vector A) { int N = A.size(); auto F = lis(A); reverse(ALL(A)); auto B = lis(A); reverse(ALL(A)); reverse(ALL(B)); // pv(ALL(A)); // pv(ALL(F)); // pv(ALL(B)); int res = 0; REP(i, N) { int val = min(F[i], B[i]) - 1; chmax(res, val); } return res; } int main2() { int N = nextLong(); vector A(N); REP(i, N) A[i] = nextLong(); int ans1 = solve(A); int maxA = *max_element(ALL(A)); REP(i, N) A[i] = maxA - A[i] + 1; int ans2 = solve(A); cout << max(ans1, ans2) << endl; return 0; } int main() { #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }