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;
const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;

#ifdef VIPJML_LOCAL
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << *vi;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const vector<pair<A, B>> &v)
{
    os << "{";
    for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << '(' << vi->first << " " << vi->second << ")";
    }
    os << "}";
    return os;
}

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using LL = long long;

struct Mint
{
    long long v;
    Mint() : v(0) {}
    Mint(long long t)
    {
        v = t % MOD;
        if (v < 0)
            v += MOD;
    }

    Mint pow(long long k)
    {
        Mint res(1), tmp(v);
        while (k)
        {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    Mint inv() { return pow(MOD - 2); }

    Mint &operator+=(Mint a)
    {
        v += a.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    Mint &operator-=(Mint a)
    {
        v += MOD - a.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    Mint &operator*=(Mint a)
    {
        v = v * a.v % MOD;
        return *this;
    }
    Mint &operator/=(Mint a) { return (*this) *= a.inv(); }

    Mint operator+(Mint a) const { return Mint(v) += a; }
    Mint operator-(Mint a) const { return Mint(v) -= a; }
    Mint operator*(Mint a) const { return Mint(v) *= a; }
    Mint operator/(Mint a) const { return Mint(v) /= a; }

    Mint operator-() const { return v ? Mint(MOD - v) : Mint(v); }

    bool operator==(const Mint a) const { return v == a.v; }
    bool operator!=(const Mint a) const { return v != a.v; }
    bool operator<(const Mint a) const { return v < a.v; }

    static Mint comb(long long n, int k)
    {
        Mint num(1), dom(1);
        for (int i = 0; i < k; i++)
        {
            num *= Mint(n - i);
            dom *= Mint(i + 1);
        }
        return num / dom;
    }

    static Mint inv(int n)
    {
        return Mint(n).inv();
    }

    static vector<Mint> getInvArray(int N)
    {
        vector<Mint> inv(N + 1, 1);
        for (int i = 2; i <= N; i++)
            inv[i] = inv[MOD % i] * (MOD - MOD / i);
        return inv;
    }
};

ostream &operator<<(ostream &os, Mint m)
{
    os << m.v;
    return os;
}

namespace NTT
{
    const int G = 3;

    vector<Mint> ntt(vector<Mint> d, bool inv = false)
    {
        int N = 1;
        while (N < d.size())
            N *= 2;
        d.resize(N);
        Mint base = Mint(G).pow((MOD - 1) / N);
        if (!inv)
        {
            base = base.inv();
        }

        vector<Mint> pp(N + 1);
        pp[0] = 1;
        for (int i = 1; i < N; i++)
        {
            pp[i] = pp[i - 1] * base;
        }

        for (int i = 0, j = 0; i < N - 1; i++)
        {
            if (i < j)
            {
                swap(d[i], d[j]);
            }
            int k = N >> 1;
            while (k <= j)
            {
                j -= k;
                k >>= 1;
            }
            j += k;
        }
        for (int len = 1; len * 2 <= N; len <<= 1)
        {
            for (int i = 0; i + len * 2 <= N; i += len * 2)
            {
                int dd = N / 2 / len;
                for (int j = 0; j < len; j++)
                {
                    Mint t = d[i + j + len] * pp[dd * j];
                    d[i + j + len] = d[i + j] - t;
                    d[i + j] += t;
                }
            }
        }
        if (inv)
        {
            Mint invN = Mint::inv(N);
            for (int i = 0; i < N; i++)
                d[i] = d[i] * invN;
        }
        return d;
    }
    vector<Mint> conv(vector<Mint> d1, vector<Mint> d2)
    {
        int num = d1.size() + d2.size() - 1;
        d1.resize(num), d2.resize(num);
        auto t1 = ntt(d1);
        auto t2 = ntt(d2);
        vector<Mint> tmp(t1.size());
        for (int i = 0; i < t1.size(); i++)
            tmp[i] = t1[i] * t2[i];
        auto r = ntt(tmp, true);
        r.resize(num);
        return r;
    }
} // namespace NTT

void solve(int caseNum)
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i];
    vector<Mint> r(1, 1);
    auto inv = Mint::getInvArray(2e5);
    vector<Mint> P(2e5 + 1, 1);
    vector<Mint> IP(2e5 + 1, 1);
    for (int i = 2; i < P.size(); i++)
    {
        P[i] = P[i - 1] * i;
        IP[i] = IP[i - 1] * inv[i];
    }

    for (int i = 0; i < n; i++)
    {
        int s = max(0, b[i] - (int)r.size() + 1);
        int e = min(a[i] + (int)r.size() - 1, a[i] + b[i]);
        vector<Mint> x(e - s + 1);
        for (int j = s; j <= e; j++)
        {
            x[j - s] = P[a[i] + b[i]] * IP[j] * IP[a[i] + b[i] - j];
        }
        auto t = NTT::conv(r, x);
        int t1 = b[i] - s;
        int t2 = min(a[i] + (int)r.size() - 1 - s, (int)t.size() - 1);
        r.resize(t2-t1+1);
        for (int j = t1; j <= t2;j++)
        {
            r[j-t1]=t[j];
        }
    }
    Mint sum;
    for (auto t : r)
        sum += t;
    cout << sum.v << endl;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    int T = 1;
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve(i);
    }
    cout.flush();
    return 0;
}