Edges Counting

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

We call a simple graph good if each component of the graph has at most one cycle.

Your task is to count the number of edges belonging to one cycle for all the good graphs with nn labeled vertices.

In order to avoid calculations of huge integers, report the sum of the number of edges modulo pp instead.

입력

There are multiple test cases. The first line of the input contains two integers TT and pp (1T30001 \le T \le 3000, 1p2301 \le p \le 2^{30}), indicating the number of test cases and the modulus. For each test case:

The first line contains the only integer nn (1n30001 \leq n \leq 3000).

출력

For each test case, output the sum of the numbers of edges modulo pp in one line.

힌트

There are three types of good graphs having four labeled vertices in which cycles exist.

The numbers of these graphs are 33, 1212 and 44 respectively. Consequently, the sum of the numbers of edges is 3×4+12×3+4×3=603 \times 4 + 12 \times 3 + 4 \times 3 = 60.