
Alin and Blin are playing a game called Palatro. They share a deck of cards labeled through . Alin writes the number on card , and Blin writes the number on card . Each player must write every number from to on exactly one card (thus and are permutations).
Clin is the referee of the game. He decides the order in which the two players must reveal their cards, giving requests of the form:
"Show the card with index ", then "Show the card with index ", and so on. Here represents a permutation of the numbers from to .
At the beginning, Clin considers the first card shown () to be the winning card. Each time a new card is revealed, Clin checks the numbers written on it: if both Alin’s number and Blin’s number are greater than those on the current winning card, then card becomes the new winning card.
More formally, Clin uses the following algorithm to determine the winning card:
winner = C[1]
for i=2...N:
if A[C[i]] > A[winner] and B[C[i]] > B[winner]:
winner = C[i]
Task
For each from to , determine in how many distinct ways Clin can give the requests such that the winning card is card . Since the answer may be very large, output it modulo .
Input data
The first line contains the integer .
The second line contains integers, the elements of permutation .
The third line contains integers, the elements of permutation .
Output data
Print integers, separated by spaces, the answer for each .
Restrictions
- .
| # | Points | Restrictions |
|---|---|---|
| 1 | 6 | and |
| 2 | 6 | |
| 3 | 14 | |
| 4 | 13 | |
| 5 | 16 | and are generated uniformly at random |
| 6 | 24 | |
| 7 | 21 | No additional restrictions |
Example
stdin
3
2 1 3
3 2 1
stdout
4 0 2
Explanation
At the end of the algorithm,
At the end of the algorithm,
At the end of the algorithm,
At the end of the algorithm,
At the end of the algorithm,
At the end of the algorithm,