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 pb push_back
#define fi first
#define se second
#define sz(x)  (int)x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , 0x3f , sizeof(x))
#define debug(x)  cerr << #x << " = " << x << '\n'
#define ddebug(x , y)  cerr << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int maxn = 2e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ; 
const int mod = 998244353 ;
struct NTT
{
    int n , m ;
    ll a[maxn << 2] , b[maxn << 2] ;
    ll up , l ;
    ll pos[maxn << 2] ;
    ll powmod(ll a , ll b)
    {
        ll ans = 1 ;
        while(b)
        {
            if(b & 1)  ans = ans * a % mod ;
            a = a * a % mod ;
            b >>= 1 ;
        }
        return ans ;
    }
    void init(int n , int m) 
    {
        up = 1 , l = 0 ;
        while(up < (n + m))  up <<= 1 , l ++ ;
        rep(i , 0 , up - 1)  pos[i] = (pos[i >> 1] >> 1) | ((i & 1) << (l - 1)) , a[i] = b[i] = 0 ;
    }
    void solve(ll *a , int mode)
    {
        rep(i , 0 , up - 1)  if(i < pos[i])  swap(a[i] , a[pos[i]]) ;
        for(int i = 1 ; i < up ; i <<= 1)
        {
            ll gn = powmod(3 , (mod - 1) / (i << 1)) ; 
            if(mode == -1)  gn = powmod(gn , mod - 2) ;
            for(int j = 0 ; j < up ; j += (i << 1))
            {
                ll g = 1 ;
                for(int k = 0 ; k < i ; k ++ , g = g * gn % mod)
                {
                    ll x = a[j + k] , y = g * a[j + k + i] % mod ;
                    a[j + k] = (x + y) % mod , a[j + k + i] = (x - y + mod) % mod ;
                }
            }
        }
        if(mode == -1) 
        {
            ll invup = powmod(up , mod - 2) ;
            rep(i , 0 , up - 1)  a[i] = a[i] * invup % mod ;
        }
    }
} ntt ; 
struct Easymath
{
    ll qpow(ll a , ll b) //快速幂
    {
        if(b < 0)  return 0 ;
        ll ans = 1 ; 
        a %= mod ;
        while(b)
        {
            if(b & 1)  ans = (ans * a) % mod ;
            b >>= 1 , a = (a * a) % mod ;
        }
        return ans % mod ;
    }
    ll ksc_log(ll x , ll y , ll mod) //快速乘
    {
        x %= mod , y %= mod ;
        ll ans = 0;
        while(y)
        {
            if(y & 1) ans = (ans + x) % mod ; 
            y >>= 1 ;
            x = (x + x) % mod ;
        }
        return ans;
    }
    ll ksc_O1(ll x , ll y , ll mod) //快速乘
    {
        x %= mod , y %= mod ;
        ll z = (ld)x * y / mod ;
        ll ans = x * y - z * mod ;
        if(ans < 0)  ans += mod ;
        else if(ans >= mod)  ans -= mod ;
        return ans ;
    }
    int cnt = 0 ;
    bool vis[maxn] ;
    int prime[maxn] ;
    void get_prime(int up) //素数筛
    {
        memset(vis , 0 , sizeof(vis)) ;
        vis[1] = 1 ;
        for(int i = 2 ; i <= up ; i ++)
        {
            if(!vis[i]) 
            prime[++ cnt] = i ;
            for(int j = 1 ; j <= cnt && i * prime[j] <= up ; j ++)
            {
                vis[i * prime[j]] = 1 ;
                if(i % prime[j] == 0) break ;
            }
        }
    }
    //begin 判定大素数
    ll mul(ll a , ll b , ll mod)
    {
        ll ret = 0 ;
        while(b) 
        {
            if(b & 1)  ret = (ret + a) % mod ;
            a = (a + a) % mod ;
            b >>= 1 ;
        }
        return ret ;
    }
    ll pow(ll a , ll b , ll mod)
    {
        ll ret = 1 ;
        while(b) 
        {
            if(b & 1)  ret = mul(ret , a , mod) ;
            a = mul(a , a , mod) ;
            b >>= 1 ;
        }
        return ret ;
    }
    bool check(ll a , ll n)
    {
        ll x = n - 1 ;
        int t = 0 ;
        while((x & 1) == 0) 
        {
            x >>= 1 ;
            t ++ ;
        }
        x = pow(a , x , n) ;
        ll y ;
        rep(i , 1 , t)
        {
            y = mul(x , x , n) ;
            if(y == 1 && x != 1 && x != n - 1)  return 1 ;
            x = y ;
        }
        if(y != 1) return 1 ;
        return 0 ;
    }
    bool Miller_Rabin(ll n) 
    {
        if(n == 2)  return 1 ;
        if(n == 1 || !(n & 1))  return 0 ;
        const int arr[12] = {2,3,5,7,11,13,17,19,23,29,31,37} ;
        rep(i , 0 , 11) 
        {
            if(arr[i] >= n) break ;
            if(check(arr[i] , n)) return 0 ;
        }
        return 1 ;
    }
    //end 判定大素数
    ll get_inv(ll x) //逆元
    {
       return qpow(x , mod - 2) % mod ;
    }
    ll inv1[maxn] ;  //乘法逆元
    void init1(int up)
    {
       inv1[1] = 1 ;
       for(int i = 2 ; i <= up ; i ++)
         inv1[i] = (ll)(mod - mod / i) * inv1[int(mod % (ll)i)] % mod ;
    }
    ll fac[maxn] ;
    ll inv[maxn] ; //阶乘逆元
    void init(int up) 
    {
       fac[0] = fac[1] = inv[0] = inv[1] = 1 ;
       for(int i = 2 ; i <= up ; i ++)
       {
         fac[i] = fac[i - 1] * i % mod ;
         inv[i] = -inv[mod % i] * (mod / i) % mod ;
         while(inv[i] < 0) inv[i] += mod ;
       }
       for(int i = 2 ; i <= up ; i ++)  
         inv[i] = inv[i] * inv[i - 1] % mod ;
    }
    ll C(int n , int m)
    {
        if(m < 0 || n < m)  return 0 ;
        return fac[n] * inv[m] % mod * inv[n - m] % mod ;
    }
} em ;
int main()
{
    ios ;
    int n ;
    cin >> n ;
    vector<int> dp(10005 , 0) ;
    em.init(200000) ;
    int m = 1 ;
    dp[1] = 1 ;
    while(n --)
    {
        int a , b ;
        cin >> a >> b ;
        ntt.init(m + 1 , m + a - b - 1 + m + 1) ;
        for(int i = 1 ; i <= m ; i ++)  ntt.a[i] = dp[i] ;
        for(int i = 1 ; i <= m + a - b - 1 + m ; i ++)  ntt.b[i] = em.C(a + b , b + i - m) ;
        ntt.solve(ntt.a , 1) ;
        ntt.solve(ntt.b , 1) ;
        rep(i , 0 , ntt.up - 1)  ntt.a[i] *= ntt.b[i] , ntt.a[i] %= mod ;
        ntt.solve(ntt.a , -1) ;
        for(int i = 1 ; i <= m + a - b ; i ++)  dp[i] = ntt.a[i + m] ;
        m += a - b ;
    }
    long long ans = 0 ;
    for(int i = 1 ; i <= m ; i ++)  ans += dp[i] , ans %= mod ;
    cout << ans << '\n' ;
    return 0 ;
}