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
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define HASK(S, x) (S.find(x) != S.end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
	#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std; 

template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b);	}
template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = max(a, (T1)b);	}

template <typename Tp> void dedup(vector <Tp>& T)
{
	sort(ALL(T));
	T.resize(unique(ALL(T)) - T.begin());
}

const int maxN = 303030, maxTS = 1 << 20, mod = 1000000007;
const long long INF = 3000000000000000000ll;

template <typename T1, typename T2> inline void addMod(T1& a, T2 b) { a = (a + b) % mod; }
template <typename T1, typename T2> inline void multMod(T1& a, T2 b) { a = a * b % mod; }

namespace STG
{
	template <typename Tp> struct Tree_t
	{
		int offset, qbegin, qend;
		Tp T[maxTS], res, x, root;
		
		void qpriv(int v, int left, int right)
		{	
			if (left >= qend or right <= qbegin)
				return;
			if (left >= qbegin and right <= qend)
			{
				if (T[v] >= x)
					root = v;
				return;
			}
			qpriv(v * 2, left, (left + right) / 2);
			qpriv(v*2+1, (left + right) / 2, right);
		}	
		
		void init(int n, long long *t = NULL)
		{
			for (offset = 1; offset < n; offset *= 2) ;
			
			if (t == NULL)
			{	fill(T, T+offset*2, -INF);	return;	}
			
			FOR(i, 0, offset)
				T[offset + i] = i < n ? t[i] : -INF;
			FORD(i, offset-1, 0)
				T[i] = max(T[i * 2], T[i*2+1]);
		}
		
		void updt(int v, long long z)
		{
			for (v += offset; v != 0; v /= 2)
				remax(T[v], z);
		}
		
		Tp query(int a, int b, long long c)
		{
			qbegin = a + offset;
			qend = b + offset;
			root = 0;
			x = c;
			qpriv(1, offset, offset * 2);
			if (root == 0)
				return 0;
			while (root < offset)
			{
				int right = root * 2 + 1;
				root = T[right] >= x ? right : right-1;
			}
			return root - offset;
		}
	};
	typedef Tree_t <long long> Tree;
	Tree treB, treE;
	
	long long Beg[maxN], End[maxN];
	int n;
	
	int invInd(int i)
	{	return n+1-i;	}
	
	void run(int nn, long long* T, long long* R, vector <int>* G)
	{
		n = nn;
		FOR(i, 1, n+1)
			Beg[i] = -(T[i] - R[i]), End[i] = T[i] + R[i];
		Beg[0] = End[0] = -INF;
		reverse(Beg+1, Beg+n+1);
		treB.init(n+1, Beg);
		treE.init(n+1, End);
		
		FOR(i, 1, n+1)
		{
			int j = treE.query(0, i, T[i]);
			if (j != 0)
				G[j].pb(i);
			j = treB.query(0, invInd(i), -T[i]);
			if (j != 0)
				G[invInd(j)].pb(i);
		}
	}		
}

namespace SCC
{
	int inCtr, sccCtr, low[maxN], in[maxN], scc[maxN], S[maxN], tp;
    vector <int>* G;

    int dfs(int v)
    {
        low[v] = in[v] = ++inCtr;
        S[tp++] = v;
        for (int u : G[v])
        	if (in[u] >= 0)
        		remin(low[v], in[u] == 0 ? dfs(u) : in[u]);
        		
        if (in[v] != low[v])
        	return low[v];
        sccCtr++;
        for (int u=-1; u!=v;)
        {
            u = S[--tp];
            scc[u] = sccCtr;
            in[u] *= -1;
        }
        return low[v];
    }
    
    void run(int n, vector <int>* gin, vector <int>* gout)
    {
    	G = gin;
    	FOR(i, 1, n+1)
    		if (in[i] == 0)
    			dfs(i);

    	FOR(i, 1, n+1) for (int j : G[i])
    	{
    		int a = scc[i], b = scc[j];
    		if (a != b)
    			gout[a].pb(b);
    	}
    	
    	FOR(i, 1, sccCtr+1)
    		dedup(gout[i]);
    }
}

namespace INT
{
	long long fs[maxN], ls[maxN];
	
	void run(int n, vector <int>* G, long long* T, long long* R, int* first, int* last)
	{
		int m = SCC::sccCtr;
		fill(fs, fs+m+1, INF), fill(ls, ls+m+1, -INF);
		FOR(i, 1, n+1)
		{
			int s = SCC::scc[i];
			remin(fs[s], T[i] - R[i]);
			remax(ls[s], T[i] + R[i]);
		}
		
		FOR(v, 1, m+1)
			for (int u : G[v])
				remin(fs[v], fs[u]), remax(ls[v], ls[u]);
				
		T[0] = -INF;
				
		FOR(v, 1, m+1)
		{
			fs[v] = lower_bound(T, T+n+1, fs[v]) - T;
			ls[v] = upper_bound(T, T+n+1, ls[v]) - T - 1;			
		}
				
		FOR(i, 1, n+1)
		{
			int s = SCC::scc[i];
			first[i] = fs[s];
			last[i] = ls[s];
		}
	}
}

template <typename Tp> struct TreeSum_t
{
	int offset, qbegin, qend;
	Tp T[maxTS], res;
	
	void qpriv(int v, int left, int right)
	{	
		if (left >= qend or right <= qbegin)
			return;
		if (left >= qbegin and right <= qend)
		{
			res += T[v];
			return;
		}
		qpriv(v * 2, left, (left + right) / 2);
		qpriv(v*2+1, (left + right) / 2, right);
	}	
	
	void init(int n)
	{
		for (offset = 1; offset < n; offset *= 2) ;
	}
	
	void updt(int v, long long dx)
	{
		for (v += offset; v != 0; v /= 2)
			T[v] += dx;
	}
	
	Tp query(int a, int b)
	{
		qbegin = a + offset;
		qend = b + offset;
		res = 0;
		qpriv(1, offset, offset * 2);
		return res % mod;
	}
};
typedef TreeSum_t <long long> TreeSum;
TreeSum treeSum;

long long T[maxN], R[maxN];
vector <int> H[maxN], G[maxN];
long long dp[maxN];
int first[maxN], last[maxN];
STG::Tree tree;
stack <int> S;

void solve()
{
	int n;
	scanf ("%d", &n);
	FOR(i, 1, n+1)
		scanf ("%lld%lld", T+i, R+i);
	STG::run(n, T, R, H);	
	SCC::run(n, H, G);	
	INT::run(n, G, T, R, first, last);
	treeSum.init(n+1);
	tree.init(n+1);
	dp[0] = 1ll;
	
	#define TVAL(i) dp[max(0, i-2)]
	
	FOR(i, 1, n+1)
	{
		while (!S.empty())
		{
			int j = S.top();
			if (j > first[i])
				S.pop(), treeSum.updt(j, -TVAL(j));
			else break;
		}
		if (first[i] == i)
			S.push(i), treeSum.updt(i, TVAL(i));

		tree.updt(i, last[i]);
		int j = tree.query(1, i+1, i+1);
		dp[i] = treeSum.query(j+1, i+1);
		addMod(dp[i], dp[i-1]);
	}
	
	printf("%lld\n", dp[n]);	
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}