QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#10993. Permutations

الإحصائيات

A permutation^{1} $p$ of a set $m$ is called an involution if $p(p(i)) = i$ for each $i ∈ M$.

By a bracket expression of length $2n$ we mean a word of length $2n$ consisting only of the characters '(' and ')'. A bracket expression is called correct if the number of opening brackets in the expression equals the number of closing brackets and in every prefix of the expression the number of the characters '(' is no less than the number of characters ')'.

We say that a permutation $p$ of length $2n$ encodes a bracket expression of length $2n$, if opening brackets of the expression (from left to right) are located at positions $p(1), p(2), \ldots, p(n)$, and closing brackets - also from left to right - at positions $p(n+1), p(n+2), \ldots, p(2n)$. In particular, in such a case both $p(1) < p(2) < \ldots < p(n)$ and $p(n+1) < p(n+2) < \ldots < p(2n)$ hold.

The values of a permutation $p$ for several arguments are known. It should be determined in how many ways the remaining values of p can be determined in such a way that it is an involution and it encodes a correct bracket expression.

^{1}. A permutation of a set $M = \{1, 2, 3, \ldots, m\}$ is any one-to-one function $p : M → M$.

Input Format

The first line of the standard input contains two integers $n$ and $k$ ($1 ≤ n ≤ 1\,000\,000$, $1 ≤ k ≤ 2n$) separated by a single space. Each of the following $k$ lines contains one pair of space-separated integers; the $i^{\text{th}}$ of these lines contains numbers $a_{i}$ and $b_{i}$ ($1 ≤ a_{i}, b_{i} ≤ 2n$), meaning that $p(a_{i}) = b_{i}$. All values $a_{i}$ are distinct and all values $b_{i}$ are distinct.

Output Format

The first and only line of the standard output should contain a single integer: the number of permutations of the set $\{1, 2, 3, \ldots, 2n\}$ that: are involutions, encode some correct bracket expression, and for which $p(a_{i}) = b_{i}$ holds for each $1 ≤ i ≤ k$.

Example

Input

3 4
1 1
2 2
4 3
6 6

Output

1

The only permutation that complies with requirements of the task is <1, 2, 4, 3, 5, 6>, and it encodes the following bracket expression: (()()).

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.