#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef ll _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "< P; struct obj{ int len,bef2,bef; obj(){ len=0; bef2=bef=-1; } obj(int len,int bef2,int bef):len(len),bef2(bef2),bef(bef){} bool operator<(const obj &that) const{ return len < that.len; } void debug(){ printf("[%d,%d,%d]",len,bef2,bef); } }; struct node{ obj best[2]; node(){} node merge(const node &that) const{ node ret; ret.best[0] = max(best[0], that.best[0]); ret.best[1] = obj(-2521,-1,-1); if(ret.best[0].bef2 != best[0].bef2)CHMAX(ret.best[1],best[0]); if(ret.best[0].bef2 != best[1].bef2)CHMAX(ret.best[1],best[1]); if(ret.best[0].bef2 != that.best[0].bef2)CHMAX(ret.best[1],that.best[0]); if(ret.best[0].bef2 != that.best[1].bef2)CHMAX(ret.best[1],that.best[1]); return ret; } void debug(){ best[0].debug(); printf(", "); best[1].debug(); printf("\n"); } }; struct segment{ int n; vector data; segment(int n_){ n=1; while(n0){ x = (x-1)/2; data[x] = data[2*x+1].merge(data[2*x+2]); } } node get(int x){ return data[x+n-1]; } node query(int l,int r,int a,int b,int k){ if(r<=a || b<=l)return node(); if(l<=a && b<=r){ return data[k]; }else{ int m = (a+b)/2; node lef = query(l,r,a,m,2*k+1); node rig = query(l,r,m,b,2*k+2); return lef.merge(rig); } } node query(int l,int r){ return query(l,r,0,n,0); } }; obj succ(const obj &o,int v){ if(o.bef2==v){ return obj(-2521,-1,-1); }else{ return obj(o.len+1, o.bef, v); } } int n; int a[125252]; int main(){ scanf("%d",&n); REP(i,n)scanf("%d",a+i); // kowai node zaatu { map M; REP(i,n)M[a[i]]=0; int it = 1; for(pair P:M){ M[P.first] = it++; } REP(i,n)a[i]=M[a[i]]; } segment up(n+10),down(n+10); int ans = 0; REP(i,n){ int v = a[i]; node nxtdown = down.get(v), nxtup = up.get(v); { vector yo; yo.push_back(nxtdown.best[0]); yo.push_back(nxtdown.best[1]); node q = up.query(v+1,n+5); yo.push_back(succ(q.best[0],v)); yo.push_back(succ(q.best[1],v)); int split_a = q.best[0].bef; int split_b = q.best[1].bef; if(v yo; yo.push_back(nxtup.best[0]); yo.push_back(nxtup.best[1]); node q = down.query(0,v); yo.push_back(succ(q.best[0],v)); yo.push_back(succ(q.best[1],v)); int split_a = q.best[0].bef; int split_b = q.best[1].bef; if(split_a