Problem:
Score : 600 points

Problem Statement

There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable.

Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line.

Choose a robot and activate it. This operation cannot be done when there is a robot moving.

While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively.

How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.

Constraints

1 \leq N \leq 2 \times 10^5

-10^9 \leq X_i \leq 10^9

1 \leq D_i \leq 10^9

X_i \neq X_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 D_1
:
X_N D_N

Output

Print the number of possible sets of robots remaining on the number line, modulo 998244353.

Sample Input 1

2
1 5
3 3

Sample Output 1

3

There are three possible sets of robots remaining on the number line: \{1, 2\}, \{1\}, and \{\}.

These can be achieved as follows:

If Takahashi activates nothing, the robots \{1, 2\} will remain.

If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.

If Takahashi activates Robot 2 and finishes doing the operation, the robot \{1\} will remain.

Sample Input 2

3
6 5
-1 10
3 3

Sample Output 2

5

There are five possible sets of robots remaining on the number line: \{1, 2, 3\}, \{1, 2\}, \{2\}, \{2, 3\}, and \{\}.

Sample Input 3

4
7 10
-10 3
4 3
-4 3

Sample Output 3

16

None of the robots influences others.

Sample Input 4

20
-8 1
26 4
0 5
9 1
19 4
22 20
28 27
11 8
-3 20
-25 17
10 4
-18 27
24 28
-11 19
2 27
-2 18
-1 12
-24 29
31 29
29 7

Sample Output 4

110

Remember to print the count modulo 998244353.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;const ll INF=1LL<<60,MOD=998244353;
void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define foreach(a,A) for(auto &a:A)
#define endl "\n"
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

template<class T, class E>
class LazySegmentTree{
  ll n = 1, logn = 0;
  function<T(T, T)> dot; T unit; function<E(E, E)> compose; E identity; function<T(E, T)> act; vector<T> tree; vector<E> lazy;
  constexpr void ascend(ll i){while(i >>= 1) tree[i] = act(lazy[i], dot(tree[i << 1], tree[i << 1 | 1]));}
  constexpr void descend(ll i){
    rep(k, logn, 0, -1){
      ll p = i >> k;
      E f = lazy[p];
      tree[p << 1] = act(f, tree[p << 1]); lazy[p << 1] = compose(f, lazy[p << 1]);
      tree[p << 1 | 1] = act(f, tree[p << 1 | 1]); lazy[p << 1 | 1] = compose(f, lazy[p << 1 | 1]);
      lazy[p] = identity;
    }
  }
public:
  LazySegmentTree(const vector<T> &A, function<T(T, T)> dot, T unit ,function<E(E, E)> compose, E identity ,function<T(E, T)> act)
  : dot(dot), unit(unit), compose(compose), identity(identity), act(act) {
    while(n < A.size()){n <<= 1; logn++;}
    tree.resize(2 * n, unit);
    lazy.resize(2 * n, identity);
    rep(i, A.size()) tree[n + i] = A[i];
    rep(i, n - 1, 0, -1) tree[i] = dot(tree[i << 1], tree[i << 1 | 1]);
  }
  constexpr void range_act(ll l, ll r, E f){
    l += n; r += n;
    // propagation isn't necessary if monoid action is commutative
    descend(l); descend(r - 1);
    ll l0 = l, r0 = r;
    while(l < r){
      if(l & 1){tree[l] = act(f, tree[l]); lazy[l] = compose(f, lazy[l]); l++;}
      if(r & 1){r--; tree[r] = act(f, tree[r]); lazy[r] = compose(f, lazy[r]);}
      l >>= 1; r >>= 1;
    }
    ascend(l0); ascend(r0 - 1);
  }
  constexpr T sum(ll l, ll r){
    descend(l += n); descend((r += n) - 1);
    T l_val = unit, r_val = unit;
    while(l < r){
      if(l & 1) l_val = dot(l_val, tree[l++]);
      if(r & 1) r_val = dot(tree[--r], r_val);
      l >>= 1; r >>= 1;
    }
    return dot(l_val, r_val);
  }
};

using pll = pair<ll, ll>;
void solve(){
  ll n; cin >> n;
  vector<pll> XD(n);
  vector<ll> X(n);
  rep(i, n) {
    ll x, d; cin >> x >> d;
    XD[i] = {x, d};
    X[i] = x;
  }
  sort(XD.begin(), XD.end());
  sort(X.begin(), X.end());

  vector<pll> A(n, {0, 1});
  A[n - 1] = {1, 1};
  auto dot = [](pll a0, pll a1){return make_pair(a0.first + a1.first, a0.second + a1.second);};
  pll unit = {0, 0};
  auto compose = [](ll f, ll g){
    if(f == INF) return g;
    else if(g == INF) return f;
    return f;
  }; 
  ll identity = INF;
  auto act = [](ll f, pll a){
    if(f == INF) return a;
    return make_pair(f * a.second, a.second);
  };
  LazySegmentTree<pll, ll> tree(A, dot, unit, compose, identity, act);
  rep(i, n - 2, -1, -1){
    ll x, y; tie(x, y) = tree.sum(i + 1, n);
    tree.range_act(i, i + 1, (x + 1) % MOD);
    ll d; tie(x, d) = XD[i];
    ll j = lower_bound(X.begin(), X.end(), x + d) - X.begin();
    tree.range_act(i + 1, j, 0);
  }

  cout << (tree.sum(0, n).first + 1) % MOD << endl;
}