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
#include <bits/stdc++.h>

#define FOR(i, b, e) for (int i = (b); i <= (e); i++)
#define FORD(i, b, e) for (int i = (e); i >= (b); i--)
#define MP make_pair
#define FS first
#define ND second
#define PB push_back
#define ALL(x) x.begin(), x.end()

using namespace std;

using LL = long long;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
template<class T>
using V = vector<T>;

template<class T>
int sz(const T& a) { return (int)a.size(); }
template<class T>
void amin(T& a, T b) { a = min(a, b); }
template<class T>
void amax(T& a, T b) { a = max(a, b); }

const int inf = 1e9;
const LL infl = 1e18;

const int N = 300000;
const int mod = int(1e9) + 7;

int n, ans = 1;
LL a[N + 1], r[N + 1];
VI g[N + 1], gr[N + 1];
bool used[N + 1];
VI order;

int c[N + 1], f;
VI comps[N + 1];

void dfs1(int v) {
  used[v] = true;
  for (int x : g[v]) if (!used[x]) dfs1(x);
  order.PB(v);
}

void dfs2(int v) {
  used[v] = true;
  c[v] = f;
  comps[f].PB(v);
  for (int x : gr[v]) if (!used[x]) dfs2(x);
}

PLL seg[N + 1], range[N + 1];
int dp[N + 1];

int main() {
  scanf("%d", &n);
  FOR(i, 1, n) scanf("%lld %lld", &a[i], &r[i]);

  FOR(i, 1, n) FOR(j, 1, n) {
    if (i != j && a[i] - r[i] <= a[j] && a[j] <= a[i] + r[i]) {
      //printf("%d -> %d\n", i, j);
      g[i].push_back(j);
      gr[j].push_back(i);
    }
  }

  FOR(i, 1, n) if (!used[i]) dfs1(i);
  fill(used, used + n + 1, false);
  FOR(i, 1, n) {
    int v = order[n-i];
    if (!used[v]) {
      ++f;
      dfs2(v);
    }
  }

  FORD(i, 1, f) {
    seg[i].FS = infl;
    seg[i].ND = -infl;

    range[i].FS = infl;
    range[i].ND = -infl;

    for (int x : comps[i]) {
      amin(seg[i].FS, a[x]);
      amax(seg[i].ND, a[x]);

      amin(range[i].FS, a[x] - r[x]);
      amax(range[i].ND, a[x] + r[x]);

      for (int y : g[x]) {
        amin(range[i].FS, range[c[y]].FS);
        amax(range[i].ND, range[c[y]].ND);
      }
    }
  }

  order.clear();
  order.resize(f);
  iota(ALL(order), 1);

  sort(ALL(order), [](int i, int j) {
    return seg[i].ND < seg[j].ND;
  });

  /*
  for (int i : order) {
    printf("%lld %lld %lld %lld\n", range[i].FS, seg[i].FS, seg[i].ND, range[i].ND);
  }
  */

  FOR(i, 0, f - 1) {
    int x = order[i];
    dp[x] = 1;
    FOR(j, 0, i - 1) {
      int y = order[j];
      if (seg[y].ND < range[x].FS && range[y].ND < seg[x].FS) {
        dp[x] = (1LL * dp[x] + dp[y]) % mod;
      }
    }
    ans = (1LL * ans + dp[x]) % mod;
  }

  printf("%d\n", ans);
}