#include #include #include #define FORR(i,b,e) for(int i=(b);i<(int)(e);++i) #define FOR(i,e) FORR(i,0,e) #define dump(var) cerr << #var ": " << var << "\n" #define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n" typedef long long ll; typedef unsigned long long ull; const double EPS = 1e-6; const int d4[] = {0, -1, 0, 1, 0}; using namespace std; const int INF = 1e6; int N; vector A(3010); int check() { vector h; h.reserve(N); int l = 0, r = N-1; for (; l <= r; ++l) { auto p = lower_bound(h.begin(), h.end(), A[l]); if (p == h.end()) { h.push_back(A[l]); } else { *p = A[l]; continue; } for (; r >= l; --r) { p = lower_bound(h.begin(), h.end(), A[r]); if (p == h.end()) { h.push_back(A[r]); r--; break; } *p = A[r]; } } return h.size(); } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; FOR(i, N) cin >> A[i]; int a1 = check(); reverse(A.begin(), A.begin()+N); int a2 = check(); cout << max(a1, a2) << endl; return 0; }