#include using namespace std; int N, A[3000], dp[3000][3000][2]; int rec(int left, int right, bool which) { if(left < 0 || right >= N) return(0); if(~dp[left][right][which]) return(dp[left][right][which]); int ret = 0; if(which) { if(left - 1 >= 0 && A[left - 1] < A[right]) { ret = max(ret, rec(left - 1, right, !which) + 1); } ret = max(ret, rec(left - 1, right, which)); } else { if(right + 1 < N && A[right + 1] < A[left]) { ret = max(ret, rec(left, right + 1, !which) + 1); } ret = max(ret, rec(left, right + 1, which)); } return(dp[left][right][which] = ret); } int main() { fill_n( **dp, 3000 * 3000 * 2, -1); cin >> N; for(int i = 0; i < N; i++) { cin >> A[i]; } int ret = 0; for(int i = 0; i < N; i++) { ret = max(ret, max(rec(i, i, true), rec(i, i, false)) + 1); } cout << ret << endl; }