Between Two Arrays

AtCoder
IDabc222_d
Time2000ms
Memory256MB
Difficulty
A sequence of $n$ numbers, $S = (s_1, s_2, \dots, s_n)$, is said to be _non-decreasing_ if and only if $s_i \leq s_{i+1}$ holds for every $i$ $(1 \leq i \leq n - 1)$. Given are non-decreasing sequences of $N$ integers each: $A = (a_1, a_2, \dots, a_N)$ and $B = (b_1, b_2, \dots, b_N)$. Consider a non-decreasing sequence of $N$ integers, $C = (c_1, c_2, \dots, c_N)$, that satisfies the following condition: * $a_i \leq c_i \leq b_i$ for every $i$ $(1 \leq i \leq N)$. Find the number, modulo $998244353$, of sequences that can be $C$. ## Constraints * $1 \leq N \leq 3000$ * $0 \leq a_i \leq b_i \leq 3000$ $(1 \leq i \leq N)$ * The sequences $A$ and $B$ are non-decreasing. * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $a_1$ $a_2$ $\dots$ $a_N$ $b_1$ $b_2$ $\dots$ $b_N$ [samples]
Samples
Input #1
2
1 1
2 3
Output #1
5

There are five sequences that can be $C$, as follows.

*   $(1, 1)$
*   $(1, 2)$
*   $(1, 3)$
*   $(2, 2)$
*   $(2, 3)$

Note that $(2, 1)$ does not satisfy the condition since it is not non-decreasing.
Input #2
3
2 2 2
2 2 2
Output #2
1

There is one sequence that can be $C$, as follows.

*   $(2, 2, 2)$
Input #3
10
1 2 3 4 5 6 7 8 9 10
1 4 9 16 25 36 49 64 81 100
Output #3
978222082

Be sure to find the count modulo $998244353$.
API Response (JSON)
{
  "problem": {
    "name": "Between Two Arrays",
    "description": {
      "content": "A sequence of $n$ numbers, $S = (s_1, s_2, \\dots, s_n)$, is said to be _non-decreasing_ if and only if $s_i \\leq s_{i+1}$ holds for every $i$ $(1 \\leq i \\leq n - 1)$. Given are non-decreasing sequence",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc222_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A sequence of $n$ numbers, $S = (s_1, s_2, \\dots, s_n)$, is said to be _non-decreasing_ if and only if $s_i \\leq s_{i+1}$ holds for every $i$ $(1 \\leq i \\leq n - 1)$.\nGiven are non-decreasing sequence...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments