문제
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 of the integers , where . He then runs the following pseudocode with arguments and
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 generates the following BST:
4
/
2 5
/ \
1 3
Let denote the depth of node in the tree corresponding to meaning the number of nodes on the path from to the root. In the above example, and
The number of inversions of is equal to the number of pairs of integers such that and The cows know that the that FJ will use to generate the BST has exactly inversions . Over all satisfying this condition, compute the remainder when is divided by for each
입력
The only line of input consists of three space-separated integers and , followed by a new line. will be a prime number in the range
출력
Print space-separated integers denoting for each
예제 입력 1
3 0 192603497
예제 출력 1
1 2 3
예제 입력 2
3 1 144408983
예제 출력 2
3 4 4
코드를 제출하려면 로그인이 필요합니다.
로그인