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

using namespace std;

int M = 1000000007;

template <typename IntType>
IntType add(IntType a, IntType b, IntType c)
    {
    //assert(c > 0 && 0 <= a && a < c && 0 <= b && b < c);
    IntType room = (c - 1) - a;
    if (b <= room)
        a += b;
    else
        a = b - room - 1;
    return a;
    }

template <typename IntType>
IntType mod(IntType a, IntType c)
    {
    //assert(c > 0);
    IntType q = a / c; // q may be negative
    a -= q * c; // now -c < a && a < c
    if (a < 0)
        a += c;
    return a;
    }

template <typename IntType>
IntType multiplyModulo(IntType a, IntType b, IntType c)
    {
    IntType result = 0;
    a = mod(a, c);
    b = mod(b, c);
    if (b > a)
        std::swap(a, b);
    while (b)
        {
        if (b & 0x1)
            result = add(result, a, c);
        a = add(a, a, c);
        b >>= 1;
        }
    return result;
    }


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

    int n;
    cin >> n;
    int pl = 0, pr = 0, ll = 0, lr = 0;
    int a,r;
    cin >> a >> r;
    ll = a;
    lr = r;
    int tot = 1;
    for (int i=1;i<n;i++) {
        int a,r;
        cin >> a >> r;

        if (ll+lr>=a && a-r<=ll) {
          //cout << "ll=" << ll << " lr=" << lr << " a=" << a << " r=" << r << "\n";
           //cout << "skip same " << a << "\n";
        } else if (ll+lr >=a) {
            if (pl == 0) pl = 2; else pl = (2*pl) % M;
            //cout << "pl=" << pl << "\n";
        } else if (a-r<=ll) {
            if (pr == 0) pr = 2; else pr = (2*pr) % M;
            //cout << "pr=" << pr << "\n";
        } else {
            int v = (pr + pl + 1) % M;
            tot = multiplyModulo(tot, v, M);
            pl = 0;
            pr = 0;
            
        }
        ll = a;
        lr = r;


    }
   int v = (pr + pl + 1) % M;
   tot = multiplyModulo(tot, v, M);
    // for (auto &x : kolizje) {
    //          cout << x.first << " ";
    //          for (auto &y : x.second) {
    //             cout << y << " ";
    //          }
    //          cout << '\n';
    // }

    int res = 7;

    cout << tot << '\n';
}