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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#include "bits/stdc++.h" // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

// https://github.com/tonowak/acmlib/blob/master/code/data-structures/rmq/main.cpp
struct RMQ_Min {
	vector<vector<int>> st;
	vector<int> pre;
	RMQ_Min(vector<int> &a) {
		int n = size(a), lg = 0;
		while((1 << lg) < n) lg++;
		st.resize(lg + 1, vector<int>(a));
		st[0] = a;
		FOR(i, 1, lg) REP(j, n) {
			st[i][j] = st[i - 1][j];
			int q = j + (1 << (i - 1));
			if(q < n) st[i][j] = min(st[i][j], st[i - 1][q]);
		}
		pre.resize(n + 1);
		FOR(i, 2, n) pre[i] = pre[i / 2] + 1;
	}
 
	int get(int l, int r) {
		int q = pre[r - l + 1], x = r - (1 << q) + 1;
		return min(st[q][l], st[q][x]);
	}
};
struct RMQ_Max {
	vector<vector<int>> st;
	vector<int> pre;
	RMQ_Max(vector<int> &a) {
		int n = size(a), lg = 0;
		while((1 << lg) < n) lg++;
		st.resize(lg + 1, vector<int>(a));
		st[0] = a;
		FOR(i, 1, lg) REP(j, n) {
			st[i][j] = st[i - 1][j];
			int q = j + (1 << (i - 1));
			if(q < n) st[i][j] = max(st[i][j], st[i - 1][q]);
		}
		pre.resize(n + 1);
		FOR(i, 2, n) pre[i] = pre[i / 2] + 1;
	}
 
	int get(int l, int r) {
		int q = pre[r - l + 1], x = r - (1 << q) + 1;
		return max(st[q][l], st[q][x]);
	}
};

// https://sio2.mimuw.edu.pl/c/wiekuisty_ontak2013/s/386781/source/
struct Tree {
	int n;
	int sz = 1;
	vector<pair<int, int>> tree;

	pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
		return {
			min(a.first, b.first),
			max(a.second, b.second)
		};
	}

	Tree(int _n, vector<int> first, vector<int> second) : n(_n) {
		while(sz < n)
			sz *= 2;
		tree.resize(2 * sz, make_pair(n, -1));
		REP(i, n)
			tree[i + sz] = {first[i], second[i]};
		for(int v = sz - 1; v > 0; --v)
			tree[v] = merge(tree[2 * v], tree[2 * v + 1]);
	}

	void clear() {
		fill(tree.begin(), tree.end(), make_pair(n, -1));
	}

	void set(int i, pair<int, int> p) {
		tree[i += sz] = p;
		while(i /= 2)
			tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
	}

	pair<int, int> get(int l, int r) {
		if(l > r)
			return {n, -1};
		l += sz;
		r += sz;
		auto ret = merge(tree[l], tree[r]);
		while(l / 2 != r / 2) {
			if(~l & 1)
				ret = merge(ret, tree[l + 1]);
			if(r & 1)
				ret = merge(ret, tree[r - 1]);
			l /= 2;
			r /= 2;
		}
		return ret;
	}
};

vector<pair<int, int>> ranges(int n) {
	vector<pair<LL, LL>> in(n);
#ifdef NOINPUT
	REP(i, n)
		in[i] = {i, rd(0, n / 100)};
#else
	for(auto &p : in)
		cin >> p.first >> p.second;
#endif
	sort(in.begin(), in.end());

	auto get_furthest_right = [&] {
		vector<int> until(n);
		iota(until.begin(), until.end(), 0);
		for(int i = n - 1; i >= 0; --i) {
			if(i != n - 1 and in[i].first + in[i].second >= in[i + 1].first)
				until[i] = until[i + 1];
			while(until[i] + 1 < n and in[i].first + in[i].second >= in[until[i] + 1].first)
				until[i] = until[until[i] + 1];
		}
		return until;
	};

	array<vector<int>, 2> range{{get_furthest_right(), {}}};
	reverse(in.begin(), in.end());
	for(auto &p : in)
		p.first *= -1;
	range[1] = get_furthest_right();
	reverse(range[1].begin(), range[1].end());
	reverse(in.begin(), in.end());
	for(int &i : range[1])
		i = n - 1 - i;
	for(auto &p : in)
		p.first *= -1;

	RMQ_Min tree_min(range[1]);
	RMQ_Max tree_max(range[0]);
	// Tree tree(n, range[1], range[0]);
	vector<pair<int, int>> ret(n);

	REP(i, n) {
		int l = range[1][i],
			r = range[0][i];
		while(true) {
			//int new_l, new_r;
			//tie(new_l, new_r) = tree.get(l, r);
			int new_l = tree_min.get(l, r),
				new_r = tree_max.get(l, r);
			if(l != new_l or r != new_r) {
				l = new_l;
				r = new_r;
			}
			else
				break;
		}
		ret[i] = {l, r};
	}
	return ret;
}

constexpr int mod = int(1e9) + 7;

int add(int a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
	return a;
}

struct Fenwick {
	int n;
	vector<int> t;

	Fenwick(int _n) : n(_n), t(n + 1) {}

	inline int last_bit(int x) {
		return x & (-x);
	}

	void add_to(int i, int val) {
		for(++i; i > 0; i -= last_bit(i))
			t[i] = add(t[i], val);
	}

	void add_to(int l, int r, int val) {
		add_to(r, val);
		if(l != 0)
			add_to(l - 1, mod - val);
	}

	int get(int i) {
		int ret = 0;
		for(++i; i <= n; i += last_bit(i)) {
			ret = add(ret, t[i]);
		}
		return ret;
	}
};

struct PrePostOrder {
	vector<int> pre, post;
	int gtime = 0;
	vector<vector<int>> sons;
	vector<int> border, last_geq;
	vector<int> sztos;

