#P1988F. Heartbeat
Heartbeat
No submission language available for this problem.
Description
For an array , define
- a prefix maximum as an index such that for all ;
- a suffix maximum as an index such that for all ;
- an ascent as an index () such that .
You are given three cost arrays: , , and .
Define the cost of an array that has prefix maximums, suffix maximums, and ascents as .
Let the sum of costs of all permutations of be . Find , , ..., modulo .
The first line contains an integer ().
The second line contains integers ().
The third line contains integers ().
The fourth line contains integers ().
Print integers: the -th one is modulo .
Input
The first line contains an integer ().
The second line contains integers ().
The third line contains integers ().
The fourth line contains integers ().
Output
Print integers: the -th one is modulo .
Note
In the second example:
- Consider permutation . Indices are prefix maximums. Index is the only suffix maximum. Indices are ascents. In conclusion, it has prefix maximums, suffix maximums, and ascents. Therefore, its cost is .
- Permutation has prefix maximums, suffix maximums, and ascent. Its cost is .
- Permutation has prefix maximums, suffix maximum, and ascent. Its cost is .
- Permutation has prefix maximums, suffix maximums, and ascent. Its cost is .
- Permutation has prefix maximum, suffix maximums, and ascent. Its cost is .
- Permutation has prefix maximum, suffix maximums, and ascents. Its cost is .
The sum of all permutations' costs is , so .