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<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 998244353
#define poly vector<int>
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=5e5+11;
int flip[MAXN];
int mul(int x,int y){return 1ll*x*y%mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y>=0?x-y:x-y+mod;}
int ksm(int a,int b){int ans=1;while(b){if(b&1) ans=mul(ans,a);a=mul(a,a);b>>=1;}return ans;}
void print(poly a){for(auto v:a) printf("%d ",v);printf("\n");return;}
void NTT(poly &f,int opt,int Len){
    for(int i=0;i<Len;i++) if(i<flip[i]) swap(f[i],f[flip[i]]);
    for(int p=2;p<=Len;p<<=1){
        int len=(p>>1),buf=ksm(3,(mod-1)/p); if(opt==-1) buf=ksm(buf,mod-2);
        for(int be=0;be<Len;be+=p){
            int tmp=1;
            for(int l=be;l<be+len;l++){
                int t=mul(f[l+len],tmp);
                f[l+len]=sub(f[l],t),f[l]=add(f[l],t);
                tmp=mul(tmp,buf);
            }
        }
    }
    if(opt==-1){
        int Inv=ksm(Len,mod-2); for(int i=0;i<Len;i++) f[i]=mul(f[i],Inv);
    }return;
}
int setN(int siz){
    int cur=1; while(cur<=siz) cur<<=1;
    for(int i=1;i<cur;i++) flip[i]=((flip[i>>1]>>1)|(i&1?cur>>1:0));
    return cur;
}
poly operator*(poly a,poly b){
    int len=a.size()+b.size()-1; int cur=setN(len);
    a.resize(cur),b.resize(cur);
    for(int i=1;i<cur;i++) flip[i]=(flip[i>>1]>>1|(i&1?cur>>1:0));
    NTT(a,1,cur),NTT(b,1,cur);
    for(int i=0;i<cur;i++) a[i]=mul(a[i],b[i]);
    NTT(a,-1,cur); a.resize(len);
    return a;
}
int fac[MAXN],ifac[MAXN],inv[MAXN],N; poly f;
signed main(){
    //freopen("B.in","r",stdin);
    fac[0]=fac[1]=ifac[0]=ifac[1]=inv[1]=1;
    for(int i=2;i<MAXN;i++) fac[i]=mul(fac[i-1],i),inv[i]=mul((mod-mod/i),inv[mod%i]),ifac[i]=mul(ifac[i-1],inv[i]);
    f.pb(0),f.pb(1); N=read();
    while(N--){
        int a=read(),b=read(); int Maxj=a-b+f.size()-1,Maxk=f.size()-1;
        poly g; g.clear();
        int X=INT_MAX;
        for(int i=1-Maxk;i<=Maxj-1;i++){
            if(a-i>=0&&b+i>=0){
                if(X==INT_MAX) X=i;g.pb(mul(ifac[b+i],ifac[a-i]));
            }
        }
        f=f*g;
        for(int i=0;i<f.size();i++) f[i]=mul(f[i],fac[a+b]);
        poly F; F.clear();
        for(int i=0;i<f.size();i++){
            if(X>=0&&X<=Maxj) F.pb(f[i]);
            X++;
        }
        f=F; f[0]=0;
        //print(f);
    } int Ans=0; for(auto v:f) Ans=add(Ans,v);
    printf("%d\n",Ans);return 0;
}