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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 2137
#endif

const uint32_t MOD = 1000000007;
 
struct mint {
  uint32_t val;
 
  mint(ll v = 0) {
    v %= MOD;
    if (v < 0) {
      v += MOD;
    }
    val = v;
  }
 
  mint& operator+=(const mint& other) {
    val += other.val;
    if (val >= MOD) {
      val -= MOD;
    }
    return *this;
  }
 
  mint& operator-=(const mint& other) {
    val += MOD - other.val;
    if (val >= MOD) {
      val -= MOD;
    }
    return *this;
  }
 
  mint& operator*=(const mint& other) {
    val = (uint64_t)val * other.val % MOD;
    return *this;
  }
 
  mint& operator/=(const mint& other) {
    return *this *= other.inv();
  }
 
  friend mint operator+(mint a, const mint& b) { return a += b; }
  friend mint operator-(mint a, const mint& b) { return a -= b; }
  friend mint operator*(mint a, const mint& b) { return a *= b; }
  friend mint operator/(mint a, const mint& b) { return a /= b; }
 
  mint pow(ll exp) const {
    mint a = *this;
    mint res = 1;
    while (exp > 0) {
      if (exp & 1) {
        res *= a;
      }
      a *= a;
      exp /= 2;
    }
    return res;
  }
 
  mint inv() const {
    assert(val != 0);
    return pow(MOD - 2);
  }
 
  friend ostream& operator<<(ostream& os, const mint& m) {
    return os << m.val;
  }
};

struct segtree {
  struct node {
    int val = -1;
  };

  int n;
  vector<node> t;

  segtree(int _n) {
    n = _n;
    t.resize(max(0, 2 * n - 1));
  }

  void push(int u, int len) {
    if (t[u].val == -1) {
      return;
    }
    for (int v : {u + 1, u + len - len % 2}) {
      t[v].val = t[u].val;
    }
    t[u].val = -1;
  }

  template<typename F>
  void rec(int u, int lo, int hi, int l, int r, bool mod, F&& f) {
    if (l <= lo && hi <= r) {
      f(u, hi - lo);
      return;
    }
    push(u, hi - lo);
    int mid = (lo + hi) / 2;
    if (mid > l) {
      rec(u + 1, lo, mid, l, r, mod, f);
    }
    if (mid < r) {
      rec(u + (mid - lo) * 2, mid, hi, l, r, mod, f);
    }
  }

  int get(int i) {
    int res = -1;
    rec(0, 0, n, i, i + 1, false, [&] (int u, int) {
      res = t[u].val;
    });
    return res;
  }

  void modify(int l, int r, int x) {
    rec(0, 0, n, l, r, true, [&] (int u, int) {
      t[u].val = x;
    });
  }
};

const int N = 500500;
int n;
int adj[N][2];
bool vis[N];
int cnt[N];
uint64_t dp[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  //n = 100000;
  /*
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
  }
  */
  /*mt19937_64 rng(2137);
  vector<int> p(2 * n);
  iota(p.begin(), p.end(), 0);
  shuffle(p.begin(), p.end(), rng);
  for (int i = 0; i < n; i++) {
    if (p[2 * i] > p[2 * i + 1]) {
      swap(p[2 * i], p[2 * i + 1]);
    }
  }*/
  segtree t(2 * n);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    /*int l = p[2 * i];
    int r = p[2 * i + 1];*/
    adj[i][0] = t.get(l);
    adj[i][1] = t.get(r);
    t.modify(l, r + 1, i);
  }
  for (int s = 0; s < n; s += 64) {
    for (int i = 0; i < n; i++) {
      dp[i] = 0;
    }
    for (int i = n - 1; i >= 0; i--) {
      if (i >= s && i < s + 64) {
        dp[i] |= 1ull << (i - s);
      }
      cnt[i] += __builtin_popcountll(dp[i]);
      for (int j : adj[i]) {
        if (j != -1) {
          dp[j] |= dp[i];
        }
      }
    }
  }
  mint ans = 0;
  for (int i = 0; i < n; i++) {
    ans += mint(1) / cnt[i];
  }
  cout << ans << '\n';
}