func_code_string: #include <bits/stdc++.h>   using namespace std;   long long powmod(long long base, long long exponent, long long mod) {     long long result = 1;     while (exponent > 0) {       if (exponent % 2 == 0) {         exponent /= 2;         base = (base * base) % mod;       } else {         result = (result * base) % mod;         exponent /= 2;         base = (base * base) % mod;       }     }     return result;   }   bool decresing(long long x, long long y) { return x > y; }   long long trin(long long start, long long stop) {     return (stop - start + 1) * (stop + start) / 2;   }   bool sortvectorf(pair<long long, long long> a, pair<long long, long long> b) {     return ((a.first > b.first) || (a.first == b.first && a.second > b.second));   }   bool sortvectorfv(pair<long long, long long> a, pair<long long, long long> b) {     return ((a.first > b.first) || (a.first == b.first && a.second < b.second));   }   bool sortvectors(pair<long long, long long> a, pair<long long, long long> b) {     return ((a.second > b.second) || (a.second == b.second && a.first > b.first));   }   bool negasortvectorf(pair<long long, long long> a,                        pair<long long, long long> b) {     return ((a.first < b.first) || (a.first == b.first && a.second < b.second));   }   bool negasortvectors(pair<long long, long long> a,                        pair<long long, long long> b) {     return ((a.second < b.second) || (a.second == b.second && a.first < b.first));   }   vector<vector<long long>> findPermutations(vector<long long> &a) {     sort(a.begin(), a.end());     vector<vector<long long>> sol;     do {       sol.push_back(a);     } while (next_permutation(a.begin(), a.end()));     return sol;   }   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     }     if (b == 0) {       return a;     }     return gcd(b % a, a);   }   bool isprime(long long n) {     for (int i = 2; i < n; i += 1) {       if (i * i > n) {         break;       }       if ((n / i) * i == n) {         return false;       }     }     return true;   }   long long fdivisor(long long n, long long fro) {     for (int i = 1; i < n + 1; i += 1) {       if ((n / i) * i == n && i >= fro) {         return i;       }     }     return -1;   }   vector<long long> divlist(long long n) {     vector<long long> curr;     for (int i = 2; i < n; i += 1) {       if ((long long)i * i > n) {         break;       }       if ((n / i) * i == n) {         curr.push_back(i);         curr.push_back(n / i);       }       if ((long long)i * i == n) {         curr.pop_back();       }     }     sort(curr.begin(), curr.end());     return curr;   }   long long digsum(long long num) {     long long cr = 0;     while (num > 0) {       cr += num % 10;       num /= 10;     }     return cr;   }   long long modInverse(long long a, long long b) {     long long m = b;     long long y = 0, x = 1;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) {       x += b;     }     return x;   }   long long azeret(long long num, long long mod) {     long long sil = 1;     while (num > 1) {       sil *= num;       sil %= mod;       num--;     }     return sil;   }   long long moddiv(long long to, long long by, long long mod) {     to %= mod;     while (to % by != 0) {       to += mod;       if (to > (by + 1) * mod) {         return -1;       }     }     return (to / by) % mod;   }   pair<long long, long long> func(pair<long long, long long> a,                                   pair<long long, long long> b) {     if (a.first < b.first) {       return a;     }     if (b.first < a.first) {       return b;     }     return {a.first, (a.second + b.second) % 1000000007};   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<long long, long long>> matrioskas(n);     set<long long> alls;     for (int i = 0; i < n; i += 1) {       cin >> matrioskas[i].second >> matrioskas[i].first;       alls.insert(matrioskas[i].first);       alls.insert(matrioskas[i].second);     }     alls.insert(0);     sort(matrioskas.begin(), matrioskas.end(), negasortvectorf);     vector<long long> ral;     for (auto it = alls.begin(); it != alls.end(); it++) {       ral.push_back(*it);     }     long long siz = ral.size();     vector<vector<long long>> cons(siz);     vector<pair<long long, long long>> pts(siz,                                            {999999999999999, 99999999999999});     pts[0] = {0, 1};     for (int i = 0; i < n; i += 1) {       long long left, right, mid;       left = 0;       right = siz - 1;       while (right > left) {         mid = (right + left + 1) / 2;         if (ral[mid] > matrioskas[i].first) {           right = mid - 1;         } else {           left = mid;         }       }       long long inpart = left;       left = 0;       right = siz - 1;       while (right > left) {         mid = (right + left + 1) / 2;         if (ral[mid] > matrioskas[i].second) {           right = mid - 1;         } else {           left = mid;         }       }       long long outpart = left;       cons[inpart].push_back(outpart);     }     for (int i = 1; i < siz; i += 1) {       pair<long long, long long> ptt = pts[i - 1];       ptt.first += ral[i] - ral[i - 1];       pts[i] = func(pts[i], ptt);       for (int ii = 0; ii < cons[i].size(); ii += 1) {         pts[cons[i][ii]] = func(pts[i], pts[cons[i][ii]]);       }     }     pair<long long, long long> ans = {999999999999999, 99999999999999};     for (int i = siz - 1; i >= 0; i += -1) {       if (cons[i].size() > 0) {         break;       }       ans = func(ans, pts[i]);     }     cout << ans.second << endl;     return 0;   }   