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
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

#ifdef USE_CERR_LOG
#define LOG if (true) cerr
const bool LogEnabled = true;
#else
#define LOG if (false) cerr
const bool LogEnabled = false;
#endif

bool LogBigEnabled = true;

#ifdef USE_FILE_CIN
ifstream fin("min.in");
#define cin fin
#endif

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;


struct Mine {
    ll pos;
    ll range;
};

struct Range {
    int from;
    int to;
};

bool operator < (const Range& r1, const Range& r2) {
    if (r1.from == r2.from) return r1.to < r2.to;
    else return r1.from < r2.from;
}

Range merge(const Range& left, const Range& right) {
    if (left.to >= right.from) return { left.from, max(left.to, right.to) };
    else return right;
}

vector<Mine> mines;
vector<Range> ranges;

void readData() {
    int n;
    cin >> n;
    
    while (n--) {
        Mine mine;
        cin >> mine.pos >> mine.range;
        mines.push_back(mine);
    }
}

void printRanges(const vector<Range>& ranges) {
    #ifdef USE_CERR_LOG
        for (Range r : ranges) LOG << "(" << r.from << "," << r.to << ") ";
        LOG << endl;
    #endif
}

void printRanges(const set<Range>& ranges) {
    #ifdef USE_CERR_LOG
        for (Range r : ranges) LOG << "(" << r.from << "," << r.to << ") ";
        LOG << endl;
    #endif
}

void printCombos(const set<set<int>>& combos) {
    #ifdef USE_CERR_LOG
        for (const set<int>& combo : combos) {
            cout << "(";
            for (int m : combo) cout << m << ",";
            cout << ") ";
        }
    #endif
}

void computeRanges() {
    vector<Range> initRanges;
    
    initRanges.push_back({0, 0});
    
    for (uint i = 1; i < mines.size(); i++) {
        Mine& mine = mines[i];
        Range range = {(int) i, (int) i};
        
        for (int j = i-1; j>=0; j--) {
            if (mine.pos - mines[j].pos > mine.range) break;
            range.from = min(range.from, initRanges[j].from);
        }
        
        initRanges.push_back(range);
    }
        
    for (int i = mines.size()-2; i>=0; i--) {
        Mine& mine = mines[i];
        Range& range = initRanges[i];
        
        for (uint j = i+1; j < mines.size(); j++) {
            if (mines[j].pos - mine.pos > mine.range) break;
            range.to = max(range.to, initRanges[j].to);
            range.from = min(range.from, initRanges[j].from);
        }
    }
    
    for (uint i = 1; i < initRanges.size(); i++) {
        Range& ri = initRanges[i];
        
        for (uint j = 0; j < i; j++) {
            if (ri.from == initRanges[j].from && ri.to < initRanges[j].to) {
                ri.to = initRanges[j].to;
            }
        }
    }
    
    printRanges(initRanges);
    
    set<Range> uniqueRanges(initRanges.begin(), initRanges.end());
    ranges.assign(uniqueRanges.begin(), uniqueRanges.end());
    
    printRanges(ranges);
}

set<int> rangeToSet(const Range& range) {
    set<int> mineSet;
    
    for (int i = range.from; i <= range.to; i++) {
        mineSet.insert(i);
    }
    
    return mineSet;
}

int solve() {
    set<set<int>> combos;
    combos.insert(rangeToSet(ranges[0]));
    
    for (uint i = 1; i < ranges.size(); i++) {
        Range& range = ranges[i];
        set<set<int>> newCombos;
        set<int> setForRange = rangeToSet(range);
        newCombos.insert(setForRange);
        
        for (const set<int>& oldCombo : combos) {
            set<int> s;
            merge(oldCombo.begin(), oldCombo.end(), setForRange.begin(), setForRange.end(), inserter(s, s.begin()));
            newCombos.insert(s);
        }
        
        combos.insert(newCombos.begin(), newCombos.end());
    }

    printCombos(combos);
    return (combos.size() + 1) % 1'000'000'007;
}

int main() {
    readData();
    
    if (mines.size() == 1) {
        cout << 2;
        return 0;
    }
    
    computeRanges();
    cout << solve();
    
    return 0;
}