#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- template class SegTree_1 { public: vector val; static V const def=0; V comp(V l,V r){ return max(l,r);}; SegTree_1(){val=vector(NV*2,def);}; V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]); } }; SegTree_1 LT,RT; int L[101010],R[101010]; int N; int A[101010]; map> M[2]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) { cin>>A[i]; M[0][A[i]].push_back(i); M[1][-A[i]].push_back(i); } int ma=0; FOR(i,2) { FORR(v,LT.val) v=0; FORR(v,RT.val) v=0; FORR(m,M[i]) { FORR(v,m.second) { L[v]=LT.getval(0,v)+1; R[v]=RT.getval(v+1,N+1)+1; ma=max(ma,min(L[v],R[v])-1); } FORR(v,m.second) { LT.update(v,L[v]); RT.update(v,R[v]); } } } cout<