#include using namespace std; using ll = long long; const int INF = 1e9; int n; vector 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]); *itr = a[i]; f[i] = lower_bound(dp.begin(), dp.end(), INF) - 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; for(int i = 1; i < n - 1; i++) { nax = max(min(frot[i-1], back[i+1]), nax); } 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; }