Problem Statement
You are going to create $N$ sequences of length $3$, satisfying the following conditions.
- For each of
$k = 1,2,3$, the following holds: - Among the
$k$-th elements of the sequences, each integer from$1$through$N$appears exactly once.
For this sequence of sequences, define sequences $a=(a_1,a_2,\ldots,a_N)$ and $b=(b_1,b_2,\ldots,b_N)$ as follows.
- Let
$s_i$be the$i$-th sequence, and let$t_i$be the reverse of the$i$-th sequence. When all of these are sorted in lexicographical order,$s_i$comes$a_i$-th, and$t_i$comes$b_i$-th. - Here, if there are identical sequences among the
$2N$sequences,$a$and$b$are not defined.
Therefore, if $a$ and $b$ are defined, each integer from $1$ through $2N$ appears exactly once in the concatenation of $a$ and $b$.
You are given sequences $A$ and $B$ of length $N$, where each element of $A$ is an integer between $1$ and $2N$, and each element of $B$ is either an integer between $1$ and $2N$ or $-1$. Also, in the concatenation of $A$ and $B$, each integer other than $-1$ appears at most once.
How many pairs of sequences $a,b$ are there such that $a$ and $b$ are defined and the following holds for each integer $i$ from $1$ through $N$?
$a_i = A_i$.$b_i = B_i$if$B_i \neq -1$.
Find the count modulo $998244353$.
Constraints
$2 \leq N \leq 3000$$1 \leq A_i \leq 2N$$1 \leq B_i \leq 2N$or$B_i = -1$.- In the concatenation of
$A$and$B$, each integer other than$-1$appears at most once. That is, $A_i \neq A_j$if$i \neq j$.$B_i \neq B_j$if$i \neq j$and$B_i,B_j \neq -1$.$A_i \neq B_j$.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
Output
Print the count modulo $998244353$.
样例
3
2 3 6
-1 1 -1
1
15
5 16 1 12 30 20 4 13 9 8 24 21 26 28 17
-1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 29 -1 -1 -1
758094847
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。