#include using namespace std; using ll = long long; const int INF = 1e9; int n; /*********************************/ template inline ostream& operator<<(ostream& os,vector arr) {os << "["; for(int i = 0; i < (int)arr.size(); i++)os << arr[i] << (i == (int)arr.size() - 1 ? "]" : ",");os << endl;return os;} template ostream& operator<<(ostream& os, const pair& p){os << "{" << p.first << "," << p.second << "}";return os; } #define prvec(v) cerr<<#v<<": [";for(int __i = 0;__i < (int)(v).size(); __i++)cerr<<((v)[__i])<<(__i+1==(int)(v).size()?"]\n":","); #define print(x) cerr<<#x<<": "<<(x)< LIS(vector a) { vector dp(n, INF); vector f(n); for(int i = 0; i < n; i++) { auto itr = lower_bound(dp.begin(), dp.end(), a[i]); f[i] = itr - dp.begin(); *itr = a[i]; // f[i] = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin(); } return f; } int f(vector a, int cof) { for(auto &i: a) i *= cof; vector frot = LIS(a); reverse(a.begin(), a.end()); vector back = LIS(a); reverse(back.begin(), back.end()); int nax = 0; /* print(frot); print(back); */ for(int i = 1; i < n - 1; i++) { nax = max(nax, min(frot[i], back[i])); } return nax; } int main() { cin >> n; vector a(n); for(int i = 0; i < n; i++)cin >> a[i]; cout << max(f(a, 1), f(a,-1)) << endl; }