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
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
const long long mod = 1000000007;

void dfs(int v, vector <int>& ile, vector <bool>& vis, vector <vector <int> > &g, vector <bitset <100000> >& bi) {
	vis[v] = 1;
	for (auto w : g[v]) {
		if (!vis[w]) {
//			cout << v << " " << w << "<\n";
			dfs(w, ile, vis, g, bi);
		}
		bi[v] |= bi[w];
		bi[v][w] = 1;
	}
	ile[v] = (int)bi[v].count();
}

ll powmod(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b % 2)
			res *= a;
		a *= a;
		a %= mod;
		res %= mod;
		b /= 2;
	}
	return res;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector <pair <int, int> > v(n);
	for (int i = n-1; i >= 0; i--) {
		cin >> v[i].ff >> v[i].ss;
	}
	vector <vector <int> > woda(n);
	vector <vector <int> > g(n);
	set <pair <int, int> > s; 
	for (int i = 0; i < n; i++) {
		pair <int, int> p1 = {v[i].ff, i};
		pair <int, int> p2 = {v[i].ss, i};
		while (true) {
			auto u = upper_bound(s.begin(), s.end(), p1);
			if (u != s.end() && (*u).ff < v[i].ss) {
				woda[(*u).ss].push_back(i);
				g[i].push_back((*u).ss);
				s.erase(u);
			}
			else 
				break;
		}
		s.insert(p1);
		s.insert(p2);
	}
	vector <int> ile(n);
	vector <bool> vis(n);
	vector <bitset <100000> > bi(n);
	for (int i = n-1; i >= 0; i--) {
		if (!vis[i]) {
			dfs(i, ile, vis, g, bi);
		}
	}
	ll lic = 0; 
	ll mia = 1;
	for (int i = 0; i < n; i++) {
		lic *= (ile[i]+1);
		lic += mia;
		mia *= (ile[i]+1);
		lic %= mod;
		mia %= mod;
	}
	cout << lic * powmod(mia, mod-2) % mod << "\n";
}