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
//#pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define un(x) x.erase(unique(ALL(x)),x.end())
#define REP(i,x,v)for(int i=x;i<=v;i++)
#define REPD(i,x,v)for(int i=x;i>=v;i--)
#define FOR(i,v)for(int i=0;i<v;i++)
#define TRAV(i,v)for(auto &i:(v))
#define REMIN(x,v) x=min(x,v);
#define REMAX(x,v) x=max(x,v);

mt19937_64 rng(134569);
int rd(int l, int r) {return uniform_int_distribution<int>(l, r)(rng);}

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vpi=vector<pii>;
const int MOD=1e9+7;//998244353;
#define MAXNODE (300003)
#define MM (1<<19)

namespace fen {
int bit[MM+2];

void czysc()
{
    FOR(i,MM+1) bit[i]=0;
}

void dodaj(int ind, int war)
{
    while(ind<MM)
    {
        bit[ind]+=war;
        if (bit[ind]>=MOD) bit[ind]-=MOD;
        ind+=(ind & -ind);
    }
}

int suma(int ind)//[1..ind]
{
    int sm=0;
    while(ind>0)
    {
        sm+=bit[ind];
        if (sm>=MOD) sm-=MOD;
        ind-=(ind & -ind);
    }
    return sm;
}
}

namespace sgt {

pii d[2*MM];

void czysc()
{
    FOR(i, 2*MM) {
      d[i]={MM, -MM};
    }
}

pii combine(const pii & A, const pii & B) {
  return {min(A.st, B.st), max(A.nd, B.nd)};
}

void ustaw(int pos,pii war)
{
    pos+=MM;
    d[pos]=war;
    pos/=2;
    while(pos>0)
    {
        d[pos]=combine(d[pos*2],d[pos*2+1]);
        pos/=2;
    }
}


pii wezmax(int a,int b)
{
    pii mx={MM, -MM};
    a+=MM;
    b+=MM;
    while(a<b)
    {
        if (a&1) mx=combine(mx,d[a++]);
        if (!(b&1)) mx=combine(mx,d[b--]);
        a>>=1;
        b>>=1;
    }
    if (a==b) mx=combine(mx,d[a]);
    return mx;
}
}


namespace sss {
  vi kr[MAXNODE],krt[MAXNODE];//grafy G i G^T
  vector<vi> skl;//wynik
  int nrskl[MAXNODE];//wynik
  bool odw[MAXNODE];
  vi stos;
  int akt;

  vi krc[MAXNODE];
  int N, Nc;//wielkosc G i wielkosc G_cond (graf sss)

  inline void dod_kr(int a,int b)
  {
      kr[a].pb(b);
      krt[b].pb(a);
  }
  void czysc(int N0)
  {
      N=N0;
      FOR(i,N) kr[i].clear();
      FOR(i,N) krt[i].clear();
      skl.clear();
  }

  void dfs(int u)
  {
      odw[u]=1;
      for(auto i: kr[u]) if (!odw[i]) dfs(i);
      stos.pb(u);
  }

  void dfst(int u)
  {
      odw[u]=1;
      nrskl[u]=akt;
      skl[akt].pb(u);
      for(auto i: krt[u]) if (!odw[i]) dfst(i);
  }

  void kosaraju()
  {
      stos.clear();
      akt=0;
      FOR(i,N) odw[i]=0;
      FOR(i,N) {
        if (!odw[i]) dfs(i);
      }
      FOR(i,N) odw[i]=0;
      REPD(i,N-1,0) if (!odw[stos[i]])
      {
          skl.pb(vi());
          dfst(stos[i]);
          akt++;
      }
      Nc=SZ(skl);
  }

  void zrob_graf(bool usun_duplikaty=1)
  {
      FOR(i,Nc)
      {
          krc[i].clear();
          for(auto j:skl[i]) for(auto u:kr[j]) if (nrskl[u]!=i) krc[i].pb(nrskl[u]);
          if (usun_duplikaty) {sort(ALL(krc[i]));krc[i].erase(unique(ALL(krc[i])),krc[i].end());}
      }
  }
}



pii seg[1<<19];




