CF1439D.INOI Final Contests

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Today is the final contest of INOI (Iranian National Olympiad in Informatics). The contest room is a row with nn computers. All computers are numbered with integers from 11 to nn from left to right. There are mm participants, numbered with integers from 11 to mm .

We have an array aa of length mm where aia_{i} ( 1ain1 \leq a_i \leq n ) is the computer behind which the ii -th participant wants to sit.

Also, we have another array bb of length mm consisting of characters 'L' and 'R'. bib_i is the side from which the ii -th participant enters the room. 'L' means the participant enters from the left of computer 11 and goes from left to right, and 'R' means the participant enters from the right of computer nn and goes from right to left.

The participants in the order from 11 to mm enter the room one by one. The ii -th of them enters the contest room in the direction bib_i and goes to sit behind the aia_i -th computer. If it is occupied he keeps walking in his direction until he reaches the first unoccupied computer. After that, he sits behind it. If he doesn't find any computer he gets upset and gives up on the contest.

The madness of the ii -th participant is the distance between his assigned computer ( aia_i ) and the computer he ends up sitting behind. The distance between computers ii and jj is equal to ij|i - j| .

The values in the array aa can be equal. There exist nm2mn^m \cdot 2^m possible pairs of arrays (a,b)(a, b) .

Consider all pairs of arrays (a,b)(a, b) such that no person becomes upset. For each of them let's calculate the sum of participants madnesses. Find the sum of all these values.

You will be given some prime modulo pp . Find this sum by modulo pp .

输入格式

The only line contains three integers nn , mm , pp ( 1mn500,108p109+91 \leq m \leq n \leq 500, 10^8 \leq p \leq 10 ^ 9 + 9 ).

It is guaranteed, that the number pp is prime.

输出格式

Print only one integer — the required sum by modulo pp .

输入输出样例

  • 输入#1

    3 1 1000000007

    输出#1

    0
  • 输入#2

    2 2 1000000009

    输出#2

    4
  • 输入#3

    3 2 998244353

    输出#3

    8
  • 输入#4

    20 10 1000000009

    输出#4

    352081045

说明/提示

In the first test, there are three possible arrays aa : {1}\{1\} , {2}\{2\} , and $ {3}$ and two possible arrays bb : {L}\{\mathtt{L}\} and {R}\{\mathtt{R}\} . For all six pairs of arrays (a,b)(a, b) , the only participant will sit behind the computer a1a_1 , so his madness will be 00 . So the total sum of madnesses will be 00 .

In the second test, all possible pairs of arrays (a,b)(a, b) , such that no person becomes upset are:

  • ({1,1},{L,L})(\{1, 1\}, \{\mathtt{L}, \mathtt{L}\}) , the sum of madnesses is 11 ;
  • ({1,1},{R,L})(\{1, 1\}, \{\mathtt{R}, \mathtt{L}\}) , the sum of madnesses is 11 ;
  • ({2,2},{R,R})(\{2, 2\}, \{\mathtt{R}, \mathtt{R}\}) , the sum of madnesses is 11 ;
  • ({2,2},{L,R})(\{2, 2\}, \{\mathtt{L}, \mathtt{R}\}) , the sum of madnesses is 11 ;
  • all possible pairs of a{{1,2},{2,1}}a \in \{\{1, 2\}, \{2, 1\}\} and b{{L,L},{R,L},{L,R},{R,R}}b \in \{\{\mathtt{L}, \mathtt{L}\}, \{\mathtt{R}, \mathtt{L}\}, \{\mathtt{L}, \mathtt{R}\}, \{\mathtt{R}, \mathtt{R}\}\} , the sum of madnesses is 00 .

So, the answer is 1+1+1+1+0=41 + 1 + 1 + 1 + 0 \ldots = 4 .

首页