#include using namespace std; template struct SegmentTree{ using Func = function; int size; vector seg; const Func merge; const Monoid def; SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){ for(size = 1; size <= n; size <<= 1); seg.assign(size*2, def); } Monoid& operator[] (int i) { return seg[i+size]; }; void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); } void update(int i, Monoid val){ seg[i += size] = val; while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]); } void add(int i, Monoid val){ update(i, val+seg[i+size]); } Monoid get(int a, int b){ Monoid l = def, r = def; for(a += size, b += size; a < b; a >>= 1, b >>= 1){ if(a & 1) l = merge(l, seg[a++]); if(b & 1) r = merge(r, seg[--b]); } return merge(l, r); } }; #define int long long #define MOD 1000000007 typedef pair P; signed main(){ int n; cin >> n; SegmentTree

seg(n, {0, 0}, [](P a, P b){ if(a.first > b.first){ return a; }else if(a.first < b.first){ return b; } a.second += b.second; a.second %= MOD; return a; }); int a[200010]; vector> azip; for(int i = 0;i < n;i++){ int b; cin >> b; a[i] = b; azip.push_back({b, i}); } sort(azip.begin(), azip.end()); int atmp = 0; int ans = 0; for(int i = n-1;i >= 0;i--){ pair pp = {a[i], i}; pair pp2 = {a[i]+1, INT_MIN}; int idx = lower_bound(azip.begin(), azip.end(), pp) - azip.begin(); int start = lower_bound(azip.begin(), azip.end(), pp2) - azip.begin(); auto get = seg.get(start, n); get.first++; if(get.second == 0) get.second = 1; seg.update(idx, get); if(atmp == get.first){ ans += get.second; ans %= MOD; }else if(atmp < get.first){ atmp = get.first; ans = get.second; } } cout << ans << endl; return 0; }