/** * @FileName a.cpp * @Author kanpurin * @Created 2020.10.02 03:32:58 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template< typename T > struct BinaryIndexedTree { std::vector< T > data; BinaryIndexedTree() {} BinaryIndexedTree(int sz) { data.assign(++sz, 0); } inline T sum(int k) const { T ret = 0; for (k; k > 0; k -= k & -k) ret += data[k]; return (ret); } inline T sum(int left, int right) const { return sum(right) - sum(left); } inline void add(int k, T x) { for (++k; k < data.size(); k += k & -k) data[k] += x; } int lower_bound(ll k) const { if (k <= 0) return 0; int res = 0; int N = 1; while (N < (int)data.size()) N *= 2; for (int i = N / 2; i > 0; i /= 2) { if (res + i < (int)data.size() && data[res + i] < k) { k -= data[res + i]; res += i; } } return res; } friend std::ostream& operator<<(std::ostream &os, const BinaryIndexedTree &bit) { os << "[ "; for (int i = 0; i < bit.data.size() - 1; i++) { os << bit.sum(i, i + 1); if (i < bit.data.size() - 2) os << ", "; } os << " ]"; } }; template< int MOD > struct mint { public: long long x; mint(long long x = 0) :x((x%MOD+MOD)%MOD) {} mint(std::string &s) { long long z = 0; for (int i = 0; i < s.size(); i++) { z *= 10; z += s[i] - '0'; z %= MOD; } this->x = z; } mint& operator+=(const mint &a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint &a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint &a) { (x *= a.x) %= MOD; return *this; } mint& operator/=(const mint &a) { long long n = MOD - 2; mint u = 1, b = a; while (n > 0) { if (n & 1) { u *= b; } b *= b; n >>= 1; } return *this *= u; } mint operator+(const mint &a) const { mint res(*this); return res += a; } mint operator-() const {return mint() -= *this; } mint operator-(const mint &a) const { mint res(*this); return res -= a; } mint operator*(const mint &a) const { mint res(*this); return res *= a; } mint operator/(const mint &a) const { mint res(*this); return res /= a; } friend std::ostream& operator<<(std::ostream &os, const mint &n) { return os << n.x; } friend std::istream &operator>>(std::istream &is, mint &n) { long long x; is >> x; n = mint(x); return is; } bool operator==(const mint &a) const { return this->x == a.x; } mint pow(long long k) const { mint ret = 1; mint p = this->x; while (k > 0) { if (k & 1) { ret *= p; } p *= p; k >>= 1; } return ret; } }; constexpr int MOD = 1e9 + 7; int main() { constexpr int INF = 1e9 + 6; int n;cin >> n; vector> a(n); vector> lis(n); int max_lis = 0; vector count_lis(n+1,0); { vector v(n,INF); for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; auto lb = lower_bound(v.begin(), v.end(), a[i].first); *lb = a[i].first; lis[i].first = lb - v.begin() + 1; lis[i].second = count_lis[lis[i].first]++; max_lis = max(max_lis,lis[i].first); } } vector>> bit(n+1); bit[0] = BinaryIndexedTree>(1); bit[0].add(0,1); for (int i = 0; i < n; i++) { bit[i+1] = BinaryIndexedTree>(count_lis[i+1]); } sort(a.begin(), a.end(), [](pair a,pair b){ return a.first != b.first ? a.first < b.first : a.second > b.second; }); mint ans = 0; vector>> st(n+1); st[0].insert({-1,0}); for (int i = 0; i < n; i++) { int idx = a[i].second; auto k = st[lis[idx].first-1].lower_bound({idx,0}); k--; mint t = bit[lis[idx].first-1].sum(k->second+1); bit[lis[idx].first].add(lis[idx].second,t); st[lis[idx].first].insert({idx,lis[idx].second}); } cout << bit[max_lis].sum(count_lis[max_lis]) << endl; return 0; }