#P5343. 【XR-1】分块
【XR-1】分块
Description
There is a sequence of length , and xht37 now wants to maintain it using block decomposition.
PinkRabbit requires that he may only divide the sequence into blocks whose lengths come from allowed lengths.
NaCly_Fish requires that he may only divide the sequence into blocks whose lengths come from allowed lengths.
The same person may request the same block length multiple times.
xht37 wants to satisfy both PinkRabbit and NaCly_Fish, so he has to use block lengths that are allowed by both of them.
xht37 wants to know how many different block decomposition schemes there are. Output the answer modulo .
Input Format
The first line contains a positive integer , which is the length of the sequence.
The second line contains a positive integer , which is the number of allowed block lengths requested by PinkRabbit.
The third line contains positive integers, representing the block lengths requested by PinkRabbit.
The fourth line contains a positive integer , which is the number of allowed block lengths requested by NaCly_Fish.
The fifth line contains positive integers, representing the block lengths requested by NaCly_Fish.
Output Format
Output one line with one integer, which is the number of different block decomposition schemes modulo .
4
3
1 2 3
3
1 2 4
5
19260817
7
8 9 6 3 7 2 1
7
4 5 2 9 7 8 3
859254329
Hint
[Sample Explanation]
The block lengths allowed by both PinkRabbit and NaCly_Fish are .
For a sequence of length , the schemes that divide it into blocks with lengths in are:
There are schemes in total.
[Constraints]
Let the maximum block length be .
For of the testdata, , , and it is guaranteed that the same person will not request the same block length multiple times.
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号