atcoder#CF16EXHIBITIONFINALA. 1D Matching
1D Matching
Score : points
Problem Statement
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 .
2
0
10
20
30
2
There are two optimal connections: and . In both connections the total length of the cables is .
3
3
10
8
7
12
5
1