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
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::pair<ll, ll> PLL;
typedef std::vector<int> VI;

const int MOD = 1000000007;
inline int DD(int a, int b){
	return (a + b >= MOD ? a + b - MOD : a + b);
}
inline int OD(int a, int b){
	return (a - b < 0 ? a - b + MOD : a - b);
}

struct BIT{
	std::vector<int> t;
	inline int LSB(int a){ return a&(-a); }
	BIT(){}
	BIT(int sz){ t.resize(sz+1); }
	void add(int x, int val){
		x++;
		while(x < (int)t.size()) t[x] = DD(t[x], val), x += LSB(x);
	}
	int query(int x){
		x++;
		int r = 0;
		while(x > 0) r = DD(r, t[x]), x -= LSB(x);
		return r;
	}
	int query(int a, int b){
		return OD(query(b), (a == 0 ? 0 : query(a-1)));
	}
};

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

	int n;
	std::cin >> n;
	std::vector<PLL> B(n);
	std::vector<ll> vals;
	FOR(i, n){
		ll a, r;
		std::cin >> a >> r;
		B[i] = MP(a, r);
		vals.push_back(a);
	}
	std::sort(vals.begin(), vals.end());
	auto after = [&](ll a){
		return static_cast<int>(std::lower_bound(vals.begin(), vals.end(), a) - vals.begin());
	};
	auto before = [&](ll a){
		return static_cast<int>(std::upper_bound(vals.begin(), vals.end(), a) - vals.begin())-1;
	};
	std::vector<PII> A(n+1, MP(-1, -1));
	TRAV(i, B){
		A[after(i.X)+1] = MP(after(i.X-i.Y)+1, before(i.X+i.Y)+1);
	}

	std::vector<int> dp(n+1);
	std::vector<bool> can(n+1, true);
	std::multiset<int, std::greater<int>> border;
	std::set<int> mam;
	mam.insert(0);
	border.insert(0);
	std::vector<std::list<int>> remove(n+2);
	BIT bit(n+5);
	dp[0] = 1;
	bit.add(0, dp[0]);
	REP(i, 1, n+1){
		TRAV(j, remove[i]) border.erase(border.find(j));
		dp[i] = bit.query(*border.begin(), i-1);
		auto it = mam.lower_bound(A[i].X);
		while(it != mam.end() && *it < i){
			auto nxt = std::next(it);
			bit.add(*it, (MOD - bit.query(*it, *it))%MOD);
			mam.erase(it);
			it = nxt;
		}
		border.insert(i);
		mam.insert(i);
		remove[A[i].Y+1].push_back(i);
		bit.add(i, dp[i]);
	}
	std::cout << bit.query(0, n) << "\n";

	return 0;
}