Ansh and Parth

All submissions for this problem are available.
Ansh and Parth love playing games with arrays. But unfortunately, Parth never succeeds to beat Ansh. But this time Parth came up with a new game which he expects Ansh to lose. Ansh has to find the number of ways to construct an array such that every consecutive element in the array has a different value. Also every element in the array should be in the range $[L, R]$ (both inclusive). Apart from these, Parth also need the elements with index $i$ and $j$ to be integers $X$ and $Y$ respectively, where $i$ and $j$ lies in the range $[1, N]$ while $X$ and $Y$ lies in the range $[L, R]$ as stated above. It is guaranteed that if $j$ = $i + 1$ then $X$ and $Y$ are different. ###Input:  First line will contain $T$, number of testcases. Then each testcase follow two lines.  First line of each testcase contains three space  separated integers : $N, L, R$ denoting size of array, lower and upper range of integers to be filled respectively.  Second line contains four spaceseparated integers $i, X, j, Y$ denoting first index, element in index $i$, second index and element in index $j$ respectively. ###Output: For each testcase, output one integer, the number of ways to fill the array. Since the answer may be large, find it modulo $10^9 + 7$. ###Constraints  $1 \leq T \leq 10$  $3 \leq N \leq 5 * 10^8$  $1 \leq L, R, X, Y \leq 10^9$  $1 \leq i \lt j \leq N$  $L\leq X, Y \leq R$ ###Sample Input: 3 3 1 5 1 1 3 2 4 1 5 2 1 4 1 10000000 1 1000000000 4 2 5 3 ###Sample Output: 3 16 980839842 ###EXPLANATION: *Sample testcase 1:* All possible arrays are: $[1, 3, 2]$, $[1, 4, 2]$ and $[1, 5, 2]$. So, the number of ways to fill the array is 3.Author:  vipulvikram 
Editorial  https://discuss.codechef.com/problems/AHAPH 
Tags  blup2019, dynamicprogramming, vipulvikram, vipulvikram 
Date Added:  29012019 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 