#P7529. [USACO21OPEN] Permutation G
[USACO21OPEN] Permutation G
Description
Bessie has favorite distinct points on the 2D plane, and no three points are collinear. For each , the -th point is given by two integers and .
Bessie draws some line segments among these points in the following way:
-
- She chooses a permutation of the points.
-
- She draws line segments between and , between and , and between and .
-
- Then, for each integer from to in order, and for every , she draws a line segment from to as long as this segment does not intersect any previously drawn segment (intersection at endpoints is allowed).
Bessie notices that for every , she draws exactly three new line segments. Compute the number of permutations she can choose in Step 1 that satisfy the property above, modulo .
Input Format
The first line contains .
The next lines each contain two space-separated integers and .
Output Format
Output one integer: the number of valid permutations modulo .
4
0 0
0 4
1 1
1 2
0
4
0 0
0 4
4 0
1 1
24
5
0 0
0 4
4 0
1 1
1 2
96
Hint
Explanation for Sample 1
No permutation satisfies the property.
Explanation for Sample 2
All permutations satisfy the property.
Explanation for Sample 3
One valid permutation is . For this permutation,
- First, she draws line segments between each pair among , , and .
- Then she draws segments from to , , and .
- Finally, she draws segments from to , , and .

Constraints
, .
Translated by ChatGPT 5
京公网安备 11011102002149号