All the DMOJ admins have come together to organize the Don Mills Programming Gala, an event where contestants come to Don Mills C. I. and show off their programming skills! The organizers have discovered that, this year, everybody is competing in a pair. To help organize the Gala,
will draw a diagram of which contestants are partners.On dots on a line representing the contestants, which have been numbered from
on the left to
on the right. No two points are on top of each other, and
is always even. can use a compass to connect pairs of dots in the diagram by drawing a perfect semicircle which begins at one dot and ends at another. These semicircles can only be drawn strictly above the line of points.
semicircles in red ink such that no two intersect. is able to erase any subset of the semicircles drawn in red, but he is only able to draw new semicircles in gray.
What is the number of distinct ways to complete semicircles drawn, every point has been connected to a different point, and no two semicircles intersect with each other. Two ways are considered distinct if two points are connected in one way while they are not in the other, or if two points are connected with the colour red in one way while they are connected with gray in the other.
Since your answer may be extremely large, output it modulo .
Constraints
For all subtasks:
is an even number.
No two semicircles initially given will intersect with each other.
Subtask 1 [5%]
Subtask 2 [5%]
Subtask 3 [10%]
Subtask 4 [20%]
Subtask 5 [20%]
Subtask 6 [30%]
Subtask 7 [10%]
Input Specification
The first line will contain a single integer, .
The following line will contain a single integer, .
The following lines will each contain two space-separated integers,
and
, where
and
represents a red semicircle which connects point
to point
. It is guaranteed that all values of
and
will be distinct, and that no two semi-circles will intersect.
Output Specification
Output a single integer, the number of ways to complete the diagram modulo
.
Sample Input 1
6
1
1 6
Sample Output 1
7
Explanation for Sample 1
There are six points on the line, with one semicircle already drawn from point (the leftmost point) to point
(the rightmost point). If we do not erase this initial semicircle, then there are two ways to complete the diagram. If we do erase it, then there are five ways.
Sample Input 2
4
1
1 3
Sample Output 2
2
Explanation for Sample 2
There is no way to complete the diagram if we do not erase the part already drawn. Points and
cannot be connected without intersecting with the connection between
and
. Therefore, we must erase the initially drawn semicircle, and this creates
ways to complete the diagram.
Sample Input 3
6
2
1 2
3 4
Sample Output 3
10
Explanation for Sample 3
There are four cases: erase nothing for way to complete the diagram, erase only the left semicircle
for
ways, erase only the right semicircle
for
ways, or erase them both for
ways. This results in
ways.
Sample Input 4
2
0
Sample Output 4
1
Comments