func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct segtree {     int n;     vector<pair<int, int>> st;     segtree(int _n) {       n = _n;       st.assign(4 * n + 5, make_pair(0, 0));     }     pair<int, int> merge(pair<int, int> a, pair<int, int> b) {       pair<int, int> res = make_pair(min(a.first, b.first), 0);       if (a.first == res.first) res.second += a.second;       if (b.first == res.first) res.second += b.second;       if (res.second >= mod) res.second -= mod;       return res;     }     void update(int id, int l, int r, int pos, int val, int num) {       if (l > pos || r < pos) return;       if (l == r) {         st[id] = make_pair(val, num);         return;       }       int mid = (l + r) >> 1;       update(id << 1, l, mid, pos, val, num);       update(id << 1 | 1, mid + 1, r, pos, val, num);       st[id] = merge(st[id << 1], st[id << 1 | 1]);     }     pair<int, int> get(int id, int l, int r, int u, int v) {       if (l > v || r < u) return make_pair((int)2e9, 0);       if (l >= u && r <= v) return st[id];       int mid = (l + r) >> 1;       pair<int, int> lnode = get(id << 1, l, mid, u, v);       pair<int, int> rnode = get(id << 1 | 1, mid + 1, r, u, v);       return merge(lnode, rnode);     }     void update(int pos, int val, int num) { update(1, 1, n, pos, val, num); }     pair<int, int> get(int l, int r) { return get(1, 1, n, l, r); }   };   const int N = 2e5 + 5;   pair<int, int> a[N];   pair<int, int> dp[N];   int n;   int maxpre[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a + 1, a + n + 1);     segtree st(n);     for (int i = 1; i <= n; i++) {       swap(a[i].first, a[i].second);       int lo = 0;       int hi = i;       while (hi - lo > 1) {         int mid = (lo + hi) >> 1;         if (a[mid].second <= a[i].first)           lo = mid;         else           hi = mid;       }       if (!lo)         dp[i] = make_pair(a[i].first, 1);       else {         dp[i] = st.get(1, lo);         dp[i].first += a[i].first;       }       st.update(i, dp[i].first - a[i].second, dp[i].second);     }     pair<int, int> ans = make_pair((int)2e9, 0);     int mx = 0;     for (int i = n; i >= 1; i--)       if (a[i].second > mx) {         if (ans.first == dp[i].first) {           ans.second += dp[i].second;           if (ans.second >= mod) ans.second -= mod;         } else if (ans.first > dp[i].first)           ans = dp[i];         mx = max(mx, a[i].first);       }     cout << ans.second;     return 0;   }   