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;

#define ll long long
#define pii pair<int, int>
#define fir first
#define sec second
#define pb emplace_back

#define gc() getchar()
inline int read()
{
    int now=0,f=1; char c=gc();
    for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
    for(;isdigit(c);now=now*10+c-48,c=gc());
    return now*f;
}

const int mod = 998244353;
inline int add(int a,int b){return a+b>=mod? a+b-mod: a+b;}
inline int sub(int a,int b){return a<b? a-b+mod: a-b;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
int qpow(int a,int b){
    int ret=1;
    for(; b; b>>=1){
        if(b&1) ret=mul(ret,a);
        a=mul(a,a);
    }
    return ret;
}

const int D = 2e5+10;
const int G = 3;
int wn[D<<4], rev[D<<4];
int NTT_init(int pn){
    int step=0; int n = 1;
    for(; n<pn; n<<=1) ++step;
    for(int i=1; i<n; i++) rev[i] = (rev[i>>1]>>1) | ((i&1)<<(step-1));
    int g = qpow(G,(mod-1)/n);
    wn[0] = 1;
    for(int i=1; i<=n; i++) wn[i] = mul(wn[i-1], g);
    return n;
}
void NTT(int a[],int n,int f){
    for(int i=0; i<n; i++){
        if(i<rev[i]) swap(a[i], a[rev[i]]);
    }
    for(int k=1; k<n; k<<=1){
        for(int i=0; i<n; i+=(k<<1)){
            int t = n/(k<<1);
            for(int j=0; j<k; j++){
                int w = (f==1)? wn[t*j]: wn[n-t*j];
                int x = a[i+j];
                int y = mul(a[i+j+k], w);
                a[i+j] = add(x, y);
                a[i+j+k] = sub(x, y);
            }
        }
    }
    if(f == -1){
        int ninv = qpow(n, mod-2);
        for(int i=0; i<n; i++) a[i] = mul(a[i], ninv);
    }
}

const int M = 1e6+10;
int fac[M], inv[M], ifac[M];
void init(int n){
    fac[0]=1;for(int i=1; i<=n; i++)fac[i]=mul(fac[i-1],i);
    inv[1]=1;for(int i=2; i<=n; i++)inv[i]=mul(sub(mod,mod/i),inv[mod%i]);
    ifac[0]=1;for(int i=1; i<=n; i++)ifac[i]=mul(ifac[i-1],inv[i]);
}
int C(int n,int m){
    return (m<0||m>n)? 0: mul(fac[n], mul(ifac[m],ifac[n-m]));
}
const int N = 5e3+10;
int a[N], b[N];
int x[D]{0}, y[D]{0}, ans[D]{0};
int main(){
    int n=read();
    for(int i=1; i<=n; i++){
        a[i]=read(); b[i]=read();
    }
    init(M-1);
    int m=1; ans[0]=1;
    for(int i=1; i<=n; i++){
        int n_m=m+a[i]-b[i];
        for(int j=0; j<m; j++) x[m+j]=ans[j];
        for(int j=max(-b[i],-m); j<=min(a[i],n_m); j++) y[m+j]=C(a[i]+b[i],b[i]+j);
        //cout<<"x:";for(int j=0; j<10; j++) cout<<x[j]<<' '; cout<<endl;
        //cout<<"y:";for(int j=0; j<10; j++) cout<<y[j]<<' '; cout<<endl;
        int len = NTT_init(4*(m+5));
        //cout<<len<<endl;
        NTT(x,len,1);
        NTT(y,len,1);
        for(int j=0; j<=len; j++) x[j]=mul(x[j],y[j]);
        NTT(x,len,-1);
        NTT(y,len,-1);
        //cout<<"after_x:"; for(int j=0; j<10; j++) cout<<x[j]<<' '; cout<<endl;
        for(int j=0; j<m+10; j++) ans[j]=0;
        for(int j=0; j<n_m; j++) ans[j]=x[2*m+j];
        //for(int j=0; j<n_m; j++) cout<<ans[j]<<' '; cout<<endl;
        for(int j=0; j<=len; j++) x[j]=y[j]=0;
        m=n_m;
    }
    int sum=0;
    for(int i=0; i<m; i++) sum=add(sum,ans[i]);
    printf("%d\n",sum);
    return 0;
}