Returning Blocks

No attempts yetTime limit1sMemory limit128 MB

Problem

With the help of a computer program, Byteasar has perfected the ways of moving kk blocks among nn drawers. Unfortunately, many other people can do the same, so to catch Bytie's attention he must come up with a more elaborate trick.

This time Byteasar has 2n2n blocks numbered 1,2,,2n1, 2, \ldots, 2n and a board of size 2×n2 \times n. He places some of the blocks on the board, one block per cell. He now wonders in how many different ways he can place the remaining blocks on the empty cells so that in every row and every column the block numbers appear in increasing order.

Write a program that:

  • reads the size of the board and the placement of the blocks already on it from standard input,
  • computes the number of ways to place the remaining blocks,
  • writes the result to standard output.

Input

The first line contains one integer nn (1n10001 \le n \le 1000). The next two lines describe the board. Each of them contains nn integers aia_i (0ai2n0 \le a_i \le 2n) separated by spaces. The first of these lines is the top row of the board and the second is the bottom row. A 00 means the cell is empty, and a positive value is the number of the block placed on that cell. Each block appears on the board at most once.

Output

Print one integer: the number of ways to place the remaining blocks on the board. The block numbers must increase along every row (from left to right) and along every column (from top to bottom).