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;

using ll = long long;

const int mod = 998244353;

const int maxn = 17000;
int fac[202020], ifac[202020];
int x[maxn], f[maxn], g[maxn];


int C(int n, int k) {
    if (k < 0 || k > n || n < 0) return 0;
    return fac[n] * (ll)ifac[k] % mod * (ll)ifac[n-k] % mod;
}

const int G = 3;

inline int add(int a, int b) { return a+b>=mod?a+b-mod:a+b; }
inline void inc(int&a, int b) { if ((a+=b)>=mod) a-=mod; }
inline int sub(int a, int b) { return a-b<0?a-b+mod:a-b; }
inline void dec(int&a, int b) { if ((a-=b)<0) a+=mod; }
inline int mul(int a, int b) { return (ll)a*b%mod; }
inline int qpow(int x, int n) { int ans=1; for ( ; n; n>>=1, x=(ll)x*x%mod) if (n&1) ans=(ll)ans*x%mod; return ans; }
//-------------------------------NTT--------------------------------
int wn[30],iwn[30]; //wn[i] = G^((P-1)/(2^i)) (mod P), iwn[i] = wn[i]^(-1) (mod P)
inline void init() {
    wn[21] = qpow(G, (mod-1)/(1<<21));
    for (int i=20; i>=0; i--) wn[i] = mul(wn[i+1], wn[i+1]);
    iwn[21] = qpow(wn[21], (1<<21)-1);
    for (int i=20; i>=0; i--) iwn[i] = mul(iwn[i+1], iwn[i+1]);
}
inline void revbin_permute(int a[], int n) {
    int i=1, j=n>>1, k;
    for ( ; i<n-1; i++) {
        if (i < j) swap(a[i], a[j]);
        for (k=n>>1; j>=k; ) { j -= k; k >>= 1; }
        if (j < k) j += k;
    }
}
void NTT(int f[], int ldn, int is) {
    int n = (1<<ldn);
    revbin_permute(f, n);
    for (int i=0; i<n; i+=2) {
        int tmp1 = f[i], tmp2 = f[i+1];
        f[i] = add(tmp1, tmp2), f[i+1] = sub(tmp1, tmp2);
    }
    for (int ldm=2; ldm<=ldn; ldm++) {
        int m = (1<<ldm), mh = (m>>1);
        int dw = is>0?wn[ldm]:iwn[ldm], w = 1;
        for (int j=0; j<mh; j++) {
            for (int r=0; r<n; r+=m) {
                int u = f[r+j], v = mul(f[r+j+mh], w);
                f[r+j] = add(u, v);
                f[r+j+mh] = sub(u, v);
            }
            w = mul(w, dw);
        }
    }
}
void convolution(int f[], int g[], int n) {
    int ldn; for (int i=20; i>=0; i--) if (n&(1<<i)) { ldn=i; break; }
    NTT(f, ldn, 1); NTT(g, ldn, 1); //会改变g
    for (int i=0; i<n; i++) f[i] = mul(f[i], g[i]);
    NTT(f, ldn, -1);
    int iv = qpow(n, mod-2);
    for (int i=0; i<n; i++) f[i] = mul(f[i], iv);
}

int main(void) {
    //freopen("g.in", "r", stdin);

    int N = 200002;
    fac[0]=1; for (int i=1; i<=N; i++) fac[i]=fac[i-1]*(ll)i%mod;
    ifac[N]=qpow(fac[N], mod-2); for (int i=N-1; i>=0; i--) ifac[i]=ifac[i+1]*(ll)(i+1)%mod;

    init();

    int n; scanf("%d", &n);

    int cur_len = 1;
    x[0] = 1;

    for (int i=0; i<n; i++) {
        int a, b; scanf("%d%d", &a, &b);

        int nex_len = cur_len + a - b;

        int tot_len = cur_len + nex_len - 1;
        int L = 2; while (L <= cur_len + tot_len) L <<= 1;

//        for (int j=0; j<L; j++) f[j] = g[j] = 0;
        for (int j=0; j<cur_len; j++) f[j] = x[j];
        for (int j=cur_len; j<L; j++) f[j] = 0;
        for (int j=0; j<tot_len; j++) {
            g[j] = C(a + b, a + cur_len-1 - j);
        }
        for (int j=tot_len; j<L; j++) g[j] = 0;

//        for (int j=0; j<tot_len; j++) printf("%d ", g[j]); puts("");

        convolution(f, g, L);

        for (int j=cur_len-1; j<cur_len-1+nex_len; j++) x[j-cur_len+1] = f[j];
        cur_len = nex_len;

//        printf("i = %d, a = %d, b = %d\n", i, a, b);
//        for (int j=0; j<cur_len; j++) printf("%d ", x[j]); puts("");
    }

    int ans = 0;
    for (int i=0; i<cur_len; i++) {
        ans = (ans + x[i]) % mod;
    }
    printf("%d\n", ans);

    return 0;
}