#include using namespace std; using ll = long long; template using vec = vector; template using vvec = vector>; template using vvvec = vector>; template class SegmentTree{ private: int sz; vector seg; const F op; const Monoid e; public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz<=n) sz <<= 1; seg.assign(2*sz,e); } void set(int k, const Monoid &x){ seg[k+sz] = x; } void build(){ for(int i=sz-1;i>0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] = x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } }; template class Compress { int N; map idx; map value; vec v; vec cmp; public: Compress(){} void add(T x){v.push_back(x);} void build(){ for(auto &x:v) cmp.push_back(x); sort(cmp.begin(),cmp.end()); cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end()); N = cmp.size(); for (int i=0;i> N; vec A(N); Compress cmp; for(auto& x:A){ cin >> x; cmp.add(x); } cmp.add(0); cmp.build(); vec L(N+1),R(N+1); int M = cmp.size(); SegmentTree seg(N,[](int a,int b){return max(a,b);},0); for(int i=0;i=0;i--){ int n = seg.query(cmp.id(A[i])+1,M); R[i+1] = n+1; seg.update(cmp.id(A[i]),n+1); } int ans = 0; for(int i=0;i=0;i--){ int n = seg.query(0,cmp.id(A[i])); R[i+1] = n+1; seg.update(cmp.id(A[i]),n+1); } for(int i=0;i