Permutation
시간 제한: 1000ms메모리 제한: 512MB출처: USACO 2021 Open GoldBOJ 21816
문제
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 .
입력
The first line contains .
Followed by lines, each containing two space-separated integers and .
출력
The number of permutations modulo .
예제
예제 1
입력
4 0 0 0 4 1 1 1 2
출력
0
예제 2
입력
4 0 0 0 4 4 0 1 1
출력
24
예제 3
입력
5 0 0 0 4 4 0 1 1 1 2
출력
96
코드를 제출하려면 로그인하세요.