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
71
72
#include<bits/stdc++.h>          
using namespace std;
typedef long long ll;
const ll MLL = 1e18;
const ll mod = 1e9 + 7;
vector<pair<int , int>> v;
set<int> w;


ll inv(ll i) {
	return i <= 1 ? i : mod - (ll)(mod/i) * inv(mod % i) % mod;			// log czas
}


bool inter(int l , int r,   int b) {
	if(r < v[b].first || v[b].second < l || (l < v[b].first &&  r > v[b].second)) return false;
	return true;
}


void flow(int x) {
	if(w.find(x) != w.end()) w.erase(w.find(x));
	for(int i = x - 1; i >= 0; i--) {
		if(w.find(i) != w.end() && inter(v[x].first , v[x].second , i)) {
			w.erase(w.find(i));
			flow(i);
		}
	}
}


void solve() {
   
	int n;
	cin >> n;
	v.resize(n);
	set<int> s;
	vector<int> p(n);
	for(int i =0 ; i < n; i++) cin >>v[i].first >> v[i].second, s.insert(i);
	for(int i = 0; i < n; i++) p[i] = i;
	ll ans = 0;
	ll comb = 0;
	do{
		comb++;
		int cur = 0;
		w.clear();
	     w = s;
		for(int x : p) {
			if(w.find(x) == w.end()) continue;
			cur++;
			flow(x);
			if(w.size() == 0) break;
		}
		ans += cur;
	}while(next_permutation(p.begin(), p.end()));
	cout << (ans * inv(comb % mod)) % mod;
}

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

	

    solve();




    return 0;
}