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
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " " << x << endl;

// #define int long long // uważaj

const int N = 300002;
const int mod = (1000 * 1000 * 1000) + 7;
const int base = (1 << 19);
// const int base = (1 << 3);

long long w[N], range[N];
int tree_min[base * 2 + 5];
int tree_max[base * 2 + 5];
int tree_sum[base * 2 + 5];

inline int minim(const int &a, const int &b) {
    return (a < b ? a : b);
}

inline int maxim(const int &a, const int &b) {
    return (a < b ? b : a);
}

// min-max tree
void insert_min_max(int v, int w1, int w2) {
    v += base;
    tree_min[v] = w1;
    tree_max[v] = w2;

    v /= 2;
    while(v) {
        tree_min[v] = minim(tree_min[2 * v], tree_min[2 * v + 1]);
        tree_max[v] = maxim(tree_max[2 * v], tree_max[2 * v + 1]);
        v /= 2;
    }
}

pair<int, int> query_min_max(int l, int r) {
    l = l + base;
    r = r + base;

    pair<int, int> re = make_pair(tree_min[l], tree_max[l]);
    if(l != r) {
        re.first = minim(re.first, tree_min[r]);
        re.second = maxim(re.second, tree_max[r]);
    }

    while(l + 1 < r) {
        if(l % 2 == 0) {
            re.first = minim(re.first, tree_min[l + 1]);
            re.second = maxim(re.second, tree_max[l + 1]);
        }
        if(r % 2 == 1) {
            re.first = minim(re.first, tree_min[r - 1]);
            re.second = maxim(re.second, tree_max[r - 1]);
        }

        l /= 2;
        r /= 2;
    }

    return re;
}

// sum tree
void insert_sum(int v, int w) {
    v += base;
    tree_sum[v] = (tree_sum[v] + w) % mod;

    v /= 2;
    while(v) {
        tree_sum[v] = (tree_sum[2 * v] + tree_sum[2 * v + 1]) % mod;
        v /= 2;
    }
}

int query_sum(int l, int r) {
    if(r < 0) return 1;
    l = l + base;
    r = r + base;

    int re = (tree_sum[l] + 1) % mod;
    if(l != r) re = (re + tree_sum[r]) % mod;

    while(l + 1 < r) {
        if(l % 2 == 0) re = (re + tree_sum[l + 1]) % mod;
        if(r % 2 == 1) re = (re + tree_sum[r - 1]) % mod;
        l /= 2;
        r /= 2;
    }

    return re;
}

void solve() {
    int n;
    cin >> n;
    // n = 300000;

    for(int i = 0; i < n; i++) {
        cin >> w[i] >> range[i];
        // w[i] = random();
        // range[i] = random();
    }

    for(int i = 0; i < n; i++) {
        long long mi = w[i] - range[i];
        int poz1 = lower_bound(w, w + n, mi) - w;

        long long ma = w[i] + range[i];
        int poz2 = upper_bound(w, w + n, ma) - w - 1;
        insert_min_max(i, poz1, poz2);
    }

    bool flag = true;
    int ile = 0;
    while(flag) {
        flag = false;

        for(int i = 0; i < n; i++) {
            int l = tree_min[i + base];
            int r = tree_max[i + base];

            pair<int, int> x = query_min_max(l, r);
            if(x != make_pair(l, r)) flag = true;

            insert_min_max(i, x.first, x.second);
        }

    }

    vector<pair<int, int> > vek; // (r, - l)

    for(int i = 0; i < n; i++) {
        vek.push_back(make_pair(tree_max[i + base], - tree_min[i + base]));
    }

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

    int ans = 1;
    for(auto x : vek) {
        int war = query_sum(0, (-x.second) - 1);
        ans = (ans + war) % mod;
        insert_sum(-x.second, war);
    }

    cout << ans << "\n";
}

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int test = 1;

	while(test--){
		solve();
	}

	return 0;
}