#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N, A[3001], dp[3001][3001][2]; int main(){ cin >> N; rep(i, N)scanf("%d", &A[i]); rep(i, N)rep(j, 2)dp[i][i][j] = 1; rep(len, N){ rep(l, N-len){ int r = l + len; rep(lr, 2){ int val = dp[l][r][lr]; if(lr == 0 && l > 0){ smax(dp[l-1][r][lr], val); if(A[r] > A[l - 1])smax(dp[l - 1][r][!lr], val+1); } if(lr == 1 && r < N-1){ smax(dp[l][r+1][lr], val); if(A[l] > A[r + 1])smax(dp[l][r + 1][!lr], val+1); } } } } int ans = 0; rep(i, 2)smax(ans, dp[0][N - 1][i]); cout << ans << endl; }