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>
//#define int long long
#define ll long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;

using namespace std;

const int C = 998244353;
vector<ll> fact, minus_fact;

ll pow1(ll x, ll y, ll z=C){
    if (y == 0){
        return 1;
    }
    if (y % 2 == 0){
        return pow1(x*x % z, y/2, z);
    }
    return pow1(x, y-1, z)*x % z;
}

void facts(int n){
    fact = {1}, minus_fact = {1};
    for (int q = 1; q <= n; q++){
        fact.push_back(fact.back()*q % C);
        minus_fact.push_back(minus_fact.back()*pow1(q, C-2) % C);
    }
}

ll c(int k, int n){
    if (k < 0 || k > n){
        return 0;
    }
    return fact[n]*minus_fact[k] % C*minus_fact[n-k] % C;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    facts(200179);
    int n;
    cin >> n;
    vector<p> a(n);
    for (int q = 0; q < n; q++){
        cin >> a[q].first >> a[q].second;
    }
    vector<int> now = {1};
    for (int q = 0; q < n; q++){
        int w3 = (now.size()+a[q].first+a[q].second+1)/2, w4 = now.size()+a[q].first+a[q].second;
        vector<__int128> will(w3-a[q].second, 0);
        vector<ll> cc(now.size()+a[q].first);
        for (int q1 = 0; q1 < cc.size(); q1++){
            cc[q1] = c(q1, a[q].first+a[q].second);
        }
        for (int q1 = a[q].second; q1 < w3; q1++){
            int w = min(q1+1, (int)now.size()), w1 = q1-a[q].second, w2 = max(0, q1-a[q].first-a[q].second);
            for (int q2 = w2; q2 < w; q2++){
                will[w1] += cc[q1-q2]*now[q2];
            }
        }
        now = {};
        for (__int128 q1: will){
            now.push_back(q1 % C);
        }
        for (int q1 = (int)now.size()-1-w4 % 2; q1 > -1; q1--){
            now.push_back(now[q1]);
        }
    }
    ll ans = 0;
    for (int q: now){
        ans += q;
    }
    cout << ans % C << endl;
    return 0;
}