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 <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;  // 2^23 * 7 * 17 + 1
const int ROOT_OF_UNITY = 15311432;
int mul(int a, int b) { return 1LL * a * b % MOD; }
int powmod(int base, int expo)
{
    int t = 1;
    for (; expo > 0; expo >>= 1) {
        if (expo & 1) t = mul(t, base);
        base = mul(base, base);
    }
    return t;
}

const int MAX2N = 1 << 23;
int roots[MAX2N], inv_roots[MAX2N];

void fft(vector<int>& a, const vector<int>&p, int root[])
{
    int n = a.size();
    for (int i = 0; i < n; ++i)
        if (i < p[i]) swap(a[i], a[p[i]]);

    for (int m = 1, t = MAX2N / 2; m < n; m *= 2, t /= 2)
        for (int i = 0; i < n; i += m * 2)
            for (int j = 0; j < m; ++j) {
                int& u = a[i + j];
                int& v = a[i + j + m];
                v = mul(v, root[j * t]);
                int tmp = u - v;
                if (tmp < 0) tmp += MOD;
                u += v;
                if (u >= MOD) u -= MOD;
                v = tmp;
            }
}

vector<int> polymul(const vector<int>& a, const vector<int>& b)
{
    int n = a.size() + b.size();
    if (__builtin_popcount(n) != 1) n = 1 << (32 - __builtin_clz(n));

    vector<int> pa(a), pb(b);
    pa.resize(n), pb.resize(n);

    vector<int> p(n);
    for (int i = 1; i < n; ++i)
        if (i & 1) p[i] = p[i - 1] + n / 2;
        else p[i] = p[i / 2] / 2;

    fft(pa, p, roots);
    fft(pb, p, roots);
    for (int i = 0; i < n; ++i)
        pa[i] = mul(pa[i], pb[i]);

    fft(pa, p, inv_roots);
    int inv_n = powmod(n, MOD - 2);
    for (int i = 0; i < n; ++i)
        pa[i] = mul(pa[i], inv_n);

    return pa;
}

const int N = 2e5;

int ft[N + 2], invft[N + 2];
int C(int n, int k) { return k >= 0 && k <= n ? mul(ft[n], mul(invft[k], invft[n - k])) : 0; }

vector<int> src(1, 1);

void add_row(int x, int y)
{
    int n = src.size();
    int m = n + x - y;
    vector<int> b;
    for (int i = 0; i < n + m; ++i)
        b.push_back(C(x + y, y - n + i));

    b = polymul(src, b);
    src.resize(m);
    copy(b.begin() + n, b.begin() + n + m, src.begin());
}

int main()
{
    ft[0] = 1;
    for (int i = 1; i <= N; ++i) ft[i] = mul(ft[i - 1], i);
    invft[N] = powmod(ft[N], MOD - 2);
    for (int i = N - 1; i >= 0; --i) invft[i] = mul(invft[i + 1], i + 1);

    roots[0] = 1;
    for (int i = 1; i < MAX2N; ++i) roots[i] = mul(roots[i - 1], ROOT_OF_UNITY);
    inv_roots[MAX2N - 1] = powmod(roots[MAX2N - 1], MOD - 2);
    for (int i = MAX2N - 2; i >= 0; --i) inv_roots[i] = mul(inv_roots[i + 1], ROOT_OF_UNITY);

    int q;
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        add_row(x, y);
    }
    int res = 0;
    for (int x : src) {
        res += x;
        if (res >= MOD) res -= MOD;
    }
    cout << res;
    return 0;
}