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>
#include"map"
#include"string"
#include"cmath"
#include"cstdio"
#include"iostream"
#include"cstring"
#include"algorithm"
#include"vector"
//#pragma GCC optimize(3, "Ofast")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, ll> pii;
inline int read() {
	int s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * w;
}
#ifdef local
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define f(i, l, r) for (int i = l; i <= r; ++i)
#define rf(i, r, l) for (int i = r; i >= l; --i)
#define all(x) (x).begin(), (x).end()
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))
#define mod1(x) ((x >= mod) && (x -= mod))
#define mod2(x) ((x < 0) && (x += mod))

const int inf = 2e9 + 7;
//const ll INF = INT64_MAX;
double eps = 1e-6;
const int mod = 998244353;
const int N = 2e5 + 10;
const double pi = acos(-1.0);
ll power(ll a, ll b) { ll res = 1; while (b) { if (b & 1)res = res * a % mod; a = a * a % mod; b >>= 1; }return res; }
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll exgcd(ll a, ll b, ll& x, ll& y) { ll c; return !b ? (x = 1, y = 0, a) : (c = exgcd(b, a % b, y, x), y -= (a / b) * x, c); }
ll INV(ll a) { ll x, y; exgcd(a, mod, x, y); x %= mod; if (x < 0)x += mod; return x; }
/*int len, C[N], clen;
int id(int v) { return lower_bound(C + 1, C + len, v) - C; }
void initC() { sort(C + 1, C + clen+1); len = unique(C + 1, C + 1 + clen) - C - 1; }*/


typedef unsigned int uint;
namespace Poly {
	typedef vector<uint> poly;
	constexpr uint Max_size = 1 << 21 | 5;
	constexpr int gn = 3;
	inline uint mf(uint x)
	{
		return (static_cast<ll>(x) << 32) / mod;
	}
	int sz;
	uint w[Max_size], w_mf[Max_size];
	inline void init(int n)
	{
		for (sz = 2; sz < n; sz <<= 1);
		uint pr = power(gn, (mod - 1) / sz);
		w[sz / 2] = 1, w_mf[sz / 2] = mf(w[sz / 2]);
		for (int i = 1; i < sz / 2; ++i)
			w[sz / 2 + i] = (ll)w[sz / 2 + i - 1] * pr % mod, w_mf[sz / 2 + i] = mf(w[sz / 2 + i]);
		for (int i = sz / 2 - 1; i; --i)
			w[i] = w[i << 1], w_mf[i] = w_mf[i << 1];
	}
	inline void NTT(poly& A, const int L)
	{
		for (int d = L >> 1; d; d >>= 1)
			for (int i = 0; i != L; i += d << 1)
				for (int j = 0; j != d; ++j)
				{
					uint x = A[i + j] + A[i + d + j];
					if (x >= mod * 2)
						x -= mod * 2;
					ll t = A[i + j] + mod * 2 - A[i + d + j];
					ll q = t * w_mf[d + j] >> 32;
					uint y = t * w[d + j] - q * mod;
					A[i + j] = x, A[i + d + j] = y;
				}
	}
	inline void INTT(poly& A, const int L)
	{
		for (int d = 1; d != L; d <<= 1)
			for (int i = 0; i != L; i += d << 1)
				for (int j = 0; j != d; ++j)
				{
					uint x = A[i + j];
					if (x >= mod * 2)
						x -= mod * 2;
					ll y = A[i + d + j];
					ll q = y * w_mf[d + j] >> 32;
					ll t = y * w[d + j] - q * mod;
					A[i + j] = x + t, A[i + d + j] = x + mod * 2 - t;
				}
		reverse(A.begin() + 1, A.end());
		int k = __builtin_ctz(L);
		for (int i = 0; i != L; ++i)
		{
			ll m = -A[i] & (L - 1);
			A[i] = (A[i] + m * mod) >> k;
		}
	}
	poly operator*(poly a, poly b) {
		int n = a.size() + b.size() - 1, R = 2;
		for (; R <= n; R <<= 1); init(R);
		a.resize(R), b.resize(R);
		NTT(a, R); NTT(b, R);
		f(i, 0, R - 1)a[i] = 1ll * b[i] * a[i] % mod;
		INTT(a, R); a.resize(n);
		f(i, 0, n - 1)if (a[i] >= mod)a[i] -= mod;
		return a;
	}
}; using namespace Poly;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef local
	freopen("in.txt", "r", stdin);
	int start = clock();
#endif
	int n; cin >> n;
	const int N2 = 4e5;
	vector<ll> fac(N2+1), ifac(fac);
	fac[0] = 1; f(i, 1, N2)fac[i] = fac[i - 1] * i % mod;
	ifac[N2] = power(fac[N2], mod - 2);
	rf(i, N2-1, 0)ifac[i] = ifac[i + 1] * (i + 1) % mod;
	poly res; res.push_back(1);
	f(i, 1, n) {
		int a, b; cin >> a >> b;
		int m = res.size();
		int m2 = m + a - b;
		poly F;
		f(j, max(0, b - (m-1)), min(a+(m-1), a + b)) {
			F.push_back(fac[a + b] * ifac[j] % mod * ifac[a + b - j] % mod);
		}
		res = res * F;
		int yu = (res.size() - m2) / 2;
		res.erase(res.end() - yu, res.end());
		res.erase(res.begin(), res.begin() + yu);
	}
	ll ans = 0;
	for (auto I : res)ans += I;
	cout << ans % mod;
#ifdef local
	int end = clock();
	//cout << '\n' << end - start << "ms";
#endif* /
}