#P1799G. Count Voting

Count Voting

No submission language available for this problem.

Description

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

ii-th person has a team tit_i (1tin1 \leq t_i \leq n) where ti=tjt_i = t_j means ii, jj 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 cic_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 998244353998\,244\,353.

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

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

The third line contains nn integers t1,t2,,tnt_1, t_2, \ldots, t_n (1tin1 \leq t_i \leq n) — team numbers.

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

Input

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

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

The third line contains nn integers t1,t2,,tnt_1, t_2, \ldots, t_n (1tin1 \leq t_i \leq n) — team numbers.

Output

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

Sample Input 1

3
1 1 1
1 2 3

Sample Output 1

2

Sample Input 2

5
2 0 1 0 2
1 2 3 4 5

Sample Output 2

10

Sample Input 3

5
1 2 2 0 0
3 5 4 3 4

Sample Output 3

5

Note

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

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