/* -*- coding: utf-8 -*- * * 127.cc: No.127 門松もどき - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 3000; /* typedef */ /* global variables */ int as[MAX_N]; int dpl[MAX_N][MAX_N], dpr[MAX_N][MAX_N]; /* subroutines */ /* main */ int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> as[i]; for (int i = 0; i < n; i++) dpl[i][i] = dpr[i][i] = 1; for (int k = 1; k < n; k++) { for (int l = 0, r = k; r < n; l++, r++) { dpl[l][r] = dpl[l][r - 1]; if (as[l] < as[r]) { int dr = dpr[l + 1][r] + 1; if (dpl[l][r] < dr) dpl[l][r] = dr; } dpr[l][r] = dpr[l + 1][r]; if (as[l] > as[r]) { int dl = dpl[l][r - 1] + 1; if (dpr[l][r] < dl) dpr[l][r] = dl; } } } int maxd = 1; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { int d = max(dpl[i][j], dpr[i][j]); if (maxd < d) maxd = d; } printf("%d\n", maxd); return 0; }