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 REP(i,a,b) for(int i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define PB push_back
#define DB pop_back
#define V(a) vector<a>

static const int N=(1<<20)+5, M=998244353, G=3;
static int fc[N],fci[N],inv[N],rev[N],rt[N];

int powM(int x,int y)
{
    int ans=1;
    while(y)
    {
        if(y&1)
            ans=1LL*ans*x%M;
        x=1LL*x*x%M;
        y>>=1;
    }
    return ans;
}

void fft(V(ll) &a,ll n,bool invert)
{
    for(int i=1; i<n; i++)
    {
        if(rev[n+i]>i)
        {
            swap(a[i],a[rev[n+i]]);
        }
    }
    for(int s=1; s<n; s<<=1)
    {
        ll y=powM(G, (M-1)/(s<<1) );
        for(int j=0; j<n; j+=(s<<1))
        {
            ll r=1;
            for(int i=0; i<s; i++)
            {
                ll u=a[i+j];
                ll v=(r*a[i+j+s])%M;

                a[i+j]=u+v;
                if(a[i+j]>M) a[i+j]-=M;

                a[i+j+s]=u-v;
                if(a[i+j+s]<0) a[i+j+s]+=M;

                r*=y;
                r%=M;
            }
        }
    }
    if(invert)
    {
        int invn=inv[n];
        REP(i,0,n)
        {
            a[i]=(a[i]*invn)%M;
        }
        reverse(a.begin()+1,a.end());
    }
    return;
}

void PolyMult(V(ll) &a,V(ll) &b,V(ll) &v)
{
    ll n=1;
    while(n<((ll)a.size())+((ll)b.size()))
    { 
        n<<=1;
    }
    V(ll) fa(a.begin(),a.end());
    fa.resize(n,0);
    V(ll) fb(b.begin(),b.end());
    fb.resize(n,0);
    // cout<<"fa"<<endl;
    // for(auto it:fa) cout<<it<<' ';cout<<endl;
    // cout<<"fb"<<endl;
    // for(auto it:fb) cout<<it<<' ';cout<<endl;
    fft(fa,n,false);
    fft(fb,n,false);
    // cout<<"fa"<<endl;
    // for(auto it:fa) cout<<it<<' ';cout<<endl;
    // cout<<"fb"<<endl;
    // for(auto it:fb) cout<<it<<' ';cout<<endl;
    v.resize(n,0);
    REP(i,0,n)
    {
        v[i]=((fa[i]*fb[i])%M);
    }
    // cout<<"v"<<endl;
    // for(auto it:v) cout<<it<<' ';cout<<endl;
    fft(v,n,true);
    // cout<<"v"<<endl;
    // for(auto it:v) cout<<it<<' ';cout<<endl;
    v.resize(((ll)a.size())+((ll)b.size())-1,0LL);
    // cout<<"v"<<endl;
    // for(auto it:v) cout<<it<<' ';cout<<endl;
    return;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    fc[0]=1;
    REP(i,1,N) fc[i] = 1LL*fc[i-1]*i % M;

    fci[N-1]=powM(fc[N-1], M-2);
    REPI(i,0,N-1) fci[i] = 1LL*fci[i+1]*(i+1) % M;

    REP(i,1,N) inv[i] = 1LL*fci[i]*fc[i-1]%M;

    rev[1]=0;
    for(int s=2; (s<<1)<=N; s<<=1)
    {
        for(int i=0; i<(s>>1); i++)
        {
            rev[s+i]=(rev[(s>>1)+i]<<1);
            rev[s+(s>>1)+i]=((rev[(s>>1)+i]<<1)|1);
        }
    }

    ll n;
    cin>>n;
    V(ll) v={1};
    while(n--)
    {
        ll a,b;
        cin>>a>>b;

        ll nv=v.size();

        // cout<<a<<' '<<b<<endl;
        // for(auto it:v) cout<<it<<' ';cout<<endl;

        V(ll) tmp(2*nv+a-b,0LL);
        REP(i,b-nv,a+nv)
        {
            if(i>=0&&i<=a+b)
            {
                tmp[i-(b-nv)]=1LL*fc[a+b]*fci[i]%M*fci[a+b-i]%M;
            }
        }

        // cout<<a<<' '<<b<<endl;
        // for(auto it:tmp) cout<<it<<' ';cout<<endl;

        V(ll) ans;
        PolyMult(v,tmp,ans);

        // cout<<a<<' '<<b<<endl;
        // for(auto it:ans) cout<<it<<' ';cout<<endl;

        V(ll) newv(nv+a-b,0LL);
        REP(i,0,nv+a-b)
        {
            newv[i]=ans[i+nv];
        }

        // cout<<a<<' '<<b<<endl;
        // for(auto it:newv) cout<<it<<' ';cout<<endl;

        v=newv;
    }

    ll ans=0;
    for(auto it:v) ans = (ans+it)%M;
    cout<<ans;

    return 0;
}