#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]); f[i] = itr - dp.begin(); *itr = a[i]; } 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(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; }