QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#13628. 普通的计数题

統計

You have a $01$ sequence, which is initially empty. You can perform two types of operations on the sequence:

  1. Append a $0$ to the end of the sequence.
  2. Delete a subsequence from the sequence and append a $1$ to the end of the sequence. Let the chosen subsequence contain $x$ zeros and $y$ ones. The chosen subsequence must satisfy the following conditions:
    • The subsequence cannot be empty, i.e., $x+y>0$.
    • If $y>0$, then $x \in A$, where $A$ is a given set.
    • If $y=0$, then $x \in B$, where $B$ is a given set.

You need to perform $n$ operations on the sequence. Find the number of different operation sequences such that the final sequence has a length of $1$. Two operation sequences are considered different if and only if the type of operation at some step is different, or if the subsequence chosen in a type-2 operation is different (subsequences are considered different if their positions are different, regardless of their values).

The answer should be modulo $998244353$.

Input

The first line contains three integers $n, |A|, |B|$, representing the number of operations, the size of set $A$, and the size of set $B$, respectively.

The second line contains $|A|$ integers $a_1, a_2, \dots, a_{|A|}$, describing the elements of set $A$.

The third line contains $|B|$ integers $b_1, b_2, \dots, b_{|B|}$, describing the elements of set $B$.

Output

Output a single integer representing the answer.

Examples

Input 1

4 1 1
1
1

Output 1

3

Input 2

10 10 10
0 1 2 3 4 5 6 7 8 9 
0 1 2 3 4 5 6 7 8 9

Output 2

362880

Subtasks

This problem uses bundled testing.

SubtaskScoreConstraints
$1$$5$$n\leq 10$
$2$$20$$n\leq 2000$
$3$$5$$|A|=|B|=n$
$4$$30$$A=B$
$5$$40$No special constraints

For all data, $1\leq n\leq 120000, 0\leq a_i, b_i < n$, all $a_i$ are distinct, and all $b_i$ are distinct.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.