Problem: Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.

The road is constructed as follows: 

  * the first row consists of 1 tile; 
  * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; 
  * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; 
  * ... 
  * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; 
  * then b_n rows follow; each of these rows contains 1 tile less than the previous row. 

<image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. 

You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile.

Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353.

Input

The first line contains one integer n (1 ≤ n ≤ 1000).

Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ 10^5; |a_i - b_i| ≤ 5).

Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles.

Output

Print one integer — the number of paths from the first row to the last row, taken modulo 998244353.

Examples

Input


2
4 2
2 3


Output


850


Input


3
4 1
2 3
3 1


Output


10150


Input


8
328 323
867 868
715 718
721 722
439 435
868 870
834 834
797 796


Output


759099319

Solution (in CPP):

Solution:
#include<cstdio>
typedef long long ll;
const int mod=119<<23|1;
const ll M2=mod*1ll*mod;
int qpow(int x,int k)
{int r=1;for(;k;k>>=1,x=x*1ll*x%mod)if(k&1)r=r*1ll*x%mod;return r;}
int fac[1111111],inv[1111111];
int C(int n,int r)
{return(r<0||n<r)?0:fac[n]*1ll*inv[r]%mod*inv[n-r]%mod;}
void init()
{
	register int i;
	const int V=1e6; 
	for(i=fac[0]=1;i<=V;i++)fac[i]=fac[i-1]*1ll*i%mod;
	for(inv[i=V]=qpow(fac[V],mod-2);i;i--)
		inv[i-1]=inv[i]*1ll*i%mod;
}
int n;
int rv[22222],wi[22222];
void swap(register int&x,register int&y){int t=x;x=y,y=t;}
void NTT(int*x,int SZ,int op)
{
	register int i,ii,iii;
	for(i=1;i<SZ;i++)rv[i]=(rv[i>>1]>>1)+(i&1)*(SZ>>1);
	for(i=1;i<SZ;i++)if(i<rv[i])swap(x[i],x[rv[i]]);
	for(i=1;i<SZ;i<<=1)
	{
		int w=qpow(3,(mod-1)/(i<<1));
		if(op<0)w=qpow(w,mod-2);
		for(iii=wi[0]=1;iii<i;iii++)wi[iii]=wi[iii-1]*1ll*w%mod;
		for(ii=0;ii<SZ;ii+=(i<<1))
			for(iii=0;iii<i;iii++)
			{
				int px=ii+iii,py=px+i;
				ll Dt=x[py]*1ll*wi[iii];
				x[py]=(x[px]+M2-Dt)%mod,x[px]=(x[px]+Dt)%mod;
			}
	}if(op<0)
	{
		int a=qpow(SZ,mod-2);
		for(i=0;i<SZ;i++)x[i]=x[i]*1ll*a%mod;
	}
}
int cur[22222],pwr,cs[22222];
void upd(int a,int b)
{
	register int i;
	int pwt=pwr+a-b,tp=pwt+pwr*2,S;
	for(i=2;i<=tp;i<<=1);S=i;
	for(i=0;i<S;i++)cs[i]=0;
	for(i=-pwr;i<=pwt;i++)cs[i+pwr]=C(a+b,b+i);
	NTT(cs,S,1),NTT(cur,S,1);
	for(i=0;i<S;i++)cur[i]=cur[i]*1ll*cs[i]%mod;
	NTT(cur,S,-1);
	for(i=0;i<=pwt;i++)cur[i]=cur[i+pwr];
	for(i=pwt+1;i<S;i++)cur[i]=0;
	pwr=pwt;
}
int main()
{
	init(),cur[0]=1,pwr=0;
	scanf("%d",&n);
	register int i;
	for(i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b),upd(a,b);
	}ll ans=0;
	for(i=0;i<=pwr;i++)ans+=cur[i];
	printf("%lld\n",ans%mod);
}
/*
Please don't let me down.
*/
// resubmission