With the help of a computer program, Byteasar has perfected the ways of moving k blocks among n 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 2n blocks numbered 1,2,…,2n and a board of size 2×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:
The first line contains one integer n (1≤n≤1000). The next two lines describe the board. Each of them contains n integers ai (0≤ai≤2n) separated by spaces. The first of these lines is the top row of the board and the second is the bottom row. A 0 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.
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).