#include #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; class mint{ static const int MOD=1e9+7; int x; public: mint():x(0){} mint(long long y){ x=y%MOD; if(x<0) x+=MOD; } mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; } mint& operator-=(const mint& m){ x-=m.x; if(x< 0) x+=MOD; return *this; } mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; } mint& operator/=(const mint& m){ return *this*=inverse(m); } mint operator+(const mint& m)const{ return mint(*this)+=m; } mint operator-(const mint& m)const{ return mint(*this)-=m; } mint operator*(const mint& m)const{ return mint(*this)*=m; } mint operator/(const mint& m)const{ return mint(*this)/=m; } friend mint inverse(const mint& m){ int a=m.x,b=MOD,u=1,v=0; while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return u; } friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; } friend ostream& operator<<(ostream& os,const mint& m){ return os< lis; rep(i,n){ auto it=lower_bound(lis.begin(),lis.end(),a[i]); if(it!=lis.end()){ *it=a[i]; dp1[i]=it-lis.begin(); } else{ lis.emplace_back(a[i]); dp1[i]=lis.size()-1; } } int len=lis.size(); vector> V(len); rep(i,n) V[dp1[i]].emplace_back(i); mint dp2[2][200000]; rep(i,V[0].size()) dp2[0][V[0][i]]=1; int curr=0,next=1; rep(t,len-1){ if(t>0) rep(i,V[t-1].size()) dp2[next][V[t-1][i]]=0; vector W(V[t].size()); vector sum(V[t].size()+1); rep(i,V[t].size()){ int u=V[t][i]; W[i]=-a[u]; sum[i+1]=sum[i]+dp2[curr][u]; } rep(i,V[t+1].size()){ int u=V[t+1][i]; int idx_r=lower_bound(V[t].begin(),V[t].end(),u)-V[t].begin(); int idx_l=upper_bound(W.begin(),W.end(),-a[u])-W.begin(); dp2[next][u]=sum[idx_r]-sum[idx_l]; } swap(curr,next); } mint ans=0; rep(i,V[len-1].size()) ans+=dp2[curr][V[len-1][i]]; printf("%d\n",ans.to_int()); return 0; }