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
#include <cstdio>
#include <algorithm>
using namespace std;

int N;
long long X[300'002];
long long R[300'002];


long long miner(int a, int b) {
  //printf("ZZ: %d..%d\n", a, b);
  //if (a+1 >= b) return 0;
  while (a < b) {
    if (X[a+1]-R[a+1] <= X[a]) a++;
    else if (X[b-1] + R[b-1] >= X[b]) b--;
    else break;
  }
  if (a >= b) return 0;
  long long res = 1; // if all clear
  for (int x = a+1; x <= b-1; x++) {
    if (X[x] - R[x] <= X[x-1]) continue; // cannot be first explosive
    // ok, x explodes. who else?
    int y = x + 1; // first not exploded
    while (y <= b) {
      long long range = X[y-1] + R[y-1];
      while (y <= b && X[y] <= range) {
        range = max(range, X[y] + R[y]);
        y++;
      }
      if (y > b) break; // that went too far
      if (y == b) { res++; res %= 1'000'000'007; break; }
      //if (y+1 == b) { res++; res %= 1'000'000'007; y++; continue; }
      res += miner(y, b);
      res %= 1'000'000'007;
      y++;
    }
  }
  return res;
}


int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%lld%lld", &X[i], &R[i]);
  X[0] = -2'000'000'000'000'000'001;
  X[N+1] = +2'000'000'000'000'000'001;
  R[0] = R[N+1] = 0;
  long long res = miner(0, N+1);
  printf("%lld\n", res);
  return 0;
}