#include #include #include using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000 int get(vector a){ int n = a.size(); vector dp(n,vector(n,vector(2,-Inf))); rep(i,n){ dp[i][i][0] = 1; dp[i][i][1] = 1; } for(int i=2;i<=n;i++){ rep(j,n){ int l = j; int r = j+i-1; if(r>=n)break; dp[l][r][0] = max(dp[l][r][0],dp[l][r-1][0]); if(a[r]>a[l])dp[l][r][0] = max(dp[l][r][0],dp[l+1][r][1]+1); dp[l][r][1] = max(dp[l][r][1],dp[l+1][r][1]); if(a[l]>a[r])dp[l][r][1] = max(dp[l][r][1],dp[l][r-1][0]+1); } } return max(dp[0][n-1][0],dp[0][n-1][1]); } int main(){ int n; cin>>n; vector a(n); rep(i,n)cin>>a[i]; int ans = get(a); rep(i,n)a[i] *= -1; // ans = max(ans,get(a)); cout<