#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair LP; template struct ModInt { long long x; ModInt() : x(0) {} ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} explicit operator int() const {return x;} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const{ int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return ModInt(u); } ModInt power(long long p) const{ int a = x; if (p==0) return 1; if (p==1) return ModInt(a); if (p%2==1) return (ModInt(a)*ModInt(a)).power(p/2)*ModInt(a); else return (ModInt(a)*ModInt(a)).power(p/2); } ModInt power(const ModInt p) const{ return ((ModInt)x).power(p.x); } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { long long x; is >> x; a = ModInt(x); return (is); } }; using modint = ModInt; template struct SegmentTree{ using F = function; int n; F f;//二項演算 T ti;//単位元 vector dat; SegmentTree(){} SegmentTree(F f,T ti):f(f),ti(ti){} void init(int n_){//sizeがn_のsegtreeを作る n=1; while(n &v){//vによってsegtreeをbuildする int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(int a,int b){//区間[a,b)に対しFを適応した値を返す if(a>=b) return ti; T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } template int find(int st,C &check,T &acc,int k,int l,int r){// if(l+1==r){ acc=f(acc,dat[k]); return check(acc)?k-n:-1; } int m=(l+r)>>1; if(m<=st) return find(st,check,acc,(k<<1)|1,m,r); if(st<=l&&!check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } int vl=find(st,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return find(st,check,acc,(k<<1)|1,m,r); } template int find(int st,C &check){ T acc=ti; return find(st,check,acc,1,0,n); } }; int n; int a[200010],b[200010],l[200010]; map> comp; vector

S[200010]; int idx[200010]; modint nu[200010]; void solve(){ cin >> n; rep(i,n){ cin >> a[i]; comp[a[i]].push_back(i); } int k=0; for(auto p:comp){ for(int s:p.second){ b[s]=k; } k+=1; } rep(i,n){ //cout << b[i] << " "; } //cout << "" << endl; auto f1=[](int a,int b){return max(a,b);}; SegmentTree lis(f1,0); lis.init(k); int max_l=0; rep(i,n){ l[i]=lis.query(0,b[i])+1; lis.set_val(b[i],l[i]); S[l[i]].push_back(P(b[i],i)); max_l=max(max_l,l[i]); //cout << l[i] << " "; } //cout << "" << endl; rep(i,max_l+1){ sort(S[i].begin(),S[i].end()); int m=0; for(P s:S[i]){ idx[s.second]=m; m+=1; } } auto f2=[](modint a,modint b){return a+b;}; SegmentTree ss(f2,0); vector> num; rep(i,max_l+1){ num.push_back(ss); num[i].init(S[i].size()); } rep(i,n){ if(l[i]==1){ num[l[i]].set_val(idx[i],1); nu[i]=1; //cout << i << " " << nu[i] << endl; continue; } auto p=upper_bound(S[l[i]-1].begin(),S[l[i]-1].end(),P(b[i],-1)); int s=p-S[l[i]-1].begin(); //cout << i << " " << l[i] << " " << s << endl; nu[i]=num[l[i]-1].query(0,s); //cout << i << " " << nu[i] << endl; num[l[i]].set_val(idx[i],nu[i]); } cout << num[max_l].query(0,S[max_l].size()) << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }