#USACOC2112C. Permutation

Permutation

Bessie has NN favorite distinct points on a 2D grid, no three of which are collinear. For each 1iN1 \leqslant i \leqslant N, the ii-th point is denoted by two integers xix_i and yiy_i.

Bessie draws some segments between the points as follows.

  1. She chooses some permutation p1,p2,,pNp_1,p_2,\ldots,p_N of the NN points.
  2. She draws segments between p1p_1 and p2p_2, p2p_2 and p3p_3, p3p_3 and p1p_1.
  3. Then for each integer ii from 44 to NN in order, she draws a line segment from pip_i to pjp_j for all j<ij \lt i such that the segment does not intersect any previously drawn segments (aside from at endpoints).

Bessie notices that for each ii, she drew exactly three new segments. Compute the number of permutations Bessie could have chosen on step 1 that would satisfy this property, modulo 109+710^9+7.

  • 3N403 \leqslant N \leqslant 40
  • 0xi,yi1040 \leqslant x_i,y_i \leqslant 10^4

Input Format

The first line contains NN.

Followed by NN lines, each containing two space-separated integers xix_i and yiy_i.

Output Format

The number of permutations modulo 109+710^9+7.

4
0 0
0 4
1 1
1 2
0

No permutations work.

4
0 0
0 4
4 0
1 1
24

All permutations work.

5
0 0
0 4
4 0
1 1
1 2
96

One permutation that satisfies the property is (0,0),(0,4),(4,0),(1,2),(1,1)(0,0),(0,4),(4,0),(1,2),(1,1). For this permutation,

  • First, she draws segments between every pair of (0,0),(0,4),(0,0),(0,4), and (4,0)(4,0).
  • Then she draws segments from (0,0),(0,4),(0,0), (0,4), and (4,0)(4,0) to (1,2)(1,2).
  • Finally, she draws segments from (1,2),(4,0),(1,2), (4,0), and (0,0)(0,0) to (1,1)(1,1). Diagram: Failed loading image file.

The permutation does not satisfy the property if its first four points are (0,0)(0,0), (1,1)(1,1), (1,2)(1,2), and (0,4)(0,4) in some order.

Scoring

  • Test cases 1-6 satisfy N8N \leqslant 8.
  • Test cases 7-20 satisfy no additional constraints.

Problem Credits

Benjamin Qi