#include using namespace std; typedef long long int ll; typedef pair pii; typedef vector vi; typedef vector > vii; #define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++) #define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++) #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) #define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--) #define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template inline void minup(T1& m, T2 x){ if(m>x) m=static_cast(x); } template inline void maxup(T1& m, T2 x){ if(m(x); } #define INF 1000000000 #define MOD 1000000007 #define EPS 1E-12 const int MAX_N = 3000; int n; int A[MAX_N]; int dp[2][MAX_N][MAX_N]; int res; int main() { cin >> n; rep(i, n) cin >> A[i]; rep(d, n) rep(L, n){ int R = L + d; if(R > n-1) break; if(L == R) dp[0][L][R] = dp[1][L][R] = 1; maxup(dp[0][L][R], dp[0][L][R-1]); maxup(dp[1][L][R], dp[1][L+1][R]); if(A[L] < A[R]) maxup(dp[0][L][R], dp[1][L+1][R]+1); if(A[L] > A[R]) maxup(dp[1][L][R], dp[0][L][R-1]+1); } rep(i, n) maxup(res, max(dp[0][0][i], dp[1][i][n-1])); cout << res << endl; return 0; }