This page is still under construction.

Parts of this page are still being built. What you see may change.

Labeled Connected Graphs

Time limit2sMemory limit512 MB

Summary
Sum the distance between vertices 1 and 2 over every labeled connected graph on n vertices, modulo a prime m.
Level

Hard9 of 10

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

Problem

You are given an integer nn and a prime modulo mm.

Calculate the sum of distances between the first and the second vertices over all distinct labeled connected graphs with nn vertices.

Output any integer congruent to the actual sum modulo mm. Formally, if the actual sum is SS, output any integer xx such that −263≤x<263-2^{63} \leq x < 2^{63} and x−Sx - S is divisible by mm.

Input

The only line contains two integers nn and mm (2≤n≤4002 \leq n \leq 400, 106+3≤m≤109+910^6 + 3 \leq m \leq 10^9+9, mm is prime), the number of vertices in the graphs and the modulo.

Output

Print a single integer: the answer to the problem.

Hint

If you manage to get WA in this problem and we reasonably believe that you did not intentionally try to do so, we might give you a cookie somehow.

Examples5

  1. Example 1

    Input
    2 998244353
    
    Expected output
    1
    
  2. Example 2

    Input
    3 1001177
    
    Expected output
    5
    
  3. Example 3

    Input
    4 1000003
    
    Expected output
    54
    
  4. Example 4

    Input
    5 1000159
    
    Expected output
    1108
    
  5. Example 5

    Input
    6 1000253
    
    Expected output
    41880