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 io_speed_up ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;} //读整型
template<typename T>void pt(T x,int c=10){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10,-1);putchar(x%10+48);if(c!=-1)putchar(c);}
template<typename T>void umax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void umin(T&x,const T&y){if(x>y)x=y;}
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define for1(i,n) for (int i=1;i<=n;i++)
#define for0(i,n) for (int i=0;i<n;i++)
#define ms(a,b)  memset(a,b,sizeof a)
#define all(n) (n).begin(), (n).end()
#define sz(x) (int)x.size()
#define fi first
#define se second
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<long,long>;
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
const int mod = 998244353;
inline int pow_mod(ll x, int n) {
    ll res;
    for(res = 1; n; n >>= 1, x = x * x % mod)
        if(n & 1)
            res = res * x % mod;
    return res;
}
 
inline int add_mod(int x, int y) {
    x += y;
    return x >= mod ? x - mod : x;
}
 
inline int sub_mod(int x, int y) {
    x -= y;
    return x < 0 ? x + mod : x;
}
 
void NTT(int a[], int n, int op) {
    for(int i = 1, j = n >> 1; i < n - 1; ++i) {
        if(i < j)
            swap(a[i], a[j]);
        int k = n >> 1;
        while(k <= j) {
            j -= k;
            k >>= 1;
        }
        j += k;
    }
    for(int len = 2; len <= n; len <<= 1) {
        int g = pow_mod(3, (mod - 1) / len);
        for(int i = 0; i < n; i += len) {
            int w = 1;
            for(int j = i; j < i + (len >> 1); ++j) {
                int u = a[j], t = 1ll * a[j + (len >> 1)] * w % mod;
                a[j] = add_mod(u, t), a[j + (len >> 1)] = sub_mod(u, t);
                w = 1ll * w * g % mod;
            }
        }
    }
    if(op == -1) {
        reverse(a + 1, a + n);
        int inv = pow_mod(n, mod - 2);
        for(int i = 0; i < n; ++i)
            a[i] = 1ll * a[i] * inv % mod;
    }
}
 
int A[maxn + 5], B[maxn + 5];
 
int pow2(int x) {
    int res = 1;
    while(res < x)
        res <<= 1;
    return res;
}
 
void convolution(int A[], int B[], int Asize, int Bsize) {
    int n = pow2(Asize + Bsize - 1);
    for(int i = Asize; i < n; ++i)
        A[i] = 0;
    for(int i = Bsize; i < n; ++i)
        B[i] = 0;
    NTT(A, n, 1);
    NTT(B, n, 1);
    for(int i = 0; i < n; ++i)
        A[i] = 1ll * A[i] * B[i] % mod;
    NTT(A, n, -1);
    return;
}
const int N = 200002;
ll jc[N+1],inv[N+1];
int C(int x,int y) {
    if(x<y || y<0) return 0;
    return jc[x] * inv[y] % mod * inv[x-y] % mod;
}
int n;
int main() {
    io_speed_up;
    jc[0] = inv[0] = 1;
    rep(i,1,N) jc[i] = jc[i-1]*i%mod;
    inv[N] = pow_mod(jc[N],mod-2);
    per(i,N-1,1) inv[i] = inv[i+1]*(i+1)%mod;
    
    cin>>n;
    A[0] = 1; 
    int Asize = 1;
    rep(i,1,n) {
        int a,b,c;
        cin>>a>>b; c = a+b;
        int sz = Asize + a - b;
        per(i,Asize-1,0) B[i] = C(c,b+i-Asize+1);
        for0(i,sz-1) B[Asize+i] = C(c,b+i+1);
        convolution(A,B,Asize,Asize+sz-1);
        for(int i=0;i<sz;i++) A[i] = A[i+Asize-1];
        Asize = sz;
    }
    int ans = 0;
    for0(i,Asize) ans = add_mod(ans, A[i]);
    cout<<ans<<"\n";
	return 0;
}