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
#include<bits/stdc++.h>
using namespace std;
using lld = long long;

int MAXM;
const int INF = 1e9;
const int mod = 1e9+7;

struct Mine{
	int nr;
	lld b,mid,e;

	void flip(void){
		swap(b,e);
		b = MAXM-b, e = MAXM-e;
		mid = MAXM-mid;
	}
};

bool cmpByB(const Mine& a, const Mine& b){
	return (a.b < b.b || (a.b == b.b && a.e < b.e));
}

int renum(vector<Mine>& t){
	vector<lld> p;
	p.reserve(3*t.size());

	for(auto& i : t){
		p.push_back(i.b);
		p.push_back(i.mid);
		p.push_back(i.e);
	}

	sort(p.begin(), p.end());
	p.resize(unique(p.begin(), p.end()) - p.begin());

	map<lld,int> M;
	for(int i=0;i<p.size();i++)
		M[p[i]] = i;

	for(auto& i : t){
		i.b = M[i.b];
		i.mid = M[i.mid];
		i.e = M[i.e];
	}

	return p.size()-1;
}

struct Seg{
	int b,e;

	Seg(int b=INF, int e=INF): b(b), e(e) {}
};

bool operator == (const Seg& a, const Seg& b){
	return a.b == b.b && a.e == b.e;
}

bool cmpByE(const Seg& a, const Seg& b){
	return (a.e < b.e || (a.e == b.e && a.b > b.b)); 
}

struct ST{
	vector<int> tree;
	int base;

	ST(int n=(1<<20)): base(1) {
		while(base < n)
			base <<= 1;

		tree.assign(2*base,INF);
	}

	void insert(int v, int x){
		v += base;
		tree[v] = min(tree[v], x);
		while(v > 1){
			v /= 2;
			tree[v] = min(tree[2*v], tree[2*v+1]);
		}
	}

	int query(int b, int e){
		b += base;
		e += base;

		int val = min(tree[b], tree[e]);
		while(b/2 != e/2){
			if(!(b&1))
				val = min(val, tree[b+1]);
			if(e&1)
				val = min(val, tree[e-1]);
			b /= 2, e /= 2;
		}

		return val;
	}
};

void buildLeftEndpoint(vector<Seg>& res, vector<Mine>& t){
	sort(t.begin(), t.end(), cmpByB);
	ST tree(MAXM+1);

	bool change;
	do{
		change = false;

		for(auto& i : t){
			int val = min((int) i.b, tree.query(i.b, i.e));

			if(val < res[i.nr].b){
				change = true;
				res[i.nr].b = val;
				tree.insert(i.mid,val);
			}
		}

		reverse(t.begin(), t.end());
	}while(change);
}

vector<Seg> buildSeg(vector<Mine> t){
	vector<Seg> res(t.size());

	buildLeftEndpoint(res,t);

	for(auto& i : t)
		i.flip();
	for(auto& i : res)
		swap(i.b,i.e);

	buildLeftEndpoint(res,t);

	for(auto& i : res){
		swap(i.b,i.e);
		i.e = MAXM-i.e;
	}	

	return res;
}

struct SUM{
	vector<int> tree;
	int base;

	SUM(int n=(1<<20)): base(1) {
		while(base < n)
			base <<= 1;

		tree.assign(2*base,0);
	}

	void insert(int v, int x){
		v += base;
		tree[v] = (tree[v]+x) % mod;
		while(v > 1){
			v /= 2;
			tree[v] = (tree[2*v] + tree[2*v+1]) % mod;
		}
	}

	int query(int b, int e){
		b += base;
		e += base;

		int val = (tree[b] + (b != e ? tree[e] : 0)) % mod;
		while(b/2 != e/2){
			if(!(b&1))
				val = (val + tree[b+1]) % mod;
			if(e&1)
				val = (val + tree[e-1]) % mod;
			b /= 2, e /= 2;
		}

		return val;
	}
};

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

	int n;
	cin >> n;

	vector<Mine> t(n);
	for(auto& i : t){
		lld r;
		cin >> i.mid >> r;
		i.b = i.mid-r;
		i.e = i.mid+r;
	}

	for(int i=0;i<n;i++)
		t[i].nr = i;

	MAXM = renum(t);

	vector<Seg> p = buildSeg(t);
	sort(p.begin(), p.end(), cmpByE);
	p.resize(unique(p.begin(), p.end()) - p.begin());

	SUM tree(MAXM+2);
	tree.insert(0,1);

	for(auto& i : p){
		lld val = tree.query(0,i.b);
		tree.insert(i.b+1,val);
	}

	cout << tree.query(0,MAXM+1) << "\n";

	return 0;
}