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 <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int N=5010,M=2e5;
const int mod=998244353,g=3,invg=332748118;
int rev_tag=0;
int cir[N<<4];
int fac[M+10],inv[M+10];
inline int C(int x,int y)
{ 
	if(x<y||y<0) return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod; 
}
inline int power(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1) res=1ll*res*a%mod;
	return res;
}
inline void mul(int *A,int *B,int x,int y){ for(int i=x;i<y;i++) A[i]=1ll*A[i]*B[i]%mod; }
inline void clear(int *A,int x,int y){ for(int i=x;i<y;i++) A[i]=0; }
inline void NTT(int *A,int lim,int tag)
{
    if(rev_tag!=lim) for(int i=0;i<=lim;i++) cir[i]=(cir[i>>1]>>1)|((i&1)?lim>>1:0); 
    rev_tag=lim; int buf,w,inv0=power(lim,mod-2); 
    for(int i=0;i<lim;i++) if(i<cir[i]) swap(A[i],A[cir[i]]);
    for(int l=2;l<=lim;l<<=1)
    {
        int r=l>>1; buf=power(tag?g:invg,(mod-1)/l),w=1;
        for(int i=0;i<lim;i+=l,w=1)
        for(int j=i;j<i+r;j++,w=1ll*w*buf%mod)
        {
            int tmp=1ll*w*A[j+r]%mod;
            A[j+r]=(A[j]-tmp+mod)%mod;
            A[j]=(A[j]+tmp)%mod;
        }
    }
    if(!tag) for(int i=0;i<lim;i++) A[i]=1ll*A[i]*inv0%mod;
}
int f[1010][N],F[N<<4],G[N<<4];
int main()
{
	fac[0]=1; for(int i=1;i<=M;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[M]=power(fac[M],mod-2); for(int i=M-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
	int n,ans=0,a,b;
	scanf("%d",&n);
	int high=1; f[0][1]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b),high+=a-b;
		int cur=high-a+b,now=high;
		for(int j=1;j<=cur;j++) F[j]=f[i-1][j];
		for(int j=-cur;j<=now;j++) G[j+cur]=C(a+b,b+j);
		int lim=1; while(lim<(now+cur+1)+cur) lim<<=1;
		NTT(F,lim,1),NTT(G,lim,1),mul(F,G,0,lim),NTT(F,lim,0);
		for(int j=1;j<=now;j++) f[i][j]=F[j+cur];
		clear(F,0,lim),clear(G,0,lim);
	}
	for(int i=1;i<=high;i++) ans=(ans+f[n][i])%mod;
	printf("%d\n",ans);
	return 0;
}