#include // clang-format off using namespace std; using Int = long long; #define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++) #define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++) #define OVERLOAD2(_1, _2, _3, name, ...) name #define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__) struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io; #ifndef _MY_DEBUG #define dump(...) #endif // clang-format on /** * author: knshnb * created: Fri Feb 14 23:02:23 JST 2020 **/ template T pow(T x, int n, const T UNION = 1) { T ret = UNION; while (n) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } template struct ModInt { int x; static unordered_map to_inv; ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % MD + MD) >= MD) x -= MD; } ModInt& operator+=(ModInt that) { if ((x += that.x) >= MD) x -= MD; return *this; } ModInt& operator*=(ModInt that) { x = (unsigned long long)x * that.x % MD; return *this; } ModInt& operator-=(ModInt that) { if ((x -= that.x) < 0) x += MD; return *this; } ModInt& operator/=(ModInt that) { x = (unsigned long long)x * that.inv().x % MD; return *this; } ModInt operator-() const { return -x < 0 ? MD - x : -x; } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } bool operator<(ModInt that) const { return true; } ModInt inv() const { return to_inv.count(this->x) ? to_inv[this->x] : (to_inv[this->x] = pow(*this, MD - 2).x); } friend ostream& operator<<(ostream& s, ModInt a) { s << a.x; return s; } friend istream& operator>>(istream& s, ModInt& a) { long long tmp; s >> tmp; a = ModInt(tmp); return s; } friend string to_string(ModInt a) { return to_string(a.x); } }; template unordered_map ModInt::to_inv; using mint = ModInt<1000000007>; vector fact, fact_inv; void init_factorial(int n) { fact = vector(n + 1, 1); fact_inv = vector(n + 1); for (int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1); fact_inv[n] = mint(1) / fact[n]; for (int i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1); // for (int i = 0; i < n + 1; i++) assert(fact[i] * fact_inv[i] == 1); } mint comb(int n, int r) { return fact[n] * fact_inv[r] * fact_inv[n - r]; } using pii = pair; signed main() { Int n; cin >> n; vector a(n); REP(i, n) cin >> a[i]; vector dp(n, 1e18); vector> g(n); for (Int x : a) { Int j = lower_bound(dp.begin(), dp.end(), x) - dp.begin(); dp[j] = x; mint cnt = 0; if (j > 0) { auto it = upper_bound(g[j - 1].begin(), g[j - 1].end(), pii(-x, 1e10)); mint minus = it == g[j - 1].begin() ? 0 : prev(it)->second; mint plus = g[j - 1].empty() ? 0 : g[j - 1].back().second; cnt += plus - minus; } else { cnt = 1; } mint prv = g[j].empty() ? 0 : g[j].back().second; g[j].push_back({-x, cnt + prv}); } Int idx = lower_bound(dp.begin(), dp.end(), 1e18) - dp.begin(); cout << g[idx - 1].back().second << endl; }