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

set<pair<int, int>> calculate_full_edges(const vector<int> &pos,
                                         const vector<int> &r) {
  set<pair<int, int>> res;
  int n = pos.size();
  vector<int> right(n), left(n);
  for (int i = 0; i < n; i++) {
    left[i] = right[i] = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (pos[i] + r[i] >= pos[j]) {
        res.insert({i, j});
        right[i] = right[j];
        j = right[j];
      } else {
        break;
      }
    }
  }
  for (int i = 0; i <= n - 1; i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (pos[i] - r[i] <= pos[j]) {
        res.insert({i, j});
        left[i] = left[j];
        j = left[j];
      } else {
        break;
      }
    }
  }
  return res;
}

int calculate_res(const vector<vector<int>> &graph, int n) {
  int combinations = 1LL << n;
  int res = 0;
  for (int i = 0; i < combinations; i++) {
    bool works = true;
    for (int n1 = 0; n1 < n; n1++) {
      for (int j = 0; j < graph[n1].size(); j++) {
        int n2 = graph[n1][j];
        if ((i & (1LL << n1)) && !(i & (1LL << n2))) {
          works = false;
          break;
        }
      }
      if (!works) {
        break;
      }
    }
    if (works) {
      res++;
    }
  }
  return res;
}

int calculate_res2(const set<pair<int, int>> &graph, int n) {
  vector<vector<int>> graph2(n);
  for (const auto &e : graph) {
      graph2[e.first].push_back(e.second);
  }
  return calculate_res(graph2, n);
}

signed main() {
  int n;
  cin >> n;
  vector<int> a(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> r[i];
  }
  set<pair<int, int>> full_edges = calculate_full_edges(a, r);
  int res = calculate_res2(full_edges, n);
  cout << res << endl;
  return 0;
}