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 mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<db, db> Pd;
typedef vector<int> Vi;
typedef Vi Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM=MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

int fac[300001],inv[300001];
int nCr(int n, int r)
{
	if(r<0)return 0;
	if(r>n)return 0;
	int c = fac[n];
	c = (1LL*c*inv[r]) % MOD;
	c = (1LL*c*inv[n - r]) % MOD;
	return c;
}
void fft(Vi &a, bool inv){
	int n = a.size(), j = 0;
	Vi roots(n/2);
	for(int i=1; i<n; i++){
		int bit = (n >> 1);
		while(j >= bit){
			j -= bit;
			bit >>= 1;
		}
		j += bit;
		if(i < j) swap(a[i], a[j]);
	}
	int ang = POW(3,(MOD-1)/n);
	if(inv) ang = POW(ang, MOD - 2);
	for(int i=0; i<n/2; i++){
		roots[i] = (i ? (1LL*roots[i-1]* ang % MOD) : 1);
	}
	for(int i=2; i<=n; i<<=1){
		int step = n / i;
		for(int j=0; j<n; j+=i){
			for(int k=0; k<i/2; k++){
				int u = a[j+k], v = (1LL*a[j+k+i/2] * roots[step * k])%MOD;
				a[j+k] = u+v;
				if(a[j+k]>=MOD)a[j+k]-=MOD;
				a[j+k+i/2] = u-v;
				if(a[j+k+i/2]<0)a[j+k+i/2]+=MOD;
			}
		}
	}
	if(inv){
		ll t=POW(n,MOD-2);
		for(int i=0; i<n; i++) a[i] =1LL*a[i]*t%MOD; // skip for OR convolution.
	} 
}

Vi multiply(Vi &v, Vi &w){
	int n = 2; while(n < v.size() + w.size()) n <<= 1;
	v.resize(n); w.resize(n);
	fft(v, 0); fft(w, 0);
	for(int i=0; i<n; i++) v[i] = (1LL*v[i]*w[i])%MOD;
	fft(v, 1);
	return v;
}

int main() {
	fac[0] = inv[0] = 1;
	fup(i, 1, 300000, 1)
		fac[i] = (1LL*fac[i - 1] * i) % MOD;
	inv[300000] = POW(fac[300000], MOD - 2);
	fdn(i, 299999, 1, 1)
		inv[i] = (1LL*inv[i + 1] * (i+1)) % MOD;
	int x=1;
	int n;
	scanf("%d",&n);
	Vi A={1};
	fup(i,0,n-1,1){
		int a,b;
		scanf("%d%d",&a,&b);
		int y=x+a-b;
		int N=a+b;
		int t=x+y-1;
		Vi B;
		int l=(N-t+1)>>1,r=(N+t)>>1;
		fup(i,l,r,1)B.pb(nCr(N,i));
		A=multiply(A,B);
		int k=x+t-2;
		l=(k-y+1)>>1,r=(k+y)>>1;
		fup(j,l,r,1)A[j-l]=A[j];
		A.resize(y);
		x=y;
	}
	ll ans=0;
	for(ll x:A)ans+=x;
	printf("%lld\n",ans%MOD);
}