QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 256 MB 總分: 100

#11139. Graphs

统计

Your task is to count directed graphs with $n$ vertices (numbered with integers from $1$ to $n$), in which every vertex has an in-degree and out-degree equal to $2$.

We only count simple graphs, i.e., those that do not contain loops or multi-edges, but may simultaneously contain edges $a \to b$ and $b \to a$. Two graphs are considered different if and only if there exists at least one ordered pair of vertices $(a, b)$ such that the edge $a \to b$ exists in exactly one of these graphs.

Since the number of such graphs can be very large, it is sufficient to provide the remainder of the division of their count by a given prime number $p$.

Input

The single line of input contains two integers $n$ and $p$ ($3 \le n \le 500$; $10^8 + 7 \le p \le 10^9 + 7$; $p$ is a prime number).

Output

The output should contain a single integer representing the number of such graphs modulo $p$.

Examples

Input 1

4 1000000007

Output 1

9

Note

For $n = 4$, there are $9$ graphs that satisfy the conditions of the problem.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#846EditorialOpen题解alpha10222026-01-28 02:19:44View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.