eolymp
bolt
Try our new interface for solving problems
Problems

Tree Depth

Tree Depth

For the new year, Farmer John decided to give his cows a festive binary search tree (BST)!

To generate the BST, FJ starts with a permutation a = {a1, a2,..., an} of the integers 1...n, where n300. He then runs the following pseudocode with arguments 1 and n.

generate(l,r):
  if l > r, return empty subtree;
  x = argmin_{l <= i <= r} a_i; // index of min a_i in {a_l,...,a_r}
  return a BST with x as the root, 
    generate(l,x-1) as the left subtree,
    generate(x+1,r) as the right subtree;

For example, the permutation {3, 2, 5, 1, 4} generates the following BST:

    4
   / \
  2   5
 / \ 
1   3

Let di(a) denote the depth of node i in the tree corresponding to a, meaning the number of nodes on the path from ai to the root. In the above example, d4(a) = 1, d2(a) = d5(a) = 2, and d1(a) = d3(a) = 3.

The number of inversions of a is equal to the number of pairs of integers (i, j) such that 1i < jn and ai > aj. The cows know that the a that FJ will use to generate the BST has exactly k inversions (0kn * (n1) / 2). Over all a satisfying this condition, compute the remainder when ∑a di(a) is divided by m for each 1in.

Input

The only line consists of three space-separated integers n, k and m. m will be a prime number in the range [108, 109 + 9].

Output

Print n integers denoting ∑a di(a) (mod m) for each 1in.

Example 1

Here, the only permutation is a = {1, 2, 3}.

Example 2

Here, the two permutations are a = {1, 3, 2} and a = {2, 1, 3}.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3 0 192603497
Output example #1
1 2 3
Input example #2
3 1 144408983
Output example #2
3 4 4
Source 2019 USACO December Platinum