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>
using namespace std;

const int maxn = 1000000;
const int mod = 998244353;
const int g = 3;
const int gi = 332748118;

int a[maxn],b[maxn],dp[maxn];
int c[maxn],pos[maxn],fac[maxn],fav[maxn];
int qpow(int a,int b,int c){
	int ans=1;
	while(b){
		if(b&1)ans=1ll*ans*a%mod;
		b>>=1;
		a=1ll*a*a%mod;
	}
	return ans;
}
int init(int n){
	int cur=1,ct=0;
	while(cur<n)cur<<=1,ct++;
	for(int i=0;i<cur;++i)pos[i]=(pos[i>>1]>>1)|((i&1)<<(ct-1));
	return cur;
}
int C(int a,int b){
	if(b<0 || b>a)return 0;
	return 1ll*fac[a]*fav[b]%mod*fav[a-b]%mod;
}
void ntt(int *a,int len,int fg){
	for(int i=0;i<len;++i)if(i<pos[i])swap(a[i],a[pos[i]]);
	for(int i=2,mid=1;i<=len;i<<=1,mid<<=1){
		int wn=qpow(fg==1?g:gi,(mod-1)/i,mod);
		for(int j=0;j<len;j+=i){
			int w=1;
			for(int k=j;k<j+mid;k++){
				int l=a[k],r=1ll*a[k+mid]*w%mod;
				a[k]=(l+r)%mod,a[k+mid]=(l-r+mod)%mod;
				w=1ll*w*wn%mod;
			}
		}
	}
	if(fg==-1){
		int invlen=qpow(len,mod-2,mod);
		for(int i=0;i<len;++i)a[i]=1ll*invlen*a[i]%mod;
	}
}
int main(){
	fac[0]=1;
	for(int i=1;i<maxn;++i)fac[i]=1ll*fac[i-1]*i%mod;
	fav[maxn-1]=qpow(fac[maxn-1],mod-2,mod);
	for(int i=maxn-2;i>=0;--i)fav[i]=1ll*fav[i+1]*(i+1)%mod;
	int n;
	scanf("%d",&n);
	dp[0]=1;
	int cur=1;
	for(int i=1;i<=n;++i){
		scanf("%d%d",&a[i],&b[i]);
		int le=2*cur+a[i]-b[i]-1;
		int len=init(le);
		for(int j=b[i]-cur+1,k=0;j<=b[i]+cur+a[i]-b[i]-1;++j,++k)c[k]=C(b[i]+a[i],j);
		for(int j=b[i]+cur+a[i]-b[i];j<len;++j)c[j]=0;
//		for(int j=0;j<len;++j)printf("%d ",c[j]);puts("");
//		for(int j=0;j<len;++j)printf("%d ",dp[j]);puts("");
		ntt(dp,len,1);
		ntt(c,len,1);
		for(int j=0;j<len;++j)dp[j]=1ll*dp[j]*c[j]%mod;
		ntt(dp,len,-1);
		for(int j=0;j<cur+a[i]-b[i];++j)dp[j]=dp[j+cur-1];
		cur+=a[i]-b[i];
//		for(int j=0;j<cur;++j)printf("%d ",dp[j]);
		for(int j=cur;j<len;++j)dp[j]=0;
//		puts("");
	}
	int ans=0;
	for(int i=0;i<cur;++i)ans=(ans+dp[i])%mod;
	printf("%d\n",ans);
}