Under construction

Still being built. Things may change

Edges Counting

Time limit2sMemory limit256 MB

Summary
For all labeled graphs on n vertices where each component has at most one cycle, sum the number of edges lying on a cycle, modulo p.
Level

Hard8 of 10

Topics
Combinatorics, Math, Dynamic programming, Graph
Solved
No attempts yet

Problem

A simple graph is called good if each of its connected components contains at most one cycle.

For all good graphs with nn labeled vertices, count the number of edges that belong to a cycle.

To avoid computing huge integers, report the sum of these edge counts modulo pp.

Input

The input contains multiple test cases. The first line contains two integers TT and pp (1≤T≤30001 \le T \le 3000, 1≤p≤2301 \le p \le 2^{30}), where TT is the number of test cases and pp is the modulus. Each test case is as follows.

The first line contains a single integer nn (1≤n≤30001 \leq n \leq 3000).

Output

For each test case, output the sum of the edge counts modulo pp on one line.

Hint

Among the good graphs with four labeled vertices, three types contain a cycle.

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

Examples1

  1. Example 1

    Input
    7 998244353
    1
    2
    3
    4
    5
    6
    7
    
    Expected output
    0
    0
    3
    60
    1050
    19380
    393750