Under construction

Still being built. Things may change

Justice For Everyone

Time limit10sMemory limit512 MB

Summary
Count the orders of pair increments that turn distinct starting numbers a into distinct targets b, keeping all numbers distinct at every step, modulo 998244353.
Level

Hard9 of 10

Topics
Combinatorics, Dynamic programming, Math
Solved
No attempts yet

Problem

Suppose you have nn pairwise different numbers on a desk, denoted by a1,a2,…,ana_1, a_2, \ldots, a_n (order matters). In one turn, you can choose two different indices i1<i2i_1 < i_2 and simultaneously increase ai1a_{i_1} and ai2a_{i_2} by one. The only condition is that the numbers on the desk must be pairwise different at every moment. Your task is to find the number of ways to obtain pairwise different numbers b1,b2,…,bnb_1, b_2, \ldots, b_n (in exactly this order). Since this number can be very large, print it modulo 998 244 353998\,244\,353.

Input

The first line contains a single integer nn (1≤n≤301 \le n \le 30). The second and third lines each contain nn space-separated integers: the arrays aia_i and bib_i, respectively (1≤ai,bi≤2001 \le a_i, b_i \le 200). All aia_i are pairwise different, and so are all bib_i.

Output

Print the answer modulo the prime number 998 244 353998\,244\,353.

Hint

In the first sample, the only way is to perform the operations in the order {2,3},{1,3},{1,2}\{2, 3\}, \{1, 3\}, \{1, 2\}. In the third sample, you can perform the three operations {1,2},{2,3},{1,3}\{1, 2\}, \{2, 3\}, \{1, 3\} in any order.

Examples3

  1. Example 1

    Input
    3
    1 2 3
    3 4 5
    
    Expected output
    1
    
  2. Example 2

    Input
    3
    1 2 3
    7 8 9
    
    Expected output
    42
    
  3. Example 3

    Input
    3
    1 4 7
    3 6 9
    
    Expected output
    6