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 L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
const int N = 2e5 + 7;
const int mod = 998244353;
const int G = 3;
const int iG = (mod + 1) / G;
int qpow(int x, int y = mod - 2) {
	int res = 1;
	for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
	return res;
}
int pp[N];
void polyinit(int len) {
	L(i, 0, len - 1) pp[i] = ((pp[i >> 1] >> 1) | ((i & 1) * (len >> 1)));
}
void NTT(int *f, int len, int flag) {
	L(i, 0, len - 1) if(pp[i] < i) swap(f[pp[i]], f[i]);
	for(int i = 2; i <= len; i <<= 1) 
		for(int j = 0, l = (i >> 1), ch = qpow(flag == 1 ? G : iG, (mod - 1) / i); j < len; j += i) 
			for(int k = j, now = 1; k < j + l; k ++) {
				int pa = f[k], pb = (ll) f[k + l] * now % mod;
				f[k] = (pa + pb) % mod, f[k + l] = (pa + mod - pb) % mod;
				now = (ll) now * ch % mod;
			}
	if(flag == -1) {
		int nylen = qpow(len);
		L(i, 0, len - 1) f[i] = (ll) f[i] * nylen % mod;
	}
}
int up(int x) {
	int lim = 1;
	for(; lim <= x; lim <<= 1);
	return lim;
}
int fac[N], ifac[N];
int C(int x, int y) {
	if(y < 0 || y > x) return 0;
	return (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
void math_init(int x) {
	fac[0] = 1;
	L(i, 1, x) fac[i] = (ll) fac[i - 1] * i % mod;
	ifac[x] = qpow(fac[x]);
	R(i, x, 1) ifac[i - 1] = (ll) ifac[i] * i % mod;
}
int n, dp[2][N], a[N], b[N];
int A[N], B[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	math_init(200000);
	int bf = 0, now = 0;
	dp[0][0] = 1;
	L(i, 1, n) {
		bf ^= 1;
		memset(dp[bf], 0, sizeof(dp[bf]));
		cin >> a[i] >> b[i];
		int las = now;
		now += a[i] - b[i];
		
		int mx = max(now, las), lim = up(now + las + mx);
		
		L(j, 0, lim - 1) A[j] = B[j] = 0; 
		L(j, 0, las) A[j] = dp[bf ^ 1][j];
		L(j, -mx, mx) B[j + mx] = C(a[i] + b[i], b[i] + j);
		polyinit(lim);
		NTT(A, lim, 1), NTT(B, lim, 1);
		L(j, 0, lim - 1) A[j] = (ll) A[j] * B[j] % mod;
		NTT(A, lim, -1);
		L(j, 0, now) dp[bf][j] = A[j + mx];
	}
	int sum = 0;
	L(i, 0, now) (sum += dp[bf][i]) %= mod;
	cout << sum << endl;
	return 0;
}