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

vector < long long > numbers;
vector < long long > rad;
bool endy[300007];
long long kinda_result[300007];
int mod=1000000007;
//int how_many_new[300007];

int bin(int beg, int en, long long x){
    int mid=(beg+en)/2;
    if(beg==en){
        return mid;
    }
    if(numbers[mid]>=x)return bin(beg,mid,x);
    else return bin(mid+1,en,x);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    long long farrest=0,result=1;
    cin >> n;
    numbers.push_back(-1);
    rad.push_back(-1);
    for(int i=1;i<=n;i++){
        long long a,r;
        cin >> a >> r;
        numbers.push_back(a);
        rad.push_back(r);
        if(farrest<a)endy[i-1]=true;
        //if(endy[i-1]==true)cout << i-1 << endl;
        farrest=max(farrest,a+r);
    }
    farrest++;
    endy[n]=true;
    for(int i=n;i>0;i--){
        if(farrest<=numbers[i])endy[i]=false;
        farrest=min(farrest,numbers[i]-rad[i]);
    }
    /*for(int i=1;i<=n;i++){
        if(endy[i]==true)cout << i << endl;
    }*/
    int bin_beg=1;
    kinda_result[1]=1;
    //cout << "kinda_result dla: 1 = " << kinda_result[1] << endl;
    farrest=numbers[1]+rad[1];
    if(endy[1]==true){
        //cout << "koncowka: " << 1 << " wynik dla tego= " << kinda_result[1] << endl;
        result*=(kinda_result[1]+1);
        farrest=numbers[1];
        kinda_result[1]=0;
    }

    //zrob co sie dzieje jak endy od jedynki jest true!!!!!!!!!!
    int magic_number=0,how_many_new_sum=0,weird_number=0;
    //how_many_new[1]=0;
    for(int i=2;i<=n;i++){
        //how_many_new[i]=how_many_new_sum;
        /*if(numbers[i]-rad[i]>numbers[i-1] && numbers[i]+rad[i]<numbers[i+1] && endy[i-1]==false && i!=n){
            //cout << "robie weird_number jak jestem na: " << i << endl;
            weird_number++;
        }*/
        int position=bin(bin_beg,i,numbers[i]-rad[i]);
        //if(position==i)cout << "position==i" << endl;
        //cout << "robie " << i << " i position to: " << position << endl;
        if(position==i){
            kinda_result[i]=kinda_result[position-1]+1+magic_number;//+magic_number*2
            //how_many_new_sum++;
            if(farrest<numbers[i] && endy[i-1]==false){
                //cout << "robie magic_number jak jestem na: " << i << endl;
                if(i!=n)magic_number++;
            }
        }
        else if(farrest>=numbers[i]){
            kinda_result[i]=kinda_result[position]+magic_number;//tu zjebalam
            /*if(numbers[i-1]+rad[i-1]<numbers[i] && endy[i-1]==false){
                //cout << "robie weird_number jak jestem na: " << i << endl;
                weird_number++;
            }*/
        }

        else{
            //cout << "robie magic_number jak jestem na: " << i << endl;
            //cout << "i jego position to jest: " << position << endl;
            if(i!=n)magic_number++;
            kinda_result[i]=kinda_result[position]+1+magic_number;
        }

        //cout << "kinda_result dla: " << i << " = " << kinda_result[i] << endl;
        farrest=max(farrest,numbers[i]+rad[i]);
        if(endy[i]==true){
            //cout << "koncowka: " << i << " wynik dla tego= " << kinda_result[i] << endl;
            result*=(kinda_result[i]+1);
            kinda_result[i]=0;
            bin_beg=i;
            farrest=numbers[i];
            magic_number=0;
            weird_number=0;
        }
    }
    cout << result << "\n";

    return 0;
}

/*17
4 18
6 18
7 13
10 6
19 13
21 13
27 20
31 4
43 18
46 13
56 13
64 6
67 3
73 20
74 11
90 14
98 16
*/