#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using namespace std; template ostream& operator<<(ostream& o,const pair &p){return o<<"("< ostream& operator<<(ostream& o,const vector &vc){o<<"sz = "<v) return; seg[x]=v; x/=2; while(x){ seg[x]=max(seg[x*2],seg[x*2+1]); x/=2; } } int getmax(int a,int b,int l=0,int r=N,int k=1){ if(b<=l||r<=a) return 0; if(a<=l&&r<=b) return seg[k]; return max(getmax(a,b,l,(l+r)/2,k*2),getmax(a,b,(l+r)/2,r,k*2+1)); } }up,down; int N; int x[100000]; vector xs; int main(){ cin>>N; rep(i,N){ scanf("%d",x+i); xs.pb(x[i]); } sort(all(xs)); xs.erase(unique(xs.begin(),xs.end()),xs.end()); int K=xs.size(); rep(i,N) x[i]=lower_bound(all(xs),x[i])-xs.begin(); int ans=0; rep(i,N){ //go up int dmx=down.getmax(0,x[i])+1; chmax(ans,dmx); up.update(x[i],dmx); //go down int umx=up.getmax(x[i]+1,K)+1; chmax(ans,umx); down.update(x[i],umx); } if(ans<=2) ans=0; cout<