#P1763D. Valid Bitonic Permutations
Valid Bitonic Permutations
Description
You are given five integers , , , , and . Find the number of bitonic permutations , of the numbers to , such that , and . Since the answer can be large, compute it modulo .
A bitonic permutation is a permutation of numbers, such that the elements of the permutation first increase till a certain index , , and then decrease till the end. Refer to notes for further clarification.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The only line of each test case contains five integers, , , , , and ( and ). It is guaranteed that and .
For each test case, output a single line containing the number of bitonic permutations satisfying the above conditions modulo .
Input
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The only line of each test case contains five integers, , , , , and ( and ). It is guaranteed that and .
Output
For each test case, output a single line containing the number of bitonic permutations satisfying the above conditions modulo .
Note
A permutation is an array consisting of distinct integers from to in arbitrary order. For example, is a permutation, but is not a permutation ( appears twice in the array) and is also not a permutation ( but there is in the array).
An array of elements is bitonic if its elements are first increasing till an index , , and then decreasing till the end. For example, is a bitonic array with , but is not a bitonic array (elements first increase till , then decrease, and then increase again).
A bitonic permutation is a permutation in which the elements follow the above-mentioned bitonic property. For example, is a bitonic permutation, but is not a bitonic permutation (since it is not a bitonic array) and is also not a bitonic permutation (since it is not a permutation).
Sample Test Case Description
For , possible permutations are , , , , , and . Among the given permutations, the bitonic permutations are and .
In the first test case, the expected permutation must be of the form , which does not satisfy either of the two bitonic permutations with , therefore the answer is 0.
In the second test case, the expected permutation must be of the form , which only satisfies the bitonic permutation , therefore, the answer is 1.