struct event {
  int type;
  int ind;
  int query;
};

bool por_event(const event& X, const event& Y) {
  if (X.ind!=Y.ind) return X.ind<Y.ind;
  return X.type<Y.type;
}

int in_sss[1<<19];

int sol(vector<ll> a, vector<ll> r) {
  int n=SZ(a);
  assert(MM>n);
  vector<pair<ll,int>> evps;
  FOR(i,n) seg[i]={i,i};
  FOR(i,n) {
    evps.pb({a[i],i});
    evps.pb({a[i]-r[i], -1-i});
  }
  sort(ALL(evps));
  int cur=-1;
  REPD(i, SZ(evps)-1, 0) {
    const auto & pa=evps[i];
    if (pa.nd>=0) {
      cur = pa.nd;
    } else {
      seg[-pa.nd-1].st = cur;
    }
  }

  evps.clear();
  FOR(i,n) {
    evps.pb({-a[i],i});
    evps.pb({-a[i]-r[i], -1-i});
  }
  sort(ALL(evps));
  cur=-1;
  REPD(i, SZ(evps)-1, 0) {
    const auto & pa=evps[i];
    if (pa.nd>=0) {
      cur = pa.nd;
    } else {
      seg[-pa.nd-1].nd = cur;
    }
  }

  sss::czysc(n);
  priority_queue<int> pq;
  REPD(i,n-1,0) {
    int j0=-1;
    while(SZ(pq)) {
      int j = -pq.top();
      if (seg[j].st>i) {
        pq.pop();
      } else {
        j0=j;
        break;
      }
    }
    if (j0!=-1) sss::dod_kr(j0,i);
    pq.push(-i);
  }
  pq = priority_queue<int>();
  FOR(i,n) {
    int j0=-1;
    while(SZ(pq)) {
      int j = pq.top();
      if (seg[j].nd<i) {
        pq.pop();
      } else {
        j0=j;
        break;
      }
    }
    if (j0!=-1) sss::dod_kr(j0,i);
    pq.push(i);
  }

  sss::kosaraju();
  sss::zrob_graf(1);
  sgt::czysc();
  FOR(i,n) sgt::d[MM+i]=seg[i];
  REPD(i, MM-1, 1) {
    sgt::d[i] = sgt::combine(sgt::d[2*i], sgt::d[2*i+1]);
  }

  REPD(i, sss::Nc-1, 0) {
  //FOR(i, sss::Nc) {
    const vi & nodes = sss::skl[i];
    int mn_node=nodes[0];
    int le=(1<<20),re=-(1<<20);
    FOR(j, SZ(nodes)) {
      int v=nodes[j];
      in_sss[v]=1;
      REMIN(mn_node, v);
      REMIN(le, seg[v].st);
      REMAX(re, seg[v].nd);
    }
    in_sss[mn_node]=0;
    pii z = sgt::wezmax(le,re);
    //int Le=le, Re=re;
    int Le = z.st, Re=z.nd;
    FOR(j, SZ(nodes)) {
      int v=nodes[j];
      seg[v]={Le, Re};
      sgt::ustaw(v, seg[v]);
    }
  }
  //return vpi(seg, seg+n);

  vi dp(n, 0);
  int sum=1;
  vector<event> evs;
  FOR(i,n) {
    event e;
    e.ind=i;
    e.type=1;
    evs.pb(e);
    e.ind=seg[i].st;
    e.type=0;
    e.query=i;
    evs.pb(e);
  }
  sort(ALL(evs), por_event);

  fen::czysc();
  for(auto e: evs) {
    if (e.type==1) {
      int i=e.ind;
      if (in_sss[i]) continue;
      dp[i]=(dp[i]+1)%MOD;
      sum=(sum+dp[i])%MOD;
      fen::dodaj(seg[i].nd+1, dp[i]);
    } else {
      int i=e.query;
      dp[i]=(fen::suma(i));
    }
  }
  return sum;
}


int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);

  int n;cin>>n;
  vector<ll>a(n), r(n);
  FOR(i, n) cin>>a[i]>>r[i];

  cout<<sol(a,r)<<"\n";
  return 0;
}