#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=0) return ret; ret=2; if(A[L]>A[R]) { for(x=RL[L]; xA[L]; x=RS[x]) ret=max(ret,1+dodo(L,x)); } else { for(x=LL[R]; x>L && A[x]<=A[R]; x=LL[x]) ; for(;x>L && A[x]>A[R]; x=LS[x]) ret=max(ret,1+dodo(x,R)); } return ret; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>A[i]; FOR(i,N) { LS[i]=LL[i]=-1; RS[i]=RL[i]=N; FOR(j,i) if(A[j]A[i]) LL[i]=j; for(j=N-1;j>i;j--) if(A[j]i;j--) if(A[j]>A[i]) RL[i]=j; } int ma=1; MINUS(memo); FOR(y,N) FOR(x,y) ma=max(ma,dodo(x,y)); cout<