Cartesian Tree

Count permutations of 1..N whose Cartesian tree has total child-position gap score at most S, modulo a prime.

Hard8Dynamic programmingTreeCombinatoricsNo attempts yetTime limit5sMemory limit512 MB

Problem

A sequence AA of distinct integers determines exactly one Cartesian tree. A Cartesian tree is a tree that meets these four conditions.

  1. It is a rooted binary tree.
  2. Each node corresponds to one element of AA.
  3. An in-order traversal of the tree visits the values in the same order as AA.
  4. The value of a node is smaller than the values of its children, so the tree is a min-heap.

The picture below is the Cartesian tree built from A=[9,3,7,1,8,12,10,20,15,18,5]A = [9, 3, 7, 1, 8, 12, 10, 20, 15, 18, 5].

Example of a Cartesian tree

Let TT be the Cartesian tree built from AA. The score of TT is computed as follows. For every node with two children, find the positions in AA of the two child values and take the difference of those positions. The score of TT is the sum of that difference over all such nodes.

In the picture the nodes with two children are 1, 3, 10, 15. The two children of node 1 are 3 and 5, which sit at positions 2 and 11 of AA, so this node scores 112=911 - 2 = 9. The other three nodes score 2, 3 and 2, so the score of TT is 9+2+3+2=169 + 2 + 3 + 2 = 16.

You are given NN, SS and MOD\text{MOD}. There are N!N! permutations of the numbers 11 through NN, and each permutation builds one Cartesian tree. Let XX be the number of those trees whose score is at most SS. Write a program that prints XX modulo MOD\text{MOD}.

Input

The first line contains NN, SS and MOD\text{MOD}, separated by spaces. (1N1001 \le N \le 100, 0S1000 \le S \le 100, 3MOD1093 \le \text{MOD} \le 10^9, MOD\text{MOD} is prime)

Output

Print on the first line how many of the N!N! permutations build a tree whose score is at most SS, modulo MOD\text{MOD}.

Note

For N=3N = 3, the permutations (2,1,3)(2, 1, 3) and (3,1,2)(3, 1, 2) score 2, and the other four permutations score 0.