Your goal is to find the number of ways to construct an array such that consecutive positions contain different values.
Specifically, we want to construct an array with elements such that each element between and , inclusive. We also want the first and last elements of the array to be and .
Given , and , find the number of ways to construct such an array. Since the answer may be large, only find it modulo .
For example, for , , , there are ways, as shown here:
Complete the function countArray
which takes input , and . Return the number of ways to construct the array such that consecutive elements are distinct.
Constraints
Subtasks
- For of the maximum score, and
Sample Input
, ,
Sample Output
Explanation
Refer to the diagram in the challenge statement.