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
#include <set>
#include <unordered_map>
#include <queue>
#include <cstdio>

#define ll long long

const ll B = 1000000007LL;

using namespace std;

ll a[303030];
ll r[303030];
ll lo[303030];
ll hi[303030];

int main(int argc, char** argv) {
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++) {
    scanf("%lld%lld", &(a[i]), &(r[i]));
    lo[i] = a[i]-r[i];
    hi[i] = a[i]+r[i];
  }

  set<ll> d;
  for(int i=0;i<n;i++) {
    for(int j=-1;j<=1;j++) {
      d.insert(a[i]+r[i]*j);
    }
  }
  unordered_map<ll, int> toId;
  int c = 0;
  for(auto it=d.begin();it != d.end();it++) {
    toId[*it] = c;
    c++;
  }

  unordered_map<int, int> b;
  for(int i=0;i<n;i++) {
    b[toId[a[i]]] = i;
  }

  set<ll> pos;
  queue<int> q;

  ll u = 1LL<<n;
  for(int i=0;i<u;i++) {
    ll res = 0;
    for(int k=0;k<n;k++) {
      if(((1LL<<k)&i)>0) {
        q.push(k);
        while(!q.empty()) {
          int p = q.front();
          q.pop();
          int from = toId[lo[p]];
          int to = toId[hi[p]];
          for(int j=from;j<=to;j++) {
            auto t = b.find(j);
            if(t != b.end()) {
              ll mask = 1L<<(t->second);
              if((res&mask)==0) {
                res |= mask;
                q.push(t->second);
              }
            }
          }
        }
      }
    }
    pos.insert(res);
  }

  printf("%d\n", pos.size() % B);
  return 0;
}