Universal Cup Judging System

Universal Cup

Süre Sınırı: 4.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

You are given a positive integer $N$ and a prime number $P$.

For a permutation $(a_1, a_2, \cdots, a_N)$ of $1, 2, \cdots, N$, define its score $f(a)$ as follows.

$$f(a) = \max\{ia_i \mid i = 1, 2, \cdots, N\}$$

Find the remainder when the sum of the scores over all permutations is divided by $P$.

Input

The first line contains $N, P$ in this order, separated by spaces. ($1 \le N \le 10^4$, $10^8 \le P < 10^9$, $P$ is prime)

Output

Print the remainder when the sum of the scores over all permutations is divided by $P$.

Examples

Sample Input 1

10 100000007

Sample Output 1

77379290

Sample Input 2

1000 998244353

Sample Output 2

168695631

Note

For the first example, for instance, $f(3, 9, 4, 10, 8, 2, 7, 5, 6, 1) = 54$.

The sum of the scores over all $10!$ permutations is $277379304$, and the remainder when this is divided by the prime $P = 10^8 + 7$ is $77379290$, so print $77379290$. Note that for this input, the prime number $P$ is the $9$-digit integer $10^8 + 7$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1531EditorialOpen题解jianglyView

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.