1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

const int mod = 1e9+7;

long long odw(long long a) {
    long long w = mod-2;
    long long p = a;
    long long ans = 1;
    while(w) {
        if(w%2) ans = (ans*p) % mod;
        w /= 2;
        p = (p*p) % mod;
    }
    return ans;
}

vi L, R;
vi nad;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	

    int n;
    cin >> n;
    L.pb(0);
    R.pb(0);
    nad.pb(0);
    for(int i = 1; i <= n; i++) {
        int li, ri;
        cin >> li >> ri;
        L.pb(li);
        R.pb(ri); 
    }
    
    for(int i = 1; i <= n; i++) {
        int count = 1;
        int left = L[i], right = R[i];
        for(int j = i+1; j <= n; j++) {
            if(R[j] < left  ||  right < L[j]) continue;
            else if(left < L[j]  &&  L[j] < right) {
                count++;
                right = max(right, R[j]);
            }
            else if(left < R[j]  &&  R[j] < right) {
                count++;
                left = min(left, L[j]);
                
            }
            else break;
        }
        
        nad.pb(count);
    }
    
    
    long long ans = 0;
    for(int i = 1; i <= n; i++) ans = (ans + odw(nad[i])) % mod;
    cout << ans << "\n";
	
    return 0;
}