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<bits/stdc++.h>
#define go(i,a,b) for(int i=a;i< b;i++)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int X=2e5,N=33e3,mo=998244353;
int fac[X+9],ivf[X+9],n,a,b,m=1,m1,n1,f[2][N],g[N],ans;
void P(int&x,ll y) {x=(x+y)%mo;}
void T(int&x,ll y) {x=x*y%mo;}
int ksm(int x,int y=mo-2) {int a=1; for(;y;y/=2,T(x,x)) if(y&1)T(a,x); return a;}
int C(int n,int m) {return m>=0&&m<=n?1ll*fac[n]*ivf[m]%mo*ivf[n-m]%mo:0;}
namespace NTT
{
	int tf[N],w[N],o;
	void build(int n)
	{
		o=__builtin_ctz(n);
		go(i,1,n) tf[i]=tf[i/2]+n*(i&1)>>1;
		for(int i=1;i<n;i*=2)
		{
			int v=ksm(3,(mo-1)/2/i); w[i]=1;
			go(j,1,i) w[i+j]=1ll*w[i+j-1]*v%mo;
		}
	}
	void DFT(int a[N],int n,bool f)
	{
		static unsigned long long b[N];
		int u=o-__builtin_ctz(n),v;
		go(i,0,n) b[i]=a[tf[i]>>u];
		for(int i=1;i<n;i*=2) for(int j=0;j<n;j+=2*i) go(k,0,i)
			v=b[i+j+k]*w[i+k]%mo, b[i+j+k]=b[j+k]-v+mo, b[j+k]+=v;
		go(i,0,n) a[i]=b[i]%mo;
		if(f)
		{
			reverse(a+1,a+n);
			v=mo-(mo-1)/n;
			go(i,0,n) T(a[i],v);
		}
	}
	void mtp(int a[N],int b[N],int n)
	{
		DFT(a,n,0); DFT(b,n,0);
		go(i,0,n) T(a[i],b[i]);
		DFT(a,n,1);
	}
}
int main()
{
	fac[0]=1;
	fo(i,1,X) fac[i]=1ll*fac[i-1]*i%mo;
	ivf[X]=ksm(fac[X]);
	fd(i,X,1) ivf[i-1]=1ll*ivf[i]*i%mo;
	NTT::build(32768);
	scanf("%d",&n); f[0][1]=1;
	fo(i,1,n)
	{
		scanf("%d%d",&a,&b); m1=m+a-b;
		int I=i&1;
		for(n1=1;n1/2<=m+m1+1;n1*=2);
		memset(g,0,4*n1);
		fo(j,0,m+m1) g[j]=C(a+b,b+j-m);
		NTT::mtp(g,f[!I],n1);
		memset(f[!I],0,4*n1);
		fo(j,1,m+a-b) f[I][j]=g[j+m];
		m=m1;
	}
	fo(i,1,m) P(ans,f[n&1][i]);
	printf("%d",ans);
}