#cf16exhibitionfinala. [cf16_exhibition_final_a]1D Matching
[cf16_exhibition_final_a]1D Matching
Problem Statement
#nck { width: 30px; height: auto; }
There are computers and sockets in a one-dimensional world. The coordinate of the -th computer is , and the coordinate of the -th socket is . It is guaranteed that these coordinates are pairwise distinct.
Snuke wants to connect each computer to a socket using a cable. Each socket can be connected to only one computer.
In how many ways can he minimize the total length of the cables? Compute the answer modulo .
Constraints
- The coordinates are integers.
- The coordinates are pairwise distinct.
Input
The input is given from Standard Input in the following format:
: :
Output
Print the number of ways to minimize the total length of the cables, modulo .
Sample Input 1
2
0
10
20
30
Sample Output 1
2
There are two optimal connections: and . In both connections the total length of the cables is .
Sample Input 2
3
3
10
8
7
12
5
Sample Output 2
1