	void dfs(int v) {
		sztos.emplace_back(v);
		pre[v] = gtime++;
		for(int u : sons[v])
			dfs(u);
		post[v] = gtime - 1;
		last_geq[v] = *upper_bound(sztos.begin(), sztos.end(), border[v]);
		sztos.pop_back();
	}

	Fenwick fenwick;

	PrePostOrder(vector<int> parents, vector<int> _border) 
			: border(_border), fenwick(size(parents)) {
		// debug(parents);
		int n = size(parents);
		sons.resize(n);
		REP(v, n)
			if(parents[v] != -1)
				sons[parents[v]].emplace_back(v);
		pre.resize(n, -1);
		post.resize(n, -1);
		last_geq.resize(n);
		REP(v, n)
			if(parents[v] == -1)
				dfs(v);
		// debug(pre, post);
		// debug(sons);
		// debug(border, last_geq);
	}

	void set_weight(int v, int w) {
		// debug() << "adding " << w << " in " << make_pair(pre[v], post[v]);
		fenwick.add_to(pre[v], post[v], w);
	}

	int get_sum(int v) {
		int ret = fenwick.get(pre[v]);
		// debug() << "fenwick " << pre[v] << " ans " << ret;
		return ret;
	}

	int get_geq(int i) {
		int ans_i = get_sum(i), ans_geq = get_sum(last_geq[i]);
		// debug(i, ans_i, ans_geq);
		return add(ans_i, mod - ans_geq);
	}
};

vector<int> rev_parents(vector<int> parents) {
	reverse(parents.begin(), parents.end());
	int n = size(parents);
	for(int &p : parents)
		p = n - 1 - p;
	return parents;
}

struct RevOrder {
	int n;
	PrePostOrder l;

	RevOrder(vector<int> parents, vector<int> border) 
			: n(size(parents)), 
			l(rev_parents(parents), rev_parents(border))
	{}

	void set_weight(int i, int val) {
		l.set_weight(n - 1 - i, val);
	}
	int get_geq(int i) {
		return l.get_geq(n - 1 - i);
	}
};

void solve() {
	int n;
#ifdef NOINPUT
	n = int(3e5);
#else
	cin >> n;
#endif
	vector<pair<int, int>> in = ranges(n);
	// debug(n, in);

	in.erase(unique(in.begin(), in.end()), in.end());
	int m = size(in);
	// debug(m, in);

	vector<pair<int, int>> sorted(m);
	REP(i, m)
		sorted[i] = {in[i].first, -i};
	sort(sorted.begin(), sorted.end());
	Tree lit(m, vector<int>(m, m), vector<int>(m, -1));
	vector<int> prev_smaller_l(m, -1);
	for(auto p : sorted) {
		int i = p.second;
		i *= -1;
		int j = lit.get(0, i - 1).second;
		prev_smaller_l[i] = j;
		lit.set(i, make_pair(i, i));
	}

	REP(i, m)
		sorted[i] = {in[i].first, i};
	sort(sorted.begin(), sorted.end());
	lit.clear();
	vector<int> next_smaller_l(m, m);
	for(auto p : sorted) {
		int i = p.second;
		int j = lit.get(i + 1, m - 1).first;
		next_smaller_l[i] = j;
		lit.set(i, make_pair(i, i));
	}
	// debug(prev_smaller_l);
	// debug(next_smaller_l);

	REP(i, m)
		sorted[i] = {in[i].second, -i};
	sort(sorted.rbegin(), sorted.rend());
	lit.clear();
	vector<int> prev_biggereq_r(m, -1);
	for(auto p : sorted) {
		int i = p.second;
		i *= -1;
		int j = lit.get(0, i - 1).second;
		prev_biggereq_r[i] = j;
		lit.set(i, make_pair(i, i));
	}

	REP(i, m)
		sorted[i] = {in[i].second, i};
	sort(sorted.rbegin(), sorted.rend());
	lit.clear();
	vector<int> next_biggereq_r(m, m);
	for(auto p : sorted) {
		int i = p.second;
		int j = lit.get(i + 1, m - 1).first;
		next_biggereq_r[i] = j;
		lit.set(i, make_pair(i, i));
	}
	// debug(prev_biggereq_r);
	// debug(next_biggereq_r);

	vector<vector<int>> ends_at(n);
	REP(i, m)
		ends_at[in[i].second].emplace_back(i);

	vector<int> dp(n);
	auto get_dp = [&](int i) {
		if(i < 0)
			return 1;
		return dp[i];
	};

	PrePostOrder ptr_left(prev_smaller_l, prev_biggereq_r);
	RevOrder ptr_right(next_smaller_l, next_biggereq_r);

	REP(R, n) {
		dp[R] = get_dp(R - 1);

		vector<int> good_ls;
		for(int i : ends_at[R])
			good_ls.emplace_back(in[i].first);
		sort(good_ls.begin(), good_ls.end());
		good_ls.erase(unique(good_ls.begin(), good_ls.end()), good_ls.end());
		// debug(R, good_ls);
		for(int L : good_ls)
			dp[R] = add(dp[R], get_dp(L - 2));

		for(int i : ends_at[R]) {
			if(prev_smaller_l[i] != -1) {
				ptr_left.set_weight(i, get_dp(in[prev_smaller_l[i]].first - 2));
				dp[R] = add(dp[R], ptr_left.get_geq(i));
			}
			if(next_smaller_l[i] != m) {
				ptr_right.set_weight(i, get_dp(in[next_smaller_l[i]].first - 2));
				dp[R] = add(dp[R], ptr_right.get_geq(i));
			}
		}
	}
	// debug(dp);

	cout << dp.back() << '\n';
}

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

	solve();
}