Justice For Everyone
Time limit10sMemory limit512 MB
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 pairwise different numbers on a desk, denoted by (order matters). In one turn, you can choose two different indices and simultaneously increase and 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 (in exactly this order). Since this number can be very large, print it modulo .
Input
The first line contains a single integer (). The second and third lines each contain space-separated integers: the arrays and , respectively (). All are pairwise different, and so are all .
Output
Print the answer modulo the prime number .
Hint
In the first sample, the only way is to perform the operations in the order . In the third sample, you can perform the three operations in any order.