Two-row table

Count ways to place fixed and shared numbers into two increasing rows so every column increases downward.

Medium6Dynamic programmingCombinatoricsNo attempts yetTime limit1sMemory limit256 MB

Problem

You are given a positive integer NN. The integers 1,2,3,,2N1, 2, 3, \dots, 2N are split into three sets AA, BB and CC. Count the number of ways to fill a table with two rows and NN columns so that all of the following hold.

  • Each cell of the table holds a single integer.
  • The integers of set AA go in the first row.
  • The integers of set BB go in the second row.
  • The integers of set CC can go in either row.
  • The numbers in each row increase from left to right.
  • The numbers in each column increase from top to bottom.

Every integer from 11 to 2N2N appears in the table exactly once.

For N=4N = 4, A={2,3}A = \{2, 3\}, B={4,7,8}B = \{4, 7, 8\} and C={1,5,6}C = \{1, 5, 6\}, exactly two tables satisfy the conditions.

1 2 3 5
4 6 7 8
1 2 3 6
4 5 7 8

Input

The first line holds the integer NN. (1<N351 < N \le 35)

The second line holds MM, the number of elements of set AA, followed by the elements of AA. (0MN0 \le M \le N)

The third line holds KK, the number of elements of set BB, followed by the elements of BB. (0KN0 \le K \le N)

AA and BB are disjoint, and every element of both sets is an integer between 11 and 2N2N. The elements on a line are not necessarily sorted. The integers that belong to neither AA nor BB form set CC.

Output

Print the number of tables that satisfy the conditions on a single line. Print 00 if no such table exists.