#include<bits/stdc++.h>
using namespace std;
const int MAXN = 503;
const int MOD = 1e9 + 7;
#define int long long
int n, l[MAXN], r[MAXN], dp[MAXN][MAXN * 2];
vector<int> vt;
vector<pair<int, int>> segment;
int pw(int a, int b){
    int res = 1;
    while(b){
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
int C(int n, int k){
    if(k > n) return 0;
    int res = 1;
    for (int i = 1; i <= k; i++){
        res = res * pw(i, MOD - 2) % MOD;
        res = res * (n - i + 1) % MOD;
    }
    return res;
}
main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> l[i] >> r[i];
        vt.push_back(l[i]);
        vt.push_back(r[i] + 1);
    }
    sort(vt.begin(), vt.end());
    segment.push_back({0, 0});
    for (int i = 1; i < vt.size(); i++){
        if (vt[i] != vt[i - 1]) segment.push_back({vt[i - 1], vt[i] - 1});
    }
    for (int j = 0; j < segment.size(); j++) dp[0][j] = 1;
    for (int i = 1; i <= n; i++){
        dp[i][0] = 1;
        for (int j = 1; j < segment.size(); j++){
            dp[i][j] = dp[i][j - 1];
            auto[a, b] = segment[j];
            int cnt = 0, sum = 0;
            for (int k = i; k >= 1; k--){
                if (l[k] <= a && b <= r[k]){
                    cnt++;
                    sum = (sum + C(b - a + 1, cnt)) % MOD;
                    dp[i][j] += dp[k - 1][j - 1] * sum % MOD;
                    dp[i][j] %= MOD;
                }
            }
            //cout << "Doan " << i << " la [" << l[i] << ", " << r[i] << "], ";
            //cout << "Segment " << j << ": [" << a << ", " << b << "], ";
            //cout << "dp[" << i << "][" << j << "]: " << dp[i][j] << '\n';
        }
    }
    cout << (dp[n][segment.size() - 1] - 1 + MOD) % MOD;
}
Compilation message (stderr)
boat.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main(){
      | ^~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |