#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll mod = 1000000007; const ll INF = (1e+18) + 7; #define rep(i,n) for(int i=0;i=0;i--) #define all(x) (x).begin(),(x).end() #define stop char nyaa;cin>>nyaa; using P = pair; using LP = pair; struct SegT { private: int sz; vector node; const LP init_c = { 0,0 }; public: SegT(int n) { sz = 1; while (sz < n)sz *= 2; node.resize(2 * sz - 1, init_c); } LP f(LP a, LP b) { if (a.first < b.first)return b; if (a.first > b.first)return a; ll res = a.second + b.second; if (res >= mod)res -= mod; return { a.first,res }; } void update(int k, LP a) { k += sz - 1; if (node[k].first == a.first) { node[k].second += a.second; if (node[k].second >= mod)node[k].second -= mod; } else if (node[k].first 0) { k = (k - 1) / 2; node[k] = f(node[k * 2 + 1], node[k * 2 + 2]); } } LP query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0)r = sz; if (r <= a || b <= l)return init_c; else if (a <= l && r <= b)return node[k]; else { LP vl = query(a, b, k * 2 + 1, l, (l + r) / 2); LP vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); } } }; void solve() { int n; cin >> n; vector a(n); rep(i, n) { cin >> a[i]; } vector x; rep(i, n)x.push_back(a[i]); x.push_back(-mod); sort(all(x)); x.erase(unique(all(x)), x.end()); map mp; rep(i, x.size())mp[x[i]] = i; rep(i, n)a[i] = mp[a[i]]; SegT st(x.size()); st.update(0,{ 0,1 }); rep(i, n) { LP p = st.query(0, a[i]); p.first++; st.update(a[i], p); } LP ans = st.query(0, x.size()); cout << ans.second << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); //int t; cin >> t;rep(i,t) solve(); solve(); stop return 0; }