#5145. Problem 3. Permutation
Problem 3. Permutation
Problem 3. Permutation
USACO 2021 US Open, Gold
Bessie has () favorite distinct points on a 2D grid, no three of which are collinear. For each , the -th point is denoted by two integers and ().
Bessie draws some segments between the points as follows.
- She chooses some permutation of the points.
- She draws segments between and , and , and and .
- Then for each integer from to in order, she draws a line segment from to for all such that the segment does not intersect any previously drawn segments (aside from at endpoints).
Bessie notices that for each , she drew exactly three new segments. Compute the number of permutations Bessie could have chosen on step 1 that would satisfy this property, modulo .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains .
Followed by lines, each containing two space-separated integers and .
OUTPUT FORMAT (print output to the terminal / stdout):
The number of permutations modulo .
SAMPLE INPUT:
4 0 0 0 4 1 1 1 2
SAMPLE OUTPUT:
0
No permutations work.
SAMPLE INPUT:
4 0 0 0 4 4 0 1 1
SAMPLE OUTPUT:
24
All permutations work.
SAMPLE INPUT:
5 0 0 0 4 4 0 1 1 1 2
SAMPLE OUTPUT:
96
One permutation that satisfies the property is For this permutation,
- First, she draws segments between every pair of and .
- Then she draws segments from and to .
- Finally, she draws segments from and to .
Diagram:
The permutation does not satisfy the property if its first four points are , , , and in some order.
SCORING: Test cases 1-6 satisfy .Test cases 7-20 satisfy no additional constraints.
Problem credits: Benjamin Qi