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;
typedef long long ll;

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2")

const ll mod = 998244353;

const int L = 15;
const int N = (1 << L);

int add(int a, int b) {
  int c = a + b;
  if (c >= mod) c -= mod;
  return c;
}
int sub(int a, int b) {
  return add(a, mod - b);
}
int mult(int a, int b) {
  return ((ll) a * b) % mod;
}

int pw(int a, int b) {
  if (!b) return 1;
  if (b & 1) return mult(pw(a, b - 1), a);
  int x = pw(a, b / 2);
  return mult(x, x);
}

int inv2;
int pws[N + 1], ipws[N + 1];

void init() {
  inv2 = pw(2, mod - 2);
  pws[N] = pw(31, pw(2, 23 - L));
  ipws[N] = pw(pws[N], mod - 2);
  for (int i = (N >> 1); i; i >>= 1) {
    pws[i] = mult(pws[i << 1], pws[i << 1]);
    ipws[i] = mult(ipws[i << 1], ipws[i << 1]);
  }
}

void fft(vector<int> &s, vector<int> &res, int n, int x, int bs = 0, int bstep = 1, int rs = 0) {
  if (n == 1) {
    res[rs] = s[bs];
    return;
  }
  fft(s, res, n >> 1, mult(x, x), bs, bstep << 1, rs);
  fft(s, res, n >> 1, mult(x, x), bs + bstep, bstep << 1, rs + (n >> 1));
  int c = 1;
  for (int i = rs; i < rs + (n >> 1); ++i) {
    int a = res[i], b = res[i + (n >> 1)];
    res[i] = add(a, mult(b, c));
    res[i + (n >> 1)] = sub(a, mult(b, c));
    c = mult(c, x);
  }
}

void poly_mult(const vector<int> &a, const vector<int> &b, vector<int> &c) {
  init();
  vector<int> fa, fb, fra, frb, rt;
  int n = 1;
  while (n < max(b.size(), a.size())) n <<= 1;
  n <<= 1;
  fa.resize(n);
  rt = frb = fra = fb = fa;
  for (int i = 0; i < a.size(); ++i) fa[i] = a[i];
  for (int i = 0; i < b.size(); ++i) fb[i] = b[i];
  fft(fa, fra, n, pws[n]);
  fft(fb, frb, n, pws[n]);
  for (int i = 0; i < n; ++i)
    fra[i] = mult(fra[i], frb[i]);
  fft(fra, rt, n, ipws[n]);
  int inv_n = pw(n, mod - 2);
  for (int i = 0; i < n; ++i)
    rt[i] = mult(rt[i], inv_n);
  c = rt;
}

const ll M = 3e5 + 5;

int fact[M], invfact[M];

int cnk(int n, int k) {
  if (n < 0 || k < 0 || n - k < 0) return 0;
  return mult(mult(fact[n], invfact[n - k]), invfact[k]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  fact[0] = 1;
  for (int i = 1; i < M; ++i) fact[i] = mult(fact[i - 1], i);
  invfact[M - 1] = pw(fact[M - 1], mod - 2);
  for (int i = M - 2; i >= 0; --i) invfact[i] = mult(invfact[i + 1], i + 1);

  int n, d = 0;
  cin >> n;
  vector<int> cur = {1};
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    int dd = d + a - b;
    vector<int> g(d + dd + 1);
    for (int j = -d; j <= dd; ++j) g[j + d] = cnk(a + b, b + j);
    vector<int> f;
    poly_mult(cur, g, f);
    cur.resize(dd + 1);
    for (int j = 0; j <= dd; ++j)
      cur[j] = f[j + d];
    d = dd;
  }
  ll ans = 0;
  for (ll x : cur) ans = (ans + x) % mod;
  cout << ans;
}