Codeforces Round 854 by cybercats (Div. 1 + Div. 2)
G
Count Voting
Codeforces
2600
原题
← FH →
翻译中…

There are $n$ people that will participate in voting. Each person has exactly one vote.

翻译中…

$i$-th person has a team $t_i$ ($1 \leq t_i \leq n$) where $t_i = t_j$ means $i$, $j$ are in the same team. By the rules each person should vote for the person from the different team. Note that it automatically means that each person can't vote for himself.

翻译中…

Each person knows the number of votes $c_i$ he wants to get. How many possible votings exists, such that each person will get the desired number of votes? Due to this number can be big, find it by modulo $998\,244\,353$.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \leq n \leq 200$) — the number of people.

翻译中…

The second line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($0 \leq c_i \leq n$) — desired number of votes. It is guaranteed, that $\sum\limits_{i=1}^{n} c_i = n$.

翻译中…

The third line contains $n$ integers $t_1, t_2, \ldots, t_n$ ($1 \leq t_i \leq n$) — team numbers.

翻译中…

Output

翻译中…

Print a single integer — the number of possible votings by modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test there are two possible votings: $(2, 3, 1)$, $(3, 1, 2)$.

翻译中…

In the third test there are five possible votings: $(3, 3, 2, 2, 1)$, $(2, 3, 2, 3, 1)$, $(3, 3, 1, 2, 2)$, $(3, 1, 2, 3, 2)$, $(2, 3, 1, 3, 2)$.

翻译中…

样例

Input #1
3
1 1 1
1 2 3
Output #1
2
InputCopy OutputCopy
Input #2
5
2 0 1 0 2
1 2 3 4 5
Output #2
10
InputCopy OutputCopy
Input #3
5
1 2 2 0 0
3 5 4 3 4
Output #3
5
InputCopy OutputCopy
题目信息
题号
1799G
时间限制
1 s
内存限制
256 MB
标签
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。