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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var h=new int[n][];
		var c=new int[n+1];
		var a=new int[n];
		var dp1=new Mint[n+1];
		var dp2=new Mint[n+1];
		St st=new St(n+1,true,false,0); 
		c[n]=n;
		st.Ud(n,n);
		dp2[n]=1;
		for(int i = 0;i<n;i++) {
			h[i]=sc.Ia;
			a[i]=h[i][0];
		}
		Array.Sort(h,(u,v)=>u[0]-v[0]);
		Array.Sort(a);
		for(int i = n-1;i>=0;i--) {
			c[i]=a.Bs(h[i][0]+h[i][1],false)-1;
			st.Ud(i,i);
			st.Ud(i,(int)st.Get(i,c[i]).d);
			if(i==n-1){
				dp1[i]=1;
				dp2[i]=1;
			}
			else{
				dp1[i]=dp1[i+1]+dp2[i+1];
				var p=st.Get(i,i).d;
				if(p==i){
					dp2[i]=dp1[p+1]+dp2[p+1];
				}
				else{
					dp2[i]=dp1[p+1]+dp2[p+1];
				}
			}
		}
		Console.WriteLine("{0}",dp1[0]+dp2[0]);
	}
}
static class Ex1{
	public static int Bs(this int[] a,int x,bool b){return Bs2(a,x,b,a.Length);}
	public static int Bs(this int[] a,int x,bool b,int ub){return Bs2(a,x,b,ub+1);}
	private static int Bs2(int[] a,int x,bool b,int ub){
		int lb=-1,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(a[mid]>=x){ub=mid;}
			else{lb=mid;}
		}
		return b?lb:ub;
	}
}
public class St{
	public class Dt{
		public int n;
		public long d;
		public Dt(long d,int n){this.d=d;this.n=n;}
		public override string ToString()=>"n:"+n.ToString()+" d:"+d.ToString();
	}
	public Dt[] dat;
	private int m=1;
	private bool mm,ku;
	private Dt du;
	private Func<Dt,Dt,bool> compare;
	public St(int n,bool mm,bool ku,long df){
		this.mm=mm;this.ku=ku;
		if(mm){du=new Dt(long.MinValue,-1);compare=CoMax;}
		else{du=new Dt(long.MaxValue,-1);compare=CoMin;}
		while(m<n){m<<=1;}
		m--;
		dat=new Dt[m+n+1];
		dat[m+n]=du;
		for(int i=m+n-1;i>=m;i--){dat[i]=new Dt(df,i-m);}
		for(int i=m-1;i>=0;i--){dat[i]=(i<<1)+1<m+n?dat[(i<<1)+1]:du;}
	}
	private bool CoMax(Dt x,Dt y){return x.d>y.d;}
	private bool CoMin(Dt x,Dt y){return x.d<y.d;}
	public void Ud(int q,long b){
		q+=m;
		if(ku){b+=dat[q].d;}
		dat[q].d=du.d;
		dat[q]=new Dt(b,q-m);
		q=(q-1)>>1;
		while(q>=0){
			Dt o=compare(dat[2*q+1],dat[2*q+2])?dat[2*q+1]:dat[2*q+2];
			if(dat[q]==o){break;}
			dat[q]=o;
			q=(q-1)>>1;
		}
	}
	private Dt Fdg(int a,int b,int k,int l,int r){
		if(r<a||b<l){return du;}
		if(a<=l&&r<=b){return dat[k];}
		Dt p=Fdg(a,b,k*2+1,l,(l+r)>>1);
		Dt q=Fdg(a,b,k*2+2,(l+r+1)>>1,r);
		return compare(p,q)?p:q;
	}
	public Dt Get(int a,int b){return Fdg(a,b,0,0,m);}
}
public struct Mint{
	const int mod=998244353;
	private long d;
	public Mint(long d){this.d=d;}
	public static implicit operator Mint(long d){return new Mint(d%mod);}
	public static explicit operator long(Mint d){return d.d;}
	public override string ToString(){return d.ToString();}
	public static Mint operator+(Mint a,long b){a.d=(a.d+b)%mod;return a;}
	public static Mint operator+(Mint a,Mint b){a.d=(a.d+b.d)%mod;return a;}
	public static Mint operator-(Mint a,long b){a.d=(mod+a.d-b)%mod;return a;}
	public static Mint operator-(Mint a,Mint b){a.d=(mod+a.d-b.d)%mod;return a;}
	public static Mint operator*(Mint a,long b){a.d=(a.d*b)%mod;return a;}
	public static Mint operator*(Mint a,Mint b){a.d=(a.d*b.d)%mod;return a;}
	public static Mint operator/(Mint a,long b){a.d=(a.d*Mi(b))%mod;return a;}
	public static Mint operator/(Mint a,Mint b){a.d=(a.d*Mi(b.d))%mod;return a;}
	private static long Mi(long a){
		a=(a+mod)%mod;
		long b=mod,u=1,v=0;
		while(b>0){
			long t=a/b;
			a-=t*b;a^=b;b^=a;a^=b;
			u-=t*v;u^=v;v^=u;u^=v;
		}
		u%=mod;
		if(u<0){u+=mod;}
		return u%mod;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}