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 <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <complex>

using namespace std;

typedef long long ll;

#define MAXN 600000

const int G = 3, MOD = 998244353;

int L;
int R[MAXN + 10];

int n;
int fac[MAXN + 10], inv[MAXN + 10];

int qpow(int a,int b){
	int ans = 1;
	for (; b; b >>= 1,a = 1ll * a * a % MOD)
		if (b & 1) ans = 1ll * ans * a % MOD;
	return ans;
}

void ntt(int a[], int len, int f){
	for (int i = 0; i < len; i++) if (i < R[i]) swap(a[i],a[R[i]]);
	for (int i = 1; i < len; i <<= 1){
		int gn = qpow(G, (MOD - 1) / (i << 1));
		for (int j = 0; j < len; j += (i << 1)){
			int g = 1;
			for (int k = 0; k < i; k++, g = 1ll * g * gn % MOD){
				int x = a[j + k],y = 1ll * g * a[j + k + i] % MOD;
				a[j + k] = (x + y) % MOD; a[j + k + i] = (x - y + MOD) % MOD;
			}
		}
	}
	if(f == 1) return;
	int nv = qpow(len, MOD - 2); reverse(a + 1, a + len);
	for(int i = 0; i < len; i++) a[i] = 1ll * a[i] * nv % MOD;
}

void NTT(int len, int A[], int B[], int C[]) {
    ntt(A, len, 1);
    ntt(B, len, 1);
    for(int i = 0;i < len; i++) C[i] = 1ll * A[i] * B[i] % MOD;
    ntt(C, len, -1);
}

void init(int up) {
    fac[0] = inv[0] = 1;
    for(int i = 1;i <= up; i++) fac[i] = (1ll * fac[i - 1] * i) % MOD;
    inv[up] = qpow(fac[up], MOD - 2);
    for(int i = up - 1;i >= 1; i--) inv[i] = (1ll * inv[i + 1] * (i + 1)) % MOD;
}

int get_C(int a, int b) {
    if(a < 0 || b < 0 || a > b) return 0;
    return ((1ll * fac[b] * inv[a]) % MOD * inv[b - a]) % MOD;
}


int A[MAXN], B[MAXN],C[MAXN];

int main(){
	scanf("%d", &n);
    A[0] = 1;
    int tot = 0;
    init(600000);
    for(int i = 0;i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        int ntot = tot + a - b;
        int p = 2 * tot + ntot;
        int len;
        L = 0;
        for(len = 1;len <= p; len <<= 1) L++;
        for(int i = 0;i < len; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
        for(int i = 0;i < len; i++) B[i] = 0;
        for(int i = -tot;i <= ntot; i++) B[tot + i] = get_C(b + i, a + b);
        // for(int i = 0;i < len; i++) printf("%d ", A[i]);
        // puts("");
        // for(int i = 0;i < len; i++) printf("%d ", B[i]);
        // puts("");
	    ntt(A, len, 1); ntt(B, len, 1);
        for(int i = 0;i < len; i++) A[i] = 1ll * A[i] * B[i] % MOD;
        ntt(A, len, -1);
        // for(int i = 0;i < len; i++) printf("%d ", A[i]);
        // puts("");
        for(int i = 0;i <= ntot; i++) A[i] = A[i + tot];
        for(int i = ntot + 1;i < len; i++) A[i] = 0;
        tot = ntot;
    }
    int ans = 0;
	for (int i = 0; i <= tot; i++) ans = (ans + A[i]) % MOD;
    printf("%d\n", ans);
	return 0;
}