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;

typedef long long ll;

const int INFi = 1e9+67;
const ll INFll = 1e18;

using NumberType = double;

//ll mod = 1e9+7;
ll mod = 998244353;

namespace std {
    template<typename a, typename b>
    struct hash<std::pair<a, b> > {
    public:
        hash() {}
        size_t operator()(const std::pair<a, b> &p) const {
            return hash<a>()(p.first) + hash<b>()(p.second)*998242353;
        }
    };
};

//integer division, correctly works with negative values
pair<ll,ll> divNorm(ll a, ll b) {
    ll res = a/b;
    ll mod = a%b;
    if (mod<0) {
        res--;
        mod+=b;
    }
    return {res, mod};
}

ll divRoundDown(ll a, ll b) {
    auto divRes = divNorm(a,b);
    return divRes.first;
}

ll divRoundUp(ll a, ll b) {
    auto divRes = divNorm(a,b);
    ll res = divRes.first;
    if (divRes.second) {
        res++;
    }
    return res;
}

ll bin_pow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res*=a;
            res %=mod;
        }
        a*=a;
        a %= mod;
        b>>=1;
    }
    return res;
}
ll reverse(ll a) {
    return bin_pow(a,mod-2);
}

template<int mod, int root, int rootPw>
struct FFT {
private:
    ll mul(ll a, ll b) {
        return (a*b) % mod;
    }

    ll bin_pow(ll a, ll b) {
        ll res = 1;
        while (b) {
            if (b & 1) {
                res = mul(res, a);
            }
            a = mul(a,a);
            b>>=1;
        }
        return res;
    }
    ll reverse(ll a) {
        return bin_pow(a,mod-2);
    }
public:
    vector<int> operator()(const vector<int>& a, int n, bool invert) {
        assert(mod==::mod);
        int root_1 = reverse(root);

        int pow2 = 1;
        while (pow2<n) {
            pow2 <<= 1;
        }
        n = pow2;
        vector<int> res(n, 0);
        std::copy(a.begin(), a.end(), res.begin());


        for (int i=1, j=0; i<n; ++i) {
            int bit = n >> 1;
            for (; j>=bit; bit>>=1)
                j -= bit;
            j += bit;
            if (i < j)
                swap (res[i], res[j]);
        }

        for (int len=2; len<=n; len<<=1) {
            int wlen = invert ? root_1 : root;
            for (int i=len; i<rootPw; i<<=1)
                wlen = int (wlen * 1ll * wlen % mod);
            for (int i=0; i<n; i+=len) {
                int w = 1;
                for (int j=0; j<len/2; ++j) {
                    int u = res[i+j],  v = int (res[i+j+len/2] * 1ll * w % mod);
                    res[i+j] = u+v < mod ? u+v : u+v-mod;
                    res[i+j+len/2] = u-v >= 0 ? u-v : u-v+mod;
                    w = int (w * 1ll * wlen % mod);
                }
            }
        }
        if (invert) {
            int nrev = reverse (n);
            for (int i=0; i<n; ++i)
                res[i] = int (res[i] * 1ll * nrev % mod);
        }
        return res;
    }
};

FFT<998244353, 15311432 /*3^(7*17)*/, 1<<23> fft;


using ld = double;

const int maxn = 3e5+7;
//const int maxn2 = maxn*maxn;

//double dp[10][maxn][maxn*maxn];

ll dpL[maxn][2], dpR[maxn][2];

ll fact[maxn], iFact[maxn];

ll C(ll n, ll k) {
    if (n<0 || k<0) return 0;
    if (n<k) return 0;
    ll kekw = fact[n];
    kekw = (kekw*iFact[n-k]) % mod;
    kekw = (kekw*iFact[k]) % mod;
    return kekw;
}

void solve() {
    fact[0] = iFact[0] = 1;
    for (int i=1;i<maxn;i++) {
        fact[i] = (fact[i-1] * i) % mod;
        iFact[i] = reverse(fact[i]);
    }
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<int> ans{1};
    for (int i=0;i<n;i++) {
        int m = ans.size();
        cin >> a[i] >> b[i];
        vector<int> otherToConv;
        for (int j=b[i]-m+1;j<=b[i]+m+a[i]-b[i]-1;j++) {
            otherToConv.push_back(C(a[i]+b[i], j));
        }
        int resLen = m-1 + (m+a[i]-b[i]);
        auto image1 = fft(otherToConv, resLen, false);
        auto image2 = fft(ans, resLen, false);
        for (int i=0;i<image1.size();i++) {
            image1[i] = (((ll) image1[i])*((ll) image2[i])) % mod;
        }
        auto out = fft(image1, resLen, true);
        ans.clear();
        for (int i=m-1;i<resLen;i++) {
            ans.push_back(out[i]);
        }
    }
    ll res = 0;
    for (int i=0;i<ans.size();i++) {
        res += ans[i];
        res %= mod;
    }
    cout << res;


}
int main() {

//        freopen("input.txt","w",stdout);
//        int n = 100'000;
//        for (int i=0;i<n;i++) {
//            cout << 1 << " ";
//        }
//        cout << "\n";
//        for (int i=1;i<n;i++) {
//            cout << 1 << " " << i+1 << "\n";
//        }
//        for (int i=0;i<n;i++) {
//            cout << 200'000 << " ";
//        }
    //    cout << 10 << " " << 0 << "\n";
    //    int starsLeft = 5;
    //    for (int i=0;i<10;i++) {
    //        for (int j=0;j<10;j++) {
    //            int kekw = rand() % 20;
    //            if (kekw==1 && starsLeft) {
    //                cout << "*";
    //                starsLeft--;
    //            } else {
    //                cout << ((char) ('0' + (rand() % 10)));
    //            }
    //        }
    //        cout << "\n";
    //    }
//        return 0;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("input.txt","r",stdin);
    //freopen("output.bin","w",stdout);
    //freopen("/tmp/output.txt","w",stdout);
    cout << setprecision(2) << fixed;
//    int t;
//    cin >> t;
//    for (int i=0;i<t;i++)
        //    ll start = clock();
        //    while (1)
        solve();
    //    double time = (clock() - start) * 1.0 / CLOCKS_PER_SEC;
    //    cout<< time << "s.";
    return 0;
}